Bug 1311797 - Implement Mochitest: event should trigger only when no content is presenting draft
authorChih-Yi Leu <cleu@mozilla.com>
Fri, 31 Mar 2017 11:47:46 +0800
changeset 554233 2464ac27ba6bc1461daca9996e8499aee40adebd
parent 554232 38bdb121dbb558fc00f0b8bbb0d4bddd1d502a3e
child 622277 60f6402c5cb43d2531039501185a328cad77cbde
push id51870
push userbmo:cleu@mozilla.com
push dateFri, 31 Mar 2017 08:01:02 +0000
bugs1311797
milestone55.0a1
Bug 1311797 - Implement Mochitest: event should trigger only when no content is presenting MozReview-Commit-ID: K0ehJOlUWLC
dom/vr/test/mochitest.ini
dom/vr/test/test_vrDisplay_onvrdisplayactivate.html
--- a/dom/vr/test/mochitest.ini
+++ b/dom/vr/test/mochitest.ini
@@ -4,9 +4,10 @@ support-files =
   requestPresent.js
   runVRTest.js
   WebVRHelpers.js
 
 [test_vrDisplay_exitPresent.html]
 [test_vrDisplay_getFrameData.html]
 [test_vrDisplay_onvrdisplaydeactivate_crosscontent.html]
 [test_vrDisplay_requestPresent.html]
+[test_vrDisplay_onvrdisplayactivate.html]
 skip-if = true
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/vr/test/test_vrDisplay_onvrdisplayactivate.html
@@ -0,0 +1,72 @@
+<html>
+  <head>
+    <title>
+      Test vrDisplay onvrdisplayactivate event
+    </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>
+
+      var isFirstPresentChange = true;
+
+      var initVRPresentation = function(content) {
+            return content.navigator.getVRDisplays().then((displays) => {
+            content.vrDisplay = displays[0];
+            content.canvas = content.document.createElement("canvas");
+            return promise_test((test) => {
+              return content.vrDisplay.requestPresent([{source:content.canvas}]);
+            });
+          });
+      }
+
+      function startTest() {
+
+        var t = async_test("vrdisplayactivate presenting test");
+
+        var iframe1 = document.getElementById("iframe1").contentWindow;
+
+        window.addEventListener("vrdisplayactivate", () => {
+          t.unreached_func("vrdisplayactivate should not be dispatched if any content is presenting.");
+        });
+
+        iframe1.addEventListener("vrdisplaypresentchange", () => {
+          t.step(() => {
+            if (isFirstPresentChange) {
+              assert_true(iframe1.vrDisplay.isPresenting, "We should be presenting now.");
+              isFirstPresentChange = false;
+            } else {
+              assert_true(!iframe1.vrDisplay.isPresenting, "We should not be presenting now.");
+              t.done();
+            }
+          });
+        });
+
+        initVRPresentation(iframe1).then(() => {
+          return promise_test((test) => {
+            return attachVRDisplay(test).then(() => {
+              return promise_test((test) => {
+                return setupVRDisplay(test).then(() => {
+                  VRSimulationDriver.SetMountState(true);
+                  VRSimulationDriver.UpdateVRDisplay();
+                });
+              });          
+            }).then(() => {
+              iframe1.vrDisplay.exitPresent();
+            });
+          });
+        });       
+      }
+
+      runVRTest(startTest);
+    </script>
+    <iframe id="iframe1"></iframe>
+  </body>
+</html>
\ No newline at end of file