tor-browser

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

dirty-contents-reselect-anchor.tentative.html (1773B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <link rel=help href="https://bugzilla.mozilla.org/show_bug.cgi?id=1738781">
      4 <link rel=help href="https://github.com/w3c/csswg-drafts/issues/6787">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <style>
      8  .padding {
      9    background: grey;
     10    border: 1px dashed black;
     11    margin: 5px;
     12    height: 200vh;
     13  }
     14 </style>
     15 <div id="content"></div>
     16 <script>
     17  const content = document.getElementById("content");
     18 
     19  const t = async_test("Scroll anchor is re-selected after adjustment if there are dirty descendants at selection time");
     20  function replaceAllContent() {
     21    content.innerHTML = `
     22      <div class="padding"></div>
     23      <button id="target">Scroll target</button>
     24      <div class="padding"></div>
     25    `;
     26  }
     27 
     28  function insertContent() {
     29    let inserted = document.createElement("div");
     30    inserted.className = "padding inserted";
     31    content.insertBefore(inserted, content.firstChild);
     32  }
     33 
     34  // Set the content, and scroll #target into view.
     35  replaceAllContent();
     36  document.getElementById("target").scrollIntoView();
     37 
     38  t.step(function() {
     39    assert_not_equals(window.scrollY, 0, "Should've scrolled");
     40  });
     41 
     42  // Save the target scroll position, which shouldn't change.
     43  const oldTargetTop = document.getElementById("target").getBoundingClientRect().top;
     44 
     45  // Replace all the content, then insert content at the top afterwards.
     46  replaceAllContent();
     47 
     48  requestAnimationFrame(() => requestAnimationFrame(t.step_func_done(function() {
     49    insertContent();
     50    const newTargetTop = document.getElementById("target").getBoundingClientRect().top;
     51    assert_equals(oldTargetTop, newTargetTop, "Scroll position should've been preserved");
     52  })));
     53 </script>
     54 <style>