gfx/layers/apz/test/mochitest/helper_zoomToFocusedInput_multiline.html
author Cosmin Sabou <csabou@mozilla.com>
Sun, 05 Feb 2023 19:37:33 +0000
changeset 651812 d8601249f1eb8c52c742b0c19c9ca0fa8f2e31fe
parent 578540 0a5a70f8ca6e1cff6a90a36cf4850e3ca1e12419
permissions -rw-r--r--
Bug 1806090 - temporarily disable browser_quickactions.js on linux for frequent failures. r=intermittent-reviewers,MasterWayZ Differential Revision: https://phabricator.services.mozilla.com/D168909

<!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 transformEndPromise = promiseTransformEnd();
  utils.zoomToFocusedInput();
  await transformEndPromise;
  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");
  transformEndPromise = promiseTransformEnd();
  utils.zoomToFocusedInput();
  await promiseApzFlushedRepaints();
  ok(prevY < window.scrollY, "scroll position is visibile position of caret");

  await transformEndPromise;

  document.getElementById("content").removeChild(div);

  // <textarea> element
  let textarea = document.createElement("textarea");
  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");
  transformEndPromise = promiseTransformEnd();
  utils.zoomToFocusedInput();
  await promiseApzFlushedRepaints();
  ok(window.scrollY > 0, "scroll position isn't top");
  prevY = window.scrollY;

  await transformEndPromise;

  textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  window.scrollTo(0, 0);
  await waitToClearOutAnyPotentialScrolls(window);
  is(0, window.scrollY, "scroll position is reset");
  transformEndPromise = promiseTransformEnd();
  utils.zoomToFocusedInput();
  await promiseApzFlushedRepaints();
  ok(prevY < window.scrollY, "scroll position is visibile position of caret");

  await transformEndPromise;

  document.getElementById("content").removeChild(textarea);
}

waitUntilApzStable().then(test).then(subtestDone, subtestFailed);
</script>
</body>
</html>