tor-browser

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

browser_cookiePermission_aboutURL.js (3229B)


      1 const { SiteDataTestUtils } = ChromeUtils.importESModule(
      2  "resource://testing-common/SiteDataTestUtils.sys.mjs"
      3 );
      4 
      5 // We will be removing the ["cookies","offlineApps"] option once we remove the
      6 // old clear history dialog in Bug 1856418 - Remove all old clear data dialog boxes
      7 let prefs = [["cookiesAndStorage"], ["cookies", "offlineApps"]];
      8 
      9 function checkDataForAboutURL() {
     10  return new Promise(resolve => {
     11    let data = true;
     12    let uri = Services.io.newURI("about:newtab");
     13    let principal = Services.scriptSecurityManager.createContentPrincipal(
     14      uri,
     15      {}
     16    );
     17    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
     18    request.onupgradeneeded = function () {
     19      data = false;
     20    };
     21    request.onsuccess = function () {
     22      resolve(data);
     23    };
     24  });
     25 }
     26 
     27 for (let itemsToClear of prefs) {
     28  add_task(async function deleteStorageInAboutURL() {
     29    info("Test about:newtab");
     30 
     31    // Let's clean up all the data.
     32    await new Promise(resolve => {
     33      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
     34    });
     35 
     36    await SpecialPowers.pushPrefEnv({
     37      set: [["browser.sanitizer.loglevel", "All"]],
     38    });
     39 
     40    // Let's create a tab with some data.
     41    await SiteDataTestUtils.addToIndexedDB("about:newtab", "foo", "bar", {});
     42 
     43    ok(await checkDataForAboutURL(), "We have data for about:newtab");
     44 
     45    // Cleaning up.
     46    await Sanitizer.runSanitizeOnShutdown();
     47 
     48    ok(await checkDataForAboutURL(), "about:newtab data is not deleted.");
     49 
     50    // Clean up.
     51    await Sanitizer.sanitize(itemsToClear);
     52 
     53    let principal =
     54      Services.scriptSecurityManager.createContentPrincipalFromOrigin(
     55        "about:newtab"
     56      );
     57    await new Promise(aResolve => {
     58      let req = Services.qms.clearStoragesForPrincipal(principal);
     59      req.callback = () => {
     60        aResolve();
     61      };
     62    });
     63  });
     64 
     65  add_task(async function deleteStorageOnlyCustomPermissionInAboutURL() {
     66    info("Test about:newtab + permissions");
     67 
     68    // Let's clean up all the data.
     69    await new Promise(resolve => {
     70      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
     71    });
     72 
     73    await SpecialPowers.pushPrefEnv({
     74      set: [["browser.sanitizer.loglevel", "All"]],
     75    });
     76 
     77    // Custom permission without considering OriginAttributes
     78    let uri = Services.io.newURI("about:newtab");
     79    PermissionTestUtils.add(
     80      uri,
     81      "cookie",
     82      Ci.nsICookiePermission.ACCESS_SESSION
     83    );
     84 
     85    // Let's create a tab with some data.
     86    await SiteDataTestUtils.addToIndexedDB("about:newtab", "foo", "bar", {});
     87 
     88    ok(await checkDataForAboutURL(), "We have data for about:newtab");
     89 
     90    // Cleaning up.
     91    await Sanitizer.runSanitizeOnShutdown();
     92 
     93    ok(await checkDataForAboutURL(), "about:newtab data is not deleted.");
     94 
     95    // Clean up.
     96    await Sanitizer.sanitize(itemsToClear);
     97 
     98    let principal =
     99      Services.scriptSecurityManager.createContentPrincipalFromOrigin(
    100        "about:newtab"
    101      );
    102    await new Promise(aResolve => {
    103      let req = Services.qms.clearStoragesForPrincipal(principal);
    104      req.callback = () => {
    105        aResolve();
    106      };
    107    });
    108 
    109    PermissionTestUtils.remove(uri, "cookie");
    110  });
    111 }