tor-browser

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

browser_sanitize-history.js (3703B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests that sanitizing history will clear storage access permissions
      5 // for sites without cookies or site data.
      6 add_task(async function sanitizeStorageAccessPermissions() {
      7  let categories = ["history", "browsingHistoryAndDownloads"];
      8 
      9  for (let pref of categories) {
     10    await SiteDataTestUtils.addToIndexedDB("https://sub.example.org");
     11    await SiteDataTestUtils.addToCookies({ origin: "https://example.com" });
     12 
     13    PermissionTestUtils.add(
     14      "https://example.org",
     15      "storageAccessAPI",
     16      Services.perms.ALLOW_ACTION
     17    );
     18    PermissionTestUtils.add(
     19      "https://example.com",
     20      "storageAccessAPI",
     21      Services.perms.ALLOW_ACTION
     22    );
     23    PermissionTestUtils.add(
     24      "http://mochi.test",
     25      "storageAccessAPI",
     26      Services.perms.ALLOW_ACTION
     27    );
     28 
     29    // Add some time in between taking the snapshot of the timestamp
     30    // to avoid flakyness.
     31    // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     32    await new Promise(c => setTimeout(c, 100));
     33    let timestamp = Date.now();
     34    // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     35    await new Promise(c => setTimeout(c, 100));
     36 
     37    PermissionTestUtils.add(
     38      "http://example.net",
     39      "storageAccessAPI",
     40      Services.perms.ALLOW_ACTION
     41    );
     42 
     43    await Sanitizer.sanitize([pref], {
     44      // Sanitizer and ClearDataService work with time range in PRTime (microseconds)
     45      range: [timestamp * 1000, Date.now() * 1000],
     46    });
     47 
     48    Assert.equal(
     49      PermissionTestUtils.testExactPermission(
     50        "http://example.net",
     51        "storageAccessAPI"
     52      ),
     53      Services.perms.UNKNOWN_ACTION
     54    );
     55    Assert.equal(
     56      PermissionTestUtils.testExactPermission(
     57        "http://mochi.test",
     58        "storageAccessAPI"
     59      ),
     60      Services.perms.ALLOW_ACTION
     61    );
     62    Assert.equal(
     63      PermissionTestUtils.testExactPermission(
     64        "https://example.com",
     65        "storageAccessAPI"
     66      ),
     67      Services.perms.ALLOW_ACTION
     68    );
     69    Assert.equal(
     70      PermissionTestUtils.testExactPermission(
     71        "https://example.org",
     72        "storageAccessAPI"
     73      ),
     74      Services.perms.ALLOW_ACTION
     75    );
     76 
     77    await Sanitizer.sanitize([pref]);
     78 
     79    Assert.equal(
     80      PermissionTestUtils.testExactPermission(
     81        "http://mochi.test",
     82        "storageAccessAPI"
     83      ),
     84      Services.perms.UNKNOWN_ACTION
     85    );
     86    Assert.equal(
     87      PermissionTestUtils.testExactPermission(
     88        "http://example.net",
     89        "storageAccessAPI"
     90      ),
     91      Services.perms.UNKNOWN_ACTION
     92    );
     93    Assert.equal(
     94      PermissionTestUtils.testExactPermission(
     95        "https://example.com",
     96        "storageAccessAPI"
     97      ),
     98      Services.perms.ALLOW_ACTION
     99    );
    100    Assert.equal(
    101      PermissionTestUtils.testExactPermission(
    102        "https://example.org",
    103        "storageAccessAPI"
    104      ),
    105      Services.perms.ALLOW_ACTION
    106    );
    107 
    108    await Sanitizer.sanitize([pref, "siteSettings"]);
    109 
    110    Assert.equal(
    111      PermissionTestUtils.testExactPermission(
    112        "http://mochi.test",
    113        "storageAccessAPI"
    114      ),
    115      Services.perms.UNKNOWN_ACTION
    116    );
    117    Assert.equal(
    118      PermissionTestUtils.testExactPermission(
    119        "https://example.com",
    120        "storageAccessAPI"
    121      ),
    122      Services.perms.UNKNOWN_ACTION
    123    );
    124    Assert.equal(
    125      PermissionTestUtils.testExactPermission(
    126        "https://example.org",
    127        "storageAccessAPI"
    128      ),
    129      Services.perms.UNKNOWN_ACTION
    130    );
    131 
    132    await new Promise(resolve => {
    133      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
    134    });
    135  }
    136 });