tor-browser

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

rel-opener-prevents-browsing-context-group-change.tentative.html (3052B)


      1 <!DOCTYPE html>
      2 <title>Prevent browsing context group changes</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/utils.js"></script>
      6 <script src="/common/dispatcher/dispatcher.js"></script>
      7 <script src="/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js"></script>
      8 
      9 <body>
     10 <script>
     11 
     12 /*
     13 * These tests are tentative. They are based on the following proposal:
     14 * https://github.com/explainers-by-googlers/future-browsing-context-group-dependency-hint
     15 */
     16 
     17 function navigateByRelOpenerAnchorToNew(remote) {
     18  function navigateByRelOpenerAnchorExecutorCreator(remote) {
     19    return (url) => {
     20      return remote.navigate((url) => {
     21        let anchor = document.createElement('a');
     22        anchor.href = url;
     23        anchor.rel = 'opener';
     24        anchor.text = 'Link';
     25        document.body.appendChild(anchor);
     26        anchor.click();
     27      }, [url]);
     28    };
     29  }
     30 
     31  return remote.helper.createContext({
     32        executorCreator: navigateByRelOpenerAnchorExecutorCreator(remote),
     33      });
     34 }
     35 
     36 function navigateBySelfOpenToNew(remote) {
     37  function navigateBySelfOpenExecutorCreator(remote) {
     38    return (url) => {
     39      return remote.navigate((url) => {
     40        window.open(url, '_self', 'opener');
     41      }, [url]);
     42    };
     43  }
     44 
     45  return remote.helper.createContext({
     46        executorCreator: navigateBySelfOpenExecutorCreator(remote),
     47      });
     48 }
     49 
     50 async function runNoGroupChangeTest(performNavigation) {
     51  const rcHelper = new RemoteContextHelper();
     52  // This test harness cannot be in the same browsing context group as the
     53  // navigating window, otherwise that would interfere with the test.
     54  const rcWindow = await rcHelper.addWindow(undefined, { features: 'noopener' });
     55 
     56  const rcWindow2 = await performNavigation(rcWindow);
     57 
     58  const rcPopup = await rcWindow2.addWindow(undefined, { target: 'my_popup' });
     59 
     60  assert_equals(await rcPopup.executeScript(() => {
     61    window.previouslyOpened = true;
     62    return window.name;
     63  }), 'my_popup', 'popup created');
     64 
     65  rcWindow2.historyBack();
     66 
     67  // In order for the original page to find the popup by name, they must be in
     68  // the same browsing context group.
     69  assert_true(await rcWindow.executeScript(() => {
     70    const popup = window.open('', 'my_popup');
     71    return popup.previouslyOpened;
     72  }), 'first page can access original popup');
     73 }
     74 
     75 promise_test(async t => {
     76  await runNoGroupChangeTest((remote) => {
     77    // Navigate away using rel=opener. The next page should remain in the same
     78    // browsing context group.
     79    return navigateByRelOpenerAnchorToNew(remote);
     80  });
     81 }, 'rel=opener prevents browsing context group change');
     82 
     83 promise_test(async t => {
     84  await runNoGroupChangeTest((remote) => {
     85    // Navigate away using window.open with the opener window feature. The next
     86    // page should remain in the same browsing context group.
     87    return navigateBySelfOpenToNew(remote);
     88  });
     89 }, 'opener window feature prevents browsing context group change');
     90 
     91 </script>
     92 </body>