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 { |
11 constructor(interfaceProvider, displayInfo, service) { | 11 constructor(interfaceProvider, displayInfo, service) { |
12 this.bindingSet_ = new bindings.BindingSet(vr_service.VRDisplay); | 12 this.bindingSet_ = new bindings.BindingSet(vr_service.VRDisplay); |
13 this.displayClient_ = new vr_service.VRDisplayClientPtr(); | 13 this.displayClient_ = new vr_service.VRDisplayClientPtr(); |
14 this.displayInfo_ = displayInfo; | 14 this.displayInfo_ = displayInfo; |
15 this.service_ = service; | 15 this.service_ = service; |
16 this.vsync_provider_ = new MockVRVSyncProvider(); | 16 this.vsync_provider_ = new MockVRVSyncProvider(); |
17 | 17 |
18 interfaceProvider.addInterfaceOverrideForTesting( | 18 interfaceProvider.addInterfaceOverrideForTesting( |
19 vr_service.VRDisplay.name, | 19 vr_service.VRDisplay.name, |
20 handle => this.bindingSet_.addBinding(this, handle)); | 20 handle => this.bindingSet_.addBinding(this, handle)); |
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, submitFrameClient) { |
28 // console.log("requestPresent"); | |
mthiesse
2017/05/18 23:39:14
nit: remove commented out log statements here and
klausw
2017/05/19 04:06:47
Done.
| |
29 this.submitFrameClient_ = submitFrameClient; | |
28 return Promise.resolve({success: true}); | 30 return Promise.resolve({success: true}); |
29 } | 31 } |
30 | 32 |
33 submitFrame(frameId, mailboxHolder) { | |
34 // console.log("submitFrame frameId=" + frameId); | |
35 this.submitFrameClient_.onSubmitFrameTransferred(); | |
36 this.submitFrameClient_.onSubmitFrameRendered(); | |
37 } | |
38 | |
31 setPose(pose) { | 39 setPose(pose) { |
32 if (pose == null) { | 40 if (pose == null) { |
33 this.vsync_provider_.pose_ = null; | 41 this.vsync_provider_.pose_ = null; |
34 } else { | 42 } else { |
35 this.vsync_provider_.initPose(); | 43 this.vsync_provider_.initPose(); |
36 this.vsync_provider_.fillPose(pose); | 44 this.vsync_provider_.fillPose(pose); |
37 } | 45 } |
38 } | 46 } |
39 | 47 |
40 getVRVSyncProvider(request) { this.vsync_provider_.bind(request); } | 48 getVRVSyncProvider(request) { |
49 this.vsync_provider_.bind(request); | |
50 } | |
41 | 51 |
42 forceActivate(reason) { | 52 forceActivate(reason) { |
43 this.displayClient_.onActivate(reason); | 53 this.displayClient_.onActivate(reason); |
44 } | 54 } |
45 | 55 |
46 notifyClientOfDisplay() { | 56 notifyClientOfDisplay() { |
47 let displayPtr = new vr_service.VRDisplayPtr(); | 57 let displayPtr = new vr_service.VRDisplayPtr(); |
48 let request = bindings.makeRequest(displayPtr); | 58 let request = bindings.makeRequest(displayPtr); |
49 let binding = new bindings.Binding( | 59 let binding = new bindings.Binding( |
50 vr_service.VRDisplay, | 60 vr_service.VRDisplay, |
51 this, request); | 61 this, request); |
52 let clientRequest = bindings.makeRequest(this.displayClient_); | 62 let clientRequest = bindings.makeRequest(this.displayClient_); |
53 this.service_.client_.onDisplayConnected(displayPtr, clientRequest, | 63 this.service_.client_.onDisplayConnected(displayPtr, clientRequest, |
54 this.displayInfo_); | 64 this.displayInfo_); |
55 } | 65 } |
56 } | 66 } |
57 | 67 |
58 class MockVRVSyncProvider { | 68 class MockVRVSyncProvider { |
59 constructor() { | 69 constructor() { |
60 this.timeDelta_ = 0; | 70 this.timeDelta_ = 0; |
61 this.binding_ = new bindings.Binding(vr_service.VRVSyncProvider, this); | 71 this.binding_ = new bindings.Binding(vr_service.VRVSyncProvider, this); |
62 this.pose_ = null; | 72 this.pose_ = null; |
63 } | 73 } |
64 bind(request) { | 74 bind(request) { |
65 this.binding_.close(); | 75 this.binding_.close(); |
66 this.binding_.bind(request); | 76 this.binding_.bind(request); |
67 } | 77 } |
68 getVSync() { | 78 getVSync() { |
79 // console.log("getVSync timeDelta=" + this.timeDelta_); | |
69 if (this.pose_) { | 80 if (this.pose_) { |
70 this.pose_.poseIndex++; | 81 this.pose_.poseIndex++; |
71 } | 82 } |
72 | 83 |
73 let retval = Promise.resolve({ | 84 let retval = Promise.resolve({ |
74 pose: this.pose_, | 85 pose: this.pose_, |
75 time: { | 86 time: { |
76 microseconds: this.timeDelta_, | 87 microseconds: this.timeDelta_, |
77 }, | 88 }, |
78 frameId: 0, | 89 frameId: 0, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 return new MockVRService(mojo.frameInterfaces); | 157 return new MockVRService(mojo.frameInterfaces); |
147 }); | 158 }); |
148 | 159 |
149 function vr_test(func, vrDisplays, name, properties) { | 160 function vr_test(func, vrDisplays, name, properties) { |
150 mockVRService.then( (service) => { | 161 mockVRService.then( (service) => { |
151 service.setVRDisplays(vrDisplays); | 162 service.setVRDisplays(vrDisplays); |
152 let t = async_test(name, properties); | 163 let t = async_test(name, properties); |
153 func(t, service); | 164 func(t, service); |
154 }); | 165 }); |
155 } | 166 } |
OLD | NEW |