| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Mock implementation of mojo PresentationService. | 2 * Mock implementation of mojo PresentationService. |
| 3 */ | 3 */ |
| 4 | 4 |
| 5 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 let presentationServiceMock = loadMojoModules( | 7 let presentationServiceMock = loadMojoModules( |
| 8 'presentationServiceMock', | 8 'presentationServiceMock', |
| 9 [ | 9 [ |
| 10 'third_party/WebKit/public/platform/modules/presentation/presentation.mojo
m', | 10 'third_party/WebKit/public/platform/modules/presentation/presentation.mojo
m', |
| 11 'url/mojo/url.mojom', | 11 'url/mojo/url.mojom', |
| 12 'mojo/public/js/bindings', | 12 'mojo/public/js/bindings', |
| 13 ]).then(mojo => { | 13 ]).then(mojo => { |
| 14 let [ presentationService, url, bindings ] = mojo.modules; | 14 let [ presentationService, url, bindings ] = mojo.modules; |
| 15 | 15 |
| 16 class MockPresentationConnection { | 16 class MockPresentationConnection { |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 class PresentationServiceMock { | 19 class PresentationServiceMock { |
| 20 constructor(interfaceProvider) { | 20 constructor(interfaceProvider) { |
| 21 interfaceProvider.addInterfaceOverrideForTesting( | 21 interfaceProvider.addInterfaceOverrideForTesting( |
| 22 presentationService.PresentationService.name, | 22 presentationService.PresentationService.name, |
| 23 handle => this.bindingSet_.addBinding(this, handle)); | 23 handle => this.bindingSet_.addBinding(this, handle)); |
| 24 this.interfaceProvider_ = interfaceProvider; | 24 this.interfaceProvider_ = interfaceProvider; |
| 25 this.pendingResponse_ = null; | 25 this.pendingResponse_ = null; |
| 26 this.bindingSet_ = new bindings.BindingSet( | 26 this.bindingSet_ = new bindings.BindingSet( |
| 27 presentationService.PresentationService); | 27 presentationService.PresentationService); |
| 28 this.controllerConnectionPtr_ = null; |
| 29 this.receiverConnectionRequest_ = null; |
| 28 | 30 |
| 29 this.onSetClient = null; | 31 this.onSetClient = null; |
| 30 } | 32 } |
| 31 | 33 |
| 32 setClient(client) { | 34 setClient(client) { |
| 33 this.client_ = client; | 35 this.client_ = client; |
| 34 | 36 |
| 35 if (this.onSetClient) | 37 if (this.onSetClient) |
| 36 this.onSetClient(); | 38 this.onSetClient(); |
| 37 } | 39 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 51 } | 53 } |
| 52 | 54 |
| 53 terminate(presentationUrl, presentationId) { | 55 terminate(presentationUrl, presentationId) { |
| 54 this.client_.onConnectionStateChanged( | 56 this.client_.onConnectionStateChanged( |
| 55 { url: presentationUrl, id: presentationId }, | 57 { url: presentationUrl, id: presentationId }, |
| 56 presentationService.PresentationConnectionState.TERMINATED); | 58 presentationService.PresentationConnectionState.TERMINATED); |
| 57 } | 59 } |
| 58 | 60 |
| 59 setPresentationConnection( | 61 setPresentationConnection( |
| 60 seesionInfo, controllerConnectionPtr, receiverConnectionRequest) { | 62 seesionInfo, controllerConnectionPtr, receiverConnectionRequest) { |
| 63 this.controllerConnectionPtr_ = controllerConnectionPtr; |
| 64 this.receiverConnectionRequest_ = receiverConnectionRequest; |
| 61 this.client_.onConnectionStateChanged( | 65 this.client_.onConnectionStateChanged( |
| 62 seesionInfo, | 66 seesionInfo, |
| 63 presentationService.PresentationConnectionState.CONNECTED); | 67 presentationService.PresentationConnectionState.CONNECTED); |
| 64 } | 68 } |
| 65 | 69 |
| 66 onReceiverConnectionAvailable(strUrl, id) { | 70 onReceiverConnectionAvailable( |
| 71 strUrl, id, opt_controllerConnectionPtr, opt_receiverConnectionReque
st) { |
| 67 const mojoUrl = new url.Url(); | 72 const mojoUrl = new url.Url(); |
| 68 mojoUrl.url = strUrl; | 73 mojoUrl.url = strUrl; |
| 69 const controllerConnectionPtr = new presentationService.PresentationCo
nnectionPtr(); | 74 var controllerConnectionPtr = opt_controllerConnectionPtr; |
| 70 const connectionBinding = new bindings.Binding( | 75 if (!controllerConnectionPtr) { |
| 71 presentationService.PresentationConnection, | 76 controllerConnectionPtr = new presentationService.PresentationConnec
tionPtr(); |
| 72 new MockPresentationConnection(), | 77 const connectionBinding = new bindings.Binding( |
| 73 bindings.makeRequest(controllerConnectionPtr)); | 78 presentationService.PresentationConnection, |
| 74 const receiverConnectionPtr = new presentationService.PresentationConn
ectionPtr(); | 79 new MockPresentationConnection(), |
| 80 bindings.makeRequest(controllerConnectionPtr)); |
| 81 } |
| 82 |
| 83 var receiverConnectionRequest = opt_receiverConnectionRequest; |
| 84 if (!receiverConnectionRequest) { |
| 85 receiverConnectionRequest = bindings.makeRequest( |
| 86 new presentationService.PresentationConnectionPtr()); |
| 87 } |
| 75 | 88 |
| 76 this.client_.onReceiverConnectionAvailable( | 89 this.client_.onReceiverConnectionAvailable( |
| 77 { url: mojoUrl, id: id }, | 90 { url: mojoUrl, id: id }, |
| 78 controllerConnectionPtr, | 91 controllerConnectionPtr, receiverConnectionRequest); |
| 79 bindings.makeRequest(receiverConnectionPtr)); | 92 } |
| 93 |
| 94 getControllerConnectionPtr() { |
| 95 return this.controllerConnectionPtr_; |
| 96 } |
| 97 |
| 98 getReceiverConnectionRequest() { |
| 99 return this.receiverConnectionRequest_; |
| 80 } | 100 } |
| 81 } | 101 } |
| 82 | 102 |
| 83 return new PresentationServiceMock(mojo.frameInterfaces); | 103 return new PresentationServiceMock(mojo.frameInterfaces); |
| 84 }); | 104 }); |
| 85 | 105 |
| 86 function waitForClick(callback, button) { | 106 function waitForClick(callback, button) { |
| 87 button.addEventListener('click', callback, { once: true }); | 107 button.addEventListener('click', callback, { once: true }); |
| 88 | 108 |
| 89 if (!('eventSender' in window)) | 109 if (!('eventSender' in window)) |
| 90 return; | 110 return; |
| 91 | 111 |
| 92 const boundingRect = button.getBoundingClientRect(); | 112 const boundingRect = button.getBoundingClientRect(); |
| 93 const x = boundingRect.left + boundingRect.width / 2; | 113 const x = boundingRect.left + boundingRect.width / 2; |
| 94 const y = boundingRect.top + boundingRect.height / 2; | 114 const y = boundingRect.top + boundingRect.height / 2; |
| 95 | 115 |
| 96 eventSender.mouseMoveTo(x, y); | 116 eventSender.mouseMoveTo(x, y); |
| 97 eventSender.mouseDown(); | 117 eventSender.mouseDown(); |
| 98 eventSender.mouseUp(); | 118 eventSender.mouseUp(); |
| 99 } | 119 } |
| OLD | NEW |