Bug 1268749 part 6 - Add test for behavior when unprefixed api is disabled. r=smaug draft
authorXidorn Quan <quanxunzhen@gmail.com>
Mon, 02 May 2016 15:36:53 +1000
changeset 363186 5dce9bd6bc53fdefd1668908fe433e6f9b592e95
parent 363185 9c41673bb69de10203c334e216773a23d1e7de53
child 363199 bc1a887188c05a734034695410c53b2627b93407
child 363586 a6d1721bffcac724d9ec296b0e052002bfc5ebbd
push id17127
push userxquan@mozilla.com
push dateWed, 04 May 2016 05:11:05 +0000
reviewerssmaug
bugs1268749
milestone49.0a1
Bug 1268749 part 6 - Add test for behavior when unprefixed api is disabled. r=smaug MozReview-Commit-ID: EUaoiTsVJK9
dom/html/test/file_fullscreen-unprefix-disabled-inner.html
dom/html/test/file_fullscreen-unprefix-disabled.html
dom/html/test/mochitest.ini
dom/html/test/test_fullscreen-api.html
new file mode 100644
--- /dev/null
+++ b/dom/html/test/file_fullscreen-unprefix-disabled-inner.html
@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>Test for Bug 1268749</title>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+  <div id="fullscreen"></div>
+<script>
+
+function ok(condition, msg) {
+  opener.opener.ok(condition, "[unprefix-disabled] " + msg);
+}
+
+function is(a, b, msg) {
+  opener.opener.is(a, b, "[unprefix-disabled] " + msg);
+}
+
+function info(msg) {
+  opener.opener.info("[unprefix-disabled] " + msg);
+}
+
+SimpleTest.requestFlakyTimeout(
+  "need to wait for a while to confirm no unexpected event is dispatched");
+
+let div = document.getElementById("fullscreen");
+let unattachedDiv = document.createElement('div');
+
+function begin() {
+  ok(!("requestFullscreen" in div), "No element.requestFullscreen");
+  ok(!("exitFullscreen" in document), "No document.exitFullscreen");
+  ok(!("fullscreenElement" in document), "No document.fullscreenElement");
+  ok(!("fullscreenEnabled" in document), "No document.fullscreenEnabled");
+  ok(!("onfullscreenchange" in document), "No document.onfullscreenchange");
+  ok(!("onfullscreenerror" in document), "No document.onfullscreenerror");
+
+  for (var event of ["fullscreenchange", "fullscreenerror"]) {
+    let customEvent = new Event(event, {bubbles: true});
+    let gotCustomEventFromWindow = false;
+    let gotCustomEventFromDocument = false;
+    let listenerForWindow = evt => {
+      ok(!gotCustomEventFromWindow,
+         "Should get custom event from window only once");
+      ok(evt == customEvent, "Should get the desired custom event");
+      gotCustomEventFromWindow = true;
+    };
+    let listenerForDocument = evt => {
+      ok(!gotCustomEventFromDocument,
+         "Should get custom event from document only once");
+      ok(evt == customEvent, "Should get the desired custom event");
+      gotCustomEventFromDocument = true;
+    };
+    window.addEventListener(event, listenerForWindow);
+    document.addEventListener(event, listenerForDocument);
+    document.dispatchEvent(customEvent);
+    ok(gotCustomEventFromWindow, "Should get the custom event from window");
+    ok(gotCustomEventFromDocument, "Should get the custom event from document");
+    window.removeEventListener(event, listenerForWindow);
+    document.removeEventListener(event, listenerForDocument);
+
+    for (var target of [window, document]) {
+      target.addEventListener(event, () => {
+        ok(false, `No ${event} should be triggered on ${target}`);
+      });
+    }
+  }
+
+  document.addEventListener("mozfullscreenchange", enteredFullscreen);
+  SimpleTest.executeSoon(() => div.mozRequestFullScreen());
+}
+
+function enteredFullscreen() {
+  document.removeEventListener("mozfullscreenchange", enteredFullscreen);
+  document.addEventListener("mozfullscreenchange", exitedFullscreen);
+  SimpleTest.executeSoon(() => document.mozCancelFullScreen());
+}
+
+function exitedFullscreen() {
+  document.removeEventListener("mozfullscreenchange", exitedFullscreen);
+  document.addEventListener("mozfullscreenerror", errorFullscreen);
+  SimpleTest.executeSoon(() => unattachedDiv.mozRequestFullScreen());
+}
+
+function errorFullscreen() {
+  document.removeEventListener("mozfullscreenerror", errorFullscreen);
+  // Wait a short time before exiting this test to confirm that there is
+  // really no unwanted event gets dispatched.
+  setTimeout(() => opener.finish(), 200);
+}
+
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/html/test/file_fullscreen-unprefix-disabled.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>Test for Bug 1268749</title>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<script>
+
+var gWindow = null;
+
+function begin() {
+  SpecialPowers.pushPrefEnv({
+    "set": [["full-screen-api.unprefix.enabled", false]]
+  }, () => {
+    gWindow = window.open("file_fullscreen-unprefix-disabled-inner.html",
+                          "", "width=500,height=500");
+    gWindow.addEventListener("load", () => {
+      gWindow.focus();
+      SimpleTest.waitForFocus(() => gWindow.begin(), gWindow);
+    });
+  });
+}
+
+function finish() {
+  gWindow.close();
+  SpecialPowers.popPrefEnv(opener.nextTest);
+}
+
+</script>
+</body>
+</html>
--- a/dom/html/test/mochitest.ini
+++ b/dom/html/test/mochitest.ini
@@ -59,16 +59,18 @@ support-files =
   file_fullscreen-nested.html
   file_fullscreen-prefixed.html
   file_fullscreen-plugins.html
   file_fullscreen-rollback.html
   file_fullscreen-scrollbar.html
   file_fullscreen-selector.html
   file_fullscreen-svg-element.html
   file_fullscreen-top-layer.html
+  file_fullscreen-unprefix-disabled-inner.html
+  file_fullscreen-unprefix-disabled.html
   file_fullscreen-utils.js
   file_iframe_sandbox_a_if1.html
   file_iframe_sandbox_a_if10.html
   file_iframe_sandbox_a_if11.html
   file_iframe_sandbox_a_if12.html
   file_iframe_sandbox_a_if13.html
   file_iframe_sandbox_a_if14.html
   file_iframe_sandbox_a_if15.html
--- a/dom/html/test/test_fullscreen-api.html
+++ b/dom/html/test/test_fullscreen-api.html
@@ -38,16 +38,17 @@ var gTestWindows = [
   "file_fullscreen-svg-element.html",
   "file_fullscreen-navigation.html",
   "file_fullscreen-scrollbar.html",
   "file_fullscreen-selector.html",
   "file_fullscreen-top-layer.html",
   "file_fullscreen-backdrop.html",
   "file_fullscreen-nested.html",
   "file_fullscreen-prefixed.html",
+  "file_fullscreen-unprefix-disabled.html",
 ];
 
 var testWindow = null;
 var gTestIndex = 0;
 
 function finish() {
   SimpleTest.finish();
 }