tor-browser

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

test_sss_sanitizeOnShutdown.js (2107B)


      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 "use strict";
      5 
      6 // The purpose of this test is to ensure that Firefox sanitizes site security
      7 // service data on shutdown if configured to do so.
      8 
      9 ChromeUtils.defineESModuleGetters(this, {
     10  Sanitizer: "resource:///modules/Sanitizer.sys.mjs",
     11  TestUtils: "resource://testing-common/TestUtils.sys.mjs",
     12 });
     13 
     14 Sanitizer.onStartup();
     15 
     16 // This helps us away from test timed out. If service worker manager(swm) hasn't
     17 // been initilaized before profile-change-teardown, this test would fail due to
     18 // the shutdown blocker added by swm. Normally, swm should be initialized before
     19 // that and the similar crash signatures are fixed. So, assume this cannot
     20 // happen in the real world and initilaize swm here as a workaround.
     21 Cc["@mozilla.org/serviceworkers/manager;1"].getService(
     22  Ci.nsIServiceWorkerManager
     23 );
     24 
     25 add_task(async function run_test() {
     26  do_get_profile();
     27  let SSService = Cc["@mozilla.org/ssservice;1"].getService(
     28    Ci.nsISiteSecurityService
     29  );
     30  let header = "max-age=50000";
     31  SSService.processHeader(Services.io.newURI("https://example.com"), header);
     32  await TestUtils.waitForCondition(() => {
     33    let stateFileContents = get_data_storage_contents(SSS_STATE_FILE_NAME);
     34    return stateFileContents
     35      ? stateFileContents.includes("example.com")
     36      : false;
     37  });
     38 
     39  // Configure Firefox to clear this data on shutdown.
     40  Services.prefs.setBoolPref(
     41    Sanitizer.PREF_SHUTDOWN_BRANCH + "siteSettings",
     42    true
     43  );
     44  Services.prefs.setBoolPref(Sanitizer.PREF_SANITIZE_ON_SHUTDOWN, true);
     45 
     46  // Simulate shutdown.
     47  Services.startup.advanceShutdownPhase(
     48    Services.startup.SHUTDOWN_PHASE_APPSHUTDOWNTEARDOWN
     49  );
     50  Services.startup.advanceShutdownPhase(
     51    Services.startup.SHUTDOWN_PHASE_APPSHUTDOWN
     52  );
     53 
     54  await TestUtils.waitForCondition(() => {
     55    let stateFile = do_get_profile();
     56    stateFile.append(SSS_STATE_FILE_NAME);
     57    return !stateFile.exists();
     58  });
     59 });