summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/user-activation/propagation-same-and-cross-origin.sub.html
blob: 31a72224484700faf90365afbdc727993196534f (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!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>
    <script src="resources/utils.js"></script>
  </head>
  <body>
    <h1>Check that cross origin iframes don't get activated</h1>
    <p>
      Tests that activating a same-origin navigable doesn't activate a cross
      origin navigable.
    </p>
    <ol id="instructions">
      <li>Click inside the yellow area.</li>
    </ol>
    <h1>Same origin</h1>
    <iframe id="so-child" width="200" height="50"></iframe>
    <h1>Cross origin</h1>
    <iframe id="xo-child" width="200" height="50"></iframe>
  </body>
  <script>
    const soChild = document.getElementById("so-child");
    const xoChild = document.getElementById("xo-child");

    function requestXOReport() {
      xoChild.contentWindow.postMessage(
        JSON.stringify({ type: "report" }),
        "*"
      );
      return receiveMessage(`child-two-report`);
    }

    promise_setup(() => {
      soChild.src = "./resources/child-one.html";
      xoChild.src =
        "http://{{hosts[alt][]}}:{{ports[http][0]}}/html/user-activation/resources/child-two.html";
      return Promise.all([
        receiveMessage("child-one-loaded"),
        receiveMessage("child-two-loaded"),
      ]);
    });

    promise_test(async (t) => {
      const unclickedCrossOrigin = await requestXOReport();
      const soActivation = soChild.contentWindow.navigator.userActivation;
      assert_false(
        navigator.userActivation.isActive,
        "top-frame navigator.userActivation.isActive must be false"
      );
      assert_false(
        navigator.userActivation.hasBeenActive,
        "top-frame navigator.userActivation.hasBeenActive must be false"
      );

      assert_false(soActivation.isActive, "child-one isActive must be false");
      assert_false(
        soActivation.hasBeenActive,
        "child-one hasBeenActive must be false"
      );
      assert_false(
        unclickedCrossOrigin.isActive,
        "child-two isActive must be false"
      );
      assert_false(
        unclickedCrossOrigin.hasBeenActive,
        "child-two hasBeenActive must be false"
      );
    }, "Check Initial states of user activation are all false");

    promise_test(async (t) => {
      await test_driver.click(soChild);
      const xoActivation = await requestXOReport();
      const soActivation = soChild.contentWindow.navigator.userActivation;
      assert_true(
        navigator.userActivation.isActive,
        "top-frame navigator.userActivation.isActive must be true"
      );
      assert_true(
        navigator.userActivation.hasBeenActive,
        "top-frame navigator.userActivation.hasBeenActive must be true"
      );
      assert_true(soActivation.isActive, "child-one isActive must be true");
      assert_true(
        soActivation.hasBeenActive,
        "child-one hasBeenActive must be true"
      );
      assert_false(xoActivation.isActive, "child-two isActive must be false");
      assert_false(
        xoActivation.hasBeenActive,
        "child-two hasBeenActive must be false"
      );
    }, "Check that activating a same-origin navigable doesn't activate a cross origin navigable");

    promise_test(async (t) => {
      await consumeTransientActivation();
      const soActivation = soChild.contentWindow.navigator.userActivation;
      // Before click...
      assert_false(
        navigator.userActivation.isActive,
        "top-frame navigator.userActivation.isActive must be false"
      );
      assert_true(
        navigator.userActivation.hasBeenActive,
        "top-frame navigator.userActivation.hasBeenActive must be true"
      );
      assert_false(soActivation.isActive, "child-one isActive must be false");
      assert_true(
        soActivation.hasBeenActive,
        "child-one hasBeenActive must be true"
      );
      const xoActivation = await requestXOReport();
      assert_false(xoActivation.isActive, "child-two isActive must be false");
      assert_false(
        xoActivation.hasBeenActive,
        "child-two hasBeenActive must be false"
      );

      // Click!
      const [, xoActivationAfterClick] = await Promise.all([
        test_driver.click(xoChild),
        receiveMessage("child-two-clicked"),
      ]);

      // After click...
      assert_true(
        navigator.userActivation.isActive,
        "top-frame navigator.userActivation.isActive must be true"
      );
      assert_true(
        navigator.userActivation.hasBeenActive,
        "top-frame navigator.userActivation.hasBeenActive must remain true"
      );
      assert_true(
        xoActivationAfterClick.isActive,
        "child-two isActive must be true"
      );
      assert_true(
        xoActivationAfterClick.hasBeenActive,
        "child-two hasBeenActive must be true"
      );
      assert_false(soActivation.isActive, "child-one isActive must be false");
      assert_true(
        soActivation.hasBeenActive,
        "child-one hasBeenActive must remain true"
      );
    }, "Clicking on the cross-origin navigable activates parent navigable.");
  </script>
</html>