browser_sanitize-siteDataExceptAddons.js (2857B)
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 ChromeUtils.defineESModuleGetters(this, { 7 PermissionTestUtils: "resource://testing-common/PermissionTestUtils.sys.mjs", 8 }); 9 10 async function createAddon() { 11 let extData = { 12 manifest: { 13 name: "Test Extension", 14 permissions: ["unlimitedStorage"], 15 }, 16 files: { 17 "testpage.html": "<h1>Extension Test Page</h1>", 18 }, 19 }; 20 21 let extension = ExtensionTestUtils.loadExtension(extData); 22 await extension.startup(); 23 24 return extension; 25 } 26 27 add_setup(async function () { 28 await SpecialPowers.pushPrefEnv({ 29 set: [["privacy.sanitize.useOldClearHistoryDialog", false]], 30 }); 31 }); 32 33 async function checkAddonPermissionClearingWithPref(prefs, expectedValue) { 34 let extension = await createAddon(); 35 36 // Use the extension policy to get the principal object 37 let policy = WebExtensionPolicy.getByID(extension.id); 38 let extensionPrincipal = policy.extension.principal; 39 40 // The addon gets a persistent-storage permission because of 41 // "unlimitedStorage" being present in loadExtension 42 Assert.equal( 43 PermissionTestUtils.testExactPermission( 44 extensionPrincipal, 45 "persistent-storage" 46 ), 47 Services.perms.ALLOW_ACTION, 48 "Addon persistent permission exists" 49 ); 50 51 // Add a site permission that is expected to be cleared 52 let siteURI = Services.io.newURI("https://testdomain.org"); 53 54 PermissionTestUtils.add( 55 siteURI, 56 "persistent-storage", 57 Services.perms.ALLOW_ACTION 58 ); 59 60 // Lets clear cookies and site data 61 let clearHistoryDialog = new ClearHistoryDialogHelper(); 62 63 clearHistoryDialog.onload = function () { 64 this.checkPrefCheckbox("cookiesAndStorage", prefs.cookiesAndStorage); 65 this.checkPrefCheckbox("siteSettings", prefs.siteSettings); 66 67 this.acceptDialog(); 68 }; 69 70 clearHistoryDialog.open(); 71 await clearHistoryDialog.promiseClosed; 72 73 Assert.equal( 74 PermissionTestUtils.testExactPermission( 75 extensionPrincipal, 76 "persistent-storage" 77 ), 78 expectedValue, 79 "Addon permission persists" 80 ); 81 82 Assert.equal( 83 PermissionTestUtils.testExactPermission(siteURI, "persistent-storage"), 84 Services.perms.UNKNOWN_ACTION, 85 "Site permission removed" 86 ); 87 88 // cleanup 89 Services.perms.removeAll(); 90 await extension.unload(); 91 } 92 93 add_task(async function test_clearing_cookiesAndStorage() { 94 await checkAddonPermissionClearingWithPref( 95 { cookiesAndStorage: true, siteSettings: false }, 96 Services.perms.ALLOW_ACTION 97 ); 98 }); 99 100 add_task(async function test_clearing_siteSettings() { 101 await checkAddonPermissionClearingWithPref( 102 { cookiesAndStorage: false, siteSettings: true }, 103 Services.perms.UNKNOWN_ACTION 104 ); 105 });