Bug 1306505 - Implement mochitest: VRDisplay.exitPresent must only be allowed by content that started VR Presentation; r=daoshengmu draft
authorChih-Yi Leu <cleu@mozilla.com>
Thu, 23 Mar 2017 10:49:45 +0800
changeset 552150 73956fc8db51e5d96707c207a1ab027f4f3c9e3a
parent 552146 5182b2c4b963ed87d038c7d9a4021463917076cd
child 621732 a63f34ea2e64c340032528233f26b56c5159f2d9
push id51255
push userbmo:cleu@mozilla.com
push dateTue, 28 Mar 2017 02:25:18 +0000
reviewersdaoshengmu
bugs1306505
milestone55.0a1
Bug 1306505 - Implement mochitest: VRDisplay.exitPresent must only be allowed by content that started VR Presentation; r=daoshengmu MozReview-Commit-ID: JSOhDU565gt
dom/vr/test/mochitest.ini
dom/vr/test/test_vrDisplay_exitPresent.html
--- a/dom/vr/test/mochitest.ini
+++ b/dom/vr/test/mochitest.ini
@@ -1,10 +1,11 @@
 [DEFAULT]
 support-files =
   VRSimulationDriver.js
   requestPresent.js
   runVRTest.js
   WebVRHelpers.js
 
 [test_vrDisplay_getFrameData.html]
+[test_vrDisplay_exitPresent.html]
 [test_vrDisplay_requestPresent.html]
 skip-if = true
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/vr/test/test_vrDisplay_exitPresent.html
@@ -0,0 +1,45 @@
+<!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="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 content.navigator.getVRDisplays().then((displays) => {
+            console.log("GetVRDisplay!!");
+            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;
+        initVRPresentation(frame1).then(() => {
+          promise_test((test) => {
+            return promise_rejects(test, null, testExitPresentOnOtherIframe(frame2));
+          }, "We cannot exist VR presentation established by another content, this promise is expected to be rejected.")
+        });
+      }
+      runVRTest(startTest);
+    </script>
+
+    <iframe id="iframe1"></iframe>
+    <iframe id="iframe2"></iframe>
+  </body>
+</html>
\ No newline at end of file