tor-browser

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

notify-event-transient-user-activation.https.html (3643B)


      1 <!DOCTYPE html>
      2 <meta name="timeout" content="long">
      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="/common/get-host-info.sub.js"></script>
     11 <script src="resources/utils.js"></script>
     12 <title>Test that fenced frame notifyEvent() requires transient activation</title>
     13 
     14 <body>
     15  <script>
     16    promise_test(async (t) => {
     17      const fencedframe = await attachFencedFrameContext(
     18                  {generator_api: 'fledge'});
     19      t.add_cleanup(async () => document.body.removeChild(fencedframe.element));
     20 
     21      let notified_promise = new Promise((resolve) => {
     22        fencedframe.element.addEventListener('fencedtreeclick', () => {
     23          resolve();
     24        });
     25      });
     26 
     27      await fencedframe.execute(() => {
     28        document.addEventListener('click', (e) => {
     29          assert_true(navigator.userActivation.isActive);
     30          window.fence.notifyEvent(e);
     31        });
     32      });
     33 
     34      let actions = new test_driver.Actions();
     35      await actions.pointerMove(10, 10, {origin: fencedframe.element})
     36        .pointerDown()
     37        .pointerUp()
     38        .send();
     39 
     40      await notified_promise;
     41 
     42      await fencedframe.execute(() => {
     43        assert_false(navigator.userActivation.isActive);
     44      });
     45 
     46      assert_true(navigator.userActivation.isActive);
     47      assert_true(navigator.userActivation.hasBeenActive);
     48    }, 'Test that notifyEvent() consumes transient user activation in the ' +
     49       'fenced frame and notifies activation to the embedder.');
     50 
     51    promise_test(async (t) => {
     52      const fencedframe = await attachFencedFrameContext(
     53                  {generator_api: 'fledge'});
     54      t.add_cleanup(async () => document.body.removeChild(fencedframe.element));
     55 
     56      let notified_promise = new Promise((resolve) => {
     57        fencedframe.element.addEventListener('fencedtreeclick', () => {
     58          resolve('notified');
     59        });
     60      });
     61 
     62      let opened_key = token();
     63      await fencedframe.execute((opened) => {
     64        document.addEventListener('click', (e) => {
     65          // We can't use `attachWindowContext` here because it requres the
     66          // event handler to be async, which means the state of the `e` may
     67          // change while we're observing it. We'll look up the key written by
     68          // embeddee.html later to determine the window opened.
     69          let opened_url = generateURL('embeddee.html', [opened]);
     70          window.open(opened_url, '_blank');
     71          window.fence.notifyEvent(e);
     72        });
     73      }, [opened_key]);
     74 
     75      let actions = new test_driver.Actions();
     76      await actions.pointerMove(10, 10, {origin: fencedframe.element})
     77        .pointerDown()
     78        .pointerUp()
     79        .send();
     80 
     81      // Confirm that the popup actually opened after clicking the fenced frame.
     82      let opened_value = await nextValueFromServer(opened_key);
     83      assert_equals(opened_value, 'PASS');
     84      // Confirmed that the call to notifyEvent never actually fired, because
     85      // opening the popup consumed user activation.
     86      let result = await Promise.race([
     87        notified_promise,
     88        new Promise((resolve) => {
     89          t.step_timeout(() => resolve('timeout'), 2000);
     90        })
     91      ]);
     92      assert_equals(result, 'timeout');
     93    }, "Test that popup navigation on click prevents notifyEvent() from " +
     94       "firing.");
     95  </script>
     96 </body>