tor-browser

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

test_top_navigation_by_user_activation.html (2343B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1744321
      5 -->
      6 <head>
      7 <meta charset="utf-8">
      8 <title>Iframe sandbox top navigation by user activation</title>
      9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 <script>
     12 function waitForMessage(aCallback) {
     13  return new Promise((aResolve) => {
     14    window.addEventListener("message", function listener(aEvent) {
     15      aCallback(aEvent);
     16      aResolve();
     17    }, { once: true });
     18  });
     19 }
     20 
     21 [
     22  {
     23    desc: "A same-origin iframe in sandbox with 'allow-top-navigation-by-user-activation' cannot navigate its top level page, if the navigation is not triggered by a user gesture",
     24    sameOrigin: true,
     25    userGesture: false,
     26  },
     27  {
     28    desc: "A same-origin iframe in sandbox with 'allow-top-navigation-by-user-activation' can navigate its top level page, if the navigation is triggered by a user gesture",
     29    sameOrigin: true,
     30    userGesture: true,
     31  },
     32  {
     33    desc: "A cross-origin iframe in sandbox with 'allow-top-navigation-by-user-activation' cannot navigate its top level page, if the navigation is not triggered by a user gesture",
     34    sameOrigin: false,
     35    userGesture: false,
     36  },
     37  {
     38    desc: "A cross-origin iframe in sandbox with 'allow-top-navigation-by-user-activation' can navigate its top level page, if the navigation is triggered by a user gesture",
     39    sameOrigin: false,
     40    userGesture: true,
     41  },
     42 ].forEach(({desc, sameOrigin, userGesture}) => {
     43  add_task(async function() {
     44    info(`Test: ${desc}`);
     45 
     46    let url = "file_top_navigation_by_user_activation.html";
     47    if (sameOrigin) {
     48      url = `${location.origin}/tests/docshell/test/iframesandbox/${url}`;
     49    }
     50 
     51    let promise = waitForMessage((e) => {
     52      is(e.data, "READY", "Ready for test");
     53    });
     54    let testWin = window.open(url);
     55    await promise;
     56 
     57    promise = waitForMessage((e) => {
     58      is(e.data, userGesture ? "NAVIGATED" : "BLOCKED", "Check the result");
     59    });
     60    testWin.postMessage(userGesture ? "CLICK" : "SCRIPT", "*");
     61    await promise;
     62    testWin.close();
     63  });
     64 });
     65 </script>
     66 </head>
     67 <body>
     68 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1744321">Mozilla Bug 1744321</a>
     69 <p id="display"></p>
     70 <div id="content">
     71 Tests for Bug 1744321
     72 </div>
     73 </body>
     74 </html>