tor-browser

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

test_privateWin.html (1751B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <head>
      3 <title>OPFS private window test</title>
      4 
      5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      6 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
      7 
      8 <script type="text/javascript">
      9 
     10 const contentPage = "http://mochi.test:8888/chrome/dom/fs/test/mochitest/page_blank.html";
     11 
     12 function testOnPrivateWindow(aCallback) {
     13  let mainWindow = window.browsingContext.topChromeWindow;
     14  let win = mainWindow.OpenBrowserWindow({private: true});
     15  win.addEventListener("load", function() {
     16    win.addEventListener("DOMContentLoaded", function onInnerLoad() {
     17      if (win.content.location.href == "about:privatebrowsing") {
     18        win.gBrowser.loadURI(Services.io.newURI(contentPage), {
     19           triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
     20        });
     21        return;
     22      }
     23      win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
     24      SimpleTest.executeSoon(function() { aCallback(win); });
     25    }, true);
     26  }, {capture: true, once: true});
     27 }
     28 
     29 function doTest() {
     30  testOnPrivateWindow(async function(privateWin) {
     31    try {
     32      let root = await privateWin.navigator.storage.getDirectory();
     33      ok(false, "Didn't block storage.getDirectory() in private browsing");
     34    } catch(e) {
     35      ok(true, "blocked storage.getDirectory() in private browsing");
     36      is(e.name, "SecurityError", "Threw right type error");
     37    }
     38    privateWin.close();
     39    SimpleTest.finish();
     40  });
     41 }
     42 
     43 function startTest() {
     44  SpecialPowers.pushPrefEnv({'set': [["dom.fs.enabled", true]]}, doTest);
     45 }
     46 
     47 SimpleTest.waitForExplicitFinish();
     48 
     49 </script>
     50 
     51 </head>
     52 
     53 <body onload="startTest();">
     54 
     55 </body>
     56 </html>