File: smooth-scrollIntoView-with-smooth-fragment-scroll.html

package info (click to toggle)
firefox-esr 140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,539,276 kB
  • sloc: cpp: 7,381,286; javascript: 6,388,710; ansic: 3,710,139; python: 1,393,780; xml: 628,165; asm: 426,918; java: 184,004; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (80 lines) | stat: -rw-r--r-- 3,157 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
  <head>
    <title>CSSOM View - Smooth scrollIntoView + smooth scroll to fragment</title>
    <link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-element-scrollintoview">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/dom/events/scrolling/scroll_support.js"></script>
  </head>
  <body>
    <style>
      iframe {
        width: 100vw;
        height: 100vh;
      }
    </style>
    <script>
      let frame = null;
      async function test_smooth_scrollintoview_with_smooth_fragment() {
        return new Promise((resolve) => {
          window.addEventListener("message", (evt) => {
            assert_equals(evt.data, "ready");

            // Check that the fragment scroll completed.
            const fragment_scroll_container =
              frame.contentDocument.getElementById("fragment_scroll_container");
            const fragment_scroll_target =
              frame.contentDocument.getElementById("fragment_scroll_target");
            assert_approx_equals(fragment_scroll_container.scrollTop,
              fragment_scroll_target.offsetTop, 1,
              "scroll to fragment was completed");

            // Check that the scrollIntoView completed.
            const scrollintoview_container =
              frame.contentDocument.getElementById("scrollintoview_container");
            const scrollintoview_target =
              frame.contentDocument.getElementById("scrollintoview_target");
            assert_approx_equals(scrollintoview_container.scrollTop,
              scrollintoview_target.offsetTop, 1,
              "scrollIntoView was completed");

            resolve();
          });
        });
      }

      promise_test(async (t) =>  {
        frame = document.createElement("iframe");
        let test_complete_promise =
          test_smooth_scrollintoview_with_smooth_fragment();
        frame.src =
          "smooth-scrollIntoView-with-smooth-fragment-scroll-iframe.html" +
          "#fragment_scroll_target";
        document.documentElement.appendChild(frame);
        await test_complete_promise;
        frame.src = "";
        frame.remove();
      }, "Smooth scroll to hash fragment (on pageload) alongside smooth " +
         "scrollIntoView runs to completion.");

      promise_test(async (t) =>  {
        frame = document.createElement("iframe");
        const iframe_load_promise = new Promise((resolve) => {
          frame.addEventListener("load", resolve);
        });
        const test_complete_promise =
          test_smooth_scrollintoview_with_smooth_fragment();
        frame.src =
          "smooth-scrollIntoView-with-smooth-fragment-scroll-iframe.html";
        document.documentElement.appendChild(frame);
        await iframe_load_promise;
        const link = frame.contentDocument.getElementById("fragment_link");
        link.click();
        await test_complete_promise;
        frame.src = "";
        frame.remove();
      }, "Smooth scroll to hash fragment (on click) alongside smooth " +
         "scrollIntoView runs to completion.");
    </script>
  </body>