tor-browser

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

browser_purgeCache_idle_daily.js (2611B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 add_task(async function test_idle_cleanup() {
      8  Services.fog.testResetFOG();
      9  Services.prefs.setBoolPref(
     10    "network.cache.shutdown_purge_in_background_task",
     11    true
     12  );
     13  Services.prefs.setBoolPref("privacy.clearOnShutdown.cache", true);
     14  Services.prefs.setBoolPref("privacy.sanitize.sanitizeOnShutdown", true);
     15  let dir = Services.dirsvc.get("ProfD", Ci.nsIFile);
     16  dir.append("cache2.2021-11-25-08-47-04.purge.bg_rm");
     17  Assert.equal(dir.exists(), false, `Folder ${dir.path} should not exist`);
     18  dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o744);
     19  Assert.equal(
     20    dir.exists(),
     21    true,
     22    `Folder ${dir.path} should have been created`
     23  );
     24 
     25  Services.obs.notifyObservers(null, "idle-daily");
     26 
     27  await TestUtils.waitForCondition(() => {
     28    return !dir.exists();
     29  });
     30 
     31  Assert.equal(
     32    dir.exists(),
     33    false,
     34    `Folder ${dir.path} should have been purged by background task`
     35  );
     36  Assert.equal(
     37    await Glean.networking.residualCacheFolderCount.testGetValue(),
     38    1
     39  );
     40  Assert.equal(
     41    await Glean.networking.residualCacheFolderRemoval.success.testGetValue(),
     42    1
     43  );
     44  Assert.equal(
     45    await Glean.networking.residualCacheFolderRemoval.failure.testGetValue(),
     46    null
     47  );
     48 
     49  // Check that telemetry properly detects folders failing to be deleted when readonly
     50  // Making folders readonly only works on windows
     51  if (AppConstants.platform == "win") {
     52    dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o744);
     53    dir.QueryInterface(Ci.nsILocalFileWin).readOnly = true;
     54 
     55    Services.obs.notifyObservers(null, "idle-daily");
     56 
     57    await BrowserTestUtils.waitForCondition(async () => {
     58      return (
     59        (await Glean.networking.residualCacheFolderRemoval.failure.testGetValue()) ==
     60        1
     61      );
     62    });
     63 
     64    Assert.equal(
     65      await Glean.networking.residualCacheFolderCount.testGetValue(),
     66      2
     67    );
     68    Assert.equal(
     69      await Glean.networking.residualCacheFolderRemoval.success.testGetValue(),
     70      1
     71    );
     72    Assert.equal(
     73      await Glean.networking.residualCacheFolderRemoval.failure.testGetValue(),
     74      1
     75    );
     76 
     77    dir.QueryInterface(Ci.nsILocalFileWin).readOnly = false;
     78    dir.remove(true);
     79  }
     80 
     81  Services.prefs.clearUserPref(
     82    "network.cache.shutdown_purge_in_background_task"
     83  );
     84  Services.prefs.clearUserPref("privacy.clearOnShutdown.cache");
     85  Services.prefs.clearUserPref("privacy.sanitize.sanitizeOnShutdown");
     86 });