tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

textarea-scroll-restoration.html (1270B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>Test textarea scroll restoration</title>
      4 <link rel="help" href="https://html.spec.whatwg.org/#the-textarea-element-2">
      5 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
      6 <link rel="author" title="Mozilla" href="https://mozilla.com">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <div id="container">
     10  <textarea id="textarea" rows=3>
     11    A
     12    B
     13    C
     14    D
     15    E
     16    F
     17    G
     18    H
     19    I
     20  </textarea>
     21 </div>
     22 <script>
     23 
     24 function frame() {
     25  return new Promise(r => {
     26    requestAnimationFrame(() => requestAnimationFrame(r));
     27  });
     28 }
     29 
     30 let container = document.getElementById("container");
     31 let textarea = document.getElementById("textarea");
     32 
     33 async function test_restoration() {
     34  textarea.scrollTop = 10000;
     35  await frame();
     36  let top = textarea.scrollTop;
     37  assert_not_equals(top, 0, "Should've scrolled down");
     38  container.style.display = "inline-block";
     39  assert_equals(textarea.scrollTop, top, "Should've preserved the scroll position");
     40  container.style.display = "";
     41 }
     42 
     43 promise_test(test_restoration);
     44 promise_test(async function() {
     45  textarea.focus();
     46  await frame();
     47  await test_restoration();
     48 }, "after focus");
     49 </script>