| OLD | NEW |
| 1 'use strict'; | 1 'use strict'; |
| 2 | 2 |
| 3 let mockVRService = loadMojoModules( | 3 let mockVRService = loadMojoModules( |
| 4 'mockVRService', | 4 'mockVRService', |
| 5 ['mojo/public/js/bindings', | 5 ['mojo/public/js/bindings', |
| 6 'device/vr/vr_service.mojom', | 6 'device/vr/vr_service.mojom', |
| 7 'services/device/public/interfaces/constants.mojom', |
| 7 ]).then(mojo => { | 8 ]).then(mojo => { |
| 8 let [bindings, vr_service] = mojo.modules; | 9 let [bindings, vr_service, deviceConstants] = mojo.modules; |
| 9 | 10 |
| 10 class MockVRDisplay { | 11 class MockVRDisplay { |
| 11 constructor(interfaceProvider, displayInfo, service) { | 12 constructor(interfaceProvider, displayInfo, service) { |
| 12 this.bindingSet_ = new bindings.BindingSet(vr_service.VRDisplay); | 13 this.bindingSet_ = new bindings.BindingSet(vr_service.VRDisplay); |
| 13 this.displayClient_ = new vr_service.VRDisplayClientPtr(); | 14 this.displayClient_ = new vr_service.VRDisplayClientPtr(); |
| 14 this.displayInfo_ = displayInfo; | 15 this.displayInfo_ = displayInfo; |
| 15 this.service_ = service; | 16 this.service_ = service; |
| 16 this.vsync_provider_ = new MockVRVSyncProvider(); | 17 this.vsync_provider_ = new MockVRVSyncProvider(); |
| 17 | 18 |
| 18 interfaceProvider.addInterfaceOverrideForTesting( | 19 interfaceProvider.addInterfaceOverrideForTesting( |
| 20 deviceConstants.kServiceName, |
| 19 vr_service.VRDisplay.name, | 21 vr_service.VRDisplay.name, |
| 20 handle => this.bindingSet_.addBinding(this, handle)); | 22 handle => this.bindingSet_.addBinding(this, handle)); |
| 21 | 23 |
| 22 if (service.client_) { | 24 if (service.client_) { |
| 23 this.notifyClientOfDisplay(); | 25 this.notifyClientOfDisplay(); |
| 24 } | 26 } |
| 25 } | 27 } |
| 26 | 28 |
| 27 requestPresent(secureOrigin) { | 29 requestPresent(secureOrigin) { |
| 28 return Promise.resolve({success: true}); | 30 return Promise.resolve({success: true}); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 } | 105 } |
| 104 | 106 |
| 105 class MockVRService { | 107 class MockVRService { |
| 106 constructor(interfaceProvider) { | 108 constructor(interfaceProvider) { |
| 107 this.bindingSet_ = new bindings.BindingSet(vr_service.VRService); | 109 this.bindingSet_ = new bindings.BindingSet(vr_service.VRService); |
| 108 this.mockVRDisplays_ = []; | 110 this.mockVRDisplays_ = []; |
| 109 | 111 |
| 110 interfaceProvider.addInterfaceOverrideForTesting( | 112 interfaceProvider.addInterfaceOverrideForTesting( |
| 113 deviceConstants.kServiceName, |
| 111 vr_service.VRService.name, | 114 vr_service.VRService.name, |
| 112 handle => this.bindingSet_.addBinding(this, handle)); | 115 handle => this.bindingSet_.addBinding(this, handle)); |
| 113 } | 116 } |
| 114 | 117 |
| 115 setVRDisplays(displays) { | 118 setVRDisplays(displays) { |
| 116 this.mockVRDisplays_ = []; | 119 this.mockVRDisplays_ = []; |
| 117 for (let i = 0; i < displays.length; i++) { | 120 for (let i = 0; i < displays.length; i++) { |
| 118 displays[i].index = i; | 121 displays[i].index = i; |
| 119 this.mockVRDisplays_.push(new MockVRDisplay(mojo.frameInterfaces, | 122 this.mockVRDisplays_.push(new MockVRDisplay(mojo.connector, |
| 120 displays[i], this)); | 123 displays[i], this)); |
| 121 } | 124 } |
| 122 } | 125 } |
| 123 | 126 |
| 124 addVRDisplay(display) { | 127 addVRDisplay(display) { |
| 125 if (this.mockVRDisplays_.length) { | 128 if (this.mockVRDisplays_.length) { |
| 126 display.index = | 129 display.index = |
| 127 this.mockVRDisplays_[this.mockVRDisplays_.length - 1] + 1; | 130 this.mockVRDisplays_[this.mockVRDisplays_.length - 1] + 1; |
| 128 } else { | 131 } else { |
| 129 display.index = 0; | 132 display.index = 0; |
| 130 } | 133 } |
| 131 this.mockVRDisplays_.push(new MockVRDisplay(mojo.frameInterfaces, | 134 this.mockVRDisplays_.push(new MockVRDisplay(mojo.connector, |
| 132 display, this)); | 135 display, this)); |
| 133 } | 136 } |
| 134 | 137 |
| 135 setClient(client) { | 138 setClient(client) { |
| 136 this.client_ = client; | 139 this.client_ = client; |
| 137 for (let i = 0; i < this.mockVRDisplays_.length; i++) { | 140 for (let i = 0; i < this.mockVRDisplays_.length; i++) { |
| 138 this.mockVRDisplays_[i].notifyClientOfDisplay(); | 141 this.mockVRDisplays_[i].notifyClientOfDisplay(); |
| 139 } | 142 } |
| 140 | 143 |
| 141 let device_number = this.mockVRDisplays_.length; | 144 let device_number = this.mockVRDisplays_.length; |
| 142 return Promise.resolve({numberOfConnectedDevices: device_number}); | 145 return Promise.resolve({numberOfConnectedDevices: device_number}); |
| 143 } | 146 } |
| 144 } | 147 } |
| 145 | 148 |
| 146 return new MockVRService(mojo.frameInterfaces); | 149 return new MockVRService(mojo.connector); |
| 147 }); | 150 }); |
| 148 | 151 |
| 149 function vr_test(func, vrDisplays, name, properties) { | 152 function vr_test(func, vrDisplays, name, properties) { |
| 150 mockVRService.then( (service) => { | 153 mockVRService.then( (service) => { |
| 151 service.setVRDisplays(vrDisplays); | 154 service.setVRDisplays(vrDisplays); |
| 152 let t = async_test(name, properties); | 155 let t = async_test(name, properties); |
| 153 func(t, service); | 156 func(t, service); |
| 154 }); | 157 }); |
| 155 } | 158 } |
| OLD | NEW |