summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-targeted-element-main-frame.html
blob: ff81dc78c5508bec5eaba2cbbea378eecc5d532f (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
<!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(JSON.parse(text));
          } else {
            requestAnimationFrame(fetchResultInternal.bind(this, url));
          }
        }
        fetchResultInternal(url);
      });
    }

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

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

        const result = await fetchResult(key);
        assert_equals([result.passed, result.errors].join(), "9,");
      }, "targeted box is selected snap target.");
    }
  </script>
</body>