summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/consume-user-activation.https.html
blob: e4ad20d17b7fdcec69f25e652dab967f9b52cf65 (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
<!DOCTYPE html>
<title>Test that user activation propagation is fenced.</title>
<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>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="resources/utils.js"></script>

<body>
<script>
// Simulate a click in frame context `frame`.
async function click(frame) {
  var actions = new test_driver.Actions();
  await actions.pointerMove(0, 0, {origin: frame})
               .pointerDown()
               .pointerUp()
               .send();
}

assert_activations = (sticky_activation, transient_activation, frame_name) => {
  if (sticky_activation) {
    assert_true(navigator.userActivation.hasBeenActive,
                frame_name + " has been activated.");
  } else {
    assert_false(navigator.userActivation.hasBeenActive,
                 frame_name + " has not been activated yet.");
  }
  if (transient_activation) {
    assert_true(navigator.userActivation.isActive,
                frame_name + " is currently active.");
  } else {
    assert_false(navigator.userActivation.isActive,
                 frame_name + " is not currently active.");
  }
};

promise_test(async () => {
  // This test checks that consumption of transient user activations is
  // fenced, i.e. that when the top-level embedder and a fenced frame are
  // both active, and one of them performs an operation that consumes
  // transient user activation (sets `navigator.userActivation.isActive`
  // to `false`), it doesn't affect the other frame.

  // Given a top-level frame A and fenced frame B, the structure of the
  // test is as follows:
  // - Activate both A and B with a click
  // - Consume A's transient user activation with `window.open`
  // - Check that A is inactive and B is active
  // - Reactivate A with a click
  // - Consume B's transient user activation with `window.open`
  // - Check that A is active and B is inactive

  const B = attachFencedFrameContext();

  // Check that both frames are inactive after loading.
  assert_activations(false, false, "A");
  await B.execute(assert_activations, [false, false, "B"]);

  // Send a click to activate the top-level frame, and check user activation.
  await click(document.documentElement);
  assert_activations(true, true, "A");
  await B.execute(assert_activations, [false, false, "B"]);

  // Send a click to activate the fenced frame, and check user activation.
  await click(B.element);
  assert_activations(true, true, "A");
  await B.execute(assert_activations, [true, true, "B"]);

  // Open a window to consume the top-level transient user activation.
  window.open('about:blank');

  // Check that it consumed the navigation in only the top-level frame.
  assert_activations(true, false, "A");
  await B.execute(assert_activations, [true, true, "B"]);

  // Reactivate this frame and check the user activation status.
  await click(document.documentElement);
  assert_activations(true, true, "A");
  await B.execute(assert_activations, [true, true, "B"]);

  // Open a window in the fenced frame to consume its transient activation.
  await B.execute(() => {
    window.open('about:blank');
  });

  // Check that B's transient user activation was consumed.
  assert_activations(true, true, "A");
  await B.execute(assert_activations, [true, false, "B"]);

}, 'user-activation');
</script>
</body>