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

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

Issue 2599113002: Add the first layout tests for WebVR to test navigator.getVRDisplays with mocked vr_service mojo in… (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/vr/resources/mock-vr-service.js
diff --git a/third_party/WebKit/LayoutTests/vr/resources/mock-vr-service.js b/third_party/WebKit/LayoutTests/vr/resources/mock-vr-service.js
new file mode 100644
index 0000000000000000000000000000000000000000..1d76e6b378da979455c979d6604c5acc60e2404a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/vr/resources/mock-vr-service.js
@@ -0,0 +1,73 @@
+'use strict';
+
+let mockVRService = loadMojoModules(
+ 'mockVRService',
+ ['mojo/public/js/bindings',
+ 'mojo/public/js/connection',
yzshen1 2017/01/03 22:29:05 Please note that "connection" is deprecated and be
bsheedy 2017/01/03 22:39:06 What do you suggest using in its place? Or should
Lei Lei 2017/01/03 22:40:35 With bindings.BindingSet, connection is not needed
+ 'mojo/public/js/router',
+ 'device/vr/vr_service.mojom',
+ ]).then(mojo => {
+ let [bindings, connection, router, vr_service] = mojo.modules;
+
+ class MockVRDisplay extends vr_service.VRDisplay.stubClass {
+ constructor(interfaceProvider) {
+ super();
+ interfaceProvider.addInterfaceOverrideForTesting(
+ vr_service.VRDisplay.name,
+ handle => this.connect_(handle));
+ }
+
+ connect_(handle) {
+ this.router_ = new router.Router(handle);
yzshen1 2017/01/03 22:29:05 Please don't use router directly, this doesn't do
bsheedy 2017/01/03 22:39:06 I'll look into changing this, then.
Lei Lei 2017/01/03 22:40:35 Thanks for fixing it!
+ this.router_.setIncomingReceiver(this);
+ }
+ }
+
+ class MockVRService extends vr_service.VRService.stubClass {
+ constructor(interfaceProvider) {
+ super();
+ interfaceProvider.addInterfaceOverrideForTesting(
+ vr_service.VRService.name,
+ handle => this.connect_(handle));
+ this.vrDisplays_ = null;
+ }
+
+ connect_(handle) {
+ this.router_ = new router.Router(handle);
+ this.router_.setIncomingReceiver(this);
+ }
+
+ setVRDisplays(displays) {
+ this.vrDisplays_ = displays;
+ }
+
+ setClient(client) {
+ if (this.vrDisplays_ != null) {
+ this.vrDisplays_.forEach(display => {
+ var displayPtr = new vr_service.VRDisplayPtr();
+ var request = bindings.makeRequest(displayPtr);
+ var binding = new bindings.Binding(
+ vr_service.VRDisplay,
+ new MockVRDisplay(mojo.frameInterfaces), request);
+ var client_handle = new bindings.InterfaceRequest(
+ connection.bindProxy(proxy => {}, vr_service.VRDisplayClient));
+ client.onDisplayConnected(displayPtr, client_handle, display);
+ });
+ return Promise.resolve(
+ {numberOfConnectedDevices: this.vrDisplays_.length});
+ }
+ return Promise.resolve({numberOfConnectedDevices: 0});
+ }
+ }
+
+ return new MockVRService(mojo.frameInterfaces);
+});
+
+function vr_test(func, vrDisplays, name, properties) {
+ promise_test(t => mockVRService.then((service) => {
+ service.setVRDisplays(vrDisplays);
+ return func();
+ }), name, properties);
+}
+
+

Powered by Google App Engine
This is Rietveld 408576698