summaryrefslogtreecommitdiffstats
path: root/dom/vr/test/mochitest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/vr/test/mochitest
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/vr/test/mochitest')
-rw-r--r--dom/vr/test/mochitest/VRSimulationDriver.js95
-rw-r--r--dom/vr/test/mochitest/WebVRHelpers.js19
-rw-r--r--dom/vr/test/mochitest/mochitest.toml26
-rw-r--r--dom/vr/test/mochitest/requestPresent.js74
-rw-r--r--dom/vr/test/mochitest/runVRTest.js18
-rw-r--r--dom/vr/test/mochitest/test_vrController_displayId.html57
-rw-r--r--dom/vr/test/mochitest/test_vrDisplay_canvas2d.html55
-rw-r--r--dom/vr/test/mochitest/test_vrDisplay_exitPresent.html51
-rw-r--r--dom/vr/test/mochitest/test_vrDisplay_getFrameData.html148
-rw-r--r--dom/vr/test/mochitest/test_vrDisplay_onvrdisplayconnect.html43
-rw-r--r--dom/vr/test/mochitest/test_vrDisplay_onvrdisplaydeactivate_crosscontent.html54
-rw-r--r--dom/vr/test/mochitest/test_vrDisplay_requestPresent.html130
12 files changed, 770 insertions, 0 deletions
diff --git a/dom/vr/test/mochitest/VRSimulationDriver.js b/dom/vr/test/mochitest/VRSimulationDriver.js
new file mode 100644
index 0000000000..5b197b88e4
--- /dev/null
+++ b/dom/vr/test/mochitest/VRSimulationDriver.js
@@ -0,0 +1,95 @@
+var VRServiceTest;
+var vrMockDisplay;
+
+var VRSimulationDriver = (function () {
+ "use strict";
+
+ var AttachWebVRDisplay = function () {
+ if (vrMockDisplay) {
+ // Avoid creating multiple displays
+ return Promise.resolve(vrMockDisplay);
+ }
+ var promise = VRServiceTest.attachVRDisplay("VRDisplayTest");
+ promise.then(function (display) {
+ assert_true(display != null, "AttachWebVRDisplay should success.");
+ vrMockDisplay = display;
+ });
+
+ return promise;
+ };
+
+ var SetVRDisplayPose = function (
+ position,
+ linearVelocity,
+ linearAcceleration,
+ orientation,
+ angularVelocity,
+ angularAcceleration
+ ) {
+ vrMockDisplay.setPose(
+ position,
+ linearVelocity,
+ linearAcceleration,
+ orientation,
+ angularVelocity,
+ angularAcceleration
+ );
+ };
+
+ var SetEyeResolution = function (width, height) {
+ vrMockDisplay.setEyeResolution(width, height);
+ };
+
+ var SetEyeParameter = function (
+ eye,
+ offsetX,
+ offsetY,
+ offsetZ,
+ upDegree,
+ rightDegree,
+ downDegree,
+ leftDegree
+ ) {
+ vrMockDisplay.setEyeParameter(
+ eye,
+ offsetX,
+ offsetY,
+ offsetZ,
+ upDegree,
+ rightDegree,
+ downDegree,
+ leftDegree
+ );
+ };
+
+ var SetMountState = function (isMounted) {
+ vrMockDisplay.setMountState(isMounted);
+ };
+
+ var UpdateVRDisplay = function () {
+ vrMockDisplay.update();
+ };
+
+ var AttachVRController = function () {
+ var promise = VRServiceTest.attachVRController("VRControllerTest");
+ promise.then(function (controller) {
+ assert_true(controller != null, "AttachVRController should success.");
+ });
+
+ return promise;
+ };
+
+ var API = {
+ AttachWebVRDisplay,
+ SetVRDisplayPose,
+ SetEyeResolution,
+ SetEyeParameter,
+ SetMountState,
+ UpdateVRDisplay,
+ AttachVRController,
+
+ none: false,
+ };
+
+ return API;
+})();
diff --git a/dom/vr/test/mochitest/WebVRHelpers.js b/dom/vr/test/mochitest/WebVRHelpers.js
new file mode 100644
index 0000000000..e19294a236
--- /dev/null
+++ b/dom/vr/test/mochitest/WebVRHelpers.js
@@ -0,0 +1,19 @@
+var WebVRHelpers = (function () {
+ "use strict";
+
+ var RequestPresentOnVRDisplay = function (vrDisplay, vrLayers, callback) {
+ if (callback) {
+ callback();
+ }
+
+ return vrDisplay.requestPresent(vrLayers);
+ };
+
+ var API = {
+ RequestPresentOnVRDisplay,
+
+ none: false,
+ };
+
+ return API;
+})();
diff --git a/dom/vr/test/mochitest/mochitest.toml b/dom/vr/test/mochitest/mochitest.toml
new file mode 100644
index 0000000000..ce2d4347d3
--- /dev/null
+++ b/dom/vr/test/mochitest/mochitest.toml
@@ -0,0 +1,26 @@
+[DEFAULT]
+skip-if = ["true"] # Dependencies for re-enabling these are tracked by meta bug 1555185
+support-files = [
+ "VRSimulationDriver.js",
+ "requestPresent.js",
+ "runVRTest.js",
+ "WebVRHelpers.js",
+]
+
+["test_vrController_displayId.html"]
+# Enable Linux after Bug 1310655 # TIMED_OUT for Android.
+
+["test_vrDisplay_canvas2d.html"]
+# skip-if = (os != "win" && release_or_beta) # Enable Linux after Bug 1310655
+
+["test_vrDisplay_exitPresent.html"]
+# skip-if = (os != "win" && release_or_beta) # Enable Linux after Bug 1310655
+
+["test_vrDisplay_getFrameData.html"]
+# Enable Linux after Bug 1310655, enable Android after Bug 1348246
+
+["test_vrDisplay_onvrdisplayconnect.html"]
+
+["test_vrDisplay_onvrdisplaydeactivate_crosscontent.html"]
+
+["test_vrDisplay_requestPresent.html"]
diff --git a/dom/vr/test/mochitest/requestPresent.js b/dom/vr/test/mochitest/requestPresent.js
new file mode 100644
index 0000000000..a2f9dd4d11
--- /dev/null
+++ b/dom/vr/test/mochitest/requestPresent.js
@@ -0,0 +1,74 @@
+// requestPresent.js
+//
+// This file provides helpers for testing VRDisplay requestPresent.
+
+function attachVRDisplay(test) {
+ assert_equals(
+ typeof navigator.getVRDisplays,
+ "function",
+ "'navigator.getVRDisplays()' must be defined."
+ );
+ return VRSimulationDriver.AttachWebVRDisplay();
+}
+
+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);
+}
diff --git a/dom/vr/test/mochitest/runVRTest.js b/dom/vr/test/mochitest/runVRTest.js
new file mode 100644
index 0000000000..c15003a6c3
--- /dev/null
+++ b/dom/vr/test/mochitest/runVRTest.js
@@ -0,0 +1,18 @@
+function runVRTest(callback) {
+ SpecialPowers.pushPrefEnv(
+ {
+ set: [
+ ["dom.vr.enabled", true],
+ ["dom.vr.puppet.enabled", true],
+ ["dom.vr.require-gesture", false],
+ ["dom.vr.test.enabled", true],
+ ["dom.vr.display.enumerate.interval", 0],
+ ["dom.vr.controller.enumerate.interval", 0],
+ ],
+ },
+ () => {
+ VRServiceTest = navigator.requestVRServiceTest();
+ callback();
+ }
+ );
+}
diff --git a/dom/vr/test/mochitest/test_vrController_displayId.html b/dom/vr/test/mochitest/test_vrController_displayId.html
new file mode 100644
index 0000000000..e69e3920d2
--- /dev/null
+++ b/dom/vr/test/mochitest/test_vrController_displayId.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>VRController DisplayId</title>
+ <meta name="timeout" content="long"/>
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="VRSimulationDriver.js"></script>
+ <script src="runVRTest.js"></script>
+ </head>
+ <body>
+ <script>
+ "use strict";
+ var vrDisplay;
+ var controllerCount = 0;
+
+ function addController() {
+ promise_test((test) => {
+ return VRSimulationDriver.AttachVRController().then((controller) => {
+ controller.newButtonEvent(0, true);
+ });
+ }, "Finish to add VRController.");
+ }
+
+ function listenControllerEvents() {
+ async_test(function(t) {
+ window.addEventListener("gamepadbuttondown", function(e) {
+ assert_equals(e.gamepad.displayId, vrDisplay.displayId, "gamepad.displayId should be equal to vrDisplay.");
+ assert_equals(e.gamepad.id, "Puppet Gamepad", "gamepad.id must be equal to 'Puppet Gamepad'.");
+ ++controllerCount;
+ if (controllerCount == 2) {
+ t.done();
+ }
+ });
+ }, "Finish to verify VRController.displayId.");
+ }
+
+ function startTest() {
+ promise_test((test) => {
+ listenControllerEvents();
+ return VRSimulationDriver.AttachWebVRDisplay().then(() => {
+ return navigator.getVRDisplays().then((displays) => {
+ vrDisplay = displays[0];
+ assert_equals(displays.length, 1, "displays.length must be one after attach.");
+ assert_equals(vrDisplay.displayName, "Puppet HMD", "display.displayName must be equal to 'Puppet HMD'.");
+ addController();
+ addController();
+ });
+ });
+ }, "Finish to add VRDisplay.");
+ }
+
+ runVRTest(startTest);
+ </script>
+ </body>
+</html>
diff --git a/dom/vr/test/mochitest/test_vrDisplay_canvas2d.html b/dom/vr/test/mochitest/test_vrDisplay_canvas2d.html
new file mode 100644
index 0000000000..4d20e21352
--- /dev/null
+++ b/dom/vr/test/mochitest/test_vrDisplay_canvas2d.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>VRDisplay Canvas2D</title>
+ <meta name="timeout" content="long"/>
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="VRSimulationDriver.js"></script>
+ <script src="runVRTest.js"></script>
+ </head>
+ <body>
+ <script>
+ "use strict";
+ var vrDisplay;
+
+ function requestPresentTest() {
+ async_test(function (test) {
+ vrDisplay.requestAnimationFrame(callback);
+
+ function callback() {
+ vrDisplay.resetPose();
+ vrDisplay.getLayers();
+ vrDisplay.submitFrame();
+ vrDisplay.getEyeParameters("right");
+ test.done();
+ }
+ }, "Finish WebVR Canvas2D requestPresentTest.");
+ }
+
+ function startTest() {
+ promise_test((test) => {
+ var canvas = document.createElement('canvas');
+ (document.body || document.documentElement).appendChild(canvas);
+ var context = canvas.getContext('2d');
+ var img = document.createElement('img');
+ img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACw=";
+
+ return VRSimulationDriver.AttachWebVRDisplay().then(() => {
+ return navigator.getVRDisplays().then((displays) => {
+ assert_equals(displays.length, 1, "displays.length must be one after attach.");
+ vrDisplay = displays[0];
+ var frameData = new VRFrameData();
+ return vrDisplay.requestPresent([{source: canvas}]).then(() => {
+ requestPresentTest();
+ });
+ });
+ });
+ }, "Finish running WebVR Canvas2D test.");
+ }
+
+ runVRTest(startTest);
+ </script>
+ </body>
+</html>
diff --git a/dom/vr/test/mochitest/test_vrDisplay_exitPresent.html b/dom/vr/test/mochitest/test_vrDisplay_exitPresent.html
new file mode 100644
index 0000000000..dc2c700723
--- /dev/null
+++ b/dom/vr/test/mochitest/test_vrDisplay_exitPresent.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>VRDisplay ExitPresent</title>
+ <meta name="timeout" content="long"/>
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="VRSimulationDriver.js"></script>
+ <script src="runVRTest.js"></script>
+ </head>
+ <body>
+ <script>
+ function testExitPresentOnOtherIframe(content) {
+ return content.navigator.getVRDisplays().then((displays) => {
+ content.vrDisplay = displays[0];
+ return content.vrDisplay.exitPresent();
+ });
+ }
+ var initVRPresentation = function(content) {
+ return VRSimulationDriver.AttachWebVRDisplay().then(() => {
+ return content.navigator.getVRDisplays().then((displays) => {
+ content.vrDisplay = displays[0];
+ content.canvas = content.document.createElement("canvas");
+ content.canvas.id = "vrCanvas";
+ return content.vrDisplay.requestPresent([{source:content.canvas}]);
+ });
+ });
+ }
+ function startTest() {
+ var ifr1 = document.getElementById("iframe1");
+ var ifr2 = document.getElementById("iframe2");
+ var frame1 = ifr1.contentWindow;
+ var frame2 = ifr2.contentWindow;
+ promise_test((test) => {
+ return VRSimulationDriver.AttachWebVRDisplay().then(() => {
+ return initVRPresentation(frame1).then(() => {
+ promise_test((test) => {
+ return promise_rejects(test, null, testExitPresentOnOtherIframe(frame2));
+ }, "We cannot exit VR presentation established by another content, this promise is expected to be rejected.")
+ });
+ });
+ }, "Finish running WebVR exitPresent test.");
+ }
+ runVRTest(startTest);
+ </script>
+
+ <iframe id="iframe1"></iframe>
+ <iframe id="iframe2"></iframe>
+ </body>
+</html>
diff --git a/dom/vr/test/mochitest/test_vrDisplay_getFrameData.html b/dom/vr/test/mochitest/test_vrDisplay_getFrameData.html
new file mode 100644
index 0000000000..c8a986ae8e
--- /dev/null
+++ b/dom/vr/test/mochitest/test_vrDisplay_getFrameData.html
@@ -0,0 +1,148 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>VRDisplay GetFrameData</title>
+ <meta name="timeout" content="long"/>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="VRSimulationDriver.js"></script>
+ <script src="WebVRHelpers.js"></script>
+ <script src="requestPresent.js"></script>
+ <script src="runVRTest.js"></script>
+</head>
+<body id="body">
+ <canvas id="webglCanvas"></canvas>
+ <script>
+ "use strict";
+ var vrDisplay;
+ var vrRAF;
+ var canvas = document.getElementById('webglCanvas');
+ function startTest() {
+ promise_test((test) => {
+ return attachVRDisplay(test).then(() => {
+ VRSimulationDriver.SetEyeResolution(1332, 1586);
+ VRSimulationDriver.SetEyeParameter("left", -0.029, 0, 0, 41.65, 35.57, 48.00, 43.97);
+ VRSimulationDriver.SetEyeParameter("right", 0.029, 0, 0, 41.65, 43.97, 48.00, 35.57);
+ var poseOrient = new Float32Array([-0.188, -0.007, 0.045, -0.980]);
+ var posePos = new Float32Array([-0.161, 0.076, -0.250]);
+ var poseAngVel = new Float32Array([0.008, -0.002, -0.006]);
+ var poseAngAcc = new Float32Array([3.404, -1.469, -5.901]);
+ var poseLinVel = new Float32Array([0.001, -0.003, -0.002]);
+ var poseLinAcc = new Float32Array([0.007, 0.068, -0.052]);
+ VRSimulationDriver.SetVRDisplayPose(posePos, poseLinVel, poseLinAcc,
+ poseOrient, poseAngVel, poseAngAcc);
+ VRSimulationDriver.UpdateVRDisplay();
+ }).then(() => {
+ return promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ return WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay,
+ [{ source: canvas }]);
+ }).then(() => {
+ assert_true(vrDisplay.isPresenting, "vrDisplay.isPresenting must be true if requestPresent is fulfilled.");
+ assert_equals(vrDisplay.getLayers().length, 1, "vrDisplay.getLayers() should return one layer.");
+
+ verifyFrameData();
+ })
+ }, "WebVR requestPresent fulfilled");
+ })
+ }, "Finish setting up VR test data.");
+
+ function verifyFrameData() {
+ async_test(function (test) {
+ navigator.getVRDisplays().then((displays) => {
+ assert_equals(displays.length, 1, "displays.length must be one after attach.");
+ vrDisplay = displays[0];
+ vrDisplay.requestAnimationFrame(callback);
+
+ function callback() {
+ var frameData1 = new VRFrameData();
+ vrDisplay.getFrameData(frameData1);
+
+ // We insert a new frame to confirm we still can get
+ // the same data as the last getter.
+ insertNewFrameData();
+
+ var frameData2 = new VRFrameData();
+ vrDisplay.getFrameData(frameData2);
+
+ assert_equals(frameData1.timestamp, frameData2.timestamp,
+ "frameData.timestamp at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(frameData1.leftProjectionMatrix,
+ frameData2.leftProjectionMatrix),
+ "frameData.leftProjectionMatrix at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(frameData1.leftViewMatrix,
+ frameData2.leftViewMatrix),
+ "frameData.leftViewMatrix at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(frameData1.rightProjectionMatrix,
+ frameData2.rightProjectionMatrix),
+ "frameData.rightProjectionMatrix at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(frameData1.rightViewMatrix,
+ frameData2.rightViewMatrix),
+ "frameData.rightViewMatrix at a frame should be equal.");
+
+ var pose1 = frameData1.pose;
+ var pose2 = frameData2.pose;
+ assert_true(checkValueInFloat32Array(pose1.position,
+ pose2.position),
+ "pose.position at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(pose1.linearVelocity,
+ pose2.linearVelocity),
+ "pose.linearVelocity at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(pose1.linearAcceleration,
+ pose2.linearAcceleration),
+ "pose.linearAcceleration at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(pose1.orientation,
+ pose2.orientation),
+ "pose.orientation at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(pose1.angularVelocity,
+ pose2.angularVelocity),
+ "pose.angularVelocity at a frame should be equal.");
+
+ assert_true(checkValueInFloat32Array(pose1.angularAcceleration,
+ pose2.angularAcceleration),
+ "pose.angularAcceleration at a frame should be equal.");
+ test.done();
+ }
+ });
+ }, "WebVR returns the same frameData within a frame fulfilled");
+ }
+
+ function insertNewFrameData() {
+ var poseOrient = new Float32Array([-0.208, -0.017, 0.055, -0.930]);
+ var posePos = new Float32Array([-0.261, 0.036, -0.150]);
+ var poseAngVel = new Float32Array([0.018, -0.001, -0.003]);
+ var poseAngAcc = new Float32Array([1.504, -1.339, -4.901]);
+ var poseLinVel = new Float32Array([0.002, -0.001, -0.003]);
+ var poseLinAcc = new Float32Array([0.017, 0.061, -0.022]);
+ VRSimulationDriver.SetVRDisplayPose(posePos, poseLinVel, poseLinAcc,
+ poseOrient, poseAngVel, poseAngAcc);
+ VRSimulationDriver.UpdateVRDisplay();
+ }
+
+ function checkValueInFloat32Array(array1, array2) {
+ if (array1.length != array2.length) {
+ return false;
+ }
+ var index = 0;
+ while (index < array2.length) {
+ if (array1[index] != array2[index]) {
+ return false;
+ }
+ ++index;
+ }
+ return true;
+ }
+ }
+
+ runVRTest(startTest);
+ </script>
+</body>
+</html>
diff --git a/dom/vr/test/mochitest/test_vrDisplay_onvrdisplayconnect.html b/dom/vr/test/mochitest/test_vrDisplay_onvrdisplayconnect.html
new file mode 100644
index 0000000000..e1912c7c41
--- /dev/null
+++ b/dom/vr/test/mochitest/test_vrDisplay_onvrdisplayconnect.html
@@ -0,0 +1,43 @@
+<html>
+ <head>
+ <title>VRDisplay onvrdisplayconnect test</title>
+ <meta name="timeout" content="long"/>
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="VRSimulationDriver.js"></script>
+ <script src="WebVRHelpers.js"></script>
+ <script src="requestPresent.js"></script>
+ <script src="runVRTest.js"></script>
+ </head>
+ <body>
+ <script>
+
+ function eventAfterConnectedTest() {
+ async_test(function (test) {
+ window.addEventListener("vrdisplayconnect", () => {
+ test.done();
+ });
+ }, "vrdisplayconnect should fire as soon as content listens for it, \
+ even if the VR display was already connected.");
+ }
+
+ function startTest() {
+ promise_test((test) => {
+ return attachVRDisplay(test).then(() => {
+ return promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ VRSimulationDriver.UpdateVRDisplay();
+ eventAfterConnectedTest();
+ VRSimulationDriver.UpdateVRDisplay();
+ });
+ });
+ });
+ });
+ }
+
+ runVRTest(startTest);
+ </script>
+ <iframe id="iframe1"></iframe>
+ </body>
+</html>
diff --git a/dom/vr/test/mochitest/test_vrDisplay_onvrdisplaydeactivate_crosscontent.html b/dom/vr/test/mochitest/test_vrDisplay_onvrdisplaydeactivate_crosscontent.html
new file mode 100644
index 0000000000..6c58e5efd1
--- /dev/null
+++ b/dom/vr/test/mochitest/test_vrDisplay_onvrdisplaydeactivate_crosscontent.html
@@ -0,0 +1,54 @@
+<html>
+ <head>
+ <title>VRDisplay onvrdisplaydeactivate Crosscontent test</title>
+ <meta name="timeout" content="long"/>
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="VRSimulationDriver.js"></script>
+ <script src="WebVRHelpers.js"></script>
+ <script src="requestPresent.js"></script>
+ <script src="runVRTest.js"></script>
+ </head>
+ <body>
+ <canvas id="vrCanvas"></canvas>
+ <script>
+
+ function startTest() {
+ var canvas = document.getElementById("vrCanvas");
+ var iframe1 = document.getElementById("iframe1").contentWindow;
+ var t = async_test("vrdisplaydeactivate crosscontent test");
+
+ window.addEventListener("vrdisplaydeactivate", () => {
+ t.step(() => {
+ assert_true(vrDisplay.isPresenting,
+ "VRDisplay should be still presenting now without being affected by the event.");
+ t.done();
+ });
+ });
+
+ iframe1.addEventListener("vrdisplaydeactivate", () => {
+ t.unreached_func("vrdisplaydeactivate should not be received by other iframe.");
+ });
+
+ promise_test((test) => {
+ return attachVRDisplay(test).then(() => {
+ return promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ VRSimulationDriver.SetMountState(true);
+ VRSimulationDriver.UpdateVRDisplay();
+ return WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{source: canvas}]);
+ }).then(() => {
+ VRSimulationDriver.SetMountState(false);
+ VRSimulationDriver.UpdateVRDisplay();
+ });
+ });
+ });
+ });
+ }
+
+ runVRTest(startTest);
+ </script>
+ <iframe id="iframe1"></iframe>
+ </body>
+</html>
diff --git a/dom/vr/test/mochitest/test_vrDisplay_requestPresent.html b/dom/vr/test/mochitest/test_vrDisplay_requestPresent.html
new file mode 100644
index 0000000000..4d021b6e0f
--- /dev/null
+++ b/dom/vr/test/mochitest/test_vrDisplay_requestPresent.html
@@ -0,0 +1,130 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>VRDisplay RequestPresent</title>
+ <meta name="timeout" content="long"/>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="VRSimulationDriver.js"></script>
+ <script src="WebVRHelpers.js"></script>
+ <script src="requestPresent.js"></script>
+ <script src="runVRTest.js"></script>
+</head>
+<body id="body">
+ <canvas id="webglCanvas"></canvas>
+ <div id="testDiv"></div>
+ <script>
+ "use strict";
+ var vrDisplay;
+ var canvas = document.getElementById('webglCanvas');
+ var div = document.getElementById('testDiv');
+ function startTest() {
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{}]));
+ }).then(() => {
+ return validateDisplayNotPresenting(test, vrDisplay);
+ });
+ }, "WebVR requestPresent rejected with empty frames");
+
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas, leftBounds: [0.0, 0.0] }]));
+ }).then(() => {
+ return validateDisplayNotPresenting(test, vrDisplay);
+ });
+ }, "WebVR requestPresent rejected with incorrect bounds (bounds arrays must be 0 or 4 long)");
+
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: div }]));
+ }).then(() => {
+ return validateDisplayNotPresenting(test, vrDisplay);
+ });
+ }, "WebVR requestPresent rejected with invalid source (must be canvas element)");
+
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas, leftBounds: [div] }]));
+ }).then(() => {
+ return validateDisplayNotPresenting(test, vrDisplay);
+ });
+ }, "WebVR requestPresent rejected with invalid bounds data type (must be able to convert to float)");
+
+ const invalidBounds = [
+ [2.0, 0.0, 0.0, 0.0],
+ [0.0, 2.0, 0.0, 0.0],
+ [0.0, 0.0, 2.0, 0.0],
+ [0.0, 0.0, 0.0, 2.0],
+ [-1.0, 0.0, 0.0, 0.0],
+ [0.0, -1.0, 0.0, 0.0],
+ [0.0, 0.0, -1.0, 0.0],
+ [0.0, 0.0, 0.0, -1.0]];
+
+ invalidBounds.forEach((bound) => {
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas, leftBounds: bound }]));
+ }).then(() => {
+ return validateDisplayNotPresenting(test, vrDisplay);
+ });
+ }, "WebVR requestPresent rejected with bounds in invalid range: [" + bound + "]");
+ });
+
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ var promise = vrDisplay.requestPresent({ source: canvas });
+ return promise_rejects(test, null, promise);
+ }).then(() => {
+ return validateDisplayNotPresenting(test, vrDisplay);
+ });
+ }, "WebVR requestPresent rejected without user initiated action");
+
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas }, { source: canvas }]));
+ }).then(() => {
+ return validateDisplayNotPresenting(test, vrDisplay);
+ });
+ }, "WebVR requestPresent rejected with more frames than max layers");
+
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ function requestAgain() {
+ // Callback for immediate requestPresent call for further testing.
+ // Cache this promise on global object since it seems to be the only object
+ // in scope across calls.
+ window.promiseSecond = vrDisplay.requestPresent([{ source: canvas }]);
+ }
+ return WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas }], requestAgain);
+ }).then(() => {
+ // First promise succeeded
+ assert_true(vrDisplay.isPresenting, "First promise should successfully fulfill");
+ // Now, validate that the subsequent requestPresent was rejected
+ return promise_rejects(test, null, window.promiseSecond);
+ }).then(() => {
+ delete window.promiseSecond;
+ assert_true(vrDisplay.isPresenting, "Should still be presenting after rejected second promise");
+ return vrDisplay.exitPresent();
+ });
+ }, "WebVR requestPresent fails while another one is in progress");
+
+ promise_test((test) => {
+ return setupVRDisplay(test).then(() => {
+ return WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas }]);
+ }).then(() => {
+ assert_true(vrDisplay.isPresenting, "vrDisplay.isPresenting must be true if requestPresent is fulfilled.");
+ assert_equals(vrDisplay.getLayers().length, 1, "vrDisplay.getLayers() should return one layer.");
+ return vrDisplay.exitPresent();
+ }).then(() => {
+ assert_false(vrDisplay.isPresenting, "vrDisplay.isPresenting must be false if exitPresent is fulfilled.");
+ // exitPresent() should reject since we are no longer presenting.
+ return promise_rejects(test, null, vrDisplay.exitPresent());
+ });
+ }, "WebVR requestPresent fulfilled");
+ }
+
+ runVRTest(startTest);
+ </script>
+</body>
+</html>