Bug 1369072 - part0: Add automated test for testing key event handlers to scroll parent document when an iframe element has or had focus r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 05 Sep 2017 15:18:02 +0900
changeset 429174 2e507cfef60d45641908a36a977d2497d77e4c84
parent 429173 5ead094a4792105cbdc4ced7424230e8e345a13b
child 429175 19f8a5d3da39cc4f2313f2dac2c4dbb04a6329e8
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1369072
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1369072 - part0: Add automated test for testing key event handlers to scroll parent document when an iframe element has or had focus r=smaug When an <iframe> element has focus and its sub document isn't scrollable, the parent document should be scrolled instead. MozReview-Commit-ID: 5LSVDHDQGtI
dom/events/test/mochitest.ini
dom/events/test/test_bug1369072.html
dom/events/test/window_bug1369072.html
--- a/dom/events/test/mochitest.ini
+++ b/dom/events/test/mochitest.ini
@@ -177,9 +177,12 @@ skip-if = toolkit == 'android' #CRASH_DU
 [test_paste_image.html]
 [test_wheel_default_action.html]
 [test_bug687787.html]
 [test_bug1305458.html]
 [test_bug1298970.html]
 [test_bug1304044.html]
 [test_bug1332699.html]
 [test_bug1339758.html]
+[test_bug1369072.html]
+support-files = window_bug1369072.html
+skip-if = toolkit == 'android'
 [test_dnd_with_modifiers.html]
