diff options
Diffstat (limited to 'browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js')
-rw-r--r-- | browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js b/browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js new file mode 100644 index 0000000000..29f4ae3fe8 --- /dev/null +++ b/browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js @@ -0,0 +1,102 @@ +const { Sanitizer } = ChromeUtils.importESModule( + "resource:///modules/Sanitizer.sys.mjs" +); +const { SiteDataTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/SiteDataTestUtils.sys.mjs" +); + +function checkDataForAboutURL() { + return new Promise(resolve => { + let data = true; + let uri = Services.io.newURI("about:newtab"); + let principal = Services.scriptSecurityManager.createContentPrincipal( + uri, + {} + ); + let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1); + request.onupgradeneeded = function(e) { + data = false; + }; + request.onsuccess = function(e) { + resolve(data); + }; + }); +} + +add_task(async function deleteStorageInAboutURL() { + info("Test about:newtab"); + + // Let's clean up all the data. + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); + }); + + await SpecialPowers.pushPrefEnv({ + set: [["browser.sanitizer.loglevel", "All"]], + }); + + // Let's create a tab with some data. + await SiteDataTestUtils.addToIndexedDB("about:newtab", "foo", "bar", {}); + + ok(await checkDataForAboutURL(), "We have data for about:newtab"); + + // Cleaning up. + await Sanitizer.runSanitizeOnShutdown(); + + ok(await checkDataForAboutURL(), "about:newtab data is not deleted."); + + // Clean up. + await Sanitizer.sanitize(["cookies", "offlineApps"]); + + let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin( + "about:newtab" + ); + await new Promise(aResolve => { + let req = Services.qms.clearStoragesForPrincipal(principal); + req.callback = () => { + aResolve(); + }; + }); +}); + +add_task(async function deleteStorageOnlyCustomPermissionInAboutURL() { + info("Test about:newtab + permissions"); + + // Let's clean up all the data. + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); + }); + + await SpecialPowers.pushPrefEnv({ + set: [["browser.sanitizer.loglevel", "All"]], + }); + + // Custom permission without considering OriginAttributes + let uri = Services.io.newURI("about:newtab"); + PermissionTestUtils.add(uri, "cookie", Ci.nsICookiePermission.ACCESS_SESSION); + + // Let's create a tab with some data. + await SiteDataTestUtils.addToIndexedDB("about:newtab", "foo", "bar", {}); + + ok(await checkDataForAboutURL(), "We have data for about:newtab"); + + // Cleaning up. + await Sanitizer.runSanitizeOnShutdown(); + + ok(await checkDataForAboutURL(), "about:newtab data is not deleted."); + + // Clean up. + await Sanitizer.sanitize(["cookies", "offlineApps"]); + + let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin( + "about:newtab" + ); + await new Promise(aResolve => { + let req = Services.qms.clearStoragesForPrincipal(principal); + req.callback = () => { + aResolve(); + }; + }); + + PermissionTestUtils.remove(uri, "cookie"); +}); |