summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-targeted-element-main-frame.html
blob: 6221b0e4b51c238e10a4ec32c47737da62a1d13a (plain)
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
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title> CSS Scroll Snap Test: snap selection with targeted element</title>
  <link rel="help" href="https://drafts.csswg.org/css-scroll-snap">
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/resources/testdriver.js"></script>
  <script src="/resources/testdriver-actions.js"></script>
  <script src="/resources/testdriver-vendor.js"></script>
  <script src="/common/utils.js"></script>
</head>

<body onload="runTest()">
  <script>
    async function fetchResult(key) {
      const url = `/css/css-scroll-snap/snap-after-relayout/` +
        `multiple-aligned-targets/stash.py?key=${key}`;
      // We may need multiple requests. Return a promise that will be resolved
      // when an actual response is received.
      return new Promise(async (resolve) => {
        async function fetchResultInternal(url) {
          const response = await fetch(url);
          const text = await response.text();
          if (text) {
            resolve(text);
          } else {
            requestAnimationFrame(fetchResultInternal.bind(this, url));
          }
        }
        fetchResultInternal(url);
      });
    }

    function runTest() {
      function test(n) {
        return promise_test(async (t) => {
          let key = token();

          test_driver.bless("Open a URL with a text fragment directive", () => {
            window.open(`prefer-targeted-element-main-frame-target.html` +
              `?key=${key}#box${n}`, "_blank", "noopener");
          });

          assert_equals(await fetchResult(key), "PASS");
        }, `targeted box${n} is selected snap target.`);
      }

      test(1);
      test(2);
      test(3);
      test(4);
      test(5);
      test(6);
      test(7);
      test(8);
      test(9);
    }
  </script>
</body>