summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js')
-rw-r--r--browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js711
1 files changed, 111 insertions, 600 deletions
diff --git a/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js b/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js
index 29f760f57f..8ae0263c82 100644
--- a/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js
+++ b/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js
@@ -20,33 +20,9 @@ ChromeUtils.defineESModuleGetters(this, {
PlacesTestUtils: "resource://testing-common/PlacesTestUtils.sys.mjs",
Timer: "resource://gre/modules/Timer.sys.mjs",
PermissionTestUtils: "resource://testing-common/PermissionTestUtils.sys.mjs",
- FileTestUtils: "resource://testing-common/FileTestUtils.sys.mjs",
Downloads: "resource://gre/modules/Downloads.sys.mjs",
});
-const kMsecPerMin = 60 * 1000;
-const kUsecPerMin = 60 * 1000000;
-let today = Date.now() - new Date().setHours(0, 0, 0, 0);
-let nowMSec = Date.now();
-let nowUSec = nowMSec * 1000;
-let fileURL;
-
-const TEST_TARGET_FILE_NAME = "test-download.txt";
-const TEST_QUOTA_USAGE_HOST = "example.com";
-const TEST_QUOTA_USAGE_ORIGIN = "https://" + TEST_QUOTA_USAGE_HOST;
-const TEST_QUOTA_USAGE_URL =
- getRootDirectory(gTestPath).replace(
- "chrome://mochitests/content",
- TEST_QUOTA_USAGE_ORIGIN
- ) + "site_data_test.html";
-
-const siteOrigins = [
- "https://www.example.com",
- "https://example.org",
- "http://localhost:8000",
- "http://localhost:3000",
-];
-
/**
* Ensures that the specified URIs are either cleared or not.
*
@@ -167,90 +143,6 @@ async function addDownloadWithMinutesAgo(aExpectedPathList, aMinutesAgo) {
aExpectedPathList.push(name);
}
-/**
- * Adds multiple downloads to the PUBLIC download list
- */
-async function addToDownloadList() {
- const url = createFileURL();
- const downloadsList = await Downloads.getList(Downloads.PUBLIC);
- let timeOptions = [1, 2, 4, 24, 128, 128];
- let buffer = 100000;
-
- for (let i = 0; i < timeOptions.length; i++) {
- let timeDownloaded = 60 * kMsecPerMin * timeOptions[i];
- if (timeOptions[i] === 24) {
- timeDownloaded = today;
- }
-
- let download = await Downloads.createDownload({
- source: { url: url.spec, isPrivate: false },
- target: { path: FileTestUtils.getTempFile(TEST_TARGET_FILE_NAME).path },
- startTime: {
- getTime: _ => {
- return nowMSec - timeDownloaded + buffer;
- },
- },
- });
-
- Assert.ok(!!download);
- downloadsList.add(download);
- }
- let items = await downloadsList.getAll();
- Assert.equal(items.length, 6, "Items were added to the list");
-}
-
-async function addToSiteUsage() {
- // Fill indexedDB with test data.
- // Don't wait for the page to load, to register the content event handler as quickly as possible.
- // If this test goes intermittent, we might have to tell the page to wait longer before
- // firing the event.
- BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_QUOTA_USAGE_URL, false);
- await BrowserTestUtils.waitForContentEvent(
- gBrowser.selectedBrowser,
- "test-indexedDB-done",
- false,
- null,
- true
- );
- BrowserTestUtils.removeTab(gBrowser.selectedTab);
-
- let siteLastAccessed = [1, 2, 4, 24];
-
- let staticUsage = 4096 * 6;
- // Add a time buffer so the site access falls within the time range
- const buffer = 10000;
-
- // Change lastAccessed of sites
- for (let index = 0; index < siteLastAccessed.length; index++) {
- let lastAccessedTime = 60 * kMsecPerMin * siteLastAccessed[index];
- if (siteLastAccessed[index] === 24) {
- lastAccessedTime = today;
- }
-
- let site = SiteDataManager._testInsertSite(siteOrigins[index], {
- quotaUsage: staticUsage,
- lastAccessed: (nowMSec - lastAccessedTime + buffer) * 1000,
- });
- Assert.ok(site, "Site added successfully");
- }
-}
-
-/**
- * Helper function to create file URL to open
- *
- * @returns {Object} a file URL
- */
-function createFileURL() {
- if (!fileURL) {
- let file = Services.dirsvc.get("TmpD", Ci.nsIFile);
- file.append("foo.txt");
- file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
-
- fileURL = Services.io.newFileURI(file);
- }
- return fileURL;
-}
-
add_setup(async function () {
requestLongerTimeout(3);
await blankSlate();
@@ -268,248 +160,6 @@ add_setup(async function () {
});
/**
- * Removes all history visits, downloads, and form entries.
- */
-async function blankSlate() {
- let publicList = await Downloads.getList(Downloads.PUBLIC);
- let downloads = await publicList.getAll();
- for (let download of downloads) {
- await publicList.remove(download);
- await download.finalize(true);
- }
-
- await FormHistory.update({ op: "remove" });
- await PlacesUtils.history.clear();
-}
-
-/**
- * This wraps the dialog and provides some convenience methods for interacting
- * with it.
- *
- * @param browserWin (optional)
- * The browser window that the dialog is expected to open in. If not
- * supplied, the initial browser window of the test run is used.
- * @param mode (optional)
- * One of
- * clear on shutdown settings context ("clearOnShutdown"),
- * clear site data settings context ("clearSiteData"),
- * clear history context ("clearHistory"),
- * browser context ("browser")
- * "browser" by default
- */
-function DialogHelper(openContext = "browser") {
- this._browserWin = window;
- this.win = null;
- this._mode = openContext;
- this.promiseClosed = new Promise(resolve => {
- this._resolveClosed = resolve;
- });
-}
-
-DialogHelper.prototype = {
- /**
- * "Presses" the dialog's OK button.
- */
- acceptDialog() {
- let dialogEl = this.win.document.querySelector("dialog");
- is(
- dialogEl.getButton("accept").disabled,
- false,
- "Dialog's OK button should not be disabled"
- );
- dialogEl.acceptDialog();
- },
-
- /**
- * "Presses" the dialog's Cancel button.
- */
- cancelDialog() {
- this.win.document.querySelector("dialog").cancelDialog();
- },
-
- /**
- * (Un)checks a history scope checkbox (browser & download history,
- * form history, etc.).
- *
- * @param aPrefName
- * The final portion of the checkbox's privacy.cpd.* preference name
- * @param aCheckState
- * True if the checkbox should be checked, false otherwise
- */
- checkPrefCheckbox(aPrefName, aCheckState) {
- var cb = this.win.document.querySelectorAll(
- "checkbox[id='" + aPrefName + "']"
- );
- is(cb.length, 1, "found checkbox for " + aPrefName + " id");
- if (cb[0].checked != aCheckState) {
- cb[0].click();
- }
- },
-
- /**
- * @param {String} aCheckboxId
- * The checkbox id name
- * @param {Boolean} aCheckState
- * True if the checkbox should be checked, false otherwise
- */
- validateCheckbox(aCheckboxId, aCheckState) {
- let cb = this.win.document.querySelectorAll(
- "checkbox[id='" + aCheckboxId + "']"
- );
- is(cb.length, 1, `found checkbox for id=${aCheckboxId}`);
- is(
- cb[0].checked,
- aCheckState,
- `checkbox for ${aCheckboxId} is ${aCheckState}`
- );
- },
-
- /**
- * Makes sure all the checkboxes are checked.
- */
- _checkAllCheckboxesCustom(check) {
- var cb = this.win.document.querySelectorAll(".clearingItemCheckbox");
- ok(cb.length, "found checkboxes for ids");
- for (var i = 0; i < cb.length; ++i) {
- if (cb[i].checked != check) {
- cb[i].click();
- }
- }
- },
-
- checkAllCheckboxes() {
- this._checkAllCheckboxesCustom(true);
- },
-
- uncheckAllCheckboxes() {
- this._checkAllCheckboxesCustom(false);
- },
-
- /**
- * @return The dialog's duration dropdown
- */
- getDurationDropdown() {
- return this.win.document.getElementById("sanitizeDurationChoice");
- },
-
- /**
- * @return The clear-everything warning box
- */
- getWarningPanel() {
- return this.win.document.getElementById("sanitizeEverythingWarningBox");
- },
-
- /**
- * @return True if the "Everything" warning panel is visible (as opposed to
- * the tree)
- */
- isWarningPanelVisible() {
- return !this.getWarningPanel().hidden;
- },
-
- /**
- * Opens the clear recent history dialog. Before calling this, set
- * this.onload to a function to execute onload. It should close the dialog
- * when done so that the tests may continue. Set this.onunload to a function
- * to execute onunload. this.onunload is optional. If it returns true, the
- * caller is expected to call promiseAsyncUpdates at some point; if false is
- * returned, promiseAsyncUpdates is called automatically.
- */
- async open() {
- let dialogPromise = BrowserTestUtils.promiseAlertDialogOpen(
- null,
- "chrome://browser/content/sanitize_v2.xhtml",
- {
- isSubDialog: true,
- }
- );
-
- // We want to simulate opening the dialog inside preferences for clear history
- // and clear site data
- if (this._mode != "browser") {
- await openPreferencesViaOpenPreferencesAPI("privacy", {
- leaveOpen: true,
- });
- let tabWindow = gBrowser.selectedBrowser.contentWindow;
- let clearDialogOpenButtonId = this._mode + "Button";
- // the id for clear on shutdown is of a different format
- if (this._mode == "clearOnShutdown") {
- // set always clear to true to enable the clear on shutdown dialog
- let enableSettingsCheckbox =
- tabWindow.document.getElementById("alwaysClear");
- if (!enableSettingsCheckbox.checked) {
- enableSettingsCheckbox.click();
- }
- clearDialogOpenButtonId = "clearDataSettings";
- }
- // open dialog
- tabWindow.document.getElementById(clearDialogOpenButtonId).click();
- }
- // We open the dialog in the chrome context in other cases
- else {
- executeSoon(() => {
- Sanitizer.showUI(this._browserWin, this._mode);
- });
- }
-
- this.win = await dialogPromise;
- this.win.addEventListener(
- "load",
- () => {
- // Run onload on next tick so that gSanitizePromptDialog.init can run first.
- executeSoon(async () => {
- await this.win.gSanitizePromptDialog.dataSizesFinishedUpdatingPromise;
- this.onload();
- });
- },
- { once: true }
- );
- this.win.addEventListener(
- "unload",
- () => {
- // Some exceptions that reach here don't reach the test harness, but
- // ok()/is() do...
- (async () => {
- if (this.onunload) {
- await this.onunload();
- }
- if (this._mode != "browser") {
- BrowserTestUtils.removeTab(gBrowser.selectedTab);
- }
- await PlacesTestUtils.promiseAsyncUpdates();
- this._resolveClosed();
- this.win = null;
- })();
- },
- { once: true }
- );
- },
-
- /**
- * Selects a duration in the duration dropdown.
- *
- * @param aDurVal
- * One of the Sanitizer.TIMESPAN_* values
- */
- selectDuration(aDurVal) {
- this.getDurationDropdown().value = aDurVal;
- if (aDurVal === Sanitizer.TIMESPAN_EVERYTHING) {
- is(
- this.isWarningPanelVisible(),
- true,
- "Warning panel should be visible for TIMESPAN_EVERYTHING"
- );
- } else {
- is(
- this.isWarningPanelVisible(),
- false,
- "Warning panel should not be visible for non-TIMESPAN_EVERYTHING"
- );
- }
- },
-};
-
-/**
* Ensures that the given pref is the expected value.
*
* @param aPrefName
@@ -533,58 +183,6 @@ function visitTimeForMinutesAgo(aMinutesAgo) {
return nowUSec - aMinutesAgo * kUsecPerMin;
}
-function promiseSanitizationComplete() {
- return TestUtils.topicObserved("sanitizer-sanitization-complete");
-}
-
-/**
- * Helper function to validate the data sizes shown for each time selection
- *
- * @param {DialogHelper} dh - dialog object to access window and timespan
- */
-async function validateDataSizes(dialogHelper) {
- let timespans = [
- "TIMESPAN_HOUR",
- "TIMESPAN_2HOURS",
- "TIMESPAN_4HOURS",
- "TIMESPAN_TODAY",
- "TIMESPAN_EVERYTHING",
- ];
-
- // get current data sizes from siteDataManager
- let cacheUsage = await SiteDataManager.getCacheSize();
- let quotaUsage = await SiteDataManager.getQuotaUsageForTimeRanges(timespans);
-
- for (let i = 0; i < timespans.length; i++) {
- // select timespan to check
- dialogHelper.selectDuration(Sanitizer[timespans[i]]);
-
- // get the elements
- let clearCookiesAndSiteDataCheckbox =
- dialogHelper.win.document.getElementById("cookiesAndStorage");
- let clearCacheCheckbox = dialogHelper.win.document.getElementById("cache");
-
- let [convertedQuotaUsage] = DownloadUtils.convertByteUnits(
- quotaUsage[timespans[i]]
- );
- let [, convertedCacheUnit] = DownloadUtils.convertByteUnits(cacheUsage);
-
- // Ensure l10n is finished before inspecting the category labels.
- await dialogHelper.win.document.l10n.translateElements([
- clearCookiesAndSiteDataCheckbox,
- clearCacheCheckbox,
- ]);
- ok(
- clearCacheCheckbox.label.includes(convertedCacheUnit),
- "Should show the cache usage"
- );
- ok(
- clearCookiesAndSiteDataCheckbox.label.includes(convertedQuotaUsage),
- `Should show the quota usage as ${convertedQuotaUsage}`
- );
- }
-}
-
/**
*
* Opens dialog in the provided context and selects the checkboxes
@@ -602,7 +200,7 @@ async function performActionsOnDialog({
cache = false,
siteSettings = false,
}) {
- let dh = new DialogHelper(context);
+ let dh = new ClearHistoryDialogHelper({ mode: context });
dh.onload = function () {
this.selectDuration(timespan);
this.checkPrefCheckbox(
@@ -622,7 +220,7 @@ async function performActionsOnDialog({
* Initializes the dialog to its default state.
*/
add_task(async function default_state() {
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = function () {
// Select "Last Hour"
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
@@ -647,7 +245,7 @@ add_task(async function test_cancel() {
}
await PlacesTestUtils.addVisits(places);
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = function () {
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
this.checkPrefCheckbox("historyFormDataAndDownloads", false);
@@ -662,6 +260,72 @@ add_task(async function test_cancel() {
await dh.promiseClosed;
});
+// test remembering user options for various entry points
+add_task(async function test_pref_remembering() {
+ let dh = new ClearHistoryDialogHelper({ mode: "clearSiteData" });
+ dh.onload = function () {
+ this.checkPrefCheckbox("cookiesAndStorage", false);
+ this.checkPrefCheckbox("siteSettings", true);
+
+ this.acceptDialog();
+ };
+ dh.open();
+ await dh.promiseClosed;
+
+ // validate if prefs are remembered
+ dh = new ClearHistoryDialogHelper({ mode: "clearSiteData" });
+ dh.onload = function () {
+ this.validateCheckbox("cookiesAndStorage", false);
+ this.validateCheckbox("siteSettings", true);
+
+ this.checkPrefCheckbox("cookiesAndStorage", true);
+ this.checkPrefCheckbox("siteSettings", false);
+
+ // we will test cancelling the dialog, to make sure it doesn't remember
+ // the prefs when cancelled
+ this.cancelDialog();
+ };
+ dh.open();
+ await dh.promiseClosed;
+
+ // validate if prefs did not change since we cancelled the dialog
+ dh = new ClearHistoryDialogHelper({ mode: "clearSiteData" });
+ dh.onload = function () {
+ this.validateCheckbox("cookiesAndStorage", false);
+ this.validateCheckbox("siteSettings", true);
+
+ this.cancelDialog();
+ };
+ dh.open();
+ await dh.promiseClosed;
+
+ // test rememebering prefs from the clear history context
+ // since clear history and clear site data have seperate remembering
+ // of prefs
+ dh = new ClearHistoryDialogHelper({ mode: "clearHistory" });
+ dh.onload = function () {
+ this.checkPrefCheckbox("cookiesAndStorage", true);
+ this.checkPrefCheckbox("siteSettings", false);
+ this.checkPrefCheckbox("cache", false);
+
+ this.acceptDialog();
+ };
+ dh.open();
+ await dh.promiseClosed;
+
+ // validate if prefs are remembered across both clear history and browser
+ dh = new ClearHistoryDialogHelper({ mode: "browser" });
+ dh.onload = function () {
+ this.validateCheckbox("cookiesAndStorage", true);
+ this.validateCheckbox("siteSettings", false);
+ this.validateCheckbox("cache", false);
+
+ this.cancelDialog();
+ };
+ dh.open();
+ await dh.promiseClosed;
+});
+
/**
* Ensures that the "Everything" duration option works.
*/
@@ -681,7 +345,7 @@ add_task(async function test_everything() {
let promiseSanitized = promiseSanitizationComplete();
await PlacesTestUtils.addVisits(places);
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = function () {
is(
this.isWarningPanelVisible(),
@@ -728,7 +392,7 @@ add_task(async function test_everything_warning() {
let promiseSanitized = promiseSanitizationComplete();
await PlacesTestUtils.addVisits(places);
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = function () {
is(
this.isWarningPanelVisible(),
@@ -761,7 +425,7 @@ add_task(async function test_everything_warning() {
* and enabled when at least one checkbox is checked
*/
add_task(async function testAcceptButtonDisabled() {
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = async function () {
let clearButton = this.win.document
.querySelector("dialog")
@@ -769,12 +433,6 @@ add_task(async function testAcceptButtonDisabled() {
this.uncheckAllCheckboxes();
await new Promise(resolve => SimpleTest.executeSoon(resolve));
is(clearButton.disabled, true, "Clear button should be disabled");
- // await BrowserTestUtils.waitForMutationCondition(
- // clearButton,
- // { attributes: true },
- // () => clearButton.disabled,
- // "Clear button should be disabled"
- // );
this.checkPrefCheckbox("cache", true);
await new Promise(resolve => SimpleTest.executeSoon(resolve));
@@ -790,7 +448,7 @@ add_task(async function testAcceptButtonDisabled() {
* Tests to see if the warning box is hidden when opened in the clear on shutdown context
*/
add_task(async function testWarningBoxInClearOnShutdown() {
- let dh = new DialogHelper("clearSiteData");
+ let dh = new ClearHistoryDialogHelper({ mode: "clearSiteData" });
dh.onload = function () {
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
is(
@@ -803,7 +461,7 @@ add_task(async function testWarningBoxInClearOnShutdown() {
dh.open();
await dh.promiseClosed;
- dh = new DialogHelper("clearOnShutdown");
+ dh = new ClearHistoryDialogHelper({ mode: "clearOnShutdown" });
dh.onload = function () {
is(
BrowserTestUtils.isVisible(this.getWarningPanel()),
@@ -853,7 +511,7 @@ add_task(async function test_history_downloads_checked() {
await PlacesTestUtils.addVisits(places);
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = function () {
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
this.checkPrefCheckbox("historyFormDataAndDownloads", true);
@@ -905,7 +563,7 @@ add_task(async function test_cannot_clear_history() {
});
let uris = [pURI];
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = function () {
var cb = this.win.document.querySelectorAll(
"checkbox[id='historyFormDataAndDownloads']"
@@ -932,7 +590,7 @@ add_task(async function test_cannot_clear_history() {
add_task(async function test_no_formdata_history_to_clear() {
let promiseSanitized = promiseSanitizationComplete();
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = function () {
var cb = this.win.document.querySelectorAll(
"checkbox[id='historyFormDataAndDownloads']"
@@ -955,7 +613,7 @@ add_task(async function test_form_entries() {
let promiseSanitized = promiseSanitizationComplete();
- let dh = new DialogHelper();
+ let dh = new ClearHistoryDialogHelper();
dh.onload = function () {
var cb = this.win.document.querySelectorAll(
"checkbox[id='historyFormDataAndDownloads']"
@@ -975,97 +633,13 @@ add_task(async function test_form_entries() {
await dh.promiseClosed;
});
-add_task(async function test_cookie_sizes() {
- await clearAndValidateDataSizes({
- clearCookies: true,
- clearCache: false,
- clearDownloads: false,
- timespan: Sanitizer.TIMESPAN_HOUR,
- });
- await clearAndValidateDataSizes({
- clearCookies: true,
- clearCache: false,
- clearDownloads: false,
- timespan: Sanitizer.TIMESPAN_4HOURS,
- });
- await clearAndValidateDataSizes({
- clearCookies: true,
- clearCache: false,
- clearDownloads: false,
- timespan: Sanitizer.TIMESPAN_EVERYTHING,
- });
-});
-
-add_task(async function test_cache_sizes() {
- await clearAndValidateDataSizes({
- clearCookies: false,
- clearCache: true,
- clearDownloads: false,
- timespan: Sanitizer.TIMESPAN_HOUR,
- });
- await clearAndValidateDataSizes({
- clearCookies: false,
- clearCache: true,
- clearDownloads: false,
- timespan: Sanitizer.TIMESPAN_4HOURS,
- });
- await clearAndValidateDataSizes({
- clearCookies: false,
- clearCache: true,
- clearDownloads: false,
- timespan: Sanitizer.TIMESPAN_EVERYTHING,
- });
-});
-
-add_task(async function test_downloads_sizes() {
- await clearAndValidateDataSizes({
- clearCookies: false,
- clearCache: false,
- clearDownloads: true,
- timespan: Sanitizer.TIMESPAN_HOUR,
- });
- await clearAndValidateDataSizes({
- clearCookies: false,
- clearCache: false,
- clearDownloads: true,
- timespan: Sanitizer.TIMESPAN_4HOURS,
- });
- await clearAndValidateDataSizes({
- clearCookies: false,
- clearCache: false,
- clearDownloads: true,
- timespan: Sanitizer.TIMESPAN_EVERYTHING,
- });
-});
-
-add_task(async function test_all_data_sizes() {
- await clearAndValidateDataSizes({
- clearCookies: true,
- clearCache: true,
- clearDownloads: true,
- timespan: Sanitizer.TIMESPAN_HOUR,
- });
- await clearAndValidateDataSizes({
- clearCookies: true,
- clearCache: true,
- clearDownloads: true,
- timespan: Sanitizer.TIMESPAN_4HOURS,
- });
- await clearAndValidateDataSizes({
- clearCookies: true,
- clearCache: true,
- clearDownloads: true,
- timespan: Sanitizer.TIMESPAN_EVERYTHING,
- });
-});
-
// test the case when we open the dialog through the clear on shutdown settings
add_task(async function test_clear_on_shutdown() {
await SpecialPowers.pushPrefEnv({
set: [["privacy.sanitize.sanitizeOnShutdown", true]],
});
- let dh = new DialogHelper("clearOnShutdown");
+ let dh = new ClearHistoryDialogHelper({ mode: "clearOnShutdown" });
dh.onload = async function () {
this.uncheckAllCheckboxes();
this.checkPrefCheckbox("historyFormDataAndDownloads", false);
@@ -1134,7 +708,7 @@ add_task(async function test_clear_on_shutdown() {
await ensureDownloadsClearedState(downloadIDs, false);
await ensureDownloadsClearedState(olderDownloadIDs, false);
- dh = new DialogHelper("clearOnShutdown");
+ dh = new ClearHistoryDialogHelper({ mode: "clearOnShutdown" });
dh.onload = async function () {
this.uncheckAllCheckboxes();
this.checkPrefCheckbox("historyFormDataAndDownloads", true);
@@ -1192,89 +766,6 @@ add_task(async function test_clear_on_shutdown() {
await SiteDataTestUtils.clear();
});
-// test default prefs for entry points
-add_task(async function test_defaults_prefs() {
- let dh = new DialogHelper("clearSiteData");
- dh.onload = function () {
- this.validateCheckbox("historyFormDataAndDownloads", false);
- this.validateCheckbox("cache", true);
- this.validateCheckbox("cookiesAndStorage", true);
- this.validateCheckbox("siteSettings", false);
-
- this.cancelDialog();
- };
- dh.open();
- await dh.promiseClosed;
-
- // We don't need to specify the mode again,
- // as the default mode is taken (browser, clear history)
-
- dh = new DialogHelper();
- dh.onload = function () {
- // Default checked for browser and clear history mode
- this.validateCheckbox("historyFormDataAndDownloads", true);
- this.validateCheckbox("cache", true);
- this.validateCheckbox("cookiesAndStorage", true);
- this.validateCheckbox("siteSettings", false);
-
- this.cancelDialog();
- };
- dh.open();
- await dh.promiseClosed;
-});
-
-/**
- * Helper function to simulate switching timespan selections and
- * validate data sizes before and after clearing
- *
- * @param {Object}
- * clearCookies - boolean
- * clearDownloads - boolean
- * clearCaches - boolean
- * timespan - one of Sanitizer.TIMESPAN_*
- */
-async function clearAndValidateDataSizes({
- clearCache,
- clearDownloads,
- clearCookies,
- timespan,
-}) {
- await blankSlate();
-
- await addToDownloadList();
- await addToSiteUsage();
- let promiseSanitized = promiseSanitizationComplete();
-
- await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
-
- let dh = new DialogHelper();
- dh.onload = async function () {
- await validateDataSizes(this);
- this.checkPrefCheckbox("cache", clearCache);
- this.checkPrefCheckbox("cookiesAndStorage", clearCookies);
- this.checkPrefCheckbox("historyFormDataAndDownloads", clearDownloads);
- this.selectDuration(timespan);
- this.acceptDialog();
- };
- dh.onunload = async function () {
- await promiseSanitized;
- };
- dh.open();
- await dh.promiseClosed;
-
- let dh2 = new DialogHelper();
- // Check if the newly cleared values are reflected
- dh2.onload = async function () {
- await validateDataSizes(this);
- this.acceptDialog();
- };
- dh2.open();
- await dh2.promiseClosed;
-
- await SiteDataTestUtils.clear();
- BrowserTestUtils.removeTab(gBrowser.selectedTab);
-}
-
add_task(async function testEntryPointTelemetry() {
Services.fog.testResetFOG();
@@ -1401,27 +892,47 @@ add_task(async function testClearingOptionsTelemetry() {
);
});
-add_task(async function testCheckboxStatesAfterMigration() {
+add_task(async function testClearHistoryCheckboxStatesAfterMigration() {
await SpecialPowers.pushPrefEnv({
set: [
- ["privacy.clearOnShutdown.history", false],
- ["privacy.clearOnShutdown.formdata", true],
- ["privacy.clearOnShutdown.cookies", true],
- ["privacy.clearOnShutdown.offlineApps", false],
- ["privacy.clearOnShutdown.sessions", false],
- ["privacy.clearOnShutdown.siteSettings", false],
- ["privacy.clearOnShutdown.cache", true],
- ["privacy.clearOnShutdown_v2.cookiesAndStorage", false],
- ["privacy.sanitize.sanitizeOnShutdown.hasMigratedToNewPrefs", false],
+ ["privacy.cpd.history", false],
+ ["privacy.cpd.formdata", true],
+ ["privacy.cpd.cookies", true],
+ ["privacy.cpd.offlineApps", false],
+ ["privacy.cpd.sessions", false],
+ ["privacy.cpd.siteSettings", false],
+ ["privacy.cpd.cache", true],
+ // Set cookiesAndStorage to verify that the pref is flipped in the test
+ ["privacy.clearHistory.cookiesAndStorage", false],
+ ["privacy.sanitize.cpd.hasMigratedToNewPrefs", false],
],
});
- let dh = new DialogHelper("clearOnShutdown");
+ let dh = new ClearHistoryDialogHelper({ mode: "clearHistory" });
dh.onload = function () {
this.validateCheckbox("cookiesAndStorage", true);
this.validateCheckbox("historyFormDataAndDownloads", false);
this.validateCheckbox("cache", true);
this.validateCheckbox("siteSettings", false);
+
+ this.checkPrefCheckbox("siteSettings", true);
+ this.checkPrefCheckbox("cookiesAndStorage", false);
+ this.acceptDialog();
+ };
+ dh.open();
+ await dh.promiseClosed;
+
+ is(
+ Services.prefs.getBoolPref("privacy.sanitize.cpd.hasMigratedToNewPrefs"),
+ true,
+ "Migration is complete for cpd branch"
+ );
+
+ // make sure the migration doesn't run again
+ dh = new ClearHistoryDialogHelper({ mode: "clearHistory" });
+ dh.onload = function () {
+ this.validateCheckbox("siteSettings", true);
+ this.validateCheckbox("cookiesAndStorage", false);
this.cancelDialog();
};
dh.open();