Bug 1268749 part 6 - Add test for behavior when unprefixed api is disabled. r=smaug a=lizzard
authorXidorn Quan <quanxunzhen@gmail.com>
Mon, 09 May 2016 09:44:38 +1000
changeset 332772 450bf777896c63ae590821487f918b7e90dab075
parent 332771 3023e4f667a3c3ed207edbbb5f2afc0f2aea63b1
child 332773 b97d2850365291df51e4a75a5dc4fa22e9bddf83
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, lizzard
bugs1268749
milestone48.0a2
Bug 1268749 part 6 - Add test for behavior when unprefixed api is disabled. r=smaug a=lizzard 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();
 }