Chromium Code Reviews| 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 'mojo/public/js/bindings', | 12 'mojo/public/js/bindings', |
| 12 ]).then(mojo => { | 13 ]).then(mojo => { |
| 13 let [ presentationService, bindings ] = mojo.modules; | 14 let [ presentationService, url, bindings ] = mojo.modules; |
| 15 | |
| 16 class MockPresentationConnection { | |
| 17 }; | |
| 14 | 18 |
| 15 class PresentationServiceMock { | 19 class PresentationServiceMock { |
| 16 constructor(interfaceProvider) { | 20 constructor(interfaceProvider) { |
| 17 interfaceProvider.addInterfaceOverrideForTesting( | 21 interfaceProvider.addInterfaceOverrideForTesting( |
| 18 presentationService.PresentationService.name, | 22 presentationService.PresentationService.name, |
| 19 handle => this.bindingSet_.addBinding(this, handle)); | 23 handle => this.bindingSet_.addBinding(this, handle)); |
| 20 this.interfaceProvider_ = interfaceProvider; | 24 this.interfaceProvider_ = interfaceProvider; |
| 21 this.pendingResponse_ = null; | 25 this.pendingResponse_ = null; |
| 22 this.bindingSet_ = new bindings.BindingSet( | 26 this.bindingSet_ = new bindings.BindingSet( |
| 23 presentationService.PresentationService); | 27 presentationService.PresentationService); |
| 24 } | 28 } |
| 25 | 29 |
| 30 setClient(client) { | |
| 31 this.client_ = client; | |
| 32 } | |
| 33 | |
| 26 startSession(urls) { | 34 startSession(urls) { |
| 27 return Promise.resolve({ | 35 return Promise.resolve({ |
| 28 sessionInfo: { url: urls[0], id: 'fakesession' }, | 36 sessionInfo: { url: urls[0], id: 'fakesession' }, |
| 29 error: null, | 37 error: null, |
| 30 }); | 38 }); |
| 31 } | 39 } |
| 32 | 40 |
| 33 joinSession(urls) { | 41 joinSession(urls) { |
| 34 return Promise.resolve({ | 42 return Promise.resolve({ |
| 35 sessionInfo: { url: urls[0], id: 'fakeSessionId' }, | 43 sessionInfo: { url: urls[0], id: 'fakeSessionId' }, |
| 36 error: null, | 44 error: null, |
| 37 }); | 45 }); |
| 38 } | 46 } |
| 47 | |
| 48 onReceiverConnectionAvailable(str_url, id) { | |
| 49 var mojo_url = new url.Url(); | |
|
mark a. foltz
2017/02/21 17:47:38
s/var/const/ here and below.
Also, Javascript var
zhaobin
2017/02/21 19:11:38
Done.
| |
| 50 mojo_url.url = str_url; | |
| 51 var controller_connection_ptr = new presentationService.PresentationCo nnectionPtr(); | |
| 52 var connectionBinding = new bindings.Binding( | |
| 53 presentationService.PresentationConnection, | |
| 54 new MockPresentationConnection(), | |
| 55 bindings.makeRequest(controller_connection_ptr)); | |
| 56 var receiver_connection_ptr = new presentationService.PresentationConn ectionPtr(); | |
| 57 | |
| 58 this.client_.onReceiverConnectionAvailable( | |
| 59 { url: mojo_url, id: id }, | |
| 60 controller_connection_ptr, | |
| 61 bindings.makeRequest(receiver_connection_ptr)); | |
| 62 } | |
| 39 } | 63 } |
| 40 | 64 |
| 41 return new PresentationServiceMock(mojo.frameInterfaces); | 65 return new PresentationServiceMock(mojo.frameInterfaces); |
| 42 }); | 66 }); |
| 43 | 67 |
| 44 function waitForClick(callback, button) { | 68 function waitForClick(callback, button) { |
| 45 button.addEventListener('click', callback, { once: true }); | 69 button.addEventListener('click', callback, { once: true }); |
| 46 | 70 |
| 47 if (!('eventSender' in window)) | 71 if (!('eventSender' in window)) |
| 48 return; | 72 return; |
| 49 | 73 |
| 50 var boundingRect = button.getBoundingClientRect(); | 74 var boundingRect = button.getBoundingClientRect(); |
| 51 var x = boundingRect.left + boundingRect.width / 2; | 75 var x = boundingRect.left + boundingRect.width / 2; |
| 52 var y = boundingRect.top + boundingRect.height / 2; | 76 var y = boundingRect.top + boundingRect.height / 2; |
| 53 | 77 |
| 54 eventSender.mouseMoveTo(x, y); | 78 eventSender.mouseMoveTo(x, y); |
| 55 eventSender.mouseDown(); | 79 eventSender.mouseDown(); |
| 56 eventSender.mouseUp(); | 80 eventSender.mouseUp(); |
| 57 } | 81 } |
| OLD | NEW |