Bug 1370780 - Test storage pressure notification according to the browser.preferences.useOldOrganization pref draft
authorFischer.json <fischer.json@gmail.com>
Fri, 09 Jun 2017 11:53:22 +0800
changeset 591671 cf2baef28f050fce0efb8683eca243d2dee81881
parent 591406 f4262773c4331d4ae139be536ce278ea9aad3436
child 632579 4d940c2c13ec990d42d42c777b7411b5c85b7b68
push id63125
push userbmo:fliu@mozilla.com
push dateFri, 09 Jun 2017 10:55:32 +0000
bugs1370780
milestone55.0a1
Bug 1370780 - Test storage pressure notification according to the browser.preferences.useOldOrganization pref On Nightly it is the new about:preferences (browser.preferences.useOldOrganization = true) so the siteDataGroup is under about:preferences#advanced. On Beta and Release it is the old about:preferences (browser.preferences.useOldOrganization = false) so the siteDataGroup is under about:preferences#privacy. This patch will detect browser.preferences.useOldOrganization to decide the right about:preferences url to check MozReview-Commit-ID: CFm0ntHfRq6
browser/base/content/test/general/browser_storagePressure_notification.js
--- a/browser/base/content/test/general/browser_storagePressure_notification.js
+++ b/browser/base/content/test/general/browser_storagePressure_notification.js
@@ -6,24 +6,51 @@ function notifyStoragePressure(usage = 1
   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 privacyAboutPrefPromise() {
+function openAboutPrefPromise() {
+  let useOldOrganization = Services.prefs.getBoolPref("browser.preferences.useOldOrganization");
+  let targetURL = useOldOrganization ? "about:preferences#advanced" : "about:preferences#privacy";
   let promises = [
-    BrowserTestUtils.waitForLocationChange(gBrowser, "about:preferences#privacy"),
+    BrowserTestUtils.waitForLocationChange(gBrowser, targetURL),
     TestUtils.topicObserved("advanced-pane-loaded", () => true)
   ];
   return Promise.all(promises);
 }
 
+async function testOverUsageThresholdNotification() {
+  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 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");
@@ -37,29 +64,17 @@ add_task(async function() {
 
   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 about:preferences when usage exceeds the given threshold
+// 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]]});
-
-  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 = privacyAboutPrefPromise();
-  prefBtn.doCommand();
-  await aboutPrefPromise;
-  let prefDoc = gBrowser.selectedBrowser.contentDocument;
-  let siteDataGroup = prefDoc.getElementById("siteDataGroup");
-  is_element_visible(siteDataGroup, "Should open the Network tab in about:preferences#privacy");
+  // Test for the old about:preferences
+  await SpecialPowers.pushPrefEnv({set: [["browser.preferences.useOldOrganization", true]]});
+  await testOverUsageThresholdNotification();
+  // Test for the new about:preferences
+  await SpecialPowers.pushPrefEnv({set: [["browser.preferences.useOldOrganization", false]]});
+  await testOverUsageThresholdNotification();
 });