tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

consume-user-activation.https.html (3582B)


      1 <!DOCTYPE html>
      2 <title>Test that user activation propagation is fenced.</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/resources/testdriver.js"></script>
      6 <script src="/resources/testdriver-actions.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <script src="/common/utils.js"></script>
      9 <script src="/common/dispatcher/dispatcher.js"></script>
     10 <script src="resources/utils.js"></script>
     11 
     12 <body>
     13 <script>
     14 // Simulate a click in frame context `frame`.
     15 async function click(frame) {
     16  var actions = new test_driver.Actions();
     17  await actions.pointerMove(0, 0, {origin: frame})
     18               .pointerDown()
     19               .pointerUp()
     20               .send();
     21 }
     22 
     23 assert_activations = (sticky_activation, transient_activation, frame_name) => {
     24  if (sticky_activation) {
     25    assert_true(navigator.userActivation.hasBeenActive,
     26                frame_name + " has been activated.");
     27  } else {
     28    assert_false(navigator.userActivation.hasBeenActive,
     29                 frame_name + " has not been activated yet.");
     30  }
     31  if (transient_activation) {
     32    assert_true(navigator.userActivation.isActive,
     33                frame_name + " is currently active.");
     34  } else {
     35    assert_false(navigator.userActivation.isActive,
     36                 frame_name + " is not currently active.");
     37  }
     38 };
     39 
     40 promise_test(async () => {
     41  // This test checks that consumption of transient user activations is
     42  // fenced, i.e. that when the top-level embedder and a fenced frame are
     43  // both active, and one of them performs an operation that consumes
     44  // transient user activation (sets `navigator.userActivation.isActive`
     45  // to `false`), it doesn't affect the other frame.
     46 
     47  // Given a top-level frame A and fenced frame B, the structure of the
     48  // test is as follows:
     49  // - Activate both A and B with a click
     50  // - Consume A's transient user activation with `window.open`
     51  // - Check that A is inactive and B is active
     52  // - Reactivate A with a click
     53  // - Consume B's transient user activation with `window.open`
     54  // - Check that A is active and B is inactive
     55 
     56  const B = attachFencedFrameContext();
     57 
     58  // Check that both frames are inactive after loading.
     59  assert_activations(false, false, "A");
     60  await B.execute(assert_activations, [false, false, "B"]);
     61 
     62  // Send a click to activate the top-level frame, and check user activation.
     63  await click(document.documentElement);
     64  assert_activations(true, true, "A");
     65  await B.execute(assert_activations, [false, false, "B"]);
     66 
     67  // Send a click to activate the fenced frame, and check user activation.
     68  await click(B.element);
     69  assert_activations(true, true, "A");
     70  await B.execute(assert_activations, [true, true, "B"]);
     71 
     72  // Open a window to consume the top-level transient user activation.
     73  window.open('about:blank');
     74 
     75  // Check that it consumed the navigation in only the top-level frame.
     76  assert_activations(true, false, "A");
     77  await B.execute(assert_activations, [true, true, "B"]);
     78 
     79  // Reactivate this frame and check the user activation status.
     80  await click(document.documentElement);
     81  assert_activations(true, true, "A");
     82  await B.execute(assert_activations, [true, true, "B"]);
     83 
     84  // Open a window in the fenced frame to consume its transient activation.
     85  await B.execute(() => {
     86    window.open('about:blank');
     87  });
     88 
     89  // Check that B's transient user activation was consumed.
     90  assert_activations(true, true, "A");
     91  await B.execute(assert_activations, [true, false, "B"]);
     92 
     93 }, 'user-activation');
     94 </script>
     95 </body>