diff --git a/browser/base/content/test/sanitize/browser.toml b/browser/base/content/test/sanitize/browser.toml index b406b9bbb2c0..a5747b33a0d1 100644 --- a/browser/base/content/test/sanitize/browser.toml +++ b/browser/base/content/test/sanitize/browser.toml @@ -14,6 +14,8 @@ support-files = [ ["browser_cookiePermission_subDomains.js"] +["browser_cookiePermission_subDomains_v2.js"] + ["browser_purgehistory_clears_sh.js"] ["browser_sanitize-cookie-exceptions.js"] diff --git a/browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js b/browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js index 7ae8ec158e5c..ada82864377d 100644 --- a/browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js +++ b/browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js @@ -2,6 +2,10 @@ const { SiteDataTestUtils } = ChromeUtils.importESModule( "resource://testing-common/SiteDataTestUtils.sys.mjs" ); +// We will be removing the ["cookies","offlineApps"] option once we remove the +// old clear history dialog in Bug 1856418 - Remove all old clear data dialog boxes +let prefs = [["cookiesAndStorage"], ["cookies", "offlineApps"]]; + function checkDataForAboutURL() { return new Promise(resolve => { let data = true; @@ -20,82 +24,88 @@ function checkDataForAboutURL() { }); } -add_task(async function deleteStorageInAboutURL() { - info("Test about:newtab"); +for (let itemsToClear of prefs) { + 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); + // 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(itemsToClear); + + let principal = + Services.scriptSecurityManager.createContentPrincipalFromOrigin( + "about:newtab" + ); + await new Promise(aResolve => { + let req = Services.qms.clearStoragesForPrincipal(principal); + req.callback = () => { + aResolve(); + }; + }); }); - await SpecialPowers.pushPrefEnv({ - set: [["browser.sanitizer.loglevel", "All"]], - }); + add_task(async function deleteStorageOnlyCustomPermissionInAboutURL() { + info("Test about:newtab + permissions"); - // Let's create a tab with some data. - await SiteDataTestUtils.addToIndexedDB("about:newtab", "foo", "bar", {}); + // Let's clean up all the data. + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); + }); - ok(await checkDataForAboutURL(), "We have data for about:newtab"); + await SpecialPowers.pushPrefEnv({ + set: [["browser.sanitizer.loglevel", "All"]], + }); - // 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" + // Custom permission without considering OriginAttributes + let uri = Services.io.newURI("about:newtab"); + PermissionTestUtils.add( + uri, + "cookie", + Ci.nsICookiePermission.ACCESS_SESSION ); - await new Promise(aResolve => { - let req = Services.qms.clearStoragesForPrincipal(principal); - req.callback = () => { - aResolve(); - }; + + // 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(itemsToClear); + + let principal = + Services.scriptSecurityManager.createContentPrincipalFromOrigin( + "about:newtab" + ); + await new Promise(aResolve => { + let req = Services.qms.clearStoragesForPrincipal(principal); + req.callback = () => { + aResolve(); + }; + }); + + PermissionTestUtils.remove(uri, "cookie"); }); -}); - -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"); -}); +} diff --git a/browser/base/content/test/sanitize/browser_cookiePermission_subDomains_v2.js b/browser/base/content/test/sanitize/browser_cookiePermission_subDomains_v2.js new file mode 100644 index 000000000000..d1887db91b32 --- /dev/null +++ b/browser/base/content/test/sanitize/browser_cookiePermission_subDomains_v2.js @@ -0,0 +1,288 @@ +const { SiteDataTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/SiteDataTestUtils.sys.mjs" +); + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.sanitize.sanitizeOnShutdown", true], + ["privacy.clearOnShutdown.cookiesAndStorage", true], + ["privacy.clearOnShutdown.cache", false], + ["privacy.clearOnShutdown.historyAndFormData", false], + ["privacy.clearOnShutdown.downloads", false], + ["privacy.clearOnShutdown.siteSettings", false], + ["browser.sanitizer.loglevel", "All"], + ["privacy.sanitize.useOldClearHistoryDialog", false], + ], + }); +}); +// 2 domains: www.mozilla.org (session-only) mozilla.org (allowed) - after the +// cleanp, mozilla.org must have data. +add_task(async function subDomains1() { + info("Test subdomains and custom setting"); + + // Let's clean up all the data. + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); + }); + + // Domains and data + let originA = "https://www.mozilla.org"; + PermissionTestUtils.add( + originA, + "cookie", + Ci.nsICookiePermission.ACCESS_SESSION + ); + + SiteDataTestUtils.addToCookies({ origin: originA }); + await SiteDataTestUtils.addToIndexedDB(originA); + + let originB = "https://mozilla.org"; + PermissionTestUtils.add( + originB, + "cookie", + Ci.nsICookiePermission.ACCESS_ALLOW + ); + + SiteDataTestUtils.addToCookies({ origin: originB }); + await SiteDataTestUtils.addToIndexedDB(originB); + + // Check + ok(SiteDataTestUtils.hasCookies(originA), "We have cookies for " + originA); + ok( + await SiteDataTestUtils.hasIndexedDB(originA), + "We have IDB for " + originA + ); + ok(SiteDataTestUtils.hasCookies(originB), "We have cookies for " + originB); + ok( + await SiteDataTestUtils.hasIndexedDB(originB), + "We have IDB for " + originB + ); + + // Cleaning up + await Sanitizer.runSanitizeOnShutdown(); + + // Check again + ok( + !SiteDataTestUtils.hasCookies(originA), + "We should not have cookies for " + originA + ); + ok( + !(await SiteDataTestUtils.hasIndexedDB(originA)), + "We should not have IDB for " + originA + ); + ok(SiteDataTestUtils.hasCookies(originB), "We have cookies for " + originB); + ok( + await SiteDataTestUtils.hasIndexedDB(originB), + "We have IDB for " + originB + ); + + // Cleaning up permissions + PermissionTestUtils.remove(originA, "cookie"); + PermissionTestUtils.remove(originB, "cookie"); +}); + +// session only cookie life-time, 2 domains (sub.mozilla.org, www.mozilla.org), +// only the former has a cookie permission. +add_task(async function subDomains2() { + info("Test subdomains and custom setting with cookieBehavior == 2"); + + // Let's clean up all the data. + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); + }); + + // Domains and data + let originA = "https://sub.mozilla.org"; + PermissionTestUtils.add( + originA, + "cookie", + Ci.nsICookiePermission.ACCESS_ALLOW + ); + + SiteDataTestUtils.addToCookies({ origin: originA }); + await SiteDataTestUtils.addToIndexedDB(originA); + + let originB = "https://www.mozilla.org"; + + SiteDataTestUtils.addToCookies({ origin: originB }); + await SiteDataTestUtils.addToIndexedDB(originB); + + // Check + ok(SiteDataTestUtils.hasCookies(originA), "We have cookies for " + originA); + ok( + await SiteDataTestUtils.hasIndexedDB(originA), + "We have IDB for " + originA + ); + ok(SiteDataTestUtils.hasCookies(originB), "We have cookies for " + originB); + ok( + await SiteDataTestUtils.hasIndexedDB(originB), + "We have IDB for " + originB + ); + + // Cleaning up + await Sanitizer.runSanitizeOnShutdown(); + + // Check again + ok(SiteDataTestUtils.hasCookies(originA), "We have cookies for " + originA); + ok( + await SiteDataTestUtils.hasIndexedDB(originA), + "We have IDB for " + originA + ); + ok( + !SiteDataTestUtils.hasCookies(originB), + "We should not have cookies for " + originB + ); + ok( + !(await SiteDataTestUtils.hasIndexedDB(originB)), + "We should not have IDB for " + originB + ); + + // Cleaning up permissions + PermissionTestUtils.remove(originA, "cookie"); +}); + +// session only cookie life-time, 3 domains (sub.mozilla.org, www.mozilla.org, mozilla.org), +// only the former has a cookie permission. Both sub.mozilla.org and mozilla.org should +// be sustained. +add_task(async function subDomains3() { + info( + "Test base domain and subdomains and custom setting with cookieBehavior == 2" + ); + + // Let's clean up all the data. + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); + }); + + // Domains and data + let originA = "https://sub.mozilla.org"; + PermissionTestUtils.add( + originA, + "cookie", + Ci.nsICookiePermission.ACCESS_ALLOW + ); + SiteDataTestUtils.addToCookies({ origin: originA }); + await SiteDataTestUtils.addToIndexedDB(originA); + + let originB = "https://mozilla.org"; + SiteDataTestUtils.addToCookies({ origin: originB }); + await SiteDataTestUtils.addToIndexedDB(originB); + + let originC = "https://www.mozilla.org"; + SiteDataTestUtils.addToCookies({ origin: originC }); + await SiteDataTestUtils.addToIndexedDB(originC); + + // Check + ok(SiteDataTestUtils.hasCookies(originA), "We have cookies for " + originA); + ok( + await SiteDataTestUtils.hasIndexedDB(originA), + "We have IDB for " + originA + ); + ok(SiteDataTestUtils.hasCookies(originB), "We have cookies for " + originB); + ok( + await SiteDataTestUtils.hasIndexedDB(originB), + "We have IDB for " + originB + ); + ok(SiteDataTestUtils.hasCookies(originC), "We have cookies for " + originC); + ok( + await SiteDataTestUtils.hasIndexedDB(originC), + "We have IDB for " + originC + ); + + // Cleaning up + await Sanitizer.runSanitizeOnShutdown(); + + // Check again + ok(SiteDataTestUtils.hasCookies(originA), "We have cookies for " + originA); + ok( + await SiteDataTestUtils.hasIndexedDB(originA), + "We have IDB for " + originA + ); + ok(SiteDataTestUtils.hasCookies(originB), "We have cookies for " + originB); + ok( + await SiteDataTestUtils.hasIndexedDB(originB), + "We have IDB for " + originB + ); + ok( + !SiteDataTestUtils.hasCookies(originC), + "We should not have cookies for " + originC + ); + ok( + !(await SiteDataTestUtils.hasIndexedDB(originC)), + "We should not have IDB for " + originC + ); + + // Cleaning up permissions + PermissionTestUtils.remove(originA, "cookie"); +}); + +// clear on shutdown, 3 domains (sub.sub.mozilla.org, sub.mozilla.org, mozilla.org), +// only the former has a cookie permission. Both sub.mozilla.org and mozilla.org should +// be sustained due to Permission of sub.sub.mozilla.org +add_task(async function subDomains4() { + info("Test subdomain cookie permission inheritance with two subdomains"); + + // Let's clean up all the data. + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); + }); + + // Domains and data + let originA = "https://sub.sub.mozilla.org"; + PermissionTestUtils.add( + originA, + "cookie", + Ci.nsICookiePermission.ACCESS_ALLOW + ); + SiteDataTestUtils.addToCookies({ origin: originA }); + await SiteDataTestUtils.addToIndexedDB(originA); + + let originB = "https://sub.mozilla.org"; + SiteDataTestUtils.addToCookies({ origin: originB }); + await SiteDataTestUtils.addToIndexedDB(originB); + + let originC = "https://mozilla.org"; + SiteDataTestUtils.addToCookies({ origin: originC }); + await SiteDataTestUtils.addToIndexedDB(originC); + + // Check + ok(SiteDataTestUtils.hasCookies(originA), "We have cookies for " + originA); + ok( + await SiteDataTestUtils.hasIndexedDB(originA), + "We have IDB for " + originA + ); + ok(SiteDataTestUtils.hasCookies(originB), "We have cookies for " + originB); + ok( + await SiteDataTestUtils.hasIndexedDB(originB), + "We have IDB for " + originB + ); + ok(SiteDataTestUtils.hasCookies(originC), "We have cookies for " + originC); + ok( + await SiteDataTestUtils.hasIndexedDB(originC), + "We have IDB for " + originC + ); + + // Cleaning up + await Sanitizer.runSanitizeOnShutdown(); + + // Check again + ok(SiteDataTestUtils.hasCookies(originA), "We have cookies for " + originA); + ok( + await SiteDataTestUtils.hasIndexedDB(originA), + "We have IDB for " + originA + ); + ok(SiteDataTestUtils.hasCookies(originB), "We have cookies for " + originB); + ok( + await SiteDataTestUtils.hasIndexedDB(originB), + "We have IDB for " + originB + ); + ok(SiteDataTestUtils.hasCookies(originC), "We have cookies for " + originC); + ok( + await SiteDataTestUtils.hasIndexedDB(originC), + "We have IDB for " + originC + ); + + // Cleaning up permissions + PermissionTestUtils.remove(originA, "cookie"); +}); diff --git a/browser/base/content/test/sanitize/browser_purgehistory_clears_sh.js b/browser/base/content/test/sanitize/browser_purgehistory_clears_sh.js index abf11017dda4..c75946bf2bcc 100644 --- a/browser/base/content/test/sanitize/browser_purgehistory_clears_sh.js +++ b/browser/base/content/test/sanitize/browser_purgehistory_clears_sh.js @@ -4,68 +4,83 @@ const url = "https://example.org/browser/browser/base/content/test/sanitize/dummy_page.html"; -add_task(async function purgeHistoryTest() { - await BrowserTestUtils.withNewTab( - { - gBrowser, - url, - }, - async function purgeHistoryTestInner(browser) { - let backButton = browser.ownerDocument.getElementById("Browser:Back"); - let forwardButton = - browser.ownerDocument.getElementById("Browser:Forward"); +// We will be removing the ["history"] option once we remove the +// old clear history dialog in Bug 1856418 - Remove all old clear data dialog boxes +let prefs = [["history"], ["historyAndFormData"]]; - ok( - !browser.webNavigation.canGoBack, - "Initial value for webNavigation.canGoBack" - ); - ok( - !browser.webNavigation.canGoForward, - "Initial value for webNavigation.canGoBack" - ); - ok(backButton.hasAttribute("disabled"), "Back button is disabled"); - ok(forwardButton.hasAttribute("disabled"), "Forward button is disabled"); +for (let itemsToClear of prefs) { + add_task(async function purgeHistoryTest() { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url, + }, + async function purgeHistoryTestInner(browser) { + let backButton = browser.ownerDocument.getElementById("Browser:Back"); + let forwardButton = + browser.ownerDocument.getElementById("Browser:Forward"); - await SpecialPowers.spawn(browser, [], async function () { - let startHistory = content.history.length; - content.history.pushState({}, ""); - content.history.pushState({}, ""); - content.history.back(); - await new Promise(function (r) { - content.onpopstate = r; + ok( + !browser.webNavigation.canGoBack, + "Initial value for webNavigation.canGoBack" + ); + ok( + !browser.webNavigation.canGoForward, + "Initial value for webNavigation.canGoBack" + ); + ok(backButton.hasAttribute("disabled"), "Back button is disabled"); + ok( + forwardButton.hasAttribute("disabled"), + "Forward button is disabled" + ); + + await SpecialPowers.spawn(browser, [], async function () { + let startHistory = content.history.length; + content.history.pushState({}, ""); + content.history.pushState({}, ""); + content.history.back(); + await new Promise(function (r) { + content.onpopstate = r; + }); + let newHistory = content.history.length; + Assert.equal(startHistory, 1, "Initial SHistory size"); + Assert.equal(newHistory, 3, "New SHistory size"); }); - let newHistory = content.history.length; - Assert.equal(startHistory, 1, "Initial SHistory size"); - Assert.equal(newHistory, 3, "New SHistory size"); - }); - ok( - browser.webNavigation.canGoBack, - "New value for webNavigation.canGoBack" - ); - ok( - browser.webNavigation.canGoForward, - "New value for webNavigation.canGoForward" - ); - ok(!backButton.hasAttribute("disabled"), "Back button was enabled"); - ok(!forwardButton.hasAttribute("disabled"), "Forward button was enabled"); + ok( + browser.webNavigation.canGoBack, + "New value for webNavigation.canGoBack" + ); + ok( + browser.webNavigation.canGoForward, + "New value for webNavigation.canGoForward" + ); + ok(!backButton.hasAttribute("disabled"), "Back button was enabled"); + ok( + !forwardButton.hasAttribute("disabled"), + "Forward button was enabled" + ); - await Sanitizer.sanitize(["history"]); + await Sanitizer.sanitize(itemsToClear); - await SpecialPowers.spawn(browser, [], async function () { - Assert.equal(content.history.length, 1, "SHistory correctly cleared"); - }); + await SpecialPowers.spawn(browser, [], async function () { + Assert.equal(content.history.length, 1, "SHistory correctly cleared"); + }); - ok( - !browser.webNavigation.canGoBack, - "webNavigation.canGoBack correctly cleared" - ); - ok( - !browser.webNavigation.canGoForward, - "webNavigation.canGoForward correctly cleared" - ); - ok(backButton.hasAttribute("disabled"), "Back button was disabled"); - ok(forwardButton.hasAttribute("disabled"), "Forward button was disabled"); - } - ); -}); + ok( + !browser.webNavigation.canGoBack, + "webNavigation.canGoBack correctly cleared" + ); + ok( + !browser.webNavigation.canGoForward, + "webNavigation.canGoForward correctly cleared" + ); + ok(backButton.hasAttribute("disabled"), "Back button was disabled"); + ok( + forwardButton.hasAttribute("disabled"), + "Forward button was disabled" + ); + } + ); + }); +} diff --git a/browser/base/content/test/sanitize/browser_sanitize-formhistory.js b/browser/base/content/test/sanitize/browser_sanitize-formhistory.js index 5547a88d6457..903dbbfebd7e 100644 --- a/browser/base/content/test/sanitize/browser_sanitize-formhistory.js +++ b/browser/base/content/test/sanitize/browser_sanitize-formhistory.js @@ -3,26 +3,30 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ add_task(async function test() { - // This test relies on the form history being empty to start with delete - // all the items first. - // The TabContextMenu initializes its strings only on a focus or mouseover event. - // Calls focus event on the TabContextMenu early in the test. - gBrowser.selectedTab.focus(); - await FormHistory.update({ op: "remove" }); + let prefs = ["history", "historyAndFormData"]; - // Sanitize now so we can test the baseline point. - await Sanitizer.sanitize(["formdata"]); - await gFindBarPromise; - ok(!gFindBar.hasTransactions, "pre-test baseline for sanitizer"); + for (let pref of prefs) { + // This test relies on the form history being empty to start with delete + // all the items first. + // The TabContextMenu initializes its strings only on a focus or mouseover event. + // Calls focus event on the TabContextMenu early in the test. + gBrowser.selectedTab.focus(); + await FormHistory.update({ op: "remove" }); - gFindBar.getElement("findbar-textbox").value = "m"; - ok(gFindBar.hasTransactions, "formdata can be cleared after input"); + // Sanitize now so we can test the baseline point. + await Sanitizer.sanitize([pref]); + await gFindBarPromise; + ok(!gFindBar.hasTransactions, "pre-test baseline for sanitizer"); - await Sanitizer.sanitize(["formdata"]); - is( - gFindBar.getElement("findbar-textbox").value, - "", - "findBar textbox should be empty after sanitize" - ); - ok(!gFindBar.hasTransactions, "No transactions after sanitize"); + gFindBar.getElement("findbar-textbox").value = "m"; + ok(gFindBar.hasTransactions, "formdata can be cleared after input"); + + await Sanitizer.sanitize(["formdata"]); + is( + gFindBar.getElement("findbar-textbox").value, + "", + "findBar textbox should be empty after sanitize" + ); + ok(!gFindBar.hasTransactions, "No transactions after sanitize"); + } }); diff --git a/browser/base/content/test/sanitize/browser_sanitize-history.js b/browser/base/content/test/sanitize/browser_sanitize-history.js index 5ca2843174a3..c9902d27cf14 100644 --- a/browser/base/content/test/sanitize/browser_sanitize-history.js +++ b/browser/base/content/test/sanitize/browser_sanitize-history.js @@ -4,129 +4,133 @@ // Tests that sanitizing history will clear storage access permissions // for sites without cookies or site data. add_task(async function sanitizeStorageAccessPermissions() { - await new Promise(resolve => { - Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); - }); + let categories = ["history", "historyAndFormData"]; - await SiteDataTestUtils.addToIndexedDB("https://sub.example.org"); - await SiteDataTestUtils.addToCookies({ origin: "https://example.com" }); + for (let pref of categories) { + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve); + }); - PermissionTestUtils.add( - "https://example.org", - "storageAccessAPI", - Services.perms.ALLOW_ACTION - ); - PermissionTestUtils.add( - "https://example.com", - "storageAccessAPI", - Services.perms.ALLOW_ACTION - ); - PermissionTestUtils.add( - "http://mochi.test", - "storageAccessAPI", - Services.perms.ALLOW_ACTION - ); + await SiteDataTestUtils.addToIndexedDB("https://sub.example.org"); + await SiteDataTestUtils.addToCookies({ origin: "https://example.com" }); - // Add some time in between taking the snapshot of the timestamp - // to avoid flakyness. - // eslint-disable-next-line mozilla/no-arbitrary-setTimeout - await new Promise(c => setTimeout(c, 100)); - let timestamp = Date.now(); - // eslint-disable-next-line mozilla/no-arbitrary-setTimeout - await new Promise(c => setTimeout(c, 100)); + PermissionTestUtils.add( + "https://example.org", + "storageAccessAPI", + Services.perms.ALLOW_ACTION + ); + PermissionTestUtils.add( + "https://example.com", + "storageAccessAPI", + Services.perms.ALLOW_ACTION + ); + PermissionTestUtils.add( + "http://mochi.test", + "storageAccessAPI", + Services.perms.ALLOW_ACTION + ); - PermissionTestUtils.add( - "http://example.net", - "storageAccessAPI", - Services.perms.ALLOW_ACTION - ); + // Add some time in between taking the snapshot of the timestamp + // to avoid flakyness. + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(c => setTimeout(c, 100)); + let timestamp = Date.now(); + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(c => setTimeout(c, 100)); - await Sanitizer.sanitize(["history"], { - // Sanitizer and ClearDataService work with time range in PRTime (microseconds) - range: [timestamp * 1000, Date.now() * 1000], - }); - - Assert.equal( - PermissionTestUtils.testExactPermission( + PermissionTestUtils.add( "http://example.net", - "storageAccessAPI" - ), - Services.perms.UNKNOWN_ACTION - ); - Assert.equal( - PermissionTestUtils.testExactPermission( - "http://mochi.test", - "storageAccessAPI" - ), - Services.perms.ALLOW_ACTION - ); - Assert.equal( - PermissionTestUtils.testExactPermission( - "https://example.com", - "storageAccessAPI" - ), - Services.perms.ALLOW_ACTION - ); - Assert.equal( - PermissionTestUtils.testExactPermission( - "https://example.org", - "storageAccessAPI" - ), - Services.perms.ALLOW_ACTION - ); + "storageAccessAPI", + Services.perms.ALLOW_ACTION + ); - await Sanitizer.sanitize(["history"]); + await Sanitizer.sanitize([pref], { + // Sanitizer and ClearDataService work with time range in PRTime (microseconds) + range: [timestamp * 1000, Date.now() * 1000], + }); - Assert.equal( - PermissionTestUtils.testExactPermission( - "http://mochi.test", - "storageAccessAPI" - ), - Services.perms.UNKNOWN_ACTION - ); - Assert.equal( - PermissionTestUtils.testExactPermission( - "http://example.net", - "storageAccessAPI" - ), - Services.perms.UNKNOWN_ACTION - ); - Assert.equal( - PermissionTestUtils.testExactPermission( - "https://example.com", - "storageAccessAPI" - ), - Services.perms.ALLOW_ACTION - ); - Assert.equal( - PermissionTestUtils.testExactPermission( - "https://example.org", - "storageAccessAPI" - ), - Services.perms.ALLOW_ACTION - ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "http://example.net", + "storageAccessAPI" + ), + Services.perms.UNKNOWN_ACTION + ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "http://mochi.test", + "storageAccessAPI" + ), + Services.perms.ALLOW_ACTION + ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "https://example.com", + "storageAccessAPI" + ), + Services.perms.ALLOW_ACTION + ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "https://example.org", + "storageAccessAPI" + ), + Services.perms.ALLOW_ACTION + ); - await Sanitizer.sanitize(["history", "siteSettings"]); + await Sanitizer.sanitize([pref]); - Assert.equal( - PermissionTestUtils.testExactPermission( - "http://mochi.test", - "storageAccessAPI" - ), - Services.perms.UNKNOWN_ACTION - ); - Assert.equal( - PermissionTestUtils.testExactPermission( - "https://example.com", - "storageAccessAPI" - ), - Services.perms.UNKNOWN_ACTION - ); - Assert.equal( - PermissionTestUtils.testExactPermission( - "https://example.org", - "storageAccessAPI" - ), - Services.perms.UNKNOWN_ACTION - ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "http://mochi.test", + "storageAccessAPI" + ), + Services.perms.UNKNOWN_ACTION + ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "http://example.net", + "storageAccessAPI" + ), + Services.perms.UNKNOWN_ACTION + ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "https://example.com", + "storageAccessAPI" + ), + Services.perms.ALLOW_ACTION + ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "https://example.org", + "storageAccessAPI" + ), + Services.perms.ALLOW_ACTION + ); + + await Sanitizer.sanitize([pref, "siteSettings"]); + + Assert.equal( + PermissionTestUtils.testExactPermission( + "http://mochi.test", + "storageAccessAPI" + ), + Services.perms.UNKNOWN_ACTION + ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "https://example.com", + "storageAccessAPI" + ), + Services.perms.UNKNOWN_ACTION + ); + Assert.equal( + PermissionTestUtils.testExactPermission( + "https://example.org", + "storageAccessAPI" + ), + Services.perms.UNKNOWN_ACTION + ); + } }); diff --git a/browser/base/content/test/sanitize/browser_sanitize-offlineData.js b/browser/base/content/test/sanitize/browser_sanitize-offlineData.js index 19c9d2dc3203..8f75de0e31db 100644 --- a/browser/base/content/test/sanitize/browser_sanitize-offlineData.js +++ b/browser/base/content/test/sanitize/browser_sanitize-offlineData.js @@ -26,8 +26,6 @@ XPCOMUtils.defineLazyServiceGetter( const oneHour = 3600000000; const fiveHours = oneHour * 5; -const itemsToClear = ["cookies", "offlineApps"]; - function waitForUnregister(host) { return new Promise(resolve => { let listener = { @@ -54,192 +52,198 @@ function moveOriginInTime(principals, endDate, host) { return false; } -add_task(async function testWithRange() { - // We have intermittent occurrences of NS_ERROR_ABORT being - // thrown at closing database instances when using Santizer.sanitize(). - // This does not seem to impact cleanup, since our tests run fine anyway. - PromiseTestUtils.allowMatchingRejectionsGlobally(/NS_ERROR_ABORT/); +// We will be removing the ["cookies","offlineApps"] option once we remove the +// old clear history dialog in Bug 1856418 - Remove all old clear data dialog boxes +let prefs = [["cookiesAndStorage"], ["cookies", "offlineApps"]]; - await SpecialPowers.pushPrefEnv({ - set: [ - ["dom.serviceWorkers.enabled", true], - ["dom.serviceWorkers.exemptFromPerDomainMax", true], - ["dom.serviceWorkers.testing.enabled", true], - ], - }); +for (let itemsToClear of prefs) { + add_task(async function testWithRange() { + // We have intermittent occurrences of NS_ERROR_ABORT being + // thrown at closing database instances when using Santizer.sanitize(). + // This does not seem to impact cleanup, since our tests run fine anyway. + PromiseTestUtils.allowMatchingRejectionsGlobally(/NS_ERROR_ABORT/); - // The service may have picked up activity from prior tests in this run. - // Clear it. - sas.testOnlyReset(); + await SpecialPowers.pushPrefEnv({ + set: [ + ["dom.serviceWorkers.enabled", true], + ["dom.serviceWorkers.exemptFromPerDomainMax", true], + ["dom.serviceWorkers.testing.enabled", true], + ], + }); - let endDate = Date.now() * 1000; - let principals = sas.getActiveOrigins(endDate - oneHour, endDate); - is(principals.length, 0, "starting from clear activity state"); + // The service may have picked up activity from prior tests in this run. + // Clear it. + sas.testOnlyReset(); - info("sanitize: " + itemsToClear.join(", ")); - await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); + let endDate = Date.now() * 1000; + let principals = sas.getActiveOrigins(endDate - oneHour, endDate); + is(principals.length, 0, "starting from clear activity state"); - await createDummyDataForHost("example.org"); - await createDummyDataForHost("example.com"); + info("sanitize: " + itemsToClear.join(", ")); + await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); - endDate = Date.now() * 1000; - principals = sas.getActiveOrigins(endDate - oneHour, endDate); - ok(!!principals, "We have an active origin."); - ok(principals.length >= 2, "We have an active origin."); + await createDummyDataForHost("example.org"); + await createDummyDataForHost("example.com"); - let found = 0; - for (let i = 0; i < principals.length; ++i) { - let principal = principals.queryElementAt(i, Ci.nsIPrincipal); - if (principal.host == "example.org" || principal.host == "example.com") { - found++; + endDate = Date.now() * 1000; + principals = sas.getActiveOrigins(endDate - oneHour, endDate); + ok(!!principals, "We have an active origin."); + ok(principals.length >= 2, "We have an active origin."); + + let found = 0; + for (let i = 0; i < principals.length; ++i) { + let principal = principals.queryElementAt(i, Ci.nsIPrincipal); + if (principal.host == "example.org" || principal.host == "example.com") { + found++; + } } - } - is(found, 2, "Our origins are active."); + is(found, 2, "Our origins are active."); - ok( - await SiteDataTestUtils.hasIndexedDB("https://example.org"), - "We have indexedDB data for example.org" - ); - ok( - SiteDataTestUtils.hasServiceWorkers("https://example.org"), - "We have serviceWorker data for example.org" - ); + ok( + await SiteDataTestUtils.hasIndexedDB("https://example.org"), + "We have indexedDB data for example.org" + ); + ok( + SiteDataTestUtils.hasServiceWorkers("https://example.org"), + "We have serviceWorker data for example.org" + ); - ok( - await SiteDataTestUtils.hasIndexedDB("https://example.com"), - "We have indexedDB data for example.com" - ); - ok( - SiteDataTestUtils.hasServiceWorkers("https://example.com"), - "We have serviceWorker data for example.com" - ); + ok( + await SiteDataTestUtils.hasIndexedDB("https://example.com"), + "We have indexedDB data for example.com" + ); + ok( + SiteDataTestUtils.hasServiceWorkers("https://example.com"), + "We have serviceWorker data for example.com" + ); - // Let's move example.com in the past. - ok( - moveOriginInTime(principals, endDate, "example.com"), - "Operation completed!" - ); + // Let's move example.com in the past. + ok( + moveOriginInTime(principals, endDate, "example.com"), + "Operation completed!" + ); - let p = waitForUnregister("example.org"); + let p = waitForUnregister("example.org"); - // Clear it - info("sanitize: " + itemsToClear.join(", ")); - await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); - await p; + // Clear it + info("sanitize: " + itemsToClear.join(", ")); + await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); + await p; - ok( - !(await SiteDataTestUtils.hasIndexedDB("https://example.org")), - "We don't have indexedDB data for example.org" - ); - ok( - !SiteDataTestUtils.hasServiceWorkers("https://example.org"), - "We don't have serviceWorker data for example.org" - ); + ok( + !(await SiteDataTestUtils.hasIndexedDB("https://example.org")), + "We don't have indexedDB data for example.org" + ); + ok( + !SiteDataTestUtils.hasServiceWorkers("https://example.org"), + "We don't have serviceWorker data for example.org" + ); - ok( - await SiteDataTestUtils.hasIndexedDB("https://example.com"), - "We still have indexedDB data for example.com" - ); - ok( - SiteDataTestUtils.hasServiceWorkers("https://example.com"), - "We still have serviceWorker data for example.com" - ); + ok( + await SiteDataTestUtils.hasIndexedDB("https://example.com"), + "We still have indexedDB data for example.com" + ); + ok( + SiteDataTestUtils.hasServiceWorkers("https://example.com"), + "We still have serviceWorker data for example.com" + ); - // We have to move example.com in the past because how we check IDB triggers - // a storage activity. - ok( - moveOriginInTime(principals, endDate, "example.com"), - "Operation completed!" - ); + // We have to move example.com in the past because how we check IDB triggers + // a storage activity. + ok( + moveOriginInTime(principals, endDate, "example.com"), + "Operation completed!" + ); - // Let's call the clean up again. - info("sanitize again to ensure clearing doesn't expand the activity scope"); - await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); + // Let's call the clean up again. + info("sanitize again to ensure clearing doesn't expand the activity scope"); + await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); - ok( - await SiteDataTestUtils.hasIndexedDB("https://example.com"), - "We still have indexedDB data for example.com" - ); - ok( - SiteDataTestUtils.hasServiceWorkers("https://example.com"), - "We still have serviceWorker data for example.com" - ); + ok( + await SiteDataTestUtils.hasIndexedDB("https://example.com"), + "We still have indexedDB data for example.com" + ); + ok( + SiteDataTestUtils.hasServiceWorkers("https://example.com"), + "We still have serviceWorker data for example.com" + ); - ok( - !(await SiteDataTestUtils.hasIndexedDB("https://example.org")), - "We don't have indexedDB data for example.org" - ); - ok( - !SiteDataTestUtils.hasServiceWorkers("https://example.org"), - "We don't have serviceWorker data for example.org" - ); + ok( + !(await SiteDataTestUtils.hasIndexedDB("https://example.org")), + "We don't have indexedDB data for example.org" + ); + ok( + !SiteDataTestUtils.hasServiceWorkers("https://example.org"), + "We don't have serviceWorker data for example.org" + ); - sas.testOnlyReset(); + sas.testOnlyReset(); - // Clean up. - await SiteDataTestUtils.clear(); -}); - -add_task(async function testExceptionsOnShutdown() { - await createDummyDataForHost("example.org"); - await createDummyDataForHost("example.com"); - - // Set exception for example.org to not get cleaned - let originALLOW = "https://example.org"; - PermissionTestUtils.add( - originALLOW, - "cookie", - Ci.nsICookiePermission.ACCESS_ALLOW - ); - - ok( - await SiteDataTestUtils.hasIndexedDB("https://example.org"), - "We have indexedDB data for example.org" - ); - ok( - SiteDataTestUtils.hasServiceWorkers("https://example.org"), - "We have serviceWorker data for example.org" - ); - - ok( - await SiteDataTestUtils.hasIndexedDB("https://example.com"), - "We have indexedDB data for example.com" - ); - ok( - SiteDataTestUtils.hasServiceWorkers("https://example.com"), - "We have serviceWorker data for example.com" - ); - - await SpecialPowers.pushPrefEnv({ - set: [ - ["browser.sanitizer.loglevel", "All"], - ["privacy.clearOnShutdown.offlineApps", true], - ["privacy.sanitize.sanitizeOnShutdown", true], - ], + // Clean up. + await SiteDataTestUtils.clear(); }); - // Clear it - await Sanitizer.runSanitizeOnShutdown(); - // Data for example.org should not have been cleared - ok( - await SiteDataTestUtils.hasIndexedDB("https://example.org"), - "We still have indexedDB data for example.org" - ); - ok( - SiteDataTestUtils.hasServiceWorkers("https://example.org"), - "We still have serviceWorker data for example.org" - ); - // Data for example.com should be cleared - ok( - !(await SiteDataTestUtils.hasIndexedDB("https://example.com")), - "We don't have indexedDB data for example.com" - ); - ok( - !SiteDataTestUtils.hasServiceWorkers("https://example.com"), - "We don't have serviceWorker data for example.com" - ); - // Clean up - await SiteDataTestUtils.clear(); - Services.perms.removeAll(); -}); + add_task(async function testExceptionsOnShutdown() { + await createDummyDataForHost("example.org"); + await createDummyDataForHost("example.com"); + + // Set exception for example.org to not get cleaned + let originALLOW = "https://example.org"; + PermissionTestUtils.add( + originALLOW, + "cookie", + Ci.nsICookiePermission.ACCESS_ALLOW + ); + + ok( + await SiteDataTestUtils.hasIndexedDB("https://example.org"), + "We have indexedDB data for example.org" + ); + ok( + SiteDataTestUtils.hasServiceWorkers("https://example.org"), + "We have serviceWorker data for example.org" + ); + + ok( + await SiteDataTestUtils.hasIndexedDB("https://example.com"), + "We have indexedDB data for example.com" + ); + ok( + SiteDataTestUtils.hasServiceWorkers("https://example.com"), + "We have serviceWorker data for example.com" + ); + + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.sanitizer.loglevel", "All"], + ["privacy.clearOnShutdown.offlineApps", true], + ["privacy.sanitize.sanitizeOnShutdown", true], + ], + }); + // Clear it + await Sanitizer.runSanitizeOnShutdown(); + // Data for example.org should not have been cleared + ok( + await SiteDataTestUtils.hasIndexedDB("https://example.org"), + "We still have indexedDB data for example.org" + ); + ok( + SiteDataTestUtils.hasServiceWorkers("https://example.org"), + "We still have serviceWorker data for example.org" + ); + // Data for example.com should be cleared + ok( + !(await SiteDataTestUtils.hasIndexedDB("https://example.com")), + "We don't have indexedDB data for example.com" + ); + ok( + !SiteDataTestUtils.hasServiceWorkers("https://example.com"), + "We don't have serviceWorker data for example.com" + ); + + // Clean up + await SiteDataTestUtils.clear(); + Services.perms.removeAll(); + }); +} diff --git a/browser/base/content/test/sanitize/browser_sanitize-timespans_v2.js b/browser/base/content/test/sanitize/browser_sanitize-timespans_v2.js new file mode 100644 index 000000000000..c732262a1a21 --- /dev/null +++ b/browser/base/content/test/sanitize/browser_sanitize-timespans_v2.js @@ -0,0 +1,1190 @@ +requestLongerTimeout(2); + +const { PlacesTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PlacesTestUtils.sys.mjs" +); + +// Bug 453440 - Test the timespan-based logic of the sanitizer code +var now_mSec = Date.now(); +var now_uSec = now_mSec * 1000; + +const kMsecPerMin = 60 * 1000; +const kUsecPerMin = 60 * 1000000; + +function promiseFormHistoryRemoved() { + return new Promise(resolve => { + Services.obs.addObserver(function onfh() { + Services.obs.removeObserver(onfh, "satchel-storage-changed"); + resolve(); + }, "satchel-storage-changed"); + }); +} + +function promiseDownloadRemoved(list) { + return new Promise(resolve => { + let view = { + onDownloadRemoved(download) { + list.removeView(view); + resolve(); + }, + }; + + list.addView(view); + }); +} + +add_task(async function test() { + await setupDownloads(); + await setupFormHistory(); + await setupHistory(); + await onHistoryReady(); +}); + +async function countEntries(name, message, check) { + var obj = {}; + if (name !== null) { + obj.fieldname = name; + } + let count = await FormHistory.count(obj); + check(count, message); +} + +async function onHistoryReady() { + var hoursSinceMidnight = new Date().getHours(); + var minutesSinceMidnight = hoursSinceMidnight * 60 + new Date().getMinutes(); + + // Should test cookies here, but nsICookieManager/nsICookieService + // doesn't let us fake creation times. bug 463127 + + await SpecialPowers.pushPrefEnv({ + set: [["privacy.sanitize.useOldClearHistoryDialog", false]], + }); + + let itemsToClear = ["historyAndFormData", "downloads"]; + + let publicList = await Downloads.getList(Downloads.PUBLIC); + let downloadPromise = promiseDownloadRemoved(publicList); + let formHistoryPromise = promiseFormHistoryRemoved(); + + // Clear 10 minutes ago + let range = [now_uSec - 10 * 60 * 1000000, now_uSec]; + await Sanitizer.sanitize(itemsToClear, { range, ignoreTimespan: false }); + + await formHistoryPromise; + await downloadPromise; + + ok( + !(await PlacesUtils.history.hasVisits("https://10minutes.com")), + "Pretend visit to 10minutes.com should now be deleted" + ); + ok( + await PlacesUtils.history.hasVisits("https://1hour.com"), + "Pretend visit to 1hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://1hour10minutes.com"), + "Pretend visit to 1hour10minutes.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://2hour.com"), + "Pretend visit to 2hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://2hour10minutes.com"), + "Pretend visit to 2hour10minutes.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour.com"), + "Pretend visit to 4hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour10minutes.com"), + "Pretend visit to 4hour10minutes.com should should still exist" + ); + if (minutesSinceMidnight > 10) { + ok( + await PlacesUtils.history.hasVisits("https://today.com"), + "Pretend visit to today.com should still exist" + ); + } + ok( + await PlacesUtils.history.hasVisits("https://before-today.com"), + "Pretend visit to before-today.com should still exist" + ); + + let checkZero = function (num, message) { + is(num, 0, message); + }; + let checkOne = function (num, message) { + is(num, 1, message); + }; + + await countEntries( + "10minutes", + "10minutes form entry should be deleted", + checkZero + ); + await countEntries("1hour", "1hour form entry should still exist", checkOne); + await countEntries( + "1hour10minutes", + "1hour10minutes form entry should still exist", + checkOne + ); + await countEntries("2hour", "2hour form entry should still exist", checkOne); + await countEntries( + "2hour10minutes", + "2hour10minutes form entry should still exist", + checkOne + ); + await countEntries("4hour", "4hour form entry should still exist", checkOne); + await countEntries( + "4hour10minutes", + "4hour10minutes form entry should still exist", + checkOne + ); + if (minutesSinceMidnight > 10) { + await countEntries( + "today", + "today form entry should still exist", + checkOne + ); + } + await countEntries( + "b4today", + "b4today form entry should still exist", + checkOne + ); + + ok( + !(await downloadExists(publicList, "fakefile-10-minutes")), + "10 minute download should now be deleted" + ); + ok( + await downloadExists(publicList, "fakefile-1-hour"), + "<1 hour download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-1-hour-10-minutes"), + "1 hour 10 minute download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-old"), + "Year old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour"), + "<2 hour old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour-10-minutes"), + "2 hour 10 minute download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour"), + "<4 hour old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour-10-minutes"), + "4 hour 10 minute download should still be present" + ); + + if (minutesSinceMidnight > 10) { + ok( + await downloadExists(publicList, "fakefile-today"), + "'Today' download should still be present" + ); + } + + downloadPromise = promiseDownloadRemoved(publicList); + formHistoryPromise = promiseFormHistoryRemoved(); + + // Clear 1 hour + Services.prefs.setIntPref(Sanitizer.PREF_TIMESPAN, 1); + await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); + + await formHistoryPromise; + await downloadPromise; + + ok( + !(await PlacesUtils.history.hasVisits("https://1hour.com")), + "Pretend visit to 1hour.com should now be deleted" + ); + ok( + await PlacesUtils.history.hasVisits("https://1hour10minutes.com"), + "Pretend visit to 1hour10minutes.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://2hour.com"), + "Pretend visit to 2hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://2hour10minutes.com"), + "Pretend visit to 2hour10minutes.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour.com"), + "Pretend visit to 4hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour10minutes.com"), + "Pretend visit to 4hour10minutes.com should should still exist" + ); + if (hoursSinceMidnight > 1) { + ok( + await PlacesUtils.history.hasVisits("https://today.com"), + "Pretend visit to today.com should still exist" + ); + } + ok( + await PlacesUtils.history.hasVisits("https://before-today.com"), + "Pretend visit to before-today.com should still exist" + ); + + await countEntries("1hour", "1hour form entry should be deleted", checkZero); + await countEntries( + "1hour10minutes", + "1hour10minutes form entry should still exist", + checkOne + ); + await countEntries("2hour", "2hour form entry should still exist", checkOne); + await countEntries( + "2hour10minutes", + "2hour10minutes form entry should still exist", + checkOne + ); + await countEntries("4hour", "4hour form entry should still exist", checkOne); + await countEntries( + "4hour10minutes", + "4hour10minutes form entry should still exist", + checkOne + ); + if (hoursSinceMidnight > 1) { + await countEntries( + "today", + "today form entry should still exist", + checkOne + ); + } + await countEntries( + "b4today", + "b4today form entry should still exist", + checkOne + ); + + ok( + !(await downloadExists(publicList, "fakefile-1-hour")), + "<1 hour download should now be deleted" + ); + ok( + await downloadExists(publicList, "fakefile-1-hour-10-minutes"), + "1 hour 10 minute download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-old"), + "Year old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour"), + "<2 hour old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour-10-minutes"), + "2 hour 10 minute download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour"), + "<4 hour old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour-10-minutes"), + "4 hour 10 minute download should still be present" + ); + + if (hoursSinceMidnight > 1) { + ok( + await downloadExists(publicList, "fakefile-today"), + "'Today' download should still be present" + ); + } + + downloadPromise = promiseDownloadRemoved(publicList); + formHistoryPromise = promiseFormHistoryRemoved(); + + // Clear 1 hour 10 minutes + range = [now_uSec - 70 * 60 * 1000000, now_uSec]; + await Sanitizer.sanitize(itemsToClear, { range, ignoreTimespan: false }); + + await formHistoryPromise; + await downloadPromise; + + ok( + !(await PlacesUtils.history.hasVisits("https://1hour10minutes.com")), + "Pretend visit to 1hour10minutes.com should now be deleted" + ); + ok( + await PlacesUtils.history.hasVisits("https://2hour.com"), + "Pretend visit to 2hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://2hour10minutes.com"), + "Pretend visit to 2hour10minutes.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour.com"), + "Pretend visit to 4hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour10minutes.com"), + "Pretend visit to 4hour10minutes.com should should still exist" + ); + if (minutesSinceMidnight > 70) { + ok( + await PlacesUtils.history.hasVisits("https://today.com"), + "Pretend visit to today.com should still exist" + ); + } + ok( + await PlacesUtils.history.hasVisits("https://before-today.com"), + "Pretend visit to before-today.com should still exist" + ); + + await countEntries( + "1hour10minutes", + "1hour10minutes form entry should be deleted", + checkZero + ); + await countEntries("2hour", "2hour form entry should still exist", checkOne); + await countEntries( + "2hour10minutes", + "2hour10minutes form entry should still exist", + checkOne + ); + await countEntries("4hour", "4hour form entry should still exist", checkOne); + await countEntries( + "4hour10minutes", + "4hour10minutes form entry should still exist", + checkOne + ); + if (minutesSinceMidnight > 70) { + await countEntries( + "today", + "today form entry should still exist", + checkOne + ); + } + await countEntries( + "b4today", + "b4today form entry should still exist", + checkOne + ); + + ok( + !(await downloadExists(publicList, "fakefile-1-hour-10-minutes")), + "1 hour 10 minute old download should now be deleted" + ); + ok( + await downloadExists(publicList, "fakefile-old"), + "Year old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour"), + "<2 hour old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour-10-minutes"), + "2 hour 10 minute download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour"), + "<4 hour old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour-10-minutes"), + "4 hour 10 minute download should still be present" + ); + if (minutesSinceMidnight > 70) { + ok( + await downloadExists(publicList, "fakefile-today"), + "'Today' download should still be present" + ); + } + + downloadPromise = promiseDownloadRemoved(publicList); + formHistoryPromise = promiseFormHistoryRemoved(); + + // Clear 2 hours + Services.prefs.setIntPref(Sanitizer.PREF_TIMESPAN, 2); + await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); + + await formHistoryPromise; + await downloadPromise; + + ok( + !(await PlacesUtils.history.hasVisits("https://2hour.com")), + "Pretend visit to 2hour.com should now be deleted" + ); + ok( + await PlacesUtils.history.hasVisits("https://2hour10minutes.com"), + "Pretend visit to 2hour10minutes.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour.com"), + "Pretend visit to 4hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour10minutes.com"), + "Pretend visit to 4hour10minutes.com should should still exist" + ); + if (hoursSinceMidnight > 2) { + ok( + await PlacesUtils.history.hasVisits("https://today.com"), + "Pretend visit to today.com should still exist" + ); + } + ok( + await PlacesUtils.history.hasVisits("https://before-today.com"), + "Pretend visit to before-today.com should still exist" + ); + + await countEntries("2hour", "2hour form entry should be deleted", checkZero); + await countEntries( + "2hour10minutes", + "2hour10minutes form entry should still exist", + checkOne + ); + await countEntries("4hour", "4hour form entry should still exist", checkOne); + await countEntries( + "4hour10minutes", + "4hour10minutes form entry should still exist", + checkOne + ); + if (hoursSinceMidnight > 2) { + await countEntries( + "today", + "today form entry should still exist", + checkOne + ); + } + await countEntries( + "b4today", + "b4today form entry should still exist", + checkOne + ); + + ok( + !(await downloadExists(publicList, "fakefile-2-hour")), + "<2 hour old download should now be deleted" + ); + ok( + await downloadExists(publicList, "fakefile-old"), + "Year old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour-10-minutes"), + "2 hour 10 minute download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour"), + "<4 hour old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour-10-minutes"), + "4 hour 10 minute download should still be present" + ); + if (hoursSinceMidnight > 2) { + ok( + await downloadExists(publicList, "fakefile-today"), + "'Today' download should still be present" + ); + } + + downloadPromise = promiseDownloadRemoved(publicList); + formHistoryPromise = promiseFormHistoryRemoved(); + + // Clear 2 hours 10 minutes + range = [now_uSec - 130 * 60 * 1000000, now_uSec]; + await Sanitizer.sanitize(itemsToClear, { range, ignoreTimespan: false }); + + await formHistoryPromise; + await downloadPromise; + + ok( + !(await PlacesUtils.history.hasVisits("https://2hour10minutes.com")), + "Pretend visit to 2hour10minutes.com should now be deleted" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour.com"), + "Pretend visit to 4hour.com should should still exist" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour10minutes.com"), + "Pretend visit to 4hour10minutes.com should should still exist" + ); + if (minutesSinceMidnight > 130) { + ok( + await PlacesUtils.history.hasVisits("https://today.com"), + "Pretend visit to today.com should still exist" + ); + } + ok( + await PlacesUtils.history.hasVisits("https://before-today.com"), + "Pretend visit to before-today.com should still exist" + ); + + await countEntries( + "2hour10minutes", + "2hour10minutes form entry should be deleted", + checkZero + ); + await countEntries("4hour", "4hour form entry should still exist", checkOne); + await countEntries( + "4hour10minutes", + "4hour10minutes form entry should still exist", + checkOne + ); + if (minutesSinceMidnight > 130) { + await countEntries( + "today", + "today form entry should still exist", + checkOne + ); + } + await countEntries( + "b4today", + "b4today form entry should still exist", + checkOne + ); + + ok( + !(await downloadExists(publicList, "fakefile-2-hour-10-minutes")), + "2 hour 10 minute old download should now be deleted" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour"), + "<4 hour old download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour-10-minutes"), + "4 hour 10 minute download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-old"), + "Year old download should still be present" + ); + if (minutesSinceMidnight > 130) { + ok( + await downloadExists(publicList, "fakefile-today"), + "'Today' download should still be present" + ); + } + + downloadPromise = promiseDownloadRemoved(publicList); + formHistoryPromise = promiseFormHistoryRemoved(); + + // Clear 4 hours + Services.prefs.setIntPref(Sanitizer.PREF_TIMESPAN, 3); + await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); + + await formHistoryPromise; + await downloadPromise; + + ok( + !(await PlacesUtils.history.hasVisits("https://4hour.com")), + "Pretend visit to 4hour.com should now be deleted" + ); + ok( + await PlacesUtils.history.hasVisits("https://4hour10minutes.com"), + "Pretend visit to 4hour10minutes.com should should still exist" + ); + if (hoursSinceMidnight > 4) { + ok( + await PlacesUtils.history.hasVisits("https://today.com"), + "Pretend visit to today.com should still exist" + ); + } + ok( + await PlacesUtils.history.hasVisits("https://before-today.com"), + "Pretend visit to before-today.com should still exist" + ); + + await countEntries("4hour", "4hour form entry should be deleted", checkZero); + await countEntries( + "4hour10minutes", + "4hour10minutes form entry should still exist", + checkOne + ); + if (hoursSinceMidnight > 4) { + await countEntries( + "today", + "today form entry should still exist", + checkOne + ); + } + await countEntries( + "b4today", + "b4today form entry should still exist", + checkOne + ); + + ok( + !(await downloadExists(publicList, "fakefile-4-hour")), + "<4 hour old download should now be deleted" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour-10-minutes"), + "4 hour 10 minute download should still be present" + ); + ok( + await downloadExists(publicList, "fakefile-old"), + "Year old download should still be present" + ); + if (hoursSinceMidnight > 4) { + ok( + await downloadExists(publicList, "fakefile-today"), + "'Today' download should still be present" + ); + } + + downloadPromise = promiseDownloadRemoved(publicList); + formHistoryPromise = promiseFormHistoryRemoved(); + + // Clear 4 hours 10 minutes + range = [now_uSec - 250 * 60 * 1000000, now_uSec]; + await Sanitizer.sanitize(itemsToClear, { range, ignoreTimespan: false }); + + await formHistoryPromise; + await downloadPromise; + + ok( + !(await PlacesUtils.history.hasVisits("https://4hour10minutes.com")), + "Pretend visit to 4hour10minutes.com should now be deleted" + ); + if (minutesSinceMidnight > 250) { + ok( + await PlacesUtils.history.hasVisits("https://today.com"), + "Pretend visit to today.com should still exist" + ); + } + ok( + await PlacesUtils.history.hasVisits("https://before-today.com"), + "Pretend visit to before-today.com should still exist" + ); + + await countEntries( + "4hour10minutes", + "4hour10minutes form entry should be deleted", + checkZero + ); + if (minutesSinceMidnight > 250) { + await countEntries( + "today", + "today form entry should still exist", + checkOne + ); + } + await countEntries( + "b4today", + "b4today form entry should still exist", + checkOne + ); + + ok( + !(await downloadExists(publicList, "fakefile-4-hour-10-minutes")), + "4 hour 10 minute download should now be deleted" + ); + ok( + await downloadExists(publicList, "fakefile-old"), + "Year old download should still be present" + ); + if (minutesSinceMidnight > 250) { + ok( + await downloadExists(publicList, "fakefile-today"), + "'Today' download should still be present" + ); + } + + // The 'Today' download might have been already deleted, in which case we + // should not wait for a download removal notification. + if (minutesSinceMidnight > 250) { + downloadPromise = promiseDownloadRemoved(publicList); + formHistoryPromise = promiseFormHistoryRemoved(); + } else { + downloadPromise = formHistoryPromise = Promise.resolve(); + } + + // Clear Today + Services.prefs.setIntPref(Sanitizer.PREF_TIMESPAN, 4); + let progress = await Sanitizer.sanitize(itemsToClear, { + ignoreTimespan: false, + }); + Assert.deepEqual(progress, { + historyAndFormData: "cleared", + downloads: "cleared", + }); + + await formHistoryPromise; + await downloadPromise; + + // Be careful. If we add our objectss just before midnight, and sanitize + // runs immediately after, they won't be expired. This is expected, but + // we should not test in that case. We cannot just test for opposite + // condition because we could cross midnight just one moment after we + // cache our time, then we would have an even worse random failure. + var today = isToday(new Date(now_mSec)); + if (today) { + ok( + !(await PlacesUtils.history.hasVisits("https://today.com")), + "Pretend visit to today.com should now be deleted" + ); + + await countEntries( + "today", + "today form entry should be deleted", + checkZero + ); + ok( + !(await downloadExists(publicList, "fakefile-today")), + "'Today' download should now be deleted" + ); + } + + ok( + await PlacesUtils.history.hasVisits("https://before-today.com"), + "Pretend visit to before-today.com should still exist" + ); + await countEntries( + "b4today", + "b4today form entry should still exist", + checkOne + ); + ok( + await downloadExists(publicList, "fakefile-old"), + "Year old download should still be present" + ); + + downloadPromise = promiseDownloadRemoved(publicList); + formHistoryPromise = promiseFormHistoryRemoved(); + + // Choose everything + Services.prefs.setIntPref(Sanitizer.PREF_TIMESPAN, 0); + await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false }); + + await formHistoryPromise; + await downloadPromise; + + ok( + !(await PlacesUtils.history.hasVisits("https://before-today.com")), + "Pretend visit to before-today.com should now be deleted" + ); + + await countEntries( + "b4today", + "b4today form entry should be deleted", + checkZero + ); + + ok( + !(await downloadExists(publicList, "fakefile-old")), + "Year old download should now be deleted" + ); +} + +async function setupHistory() { + let places = []; + + function addPlace(aURI, aTitle, aVisitDate) { + places.push({ + uri: aURI, + title: aTitle, + visitDate: aVisitDate, + transition: Ci.nsINavHistoryService.TRANSITION_LINK, + }); + } + + addPlace( + "https://10minutes.com/", + "10 minutes ago", + now_uSec - 10 * kUsecPerMin + ); + addPlace( + "https://1hour.com/", + "Less than 1 hour ago", + now_uSec - 45 * kUsecPerMin + ); + addPlace( + "https://1hour10minutes.com/", + "1 hour 10 minutes ago", + now_uSec - 70 * kUsecPerMin + ); + addPlace( + "https://2hour.com/", + "Less than 2 hours ago", + now_uSec - 90 * kUsecPerMin + ); + addPlace( + "https://2hour10minutes.com/", + "2 hours 10 minutes ago", + now_uSec - 130 * kUsecPerMin + ); + addPlace( + "https://4hour.com/", + "Less than 4 hours ago", + now_uSec - 180 * kUsecPerMin + ); + addPlace( + "https://4hour10minutes.com/", + "4 hours 10 minutesago", + now_uSec - 250 * kUsecPerMin + ); + + let today = new Date(); + today.setHours(0); + today.setMinutes(0); + today.setSeconds(0); + today.setMilliseconds(1); + addPlace("https://today.com/", "Today", today.getTime() * 1000); + + let lastYear = new Date(); + lastYear.setFullYear(lastYear.getFullYear() - 1); + addPlace( + "https://before-today.com/", + "Before Today", + lastYear.getTime() * 1000 + ); + await PlacesTestUtils.addVisits(places); +} + +async function setupFormHistory() { + function searchEntries(terms, params) { + return FormHistory.search(terms, params); + } + + // Make sure we've got a clean DB to start with, then add the entries we'll be testing. + await FormHistory.update([ + { + op: "remove", + }, + { + op: "add", + fieldname: "10minutes", + value: "10m", + }, + { + op: "add", + fieldname: "1hour", + value: "1h", + }, + { + op: "add", + fieldname: "1hour10minutes", + value: "1h10m", + }, + { + op: "add", + fieldname: "2hour", + value: "2h", + }, + { + op: "add", + fieldname: "2hour10minutes", + value: "2h10m", + }, + { + op: "add", + fieldname: "4hour", + value: "4h", + }, + { + op: "add", + fieldname: "4hour10minutes", + value: "4h10m", + }, + { + op: "add", + fieldname: "today", + value: "1d", + }, + { + op: "add", + fieldname: "b4today", + value: "1y", + }, + ]); + + // Artifically age the entries to the proper vintage. + let timestamp = now_uSec - 10 * kUsecPerMin; + let results = await searchEntries(["guid"], { fieldname: "10minutes" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + timestamp = now_uSec - 45 * kUsecPerMin; + results = await searchEntries(["guid"], { fieldname: "1hour" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + timestamp = now_uSec - 70 * kUsecPerMin; + results = await searchEntries(["guid"], { fieldname: "1hour10minutes" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + timestamp = now_uSec - 90 * kUsecPerMin; + results = await searchEntries(["guid"], { fieldname: "2hour" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + timestamp = now_uSec - 130 * kUsecPerMin; + results = await searchEntries(["guid"], { fieldname: "2hour10minutes" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + timestamp = now_uSec - 180 * kUsecPerMin; + results = await searchEntries(["guid"], { fieldname: "4hour" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + timestamp = now_uSec - 250 * kUsecPerMin; + results = await searchEntries(["guid"], { fieldname: "4hour10minutes" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + let today = new Date(); + today.setHours(0); + today.setMinutes(0); + today.setSeconds(0); + today.setMilliseconds(1); + timestamp = today.getTime() * 1000; + results = await searchEntries(["guid"], { fieldname: "today" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + let lastYear = new Date(); + lastYear.setFullYear(lastYear.getFullYear() - 1); + timestamp = lastYear.getTime() * 1000; + results = await searchEntries(["guid"], { fieldname: "b4today" }); + await FormHistory.update({ + op: "update", + firstUsed: timestamp, + guid: results[0].guid, + }); + + var checks = 0; + let checkOne = function (num, message) { + is(num, 1, message); + checks++; + }; + + // Sanity check. + await countEntries( + "10minutes", + "Checking for 10minutes form history entry creation", + checkOne + ); + await countEntries( + "1hour", + "Checking for 1hour form history entry creation", + checkOne + ); + await countEntries( + "1hour10minutes", + "Checking for 1hour10minutes form history entry creation", + checkOne + ); + await countEntries( + "2hour", + "Checking for 2hour form history entry creation", + checkOne + ); + await countEntries( + "2hour10minutes", + "Checking for 2hour10minutes form history entry creation", + checkOne + ); + await countEntries( + "4hour", + "Checking for 4hour form history entry creation", + checkOne + ); + await countEntries( + "4hour10minutes", + "Checking for 4hour10minutes form history entry creation", + checkOne + ); + await countEntries( + "today", + "Checking for today form history entry creation", + checkOne + ); + await countEntries( + "b4today", + "Checking for b4today form history entry creation", + checkOne + ); + is(checks, 9, "9 checks made"); +} + +async function setupDownloads() { + let publicList = await Downloads.getList(Downloads.PUBLIC); + + let download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169", + target: "fakefile-10-minutes", + }); + download.startTime = new Date(now_mSec - 10 * kMsecPerMin); // 10 minutes ago + download.canceled = true; + await publicList.add(download); + + download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", + target: "fakefile-1-hour", + }); + download.startTime = new Date(now_mSec - 45 * kMsecPerMin); // 45 minutes ago + download.canceled = true; + await publicList.add(download); + + download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169", + target: "fakefile-1-hour-10-minutes", + }); + download.startTime = new Date(now_mSec - 70 * kMsecPerMin); // 70 minutes ago + download.canceled = true; + await publicList.add(download); + + download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", + target: "fakefile-2-hour", + }); + download.startTime = new Date(now_mSec - 90 * kMsecPerMin); // 90 minutes ago + download.canceled = true; + await publicList.add(download); + + download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169", + target: "fakefile-2-hour-10-minutes", + }); + download.startTime = new Date(now_mSec - 130 * kMsecPerMin); // 130 minutes ago + download.canceled = true; + await publicList.add(download); + + download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", + target: "fakefile-4-hour", + }); + download.startTime = new Date(now_mSec - 180 * kMsecPerMin); // 180 minutes ago + download.canceled = true; + await publicList.add(download); + + download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169", + target: "fakefile-4-hour-10-minutes", + }); + download.startTime = new Date(now_mSec - 250 * kMsecPerMin); // 250 minutes ago + download.canceled = true; + await publicList.add(download); + + // Add "today" download + let today = new Date(); + today.setHours(0); + today.setMinutes(0); + today.setSeconds(0); + today.setMilliseconds(1); + + download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", + target: "fakefile-today", + }); + download.startTime = today; // 12:00:01 AM this morning + download.canceled = true; + await publicList.add(download); + + // Add "before today" download + let lastYear = new Date(); + lastYear.setFullYear(lastYear.getFullYear() - 1); + + download = await Downloads.createDownload({ + source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", + target: "fakefile-old", + }); + download.startTime = lastYear; + download.canceled = true; + await publicList.add(download); + + // Confirm everything worked + let downloads = await publicList.getAll(); + is(downloads.length, 9, "9 Pretend downloads added"); + + ok( + await downloadExists(publicList, "fakefile-old"), + "Pretend download for everything case should exist" + ); + ok( + await downloadExists(publicList, "fakefile-10-minutes"), + "Pretend download for 10-minutes case should exist" + ); + ok( + await downloadExists(publicList, "fakefile-1-hour"), + "Pretend download for 1-hour case should exist" + ); + ok( + await downloadExists(publicList, "fakefile-1-hour-10-minutes"), + "Pretend download for 1-hour-10-minutes case should exist" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour"), + "Pretend download for 2-hour case should exist" + ); + ok( + await downloadExists(publicList, "fakefile-2-hour-10-minutes"), + "Pretend download for 2-hour-10-minutes case should exist" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour"), + "Pretend download for 4-hour case should exist" + ); + ok( + await downloadExists(publicList, "fakefile-4-hour-10-minutes"), + "Pretend download for 4-hour-10-minutes case should exist" + ); + ok( + await downloadExists(publicList, "fakefile-today"), + "Pretend download for Today case should exist" + ); +} + +/** + * Checks to see if the downloads with the specified id exists. + * + * @param aID + * The ids of the downloads to check. + */ +let downloadExists = async function (list, path) { + let listArray = await list.getAll(); + return listArray.some(i => i.target.path == path); +}; + +function isToday(aDate) { + return aDate.getDate() == new Date().getDate(); +} diff --git a/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js b/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js index 4528f1402525..f66d9afaa86e 100644 --- a/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js +++ b/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js @@ -1009,27 +1009,27 @@ add_task(async function test_clear_on_shutdown() { } boolPrefIs( - "clearOnShutdown.historyAndFormData", + "clearOnShutdown_v2.historyAndFormData", true, - "clearOnShutdown history should be true " + "clearOnShutdown_v2 history should be true " ); boolPrefIs( - "clearOnShutdown.cookiesAndStorage", + "clearOnShutdown_v2.cookiesAndStorage", true, - "clearOnShutdown cookies should be true" + "clearOnShutdown_v2 cookies should be true" ); boolPrefIs( - "clearOnShutdown.downloads", + "clearOnShutdown_v2.downloads", false, - "clearOnShutdown downloads should be false" + "clearOnShutdown_v2 downloads should be false" ); boolPrefIs( - "clearOnShutdown.cache", + "clearOnShutdown_v2.cache", false, - "clearOnShutdown cache should be false" + "clearOnShutdown_v2 cache should be false" ); await createDummyDataForHost("example.org"); @@ -1066,6 +1066,7 @@ add_task(async function test_clear_on_shutdown() { dh.setMode("clearOnShutdown"); dh.onload = async function () { this.uncheckAllCheckboxes(); + this.checkPrefCheckbox("historyAndFormData", true); this.checkPrefCheckbox("downloads", true); this.acceptDialog(); }; @@ -1073,27 +1074,27 @@ add_task(async function test_clear_on_shutdown() { await dh.promiseClosed; boolPrefIs( - "clearOnShutdown.historyAndFormData", - false, - "clearOnShutdown history should be false" - ); - - boolPrefIs( - "clearOnShutdown.cookiesAndStorage", - false, - "clearOnShutdown cookies should be false" - ); - - boolPrefIs( - "clearOnShutdown.downloads", + "clearOnShutdown_v2.historyAndFormData", true, - "clearOnShutdown downloads should be true" + "clearOnShutdown_v2 history should be true" ); boolPrefIs( - "clearOnShutdown.cache", + "clearOnShutdown_v2.cookiesAndStorage", false, - "clearOnShutdown cache should be false" + "clearOnShutdown_v2 cookies should be false" + ); + + boolPrefIs( + "clearOnShutdown_v2.downloads", + true, + "clearOnShutdown_v2 downloads should be true" + ); + + boolPrefIs( + "clearOnShutdown_v2.cache", + false, + "clearOnShutdown_v2 cache should be false" ); ok(