tor-browser

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

browser_localStorage_privatestorageevent.js (2558B)


      1 add_task(async function () {
      2  var privWin = OpenBrowserWindow({ private: true });
      3  await new privWin.Promise(resolve => {
      4    privWin.addEventListener(
      5      "load",
      6      function () {
      7        resolve();
      8      },
      9      { once: true }
     10    );
     11  });
     12 
     13  var pubWin = OpenBrowserWindow({ private: false });
     14  await new pubWin.Promise(resolve => {
     15    pubWin.addEventListener(
     16      "load",
     17      function () {
     18        resolve();
     19      },
     20      { once: true }
     21    );
     22  });
     23 
     24  var URL =
     25    "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html";
     26 
     27  var privTab = BrowserTestUtils.addTab(privWin.gBrowser, URL);
     28  await BrowserTestUtils.browserLoaded(
     29    privWin.gBrowser.getBrowserForTab(privTab)
     30  );
     31  var privBrowser = gBrowser.getBrowserForTab(privTab);
     32 
     33  var pubTab = BrowserTestUtils.addTab(pubWin.gBrowser, URL);
     34  await BrowserTestUtils.browserLoaded(
     35    pubWin.gBrowser.getBrowserForTab(pubTab)
     36  );
     37  var pubBrowser = gBrowser.getBrowserForTab(pubTab);
     38 
     39  // Check if pubWin can see privWin's storage events
     40  await SpecialPowers.spawn(pubBrowser, [], function () {
     41    content.window.gotStorageEvent = false;
     42    content.window.addEventListener("storage", () => {
     43      content.window.gotStorageEvent = true;
     44    });
     45  });
     46 
     47  await SpecialPowers.spawn(privBrowser, [], function () {
     48    content.window.localStorage.key = "ablooabloo";
     49  });
     50 
     51  let pubSaw = await SpecialPowers.spawn(pubBrowser, [], function () {
     52    return content.window.gotStorageEvent;
     53  });
     54 
     55  ok(!pubSaw, "pubWin shouldn't be able to see privWin's storage events");
     56 
     57  await SpecialPowers.spawn(privBrowser, [], function () {
     58    content.window.gotStorageEvent = false;
     59    content.window.addEventListener("storage", () => {
     60      content.window.gotStorageEvent = true;
     61    });
     62  });
     63 
     64  // Check if privWin can see pubWin's storage events
     65  await SpecialPowers.spawn(privBrowser, [], function () {
     66    content.window.gotStorageEvent = false;
     67    content.window.addEventListener("storage", () => {
     68      content.window.gotStorageEvent = true;
     69    });
     70  });
     71 
     72  await SpecialPowers.spawn(pubBrowser, [], function () {
     73    content.window.localStorage.key = "ablooabloo";
     74  });
     75 
     76  let privSaw = await SpecialPowers.spawn(privBrowser, [], function () {
     77    return content.window.gotStorageEvent;
     78  });
     79 
     80  ok(!privSaw, "privWin shouldn't be able to see pubWin's storage events");
     81 
     82  BrowserTestUtils.removeTab(privTab);
     83  await BrowserTestUtils.closeWindow(privWin);
     84 
     85  BrowserTestUtils.removeTab(pubTab);
     86  await BrowserTestUtils.closeWindow(pubWin);
     87 });