| 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 ]).then(mojo => { | 7 ]).then(mojo => { |
| 8 let [bindings, vr_service] = mojo.modules; | 8 let [bindings, vr_service] = mojo.modules; |
| 9 | 9 |
| 10 class MockVRDisplay { | 10 class MockVRDisplay { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 if (service.client_) { | 22 if (service.client_) { |
| 23 this.notifyClientOfDisplay(); | 23 this.notifyClientOfDisplay(); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 requestPresent(secureOrigin) { | 27 requestPresent(secureOrigin) { |
| 28 return Promise.resolve({success: true}); | 28 return Promise.resolve({success: true}); |
| 29 } | 29 } |
| 30 | 30 |
| 31 setPose(pose) { |
| 32 if (pose == null) { |
| 33 this.vsync_provider_.pose_ = null; |
| 34 } else { |
| 35 this.vsync_provider_.initPose(); |
| 36 this.vsync_provider_.fillPose(pose); |
| 37 } |
| 38 } |
| 39 |
| 31 getVRVSyncProvider(request) { this.vsync_provider_.bind(request); } | 40 getVRVSyncProvider(request) { this.vsync_provider_.bind(request); } |
| 32 | 41 |
| 33 forceActivate(reason) { | 42 forceActivate(reason) { |
| 34 this.displayClient_.onActivate(reason); | 43 this.displayClient_.onActivate(reason); |
| 35 } | 44 } |
| 36 | 45 |
| 37 notifyClientOfDisplay() { | 46 notifyClientOfDisplay() { |
| 38 let displayPtr = new vr_service.VRDisplayPtr(); | 47 let displayPtr = new vr_service.VRDisplayPtr(); |
| 39 let request = bindings.makeRequest(displayPtr); | 48 let request = bindings.makeRequest(displayPtr); |
| 40 let binding = new bindings.Binding( | 49 let binding = new bindings.Binding( |
| 41 vr_service.VRDisplay, | 50 vr_service.VRDisplay, |
| 42 this, request); | 51 this, request); |
| 43 let clientRequest = bindings.makeRequest(this.displayClient_); | 52 let clientRequest = bindings.makeRequest(this.displayClient_); |
| 44 this.service_.client_.onDisplayConnected(displayPtr, clientRequest, | 53 this.service_.client_.onDisplayConnected(displayPtr, clientRequest, |
| 45 this.displayInfo_); | 54 this.displayInfo_); |
| 46 } | 55 } |
| 47 } | 56 } |
| 48 | 57 |
| 49 class MockVRVSyncProvider { | 58 class MockVRVSyncProvider { |
| 50 constructor() { | 59 constructor() { |
| 51 this.timeDelta_ = 0; | 60 this.timeDelta_ = 0; |
| 52 this.binding_ = new bindings.Binding(vr_service.VRVSyncProvider, this); | 61 this.binding_ = new bindings.Binding(vr_service.VRVSyncProvider, this); |
| 62 this.pose_ = null; |
| 53 } | 63 } |
| 54 bind(request) { | 64 bind(request) { |
| 55 this.binding_.close(); | 65 this.binding_.close(); |
| 56 this.binding_.bind(request); | 66 this.binding_.bind(request); |
| 57 } | 67 } |
| 58 getVSync() { | 68 getVSync() { |
| 59 this.timeDelta_ += 1000.0 / 60.0; | 69 if (this.pose_) { |
| 60 return Promise.resolve({ | 70 this.pose_.timestamp = this.timeDelta_; |
| 61 pose: null, | 71 this.pose_.poseIndex++; |
| 72 } |
| 73 |
| 74 let retval = Promise.resolve({ |
| 75 pose: this.pose_, |
| 62 time: { | 76 time: { |
| 63 microseconds: this.timeDelta_, | 77 microseconds: this.timeDelta_, |
| 64 }, | 78 }, |
| 65 }); | 79 }); |
| 80 |
| 81 this.timeDelta_ += 1000.0 / 60.0; |
| 82 return retval; |
| 83 } |
| 84 initPose() { |
| 85 this.pose_ = { |
| 86 timestamp: 0, |
| 87 orientation: null, |
| 88 position: null, |
| 89 angularVelocity: null, |
| 90 linearVelocity: null, |
| 91 angularAcceleration: null, |
| 92 linearAcceleration: null, |
| 93 poseIndex: 0 |
| 94 }; |
| 95 } |
| 96 fillPose(pose) { |
| 97 for (var field in pose) { |
| 98 if (this.pose_.hasOwnProperty(field)) { |
| 99 this.pose_[field] = pose[field]; |
| 100 } |
| 101 } |
| 66 } | 102 } |
| 67 } | 103 } |
| 68 | 104 |
| 69 class MockVRService { | 105 class MockVRService { |
| 70 constructor(interfaceProvider) { | 106 constructor(interfaceProvider) { |
| 71 this.bindingSet_ = new bindings.BindingSet(vr_service.VRService); | 107 this.bindingSet_ = new bindings.BindingSet(vr_service.VRService); |
| 72 this.mockVRDisplays_ = []; | 108 this.mockVRDisplays_ = []; |
| 73 | 109 |
| 74 interfaceProvider.addInterfaceOverrideForTesting( | 110 interfaceProvider.addInterfaceOverrideForTesting( |
| 75 vr_service.VRService.name, | 111 vr_service.VRService.name, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 return new MockVRService(mojo.frameInterfaces); | 146 return new MockVRService(mojo.frameInterfaces); |
| 111 }); | 147 }); |
| 112 | 148 |
| 113 function vr_test(func, vrDisplays, name, properties) { | 149 function vr_test(func, vrDisplays, name, properties) { |
| 114 mockVRService.then( (service) => { | 150 mockVRService.then( (service) => { |
| 115 service.setVRDisplays(vrDisplays); | 151 service.setVRDisplays(vrDisplays); |
| 116 let t = async_test(name, properties); | 152 let t = async_test(name, properties); |
| 117 func(t, service); | 153 func(t, service); |
| 118 }); | 154 }); |
| 119 } | 155 } |
| OLD | NEW |