tor-browser

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

user-activation.https.html (3475B)


      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_activation = (should_be_active, frame_name) => {
     24  if (should_be_active) {
     25    assert_true(navigator.userActivation.hasBeenActive,
     26                frame_name + " has been activated.");
     27    assert_true(navigator.userActivation.isActive,
     28                frame_name + " is currently active.");
     29  } else {
     30    assert_false(navigator.userActivation.hasBeenActive,
     31                 frame_name + " has not been activated yet.");
     32    assert_false(navigator.userActivation.isActive,
     33                 frame_name + " is not currently active.");
     34  }
     35 };
     36 
     37 promise_test(async () => {
     38  // This test ensures that user activations (e.g. click events) don't
     39  // propagate across fenced frame boundaries. Specifically, activations
     40  // are visible through the `navigator.userActivation` object.
     41  //
     42  // The layout of the page is as follows:
     43  // A: top-level frame
     44  //   B: iframe
     45  //   C: fencedframe
     46  //   D: iframe
     47  //   E: fencedframe
     48  //
     49  // This order is chosen to test all kinds of fenced tree traversal. We:
     50  // - Click in C and check that only C gets activated (not A, B, D, or E)
     51  // - Click in A and check that only A, B, and D get activated (not E)
     52  // - Click in B and D and check that E wasn't activated
     53 
     54  const B = attachIFrameContext();
     55  const C = attachFencedFrameContext();
     56  const D = attachIFrameContext();
     57  const E = attachFencedFrameContext();
     58 
     59  // Define some helpers to check activations more concisely.
     60  const frames = [[B, "B"], [C, "C"], [D, "D"], [E, "E"]];
     61  const assert_activations = async (should_be_actives) => {
     62    assert_equals(frames.length, should_be_actives.length);
     63    for ([i, [frame, frame_name]] of frames.entries()) {
     64      await frame.execute(assert_activation, [should_be_actives[i], frame_name]);
     65    }
     66  };
     67 
     68  // Check that all the frames  are inactive before we start.
     69  assert_activation(false, "A");
     70  await assert_activations([false/*B*/, false/*C*/, false/*D*/, false/*E*/]);
     71 
     72  // Simulate a click in C (the first fenced frame).
     73  await click(C.element);
     74 
     75  // Check that only C has been activated.
     76  assert_activation(false, "A");
     77  await assert_activations([false/*B*/, true/*C*/, false/*D*/, false/*E*/]);
     78 
     79  // Simulate a click in A (the top-level site).
     80  await click(document.documentElement);
     81 
     82  // Check that A, B, and D were activated.
     83  assert_activation(true, "A");
     84  await assert_activations([true/*B*/, true/*C*/, true/*D*/, false/*E*/]);
     85 
     86  // Simulate a click in B and D (the two iframes).
     87  await click(B.element);
     88  await click(D.element);
     89 
     90  // Check that E has still not been activated.
     91  assert_activation(true, "A");
     92  await assert_activations([true/*B*/, true/*C*/, true/*D*/, false/*E*/]);
     93 }, 'user-activation');
     94 </script>
     95 </body>