Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE>
<html>
  <head>
  <title>Checking zoomToFocusedInput scrolls that focused non-input element is visible position</title>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  </head>
<body>
<div style="height: 8000px;">ABC</div>
<div id="content">
</div>
<!-- Leave additional room below the element so it can be scrolled to the center -->
<div style="height: 1000px;">ABC</div>
<script type="application/javascript">
async function test() {
  let utils = SpecialPowers.getDOMWindowUtils(window);
  // contenteditable
  let div = document.createElement("div");
  div.setAttribute("contenteditable", "true");
  for (let i = 0; i < 200; i++) {
    div.innerHTML += "foo<br>";
  }
  div.innerHTML += "<span id=last>bar</span>";
  document.getElementById("content").appendChild(div);
  let selection = window.getSelection();
  selection.collapse(div.firstChild, 0);
  window.scrollTo(0, 0);
  await waitToClearOutAnyPotentialScrolls(window);
  is(0, window.scrollY, "scroll position is reset");
  let scrollendPromise = promiseScrollend();
  utils.zoomToFocusedInput();
  await scrollendPromise;
  await promiseApzFlushedRepaints();
  ok(window.scrollY > 0, "scroll position isn't top");
  let prevY = window.scrollY;
  selection.collapse(document.getElementById("last").firstChild, 0);
  window.scrollTo(0, 0);
  await waitToClearOutAnyPotentialScrolls(window);
  is(0, window.scrollY, "scroll position is reset");
  scrollendPromise = promiseScrollend();
  utils.zoomToFocusedInput();
  await scrollendPromise;
  await promiseApzFlushedRepaints();
  ok(prevY < window.scrollY, "scroll position is visibile position of caret");
  document.getElementById("content").removeChild(div);
  // Create a scrollable and overflowed in the viewport <textarea> element
  let textarea = document.createElement("textarea");
  textarea.style.overflow = "scroll";
  textarea.style.height = "150vh";
  // The textarea row is 200 so that "150vh / 100" is a reasonable font-size
  // to overflow the area.
  textarea.style.fontSize = "calc(150vh / 100)";
  textarea.rows = 200;
  for (let i = 0; i < 200; i++) {
    textarea.value += "foo\n";
  }
  document.getElementById("content").appendChild(textarea);
  textarea.focus();
  await waitToClearOutAnyPotentialScrolls(window);
  textarea.setSelectionRange(0, 0);
  window.scrollTo(0, 0);
  await waitToClearOutAnyPotentialScrolls(window);
  is(0, window.scrollY, "scroll position is reset");
  scrollendPromise = promiseScrollend();
  utils.zoomToFocusedInput();
  await scrollendPromise;
  await promiseApzFlushedRepaints();
  ok(window.scrollY > 0, "scroll position isn't top");
  prevY = window.scrollY;
  textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  window.scrollTo(0, 0);
  await waitToClearOutAnyPotentialScrolls(window);
  is(0, window.scrollY, "scroll position is reset");
  const scrollTopInTextArea = textarea.scrollTop;
  const scrollLeftInTextArea = textarea.scrollLeft;
  scrollendPromise = promiseScrollend();
  utils.zoomToFocusedInput();
  await scrollendPromise;
  await promiseApzFlushedRepaints();
  ok(prevY < window.scrollY, "scroll position is visibile position of caret");
  isfuzzy(textarea.scrollTop, scrollTopInTextArea, 2,
     "textarea's scrollTop is unchanged");
  isfuzzy(textarea.scrollLeft, scrollLeftInTextArea, 2,
     "textarea's scrollLeft is unchanged");
  document.getElementById("content").removeChild(textarea);
}
waitUntilApzStable().then(test).then(subtestDone, subtestFailed);
</script>
</body>
</html>