tor-browser

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

target_blank_useractivation.html (2598B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset=utf-8>
      5 <title>Test that clicking target=_blank links consumes userActivation</title>
      6 <link rel="help" href="https://html.spec.whatwg.org/#following-hyperlinks-2">
      7 <link rel="help" href="https://html.spec.whatwg.org/#the-rules-for-choosing-a-navigable">
      8 <script src=/resources/testharness.js></script>
      9 <script src=/resources/testharnessreport.js></script>
     10 <script src="/resources/testdriver.js"></script>
     11 <script src="/resources/testdriver-actions.js"></script>
     12 <script src="/resources/testdriver-vendor.js"></script>
     13 </head>
     14 <body>
     15 <a target="_blank" id="a_click_target">Click me</a>
     16 <map id="map">
     17 <area coords="0,0,50,50" target="_blank">
     18 </map>
     19 <img src="/images/blue.png" usemap="#map" style="width: 50px; height: 50px" id="area_click_target">
     20 <script>
     21 
     22 const testUrl = "support/target-blank-useractivation.html";
     23 
     24 function waitForNewWindow(aBroadcastChannelId) {
     25  return new Promise(resolve => {
     26    let channel = new BroadcastChannel(aBroadcastChannelId);
     27    channel.addEventListener("message", (e) => {
     28      assert_equals(e.data, "ready");
     29      channel.postMessage("close");
     30      resolve();
     31    }, {once: true});
     32  });
     33 }
     34 
     35 ["a", "area"].forEach(tag => {
     36  const link = document.querySelector(tag);
     37 
     38  promise_test(async () => {
     39    let broadcastChannelId = `${tag}_click_script`;
     40    link.href = `${testUrl}?${broadcastChannelId}`;
     41 
     42    await test_driver.bless('transient activation');
     43    assert_true(navigator.userActivation.isActive, 'should have user activation');
     44 
     45    let newWindowPromise = waitForNewWindow(broadcastChannelId);
     46    link.click();
     47    await newWindowPromise;
     48    assert_false(navigator.userActivation.isActive, 'navigator.userActivation.isActive after opening a new window');
     49  }, `<${tag} target=_blank">.click()`);
     50 
     51  promise_test(async () => {
     52    let broadcastChannelId = `${tag}_click`;
     53    link.href = `${testUrl}?${broadcastChannelId}`;
     54 
     55    let newWindowPromise = waitForNewWindow(broadcastChannelId);
     56    link.addEventListener("click", () => {
     57      assert_true(navigator.userActivation.isActive, 'should have user activation');
     58    });
     59    // test_driver.click() doesn't work with <area> element in Chrome.
     60    await new test_driver.Actions()
     61        .pointerMove(1, 1, { origin: document.getElementById(`${tag}_click_target`) })
     62        .pointerDown()
     63        .pointerUp()
     64        .send();
     65    await newWindowPromise;
     66    assert_false(navigator.userActivation.isActive, 'navigator.userActivation.isActive after opening a new window');
     67  }, `<${tag} target=_blank"> mouse click`);
     68 });
     69 </script>
     70 </body>
     71 </html>