forked from mirrors/gecko-dev
MozReview-Commit-ID: GNPcQGUTUKJ --HG-- rename : browser/components/preferences/in-content-new/findInPage.js => browser/components/preferences/in-content/findInPage.js rename : browser/components/preferences/in-content-new/searchResults.xul => browser/components/preferences/in-content/searchResults.xul rename : browser/components/preferences/in-content-new/tests/browser_checkspelling.js => browser/components/preferences/in-content/tests/browser_checkspelling.js rename : browser/components/preferences/in-content-new/tests/browser_engines.js => browser/components/preferences/in-content/tests/browser_engines.js rename : browser/components/preferences/in-content-new/tests/browser_layersacceleration.js => browser/components/preferences/in-content/tests/browser_layersacceleration.js rename : browser/components/preferences/in-content-new/tests/browser_masterpassword.js => browser/components/preferences/in-content/tests/browser_masterpassword.js rename : browser/components/preferences/in-content-new/tests/browser_permissions_dialog.js => browser/components/preferences/in-content/tests/browser_permissions_dialog.js rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_1.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_1.js rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_2.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_2.js rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_3.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_3.js rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_4.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_4.js rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_5.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_5.js rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_6.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_6.js rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_7.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_7.js rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_8.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_8.js rename : browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js => browser/components/preferences/in-content/tests/browser_search_within_preferences_2.js rename : browser/components/preferences/in-content-new/tests/browser_search_within_preferences_command.js => browser/components/preferences/in-content/tests/browser_search_within_preferences_command.js rename : browser/components/preferences/in-content-new/tests/browser_security-1.js => browser/components/preferences/in-content/tests/browser_security-1.js rename : browser/components/preferences/in-content-new/tests/browser_security-2.js => browser/components/preferences/in-content/tests/browser_security-2.js extra : rebase_source : 9adc8231c896f93f7f262a09482b44a2875bd5fd
90 lines
4.4 KiB
JavaScript
90 lines
4.4 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
*/
|
|
/* eslint-disable mozilla/no-arbitrary-setTimeout */
|
|
|
|
function notifyStoragePressure(usage = 100) {
|
|
let notifyPromise = TestUtils.topicObserved("QuotaManager::StoragePressure", () => true);
|
|
let usageWrapper = Cc["@mozilla.org/supports-PRUint64;1"]
|
|
.createInstance(Ci.nsISupportsPRUint64);
|
|
usageWrapper.data = usage;
|
|
Services.obs.notifyObservers(usageWrapper, "QuotaManager::StoragePressure");
|
|
return notifyPromise;
|
|
}
|
|
|
|
function openAboutPrefPromise() {
|
|
let promises = [
|
|
BrowserTestUtils.waitForLocationChange(gBrowser, "about:preferences#privacy"),
|
|
TestUtils.topicObserved("privacy-pane-loaded", () => true)
|
|
];
|
|
return Promise.all(promises);
|
|
}
|
|
|
|
// Test only displaying notification once within the given interval
|
|
add_task(async function() {
|
|
const TEST_NOTIFICATION_INTERVAL_MS = 2000;
|
|
await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
|
|
await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.pressureNotification.minIntervalMS", TEST_NOTIFICATION_INTERVAL_MS]]});
|
|
|
|
await notifyStoragePressure();
|
|
let notificationbox = document.getElementById("high-priority-global-notificationbox");
|
|
let notification = notificationbox.getNotificationWithValue("storage-pressure-notification");
|
|
ok(notification instanceof XULElement, "Should display storage pressure notification");
|
|
notification.close();
|
|
|
|
await notifyStoragePressure();
|
|
notification = notificationbox.getNotificationWithValue("storage-pressure-notification");
|
|
is(notification, null, "Should not display storage pressure notification more than once within the given interval");
|
|
|
|
await new Promise(resolve => setTimeout(resolve, TEST_NOTIFICATION_INTERVAL_MS + 1));
|
|
await notifyStoragePressure();
|
|
notification = notificationbox.getNotificationWithValue("storage-pressure-notification");
|
|
ok(notification instanceof XULElement, "Should display storage pressure notification after the given interval");
|
|
notification.close();
|
|
});
|
|
|
|
// Test guiding user to the about:preferences when usage exceeds the given threshold
|
|
add_task(async function() {
|
|
await SpecialPowers.pushPrefEnv({ set: [["browser.storageManager.enabled", true]] });
|
|
await SpecialPowers.pushPrefEnv({ set: [["browser.storageManager.pressureNotification.minIntervalMS", 0]] });
|
|
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "https://example.com");
|
|
|
|
const BYTES_IN_GIGABYTE = 1073741824;
|
|
const USAGE_THRESHOLD_BYTES = BYTES_IN_GIGABYTE *
|
|
Services.prefs.getIntPref("browser.storageManager.pressureNotification.usageThresholdGB");
|
|
await notifyStoragePressure(USAGE_THRESHOLD_BYTES);
|
|
let notificationbox = document.getElementById("high-priority-global-notificationbox");
|
|
let notification = notificationbox.getNotificationWithValue("storage-pressure-notification");
|
|
ok(notification instanceof XULElement, "Should display storage pressure notification");
|
|
|
|
let prefBtn = notification.getElementsByTagName("button")[1];
|
|
let aboutPrefPromise = openAboutPrefPromise();
|
|
prefBtn.doCommand();
|
|
await aboutPrefPromise;
|
|
let aboutPrefTab = gBrowser.selectedTab;
|
|
let prefDoc = gBrowser.selectedBrowser.contentDocument;
|
|
let siteDataGroup = prefDoc.getElementById("siteDataGroup");
|
|
is_element_visible(siteDataGroup, "Should open to the siteDataGroup section in about:preferences");
|
|
await BrowserTestUtils.removeTab(aboutPrefTab);
|
|
await BrowserTestUtils.removeTab(tab);
|
|
});
|
|
|
|
// Test not displaying the 2nd notification if one is already being displayed
|
|
add_task(async function() {
|
|
const TEST_NOTIFICATION_INTERVAL_MS = 0;
|
|
await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
|
|
await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.pressureNotification.minIntervalMS", TEST_NOTIFICATION_INTERVAL_MS]]});
|
|
|
|
await notifyStoragePressure();
|
|
await notifyStoragePressure();
|
|
let notificationbox = document.getElementById("high-priority-global-notificationbox");
|
|
let allNotifications = notificationbox.allNotifications;
|
|
let pressureNotificationCount = 0;
|
|
allNotifications.forEach(notification => {
|
|
if (notification.getAttribute("value") == "storage-pressure-notification") {
|
|
pressureNotificationCount++;
|
|
}
|
|
});
|
|
is(pressureNotificationCount, 1, "Should not display the 2nd notification when there is already one");
|
|
notificationbox.removeAllNotifications();
|
|
});
|