new file mode 100644
--- /dev/null
+++ b/dom/events/test/test_bug1369072.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1369072
+-->
+<head>
+  <title>Test for Bug 1369072</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1369072">Mozilla Bug 1369072</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 1369072 **/
+
+SimpleTest.waitForExplicitFinish();
+
+var subWin = window.open("window_bug1369072.html", "_blank",
+                         "width=500,height=500");
+
+function finish()
+{
+  subWin.close();
+  SimpleTest.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/events/test/window_bug1369072.html
@@ -0,0 +1,156 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1369072
+-->
+<head>
+  <title>Test for Bug 1369072</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1369072">Mozilla Bug 1369072</a>
+<div id="display">
+<iframe id="iframe" srcdoc="<a id='anchor' href='about:home'>anchor text</a><div id='div'></div>" style="width: 300px; height: 300px;"></iframe>
+<!-- make <body> contents overflow -->
+<div style="width: 1000px; height: 1000px;"></div>
+</div>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(runTests, window);
+
+function ok()
+{
+  window.opener.ok.apply(window.opener, arguments);
+}
+
+function is()
+{
+  window.opener.is.apply(window.opener, arguments);
+}
+
+async function runTests()
+{
+  var iframe = document.getElementById("iframe");
+  var anchor = iframe.contentDocument.getElementById("anchor");
+  var div = iframe.contentDocument.getElementById("div");
+
+  function resetScroll()
+  {
+    return new Promise(resolve => {
+      var scrollParent = document.documentElement.scrollTop || document.documentElement.scrollLeft;
+      var scrollChild = iframe.contentDocument.documentElement.scrollTop || iframe.contentDocument.documentElement.scrollLeft;
+      if (scrollParent) {
+        window.addEventListener("scroll", () => {
+          scrollParent = false;
+          if (!scrollChild) {
+            SimpleTest.executeSoon(resolve);
+          }
+        }, { once: true });
+      }
+      if (scrollChild) {
+        iframe.contentWindow.addEventListener("scroll", () => {
+          scrollChild = false;
+          if (!scrollParent) {
+            SimpleTest.executeSoon(resolve);
+          }
+        }, { once: true });
+      }
+      document.documentElement.scrollTop = 0;
+      document.documentElement.scrollLeft = 0;
+      iframe.contentDocument.documentElement.scrollTop = 0;
+      iframe.contentDocument.documentElement.scrollLeft = 0;
+      if (!scrollParent && !scrollChild) {
+        SimpleTest.executeSoon(resolve);
+      }
+    });
+  }
+
+  async function tryToScrollWithKey(aVertical)
+  {
+    await resetScroll();
+
+    return new Promise(resolve => {
+      // Wait scroll event
+      function onScroll() {
+        SimpleTest.executeSoon(resolve);
+      }
+      window.addEventListener("scroll", onScroll, { once: true });
+      iframe.contentWindow.addEventListener("scroll", onScroll, { once: true });
+
+      if (aVertical) {
+        synthesizeKey("KEY_ArrowDown", { code: "ArrowDown" });
+      } else {
+        synthesizeKey("KEY_ArrowRight", { code: "ArrowRight" });
+      }
+    });
+  }
+
+  // When iframe element has focus and the iframe document isn't scrollable, the parent document should be scrolled instead.
+  document.body.focus();
+  iframe.focus();
+  await tryToScrollWithKey(true);
+  ok(document.documentElement.scrollTop > 0, "ArrowDown keydown event at the iframe whose content is not scrollable should cause scrolling the parent document");
+  await tryToScrollWithKey(false);
+  ok(document.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is not scrollable should cause scrolling the parent document");
+  await resetScroll();
+
+  // When iframe element has focus and the iframe document scrollable, the parent document shouldn't be scrolled.
+  document.body.focus();
+  div.style.height = "1000px";
+  div.style.width = "1000px";
+  iframe.focus();
+  await tryToScrollWithKey(true);
+  is(document.documentElement.scrollTop, 0, "ArrowDown keydown event at the iframe whose content is scrollable shouldn't cause scrolling the parent document");
+  ok(iframe.contentDocument.documentElement.scrollTop > 0, "ArrowDown keydown event at the iframe whose content is scrollable should cause scrolling the iframe document");
+  await tryToScrollWithKey(false);
+  is(document.documentElement.scrollLeft, 0, "ArrowRight keydown event at the iframe whose content is scrollable shouldn't cause scrolling the parent document");
+  ok(iframe.contentDocument.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is scrollable should cause scrolling the iframe document");
+  await resetScroll();
+
+  // If iframe document cannot scroll to specific direction, parent document should be scrolled instead.
+  div.style.height = "1px";
+  div.style.width = "1000px";
+  iframe.focus();
+  await tryToScrollWithKey(true);
+  ok(document.documentElement.scrollTop > 0, "ArrowDown keydown event at the iframe whose content is scrollable only horizontally should cause scrolling the parent document");
+  await tryToScrollWithKey(false);
+  is(document.documentElement.scrollLeft, 0, "ArrowRight keydown event at the iframe whose content is scrollable only horizontally shouldn't cause scrolling the parent document");
+  ok(iframe.contentDocument.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is scrollable only horizontally should cause scrolling the iframe document");
+  await resetScroll();
+
+  div.style.height = "1000px";
+  div.style.width = "1px";
+  iframe.focus();
+  await tryToScrollWithKey(true);
+  is(document.documentElement.scrollTop, 0, "ArrowDown keydown event at the iframe whose content is scrollable only vertically shouldn't cause scrolling the parent document");
+  ok(iframe.contentDocument.documentElement.scrollTop > 0, "ArrowDown keydown event at the iframe whose content is scrollable only vertically should cause scrolling the iframe document");
+  await tryToScrollWithKey(false);
+  ok(document.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is scrollable only vertically should cause scrolling the parent document");
+  await resetScroll();
+
+  // Hidden iframe shouldn't consume keyboard events if it was not scrollable.
+  document.body.focus();
+  anchor.focus();
+  iframe.style.display = "none";
+  await tryToScrollWithKey(true);
+  ok(document.documentElement.scrollTop > 0, "ArrowDown keydown event after hiding the iframe should cause scrolling the parent document");
+  await tryToScrollWithKey(false);
+  ok(document.documentElement.scrollLeft > 0, "ArrowRight keydown event after hiding the iframe should cause scrolling the parent document");
+  await resetScroll();
+
+  // Make sure the result visible in the viewport.
+  document.documentElement.scrollTop = 0;
+  document.documentElement.scrollLeft = 0;
+  window.opener.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>