summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/user-activation/navigation-state-reset-sameorigin.html
blob: c240f96b2c3da884c0dcbe706c4064fa4544b9ef (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>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/resources/testdriver.js"></script>
    <script src="/resources/testdriver-vendor.js"></script>
  </head>
  <body>
    <h1>Post-navigation activation state in child</h1>
    <p>
      Tests that navigating a same-origin child frame resets its activation
      states.
    </p>
    <ol id="instructions">
      <li>Click inside the yellow area.</li>
    </ol>

    <iframe id="child" width="200" height="50"> </iframe>
    <script>
      function message(type) {
        return new Promise((resolve) => {
          window.addEventListener("message", function listener(event) {
            const data = JSON.parse(event.data);
            if (data.type === type) {
              window.removeEventListener("message", listener);
              resolve(data);
            }
          });
        });
      }
      promise_test(async (t) => {
        var child = document.getElementById("child");
        child.src = "./resources/child-one.html";
        const unclickeData = await message("child-one-loaded");
        assert_false(navigator.userActivation.isActive);
        assert_false(navigator.userActivation.hasBeenActive);
        assert_false(unclickeData.isActive);
        assert_false(unclickeData.hasBeenActive);

        const [, child1Data] = await Promise.all([
          test_driver.click(child),
          message("child-one-clicked"),
        ]);

        assert_true(navigator.userActivation.isActive);
        assert_true(navigator.userActivation.hasBeenActive);
        assert_true(child1Data.isActive);
        assert_true(child1Data.hasBeenActive);

        child.src = "./resources/child-two.html";

        const child2Data = await message("child-two-loaded");

        assert_true(navigator.userActivation.isActive);
        assert_true(navigator.userActivation.hasBeenActive);
        assert_false(child2Data.isActive);
        assert_false(child2Data.hasBeenActive);
      }, "Post-navigation state reset.");
    </script>
  </body>
</html>