Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: third_party/WebKit/LayoutTests/vr/resources/mock-vr-service.js

Issue 2624263003: Add more WebVR layout tests and fix small issues they found (Closed)
Patch Set: Added a few clarifying comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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) { 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();
14 this.displayInfo_ = displayInfo;
15 this.service_ = service;
13 16
14 interfaceProvider.addInterfaceOverrideForTesting( 17 interfaceProvider.addInterfaceOverrideForTesting(
15 vr_service.VRDisplay.name, 18 vr_service.VRDisplay.name,
16 handle => this.bindingSet_.addBinding(this, handle)); 19 handle => this.bindingSet_.addBinding(this, handle));
20
21 if (service.client_) {
22 this.notifyClientOfDisplay();
23 }
17 } 24 }
18 25
19 requestPresent(secureOrigin) { 26 requestPresent(secureOrigin) {
20 return Promise.resolve({success: true}); 27 return Promise.resolve({success: true});
21 } 28 }
29
30 forceActivate(reason) {
31 this.displayClient_.onActivate(reason);
32 }
33
34 notifyClientOfDisplay() {
35 let displayPtr = new vr_service.VRDisplayPtr();
36 let request = bindings.makeRequest(displayPtr);
37 let binding = new bindings.Binding(
38 vr_service.VRDisplay,
39 this, request);
40 let clientRequest = bindings.makeRequest(this.displayClient_);
41 this.service_.client_.onDisplayConnected(displayPtr, clientRequest,
42 this.displayInfo_);
43 }
22 } 44 }
23 45
24 class MockVRService { 46 class MockVRService {
25 constructor(interfaceProvider) { 47 constructor(interfaceProvider) {
26 this.bindingSet_ = new bindings.BindingSet(vr_service.VRService); 48 this.bindingSet_ = new bindings.BindingSet(vr_service.VRService);
27 this.displayClient_ = new vr_service.VRDisplayClientPtr(); 49 this.mockVRDisplays_ = [];
28 this.vrDisplays_ = null;
29 50
30 interfaceProvider.addInterfaceOverrideForTesting( 51 interfaceProvider.addInterfaceOverrideForTesting(
31 vr_service.VRService.name, 52 vr_service.VRService.name,
32 handle => this.bindingSet_.addBinding(this, handle)); 53 handle => this.bindingSet_.addBinding(this, handle));
33 } 54 }
34 55
35 setVRDisplays(displays) { 56 setVRDisplays(displays) {
57 this.mockVRDisplays_ = [];
36 for (let i = 0; i < displays.length; i++) { 58 for (let i = 0; i < displays.length; i++) {
37 displays[i].index = i; 59 displays[i].index = i;
60 this.mockVRDisplays_.push(new MockVRDisplay(mojo.frameInterfaces,
61 displays[i], this));
38 } 62 }
39 this.vrDisplays_ = displays;
40 } 63 }
41 64
42 notifyClientOfDisplays() { 65 addVRDisplay(display) {
43 if (this.vrDisplays_ == null) { 66 if (this.mockVRDisplays_.length) {
44 return; 67 display.index =
68 this.mockVRDisplays_[this.mockVRDisplays_.length - 1] + 1;
69 } else {
70 display.index = 0;
45 } 71 }
46 for (let i = 0; i < this.vrDisplays_.length; i++) { 72 this.mockVRDisplays_.push(new MockVRDisplay(mojo.frameInterfaces,
47 let displayPtr = new vr_service.VRDisplayPtr(); 73 display, this));
48 let request = bindings.makeRequest(displayPtr);
49 let binding = new bindings.Binding(
50 vr_service.VRDisplay,
51 new MockVRDisplay(mojo.frameInterfaces), request);
52 let clientRequest = bindings.makeRequest(this.displayClient_);
53 this.client_.onDisplayConnected(displayPtr, clientRequest, this.vrDispla ys_[i]);
54 }
55 } 74 }
56 75
57 setClient(client) { 76 setClient(client) {
58 this.client_ = client; 77 this.client_ = client;
59 this.notifyClientOfDisplays(); 78 for (let i = 0; i < this.mockVRDisplays_.length; i++) {
79 this.mockVRDisplays_[i].notifyClientOfDisplay();
80 }
60 81
61 var device_number = (this.vrDisplays_== null ? 0 : this.vrDisplays_.length ); 82 let device_number = this.mockVRDisplays_.length;
62 return Promise.resolve({numberOfConnectedDevices: device_number}); 83 return Promise.resolve({numberOfConnectedDevices: device_number});
63 } 84 }
64 } 85 }
65 86
66 return new MockVRService(mojo.frameInterfaces); 87 return new MockVRService(mojo.frameInterfaces);
67 }); 88 });
68 89
69 function vr_test(func, vrDisplays, name, properties) { 90 function vr_test(func, vrDisplays, name, properties) {
70 mockVRService.then( (service) => { 91 mockVRService.then( (service) => {
71 service.setVRDisplays(vrDisplays); 92 service.setVRDisplays(vrDisplays);
72 let t = async_test(name, properties); 93 let t = async_test(name, properties);
73 func(t); 94 func(t, service);
74 }); 95 });
75 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698