From d7b6a3ff79d550b848c91318f6b808b3f28e78bc Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Thu, 2 Mar 2017 00:00:23 +0800 Subject: [PATCH] Bug 1323328 - Part 3: Add VR display request present mochitest; r=kip MozReview-Commit-ID: 13WuFhUFcTo --HG-- extra : rebase_source : 00d5c0f36f3550c19367c4a9b6882c10175a0862 --- dom/vr/moz.build | 2 + dom/vr/test/VRSimulationDriver.js | 45 ++++++ dom/vr/test/WebVRHelpers.js | 21 +++ dom/vr/test/mochitest.ini | 9 ++ dom/vr/test/requestPresent.js | 34 +++++ dom/vr/test/runVRTest.js | 9 ++ .../test/test_vrDisplay_requestPresent.html | 130 ++++++++++++++++++ modules/libpref/init/all.js | 2 + 8 files changed, 252 insertions(+) create mode 100644 dom/vr/test/VRSimulationDriver.js create mode 100644 dom/vr/test/WebVRHelpers.js create mode 100644 dom/vr/test/mochitest.ini create mode 100644 dom/vr/test/requestPresent.js create mode 100644 dom/vr/test/runVRTest.js create mode 100644 dom/vr/test/test_vrDisplay_requestPresent.html diff --git a/dom/vr/moz.build b/dom/vr/moz.build index 9db95706b17f..c04dfbb8413d 100644 --- a/dom/vr/moz.build +++ b/dom/vr/moz.build @@ -27,3 +27,5 @@ FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ '/dom/base' ] + +MOCHITEST_MANIFESTS += ['test/mochitest.ini'] \ No newline at end of file diff --git a/dom/vr/test/VRSimulationDriver.js b/dom/vr/test/VRSimulationDriver.js new file mode 100644 index 000000000000..4e175e469239 --- /dev/null +++ b/dom/vr/test/VRSimulationDriver.js @@ -0,0 +1,45 @@ + +var VRServiceTest; + +var VRSimulationDriver = (function() { +"use strict"; + +var AttachWebVRDisplay = function() { + return VRServiceTest.attachVRDisplay("VRDisplayTest"); +}; + +var SetVRDisplayPose = function(vrDisplay, position, + linearVelocity, linearAcceleration, + orientation, angularVelocity, + angularAcceleration) { + vrDisplay.setPose(position, linearVelocity, linearAcceleration, + orientation, angularVelocity, angularAcceleration); +}; + +var SetEyeResolution = function(width, height) { + vrDisplay.setEyeResolution(width, height); +} + +var SetEyeParameter = function(vrDisplay, eye, offsetX, offsetY, offsetZ, + upDegree, rightDegree, downDegree, leftDegree) { + vrDisplay.setEyeParameter(eye, offsetX, offsetY, offsetZ, upDegree, rightDegree, + downDegree, leftDegree); +} + +var UpdateVRDisplay = function(vrDisplay) { + vrDisplay.update(); +} + +var API = { + AttachWebVRDisplay: AttachWebVRDisplay, + SetVRDisplayPose: SetVRDisplayPose, + SetEyeResolution: SetEyeResolution, + SetEyeParameter: SetEyeParameter, + UpdateVRDisplay: UpdateVRDisplay, + + none: false +}; + +return API; + +}()); \ No newline at end of file diff --git a/dom/vr/test/WebVRHelpers.js b/dom/vr/test/WebVRHelpers.js new file mode 100644 index 000000000000..e8e947abafeb --- /dev/null +++ b/dom/vr/test/WebVRHelpers.js @@ -0,0 +1,21 @@ + +var WebVRHelpers = (function() { +"use strict"; + +var RequestPresentOnVRDisplay = function(vrDisplay, vrLayers, callback) { + if (callback) { + callback(); + } + + return vrDisplay.requestPresent(vrLayers); +}; + +var API = { + RequestPresentOnVRDisplay: RequestPresentOnVRDisplay, + + none: false +}; + +return API; + +}()); \ No newline at end of file diff --git a/dom/vr/test/mochitest.ini b/dom/vr/test/mochitest.ini new file mode 100644 index 000000000000..f8834dddb2c3 --- /dev/null +++ b/dom/vr/test/mochitest.ini @@ -0,0 +1,9 @@ +[DEFAULT] +support-files = + VRSimulationDriver.js + requestPresent.js + runVRTest.js + WebVRHelpers.js + +[test_vrDisplay_requestPresent.html] +skip-if = true diff --git a/dom/vr/test/requestPresent.js b/dom/vr/test/requestPresent.js new file mode 100644 index 000000000000..b6b79fb68e6f --- /dev/null +++ b/dom/vr/test/requestPresent.js @@ -0,0 +1,34 @@ +// requestPresent.js +// +// This file provides helpers for testing VRDisplay requestPresent. + +function setupVRDisplay(test) { + assert_equals(typeof (navigator.getVRDisplays), "function", "'navigator.getVRDisplays()' must be defined."); + return VRSimulationDriver.AttachWebVRDisplay().then(() => { + return navigator.getVRDisplays(); + }).then((displays) => { + assert_equals(displays.length, 1, "displays.length must be one after attach."); + vrDisplay = displays[0]; + return validateNewVRDisplay(test, vrDisplay); + }); +} + +// Validate the settings off a freshly created VRDisplay (prior to calling +// requestPresent). +function validateNewVRDisplay(test, display) { + assert_true(display.capabilities.canPresent, "display.capabilities.canPresent must always be true for HMDs."); + assert_equals(display.capabilities.maxLayers, 1, "display.capabilities.maxLayers must always be 1 when display.capabilities.canPresent is true for current spec revision."); + assert_false(display.isPresenting, "display.isPresenting must be false before calling requestPresent."); + assert_equals(display.getLayers().length, 0, "display.getLayers() should have no layers if not presenting."); + var promise = display.exitPresent(); + return promise_rejects(test, null, promise); +} + +// Validate the settings off a VRDisplay after requestPresent promise is +// rejected or after exitPresent is fulfilled. +function validateDisplayNotPresenting(test, display) { + assert_false(display.isPresenting, "display.isPresenting must be false if requestPresent is rejected or after exitPresent is fulfilled."); + assert_equals(display.getLayers().length, 0, "display.getLayers() should have no layers if requestPresent is rejected or after exitPresent is fulfilled."); + var promise = display.exitPresent(); + return promise_rejects(test, null, promise); +} \ No newline at end of file diff --git a/dom/vr/test/runVRTest.js b/dom/vr/test/runVRTest.js new file mode 100644 index 000000000000..25b1dced1612 --- /dev/null +++ b/dom/vr/test/runVRTest.js @@ -0,0 +1,9 @@ +function runVRTest(callback) { + SpecialPowers.pushPrefEnv({"set" : [["dom.vr.enabled", true], + ["dom.vr.puppet.enabled", true], + ["dom.vr.test.enabled", true]]}, + () => { + VRServiceTest = navigator.requestVRServiceTest(); + callback(); + }); +} \ No newline at end of file diff --git a/dom/vr/test/test_vrDisplay_requestPresent.html b/dom/vr/test/test_vrDisplay_requestPresent.html new file mode 100644 index 000000000000..416f9e35c636 --- /dev/null +++ b/dom/vr/test/test_vrDisplay_requestPresent.html @@ -0,0 +1,130 @@ + + + + VRDisplay RequestPresent + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 19f3d698206b..8fbc91891ccf 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5036,6 +5036,8 @@ pref("gfx.vr.osvr.utilLibPath", ""); pref("gfx.vr.osvr.commonLibPath", ""); pref("gfx.vr.osvr.clientLibPath", ""); pref("gfx.vr.osvr.clientKitLibPath", ""); +// Puppet device, used for simulating VR hardware within tests and dev tools +pref("dom.vr.puppet.enabled", false); pref("dom.vr.test.enabled", false); // MMS UA Profile settings pref("wap.UAProf.url", "");