DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1aeaa33a64f9)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 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");
      } else {
        synthesizeKey("KEY_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>