tor-browser

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

simultaneousScrollIntoViews.js (1800B)


      1 // Copyright 2024 The Chromium Authors
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 async function reset(t, scrollers) {
      6  for (const scroller of scrollers) {
      7    await waitForScrollReset(t, scroller);
      8  }
      9 }
     10 
     11 /**
     12 * This tests executing scrollIntoView on multiple scroll containers at the same
     13 * time. It assumes and verifies vertical scrolling.
     14 */
     15 async function simultaneousScrollIntoViewsTest(test,
     16                                               behaviors,
     17                                               targets,
     18                                               scrollers,
     19                                               target_offsets) {
     20  assert_equals(targets.length, behaviors.length,
     21    "equal numbers of targets and behaviors provided");
     22  assert_equals(scrollers.length, target_offsets.length,
     23    "equal numbers of scrollers and target_offsets provided");
     24  await reset(test, scrollers);
     25  await waitForCompositorCommit();
     26 
     27  // All scrollers should be at an offset of 0.
     28  for (const scroller of scrollers) {
     29    assert_equals(scroller.scrollTop, 0, `${scroller.id}'s scrollTop is reset`);
     30  }
     31 
     32  const scrollend_promises = Array.from(scrollers, (scroller) => {
     33    return waitForScrollEndFallbackToDelayWithoutScrollEvent(scroller);
     34  });
     35 
     36  // Scroll all targets into view.
     37  for (let idx = 0; idx < targets.length; idx++) {
     38    targets[idx].scrollIntoView({
     39      block: "start",
     40      behavior: behaviors[idx]
     41    });
     42  }
     43  await Promise.all(scrollend_promises);
     44 
     45  // Verify the expected positions os all scrollers.
     46  for (let idx = 0; idx < scrollers.length; idx++) {
     47    assert_approx_equals(scrollers[idx].scrollTop, target_offsets[idx], 1,
     48      `scrollIntoView finished executing on ${scrollers[idx].id}`
     49    );
     50  }
     51 }