import { WindowLike } from '../protocol/comms' ; import { ListenerManager } from './listeners' ; import { createMessageEvent } from './messages' ; export class MockWindow implements WindowLike { parent : WindowLike ; opener : WindowLike | null ; private listeners : ListenerManager ; constructor ( parent ? , opener ? ) { this . parent = parent || this ; this . opener = opener || null ; this . listeners = new ListenerManager ( ) ; } close ( ) { } ; postMessage ( data , targetOrigin , transfer ? ) { this . postMessageFromOrigin ( data , transfer || null , 'https://default.mockwindoworigin.com' , this ) ; } ; postMessageFromOrigin ( data , ports , sourceOrigin , sourceWindow ) { let event = createMessageEvent ( data , sourceOrigin , ports || undefined , sourceWindow ) ; this . dispatchEvent ( event ) ; } /**
     * Naive implementation that dispatches events to every listener,
     * i.e. the ignoring the message's type.
     */ addEventListener ( type , listener ) { this . listeners . add ( type , listener ) ; } removeEventListener ( type , listener ) { this . listeners . remove ( type , listener ) ; } dispatchEvent ( event ) { this . listeners . dispatch ( event . type , event ) ; return true ; } } /**
 * Create a mocked SmartLock frame to be injected in tests.
 */ export function createSpyFrame ( id ) { let frame = jasmine . createSpyObj ( 'frame' , [ 'load' , 'display' , 'sendMessage' , 'hide' , 'dispose' ] ) ; frame . id = id ; return frame ; }