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/. */
6 // The purpose of this test is to ensure that Firefox sanitizes site security
7 // service data on shutdown if configured to do so.
9 ChromeUtils.defineESModuleGetters(this, {
10 Sanitizer: "resource:///modules/Sanitizer.sys.mjs",
11 TestUtils: "resource://testing-common/TestUtils.sys.mjs",
14 Sanitizer.onStartup();
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
25 add_task(async function run_test() {
27 let SSService = Cc["@mozilla.org/ssservice;1"].getService(
28 Ci.nsISiteSecurityService
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")
39 // Configure Firefox to clear this data on shutdown.
40 Services.prefs.setBoolPref(
41 Sanitizer.PREF_SHUTDOWN_BRANCH + "siteSettings",
44 Services.prefs.setBoolPref(Sanitizer.PREF_SANITIZE_ON_SHUTDOWN, true);
47 Services.startup.advanceShutdownPhase(
48 Services.startup.SHUTDOWN_PHASE_APPSHUTDOWNTEARDOWN
50 Services.startup.advanceShutdownPhase(
51 Services.startup.SHUTDOWN_PHASE_APPSHUTDOWN
54 await TestUtils.waitForCondition(() => {
55 let stateFile = do_get_profile();
56 stateFile.append(SSS_STATE_FILE_NAME);
57 return !stateFile.exists();