Bug 1445188 - Move site data tests into their own subdirectory. r=jaws draft
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 13 Mar 2018 10:41:38 +0100
changeset 766826 3e2b17c953bdc3c1daf3edce9cc96ba7c087745d
parent 765246 f1965cf7425fe422c9e9c78018f11b97e0a0f229
push id102400
push userjhofmann@mozilla.com
push dateTue, 13 Mar 2018 10:22:52 +0000
reviewersjaws
bugs1445188
milestone60.0a1
Bug 1445188 - Move site data tests into their own subdirectory. r=jaws This commit is mostly about moving files but also contains a few test cleanups. MozReview-Commit-ID: AkDhFxlGdCT
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_clearSiteData.js
browser/components/preferences/in-content/tests/browser_siteData.js
browser/components/preferences/in-content/tests/browser_siteData2.js
browser/components/preferences/in-content/tests/browser_siteData3.js
browser/components/preferences/in-content/tests/head.js
browser/components/preferences/in-content/tests/offline/manifest.appcache
browser/components/preferences/in-content/tests/offline/offline.html
browser/components/preferences/in-content/tests/service_worker_test.html
browser/components/preferences/in-content/tests/service_worker_test.js
browser/components/preferences/in-content/tests/siteData/browser.ini
browser/components/preferences/in-content/tests/siteData/browser_clearSiteData.js
browser/components/preferences/in-content/tests/siteData/browser_siteData.js
browser/components/preferences/in-content/tests/siteData/browser_siteData2.js
browser/components/preferences/in-content/tests/siteData/browser_siteData3.js
browser/components/preferences/in-content/tests/siteData/head.js
browser/components/preferences/in-content/tests/siteData/offline/manifest.appcache
browser/components/preferences/in-content/tests/siteData/offline/offline.html
browser/components/preferences/in-content/tests/siteData/service_worker_test.html
browser/components/preferences/in-content/tests/siteData/service_worker_test.js
browser/components/preferences/in-content/tests/siteData/site_data_test.html
browser/components/preferences/in-content/tests/site_data_test.html
browser/components/preferences/moz.build
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -1,22 +1,17 @@
 [DEFAULT]
 prefs =
   extensions.formautofill.available='on'
   extensions.formautofill.creditCards.available=true
 support-files =
   head.js
   privacypane_tests_perwindow.js
-  site_data_test.html
-  service_worker_test.html
-  service_worker_test.js
   addons/set_homepage.xpi
   addons/set_newtab.xpi
-  offline/offline.html
-  offline/manifest.appcache
 
 [browser_applications_selection.js]
 skip-if = os == 'linux' # bug 1382057
 [browser_advanced_update.js]
 skip-if = !updater
 [browser_basic_rebuild_fonts_test.js]
 [browser_bug410900.js]
 [browser_bug705422.js]
@@ -40,17 +35,16 @@ skip-if = !updater
 [browser_engines.js]
 support-files =
   browser_bug1184989_prevent_scrolling_when_preferences_flipped.xul
 [browser_change_app_handler.js]
 skip-if = os != "win" || (os == "win" && os_version == "6.1")
 # This test tests the windows-specific app selection dialog, so can't run on non-Windows.
 # Skip the test on Window 7, see the detail at Bug 1381706.
 [browser_checkspelling.js]
-[browser_clearSiteData.js]
 [browser_connection.js]
 [browser_connection_bug388287.js]
 [browser_cookies_exceptions.js]
 [browser_defaultbrowser_alwayscheck.js]
 [browser_healthreport.js]
 skip-if = true || !healthreport # Bug 1185403 for the "true"
 [browser_homepages_filter_aboutpreferences.js]
 [browser_extension_controlled.js]
@@ -77,19 +71,16 @@ run-if = nightly_build
 [browser_privacypane_4.js]
 [browser_privacypane_5.js]
 [browser_privacypane_8.js]
 [browser_sanitizeOnShutdown_prefLocked.js]
 [browser_searchShowSuggestionsFirst.js]
 [browser_searchsuggestions.js]
 [browser_security-1.js]
 [browser_security-2.js]
-[browser_siteData.js]
-[browser_siteData2.js]
-[browser_siteData3.js]
 [browser_spotlight.js]
 [browser_site_login_exceptions.js]
 [browser_permissions_dialog.js]
 [browser_subdialogs.js]
 support-files =
   subdialog.xul
   subdialog2.xul
 [browser_telemetry.js]
--- a/browser/components/preferences/in-content/tests/head.js
+++ b/browser/components/preferences/in-content/tests/head.js
@@ -1,15 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 ChromeUtils.import("resource://gre/modules/Promise.jsm", this);
 
-XPCOMUtils.defineLazyServiceGetter(this, "serviceWorkerManager", "@mozilla.org/serviceworkers/manager;1", "nsIServiceWorkerManager");
-
 const kDefaultWait = 2000;
 
 function is_hidden(aElement) {
   var style = aElement.ownerGlobal.getComputedStyle(aElement);
   if (style.display == "none")
     return true;
   if (style.visibility != "visible")
     return true;
@@ -139,56 +137,16 @@ function openPreferencesViaOpenPreferenc
           gBrowser.removeCurrentTab();
         resolve({ selectedPane });
       }, { once: true });
     }, { capture: true, once: true });
 
   });
 }
 
-function promiseWindowDialogOpen(buttonAction, url) {
-  return BrowserTestUtils.promiseAlertDialogOpen(buttonAction, url);
-}
-
-function promiseAlertDialogOpen(buttonAction) {
-  return BrowserTestUtils.promiseAlertDialogOpen(buttonAction);
-}
-
-function promiseSiteDataManagerSitesUpdated() {
-  return TestUtils.topicObserved("sitedatamanager:sites-updated", () => true);
-}
-
-function openSiteDataSettingsDialog() {
-  let doc = gBrowser.selectedBrowser.contentDocument;
-  let settingsBtn = doc.getElementById("siteDataSettings");
-  let dialogOverlay = content.gSubDialog._preloadDialog._overlay;
-  let dialogLoadPromise = promiseLoadSubDialog("chrome://browser/content/preferences/siteDataSettings.xul");
-  let dialogInitPromise = TestUtils.topicObserved("sitedata-settings-init", () => true);
-  let fullyLoadPromise = Promise.all([dialogLoadPromise, dialogInitPromise]).then(() => {
-    is(dialogOverlay.style.visibility, "visible", "The Settings dialog should be visible");
-  });
-  settingsBtn.doCommand();
-  return fullyLoadPromise;
-}
-
-function assertSitesListed(doc, hosts) {
-  let frameDoc = content.gSubDialog._topDialog._frame.contentDocument;
-  let removeBtn = frameDoc.getElementById("removeSelected");
-  let removeAllBtn = frameDoc.getElementById("removeAll");
-  let sitesList = frameDoc.getElementById("sitesList");
-  let totalSitesNumber = sitesList.getElementsByTagName("richlistitem").length;
-  is(totalSitesNumber, hosts.length, "Should list the right sites number");
-  hosts.forEach(host => {
-    let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
-    ok(site, `Should list the site of ${host}`);
-  });
-  is(removeBtn.disabled, true, "Should disable the removeSelected button");
-  is(removeAllBtn.disabled, false, "Should enable the removeAllBtn button");
-}
-
 async function evaluateSearchResults(keyword, searchReults) {
   searchReults = Array.isArray(searchReults) ? searchReults : [searchReults];
   searchReults.push("header-searchResults");
 
   let searchInput = gBrowser.contentDocument.getElementById("searchInput");
   searchInput.focus();
   let searchCompletedPromise = BrowserTestUtils.waitForEvent(
     gBrowser.contentWindow, "PreferencesSearchCompleted", evt => evt.detail == keyword);
@@ -201,116 +159,8 @@ async function evaluateSearchResults(key
     if (searchReults.includes(child.id)) {
       is_element_visible(child, "Should be in search results");
     } else if (child.id) {
       is_element_hidden(child, "Should not be in search results");
     }
   }
 }
 
-const mockSiteDataManager = {
-
-  _SiteDataManager: null,
-  _originalQMS: null,
-  _originalRemoveQuotaUsage: null,
-
-  getUsage(onUsageResult) {
-    let result = this.fakeSites.map(site => ({
-      origin: site.principal.origin,
-      usage: site.usage,
-      persisted: site.persisted,
-      lastAccessed: site.lastAccessed,
-    }));
-    onUsageResult({ result, resultCode: Cr.NS_OK });
-  },
-
-  _removeQuotaUsage(site) {
-    var target = site.principals[0].URI.host;
-    this.fakeSites = this.fakeSites.filter(fakeSite => {
-      return fakeSite.principal.URI.host != target;
-    });
-  },
-
-  register(SiteDataManager, fakeSites) {
-    this._SiteDataManager = SiteDataManager;
-    this._originalQMS = this._SiteDataManager._qms;
-    this._SiteDataManager._qms = this;
-    this._originalRemoveQuotaUsage = this._SiteDataManager._removeQuotaUsage;
-    this._SiteDataManager._removeQuotaUsage = this._removeQuotaUsage.bind(this);
-    // Add some fake data.
-    this.fakeSites = fakeSites;
-    for (let site of fakeSites) {
-      if (!site.principal) {
-        site.principal = Services.scriptSecurityManager
-          .createCodebasePrincipalFromOrigin(site.origin);
-      }
-
-      let uri = site.principal.URI;
-      try {
-        site.baseDomain = Services.eTLD.getBaseDomainFromHost(uri.host);
-      } catch (e) {
-        site.baseDomain = uri.host;
-      }
-
-      // Add some cookies if needed.
-      for (let i = 0; i < (site.cookies || 0); i++) {
-        Services.cookies.add(uri.host, uri.pathQueryRef, Cu.now(), i,
-          false, false, false, Date.now() + 1000 * 60 * 60);
-      }
-    }
-  },
-
-  async unregister() {
-    await this._SiteDataManager.removeAll();
-    this.fakeSites = null;
-    this._SiteDataManager._qms = this._originalQMS;
-    this._SiteDataManager._removeQuotaUsage = this._originalRemoveQuotaUsage;
-  }
-};
-
-function getQuotaUsage(origin) {
-  return new Promise(resolve => {
-    let uri = NetUtil.newURI(origin);
-    let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
-    Services.qms.getUsageForPrincipal(principal, request => resolve(request.result.usage));
-  });
-}
-
-function promiseCookiesCleared() {
-  return TestUtils.topicObserved("cookie-changed", (subj, data) => {
-    return data === "cleared";
-  });
-}
-
-async function loadServiceWorkerTestPage(url) {
-  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
-  await BrowserTestUtils.waitForCondition(() => {
-    return ContentTask.spawn(tab.linkedBrowser, {}, () =>
-      content.document.body.getAttribute("data-test-service-worker-registered") === "true");
-  }, `Fail to load service worker test ${url}`);
-  await BrowserTestUtils.removeTab(tab);
-}
-
-function promiseServiceWorkersCleared() {
-  return BrowserTestUtils.waitForCondition(() => {
-    let serviceWorkers = serviceWorkerManager.getAllRegistrations();
-    if (serviceWorkers.length == 0) {
-      ok(true, "Cleared all service workers");
-      return true;
-    }
-    return false;
-  }, "Should clear all service workers");
-}
-
-function promiseServiceWorkerRegisteredFor(url) {
-  return BrowserTestUtils.waitForCondition(() => {
-    try {
-      let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin(url);
-      let sw = serviceWorkerManager.getRegistrationByPrincipal(principal, principal.URI.spec);
-      if (sw) {
-        ok(true, `Found the service worker registered for ${url}`);
-        return true;
-      }
-    } catch (e) {}
-    return false;
-  }, `Should register service worker for ${url}`);
-}
-
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/siteData/browser.ini
@@ -0,0 +1,13 @@
+[DEFAULT]
+support-files =
+  head.js
+  site_data_test.html
+  service_worker_test.html
+  service_worker_test.js
+  offline/offline.html
+  offline/manifest.appcache
+
+[browser_clearSiteData.js]
+[browser_siteData.js]
+[browser_siteData2.js]
+[browser_siteData3.js]
rename from browser/components/preferences/in-content/tests/browser_clearSiteData.js
rename to browser/components/preferences/in-content/tests/siteData/browser_clearSiteData.js
--- a/browser/components/preferences/in-content/tests/browser_clearSiteData.js
+++ b/browser/components/preferences/in-content/tests/siteData/browser_clearSiteData.js
@@ -1,26 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 ChromeUtils.import("resource:///modules/SitePermissions.jsm");
 
-const { SiteDataManager } = ChromeUtils.import("resource:///modules/SiteDataManager.jsm", {});
-const { DownloadUtils } = ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm", {});
-
-const TEST_QUOTA_USAGE_HOST = "example.com";
-const TEST_QUOTA_USAGE_ORIGIN = "https://" + TEST_QUOTA_USAGE_HOST;
-const TEST_QUOTA_USAGE_URL = TEST_QUOTA_USAGE_ORIGIN + "/browser/browser/components/preferences/in-content/tests/site_data_test.html";
-const TEST_OFFLINE_HOST = "example.org";
-const TEST_OFFLINE_ORIGIN = "https://" + TEST_OFFLINE_HOST;
-const TEST_OFFLINE_URL = TEST_OFFLINE_ORIGIN + "/browser/browser/components/preferences/in-content/tests/offline/offline.html";
-const TEST_SERVICE_WORKER_URL = TEST_OFFLINE_ORIGIN + "/browser/browser/components/preferences/in-content/tests/service_worker_test.html";
-
 async function testClearData(clearSiteData, clearCache) {
   let quotaURI = Services.io.newURI(TEST_QUOTA_USAGE_ORIGIN);
   SitePermissions.set(quotaURI, "persistent-storage", SitePermissions.ALLOW);
 
   // Open a test site which saves into appcache.
   await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_OFFLINE_URL);
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 
@@ -84,17 +73,17 @@ async function testClearData(clearSiteDa
   clearCacheCheckbox.checked = clearCache;
 
   // Some additional promises/assertions to wait for
   // when deleting site data.
   let acceptPromise;
   let updatePromise;
   let cookiesClearedPromise;
   if (clearSiteData) {
-    acceptPromise = promiseAlertDialogOpen("accept");
+    acceptPromise = BrowserTestUtils.promiseAlertDialogOpen("accept");
     updatePromise = promiseSiteDataManagerSitesUpdated();
     cookiesClearedPromise = promiseCookiesCleared();
   }
 
   let dialogClosed = BrowserTestUtils.waitForEvent(dialogWin, "unload");
 
   let clearButton = dialogWin.document.getElementById("clearButton");
   if (!clearSiteData && !clearCache) {
rename from browser/components/preferences/in-content/tests/browser_siteData.js
rename to browser/components/preferences/in-content/tests/siteData/browser_siteData.js
--- a/browser/components/preferences/in-content/tests/browser_siteData.js
+++ b/browser/components/preferences/in-content/tests/siteData/browser_siteData.js
@@ -1,38 +1,22 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-const TEST_QUOTA_USAGE_HOST = "example.com";
-const TEST_QUOTA_USAGE_ORIGIN = "https://" + TEST_QUOTA_USAGE_HOST;
-const TEST_QUOTA_USAGE_URL = TEST_QUOTA_USAGE_ORIGIN + "/browser/browser/components/preferences/in-content/tests/site_data_test.html";
-const TEST_OFFLINE_HOST = "example.org";
-const TEST_OFFLINE_ORIGIN = "https://" + TEST_OFFLINE_HOST;
-const TEST_OFFLINE_URL = TEST_OFFLINE_ORIGIN + "/browser/browser/components/preferences/in-content/tests/offline/offline.html";
-const TEST_SERVICE_WORKER_URL = TEST_OFFLINE_ORIGIN + "/browser/browser/components/preferences/in-content/tests/service_worker_test.html";
-const REMOVE_DIALOG_URL = "chrome://browser/content/preferences/siteDataRemoveSelected.xul";
-
-const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm", {});
-const { DownloadUtils } = ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm", {});
-const { SiteDataManager } = ChromeUtils.import("resource:///modules/SiteDataManager.jsm", {});
-const { OfflineAppCacheHelper } = ChromeUtils.import("resource:///modules/offlineAppCache.jsm", {});
-
 function getPersistentStoragePermStatus(origin) {
-  let uri = NetUtil.newURI(origin);
+  let uri = Services.io.newURI(origin);
   let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
   return Services.perms.testExactPermissionFromPrincipal(principal, "persistent-storage");
 }
 
 // Test listing site using quota usage or site using appcache
 // This is currently disabled because of bug 1414751.
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
-
   // Open a test site which would save into appcache
   await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_OFFLINE_URL);
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 
   // Open a test site which would save into quota manager
   BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_QUOTA_USAGE_URL);
   await BrowserTestUtils.waitForContentEvent(
     gBrowser.selectedBrowser, "test-indexedDB-done", false, null, true);
@@ -66,17 +50,16 @@ add_task(async function() {
   });
 
   await SiteDataManager.removeAll();
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 }).skip(); // Bug 1414751
 
 // Test buttons are disabled and loading message shown while updating sites
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
   let updatedPromise = promiseSiteDataManagerSitesUpdated();
   await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
   await updatedPromise;
   let cacheSize = await SiteDataManager.getCacheSize();
 
   let actual = null;
   let expected = null;
   let doc = gBrowser.selectedBrowser.contentDocument;
@@ -113,25 +96,24 @@ add_task(async function() {
                           is(actual, expected, "Should show the right total site data size");
                        });
 
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 // Test clearing service wroker through the settings panel
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
   // Register a test service worker
   await loadServiceWorkerTestPage(TEST_SERVICE_WORKER_URL);
   await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
   // Test the initial states
   await promiseServiceWorkerRegisteredFor(TEST_SERVICE_WORKER_URL);
   // Open the Site Data Settings panel and remove the site
   await openSiteDataSettingsDialog();
-  let acceptRemovePromise = promiseAlertDialogOpen("accept");
+  let acceptRemovePromise = BrowserTestUtils.promiseAlertDialogOpen("accept");
   let updatePromise = promiseSiteDataManagerSitesUpdated();
   ContentTask.spawn(gBrowser.selectedBrowser, { TEST_OFFLINE_HOST }, args => {
     let host = args.TEST_OFFLINE_HOST;
     let frameDoc = content.gSubDialog._topDialog._frame.contentDocument;
     let sitesList = frameDoc.getElementById("sitesList");
     let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
     if (site) {
       let removeBtn = frameDoc.getElementById("removeSelected");
@@ -181,17 +163,17 @@ add_task(async function() {
 
   let creationDate1 = formatter.format(new Date(cookie1.lastAccessed / 1000));
   let creationDate2 = formatter.format(new Date(cookie2.lastAccessed / 1000));
 
   await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
 
   // Open the site data manager and remove one site.
   await openSiteDataSettingsDialog();
-  let removeDialogOpenPromise = promiseWindowDialogOpen("accept", REMOVE_DIALOG_URL);
+  let removeDialogOpenPromise = BrowserTestUtils.promiseAlertDialogOpen("accept", REMOVE_DIALOG_URL);
   await ContentTask.spawn(gBrowser.selectedBrowser, {creationDate1, creationDate2}, function(args) {
     let frameDoc = content.gSubDialog._topDialog._frame.contentDocument;
 
     let siteItems = frameDoc.getElementsByTagName("richlistitem");
     is(siteItems.length, 2, "Should list two sites with cookies");
     let sitesList = frameDoc.getElementById("sitesList");
     let site1 = sitesList.querySelector(`richlistitem[host="example.com"]`);
     let site2 = sitesList.querySelector(`richlistitem[host="example.org"]`);
@@ -216,17 +198,17 @@ add_task(async function() {
   });
   await removeDialogOpenPromise;
 
   await TestUtils.waitForCondition(() => Services.cookies.countCookiesFromHost(uri2.host) == 0, "Cookies from the first host should be cleared");
   is(Services.cookies.countCookiesFromHost(uri.host), 2, "Cookies from the second host should not be cleared");
 
   // Open the site data manager and remove another site.
   await openSiteDataSettingsDialog();
-  let acceptRemovePromise = promiseAlertDialogOpen("accept");
+  let acceptRemovePromise = BrowserTestUtils.promiseAlertDialogOpen("accept");
   await ContentTask.spawn(gBrowser.selectedBrowser, {creationDate1}, function(args) {
     let frameDoc = content.gSubDialog._topDialog._frame.contentDocument;
 
     let siteItems = frameDoc.getElementsByTagName("richlistitem");
     is(siteItems.length, 1, "Should list one site with cookies");
     let sitesList = frameDoc.getElementById("sitesList");
     let site1 = sitesList.querySelector(`richlistitem[host="example.com"]`);
 
rename from browser/components/preferences/in-content/tests/browser_siteData2.js
rename to browser/components/preferences/in-content/tests/siteData/browser_siteData2.js
--- a/browser/components/preferences/in-content/tests/browser_siteData2.js
+++ b/browser/components/preferences/in-content/tests/siteData/browser_siteData2.js
@@ -1,11 +1,9 @@
 "use strict";
-const { SiteDataManager } = ChromeUtils.import("resource:///modules/SiteDataManager.jsm", {});
-const REMOVE_DIALOG_URL = "chrome://browser/content/preferences/siteDataRemoveSelected.xul";
 
 /* eslint-disable mozilla/no-cpows-in-tests */
 
 function promiseSettingsDialogClose() {
   return new Promise(resolve => {
     let win = gBrowser.selectedBrowser.contentWindow;
     let dialogOverlay = win.gSubDialog._topDialog._overlay;
     let dialogWin = win.gSubDialog._topDialog._frame.contentWindow;
@@ -26,17 +24,16 @@ function assertAllSitesNotListed(win) {
   let sites = sitesList.getElementsByTagName("richlistitem");
   is(sites.length, 0, "Should not list all sites");
   is(removeBtn.disabled, true, "Should disable the removeSelected button");
   is(removeAllBtn.disabled, true, "Should disable the removeAllBtn button");
 }
 
 // Test selecting and removing all sites one by one
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
   mockSiteDataManager.register(SiteDataManager, [
     {
       usage: 1024,
       origin: "https://account.xyz.com",
       persisted: true
     },
     {
       usage: 1024,
@@ -78,32 +75,32 @@ add_task(async function() {
   removeAllSitesOneByOne();
   assertAllSitesNotListed(win);
   cancelBtn.doCommand();
   await settingsDialogClosePromise;
   await openSiteDataSettingsDialog();
   assertSitesListed(doc, fakeHosts);
 
   // Test the "Save Changes" button but cancelling save
-  let cancelPromise = promiseAlertDialogOpen("cancel");
+  let cancelPromise = BrowserTestUtils.promiseAlertDialogOpen("cancel");
   settingsDialogClosePromise = promiseSettingsDialogClose();
   frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
   saveBtn = frameDoc.getElementById("save");
   cancelBtn = frameDoc.getElementById("cancel");
   removeAllSitesOneByOne();
   assertAllSitesNotListed(win);
   saveBtn.doCommand();
   await cancelPromise;
   cancelBtn.doCommand();
   await settingsDialogClosePromise;
   await openSiteDataSettingsDialog();
   assertSitesListed(doc, fakeHosts);
 
   // Test the "Save Changes" button and accepting save
-  let acceptPromise = promiseAlertDialogOpen("accept");
+  let acceptPromise = BrowserTestUtils.promiseAlertDialogOpen("accept");
   settingsDialogClosePromise = promiseSettingsDialogClose();
   updatePromise = promiseSiteDataManagerSitesUpdated();
   frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
   saveBtn = frameDoc.getElementById("save");
   removeAllSitesOneByOne();
   assertAllSitesNotListed(win);
   saveBtn.doCommand();
   await acceptPromise;
@@ -124,17 +121,16 @@ add_task(async function() {
       sites[i].click();
       removeBtn.doCommand();
     }
   }
 });
 
 // Test selecting and removing partial sites
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
   mockSiteDataManager.register(SiteDataManager, [
     {
       usage: 1024,
       origin: "https://account.xyz.com",
       persisted: true
     },
     {
       usage: 1024,
@@ -192,32 +188,32 @@ add_task(async function() {
   removeSelectedSite(fakeHosts.slice(0, 2));
   assertSitesListed(doc, fakeHosts.slice(2));
   cancelBtn.doCommand();
   await settingsDialogClosePromise;
   await openSiteDataSettingsDialog();
   assertSitesListed(doc, fakeHosts);
 
   // Test the "Save Changes" button but canceling save
-  removeDialogOpenPromise = promiseWindowDialogOpen("cancel", REMOVE_DIALOG_URL);
+  removeDialogOpenPromise = BrowserTestUtils.promiseAlertDialogOpen("cancel", REMOVE_DIALOG_URL);
   settingsDialogClosePromise = promiseSettingsDialogClose();
   frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
   saveBtn = frameDoc.getElementById("save");
   cancelBtn = frameDoc.getElementById("cancel");
   removeSelectedSite(fakeHosts.slice(0, 2));
   assertSitesListed(doc, fakeHosts.slice(2));
   saveBtn.doCommand();
   await removeDialogOpenPromise;
   cancelBtn.doCommand();
   await settingsDialogClosePromise;
   await openSiteDataSettingsDialog();
   assertSitesListed(doc, fakeHosts);
 
   // Test the "Save Changes" button and accepting save
-  removeDialogOpenPromise = promiseWindowDialogOpen("accept", REMOVE_DIALOG_URL);
+  removeDialogOpenPromise = BrowserTestUtils.promiseAlertDialogOpen("accept", REMOVE_DIALOG_URL);
   settingsDialogClosePromise = promiseSettingsDialogClose();
   frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
   saveBtn = frameDoc.getElementById("save");
   removeSelectedSite(fakeHosts.slice(0, 2));
   assertSitesListed(doc, fakeHosts.slice(2));
   saveBtn.doCommand();
   await removeDialogOpenPromise;
   await settingsDialogClosePromise;
@@ -242,17 +238,16 @@ add_task(async function() {
         ok(false, `Should not select and remove inexistent site of ${host}`);
       }
     });
   }
 });
 
 // Test searching and then removing only visible sites
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
   mockSiteDataManager.register(SiteDataManager, [
     {
       usage: 1024,
       origin: "https://account.xyz.com",
       persisted: true
     },
     {
       usage: 1024,
@@ -283,17 +278,17 @@ add_task(async function() {
   let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
   let searchBox = frameDoc.getElementById("searchBox");
   searchBox.value = "xyz";
   searchBox.doCommand();
   assertSitesListed(doc, fakeHosts.filter(host => host.includes("xyz")));
 
   // Test only removing all visible sites listed
   updatePromise = promiseSiteDataManagerSitesUpdated();
-  let acceptRemovePromise = promiseWindowDialogOpen("accept", REMOVE_DIALOG_URL);
+  let acceptRemovePromise = BrowserTestUtils.promiseAlertDialogOpen("accept", REMOVE_DIALOG_URL);
   let settingsDialogClosePromise = promiseSettingsDialogClose();
   let removeAllBtn = frameDoc.getElementById("removeAll");
   let saveBtn = frameDoc.getElementById("save");
   removeAllBtn.doCommand();
   saveBtn.doCommand();
   await acceptRemovePromise;
   await settingsDialogClosePromise;
   await updatePromise;
@@ -301,17 +296,16 @@ add_task(async function() {
   assertSitesListed(doc, fakeHosts.filter(host => !host.includes("xyz")));
 
   await mockSiteDataManager.unregister();
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 // Test dynamically clearing all site data
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
   mockSiteDataManager.register(SiteDataManager, [
     {
       usage: 1024,
       origin: "https://account.xyz.com",
       persisted: true
     },
     {
       usage: 1024,
@@ -341,17 +335,17 @@ add_task(async function() {
                        .createCodebasePrincipalFromOrigin("http://email.bar.com"),
     persisted: false
   });
 
   // Test clearing all site data dynamically
   let win = gBrowser.selectedBrowser.contentWindow;
   let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
   updatePromise = promiseSiteDataManagerSitesUpdated();
-  let acceptRemovePromise = promiseAlertDialogOpen("accept");
+  let acceptRemovePromise = BrowserTestUtils.promiseAlertDialogOpen("accept");
   let settingsDialogClosePromise = promiseSettingsDialogClose();
   let removeAllBtn = frameDoc.getElementById("removeAll");
   let saveBtn = frameDoc.getElementById("save");
   removeAllBtn.doCommand();
   saveBtn.doCommand();
   await acceptRemovePromise;
   await settingsDialogClosePromise;
   await updatePromise;
rename from browser/components/preferences/in-content/tests/browser_siteData3.js
rename to browser/components/preferences/in-content/tests/siteData/browser_siteData3.js
--- a/browser/components/preferences/in-content/tests/browser_siteData3.js
+++ b/browser/components/preferences/in-content/tests/siteData/browser_siteData3.js
@@ -1,15 +1,12 @@
 "use strict";
-const { SiteDataManager } = ChromeUtils.import("resource:///modules/SiteDataManager.jsm", {});
-const { DownloadUtils } = ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm", {});
 
 // Test not displaying sites which store 0 byte and don't have persistent storage.
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({ set: [["browser.storageManager.enabled", true]] });
   mockSiteDataManager.register(SiteDataManager, [
     {
       usage: 0,
       origin: "https://account.xyz.com",
       persisted: true
     },
     {
       usage: 0,
@@ -43,17 +40,16 @@ add_task(async function() {
   assertSitesListed(doc, fakeHosts.filter(host => host != "shopping.xyz.com"));
 
   await mockSiteDataManager.unregister();
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 // Test grouping and listing sites across scheme, port and origin attributes by host
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({ set: [["browser.storageManager.enabled", true]] });
   const quotaUsage = 1024;
   mockSiteDataManager.register(SiteDataManager, [
     {
       usage: quotaUsage,
       origin: "https://account.xyz.com^userContextId=1",
       cookies: 2,
       persisted: true
     },
@@ -102,17 +98,16 @@ add_task(async function() {
   is(columns[2].value, expected, "Should sum up usages across scheme, port, origin attributes and persistent status");
 
   await mockSiteDataManager.unregister();
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 // Test sorting
 add_task(async function() {
-  await SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
   mockSiteDataManager.register(SiteDataManager, [
     {
       usage: 1024,
       origin: "https://account.xyz.com",
       cookies: 6,
       persisted: true,
     },
     {
copy from browser/components/preferences/in-content/tests/head.js
copy to browser/components/preferences/in-content/tests/siteData/head.js
--- a/browser/components/preferences/in-content/tests/head.js
+++ b/browser/components/preferences/in-content/tests/siteData/head.js
@@ -1,16 +1,32 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-ChromeUtils.import("resource://gre/modules/Promise.jsm", this);
+"use strict";
+
+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 TEST_OFFLINE_HOST = "example.org";
+const TEST_OFFLINE_ORIGIN = "https://" + TEST_OFFLINE_HOST;
+const TEST_OFFLINE_URL = getRootDirectory(gTestPath).replace("chrome://mochitests/content", TEST_OFFLINE_ORIGIN) + "/offline/offline.html";
+const TEST_SERVICE_WORKER_URL = getRootDirectory(gTestPath).replace("chrome://mochitests/content", TEST_OFFLINE_ORIGIN) + "/service_worker_test.html";
+
+const REMOVE_DIALOG_URL = "chrome://browser/content/preferences/siteDataRemoveSelected.xul";
+
+const { DownloadUtils } = ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm", {});
+const { SiteDataManager } = ChromeUtils.import("resource:///modules/SiteDataManager.jsm", {});
+const { OfflineAppCacheHelper } = ChromeUtils.import("resource:///modules/offlineAppCache.jsm", {});
 
 XPCOMUtils.defineLazyServiceGetter(this, "serviceWorkerManager", "@mozilla.org/serviceworkers/manager;1", "nsIServiceWorkerManager");
 
-const kDefaultWait = 2000;
+function promiseSiteDataManagerSitesUpdated() {
+  return TestUtils.topicObserved("sitedatamanager:sites-updated", () => true);
+}
 
 function is_hidden(aElement) {
   var style = aElement.ownerGlobal.getComputedStyle(aElement);
   if (style.display == "none")
     return true;
   if (style.visibility != "visible")
     return true;
 
@@ -26,30 +42,16 @@ function is_element_visible(aElement, aM
   ok(!is_hidden(aElement), aMsg);
 }
 
 function is_element_hidden(aElement, aMsg) {
   isnot(aElement, null, "Element should not be null, when checking visibility");
   ok(is_hidden(aElement), aMsg);
 }
 
-function open_preferences(aCallback) {
-  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:preferences");
-  let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
-  newTabBrowser.addEventListener("Initialized", function() {
-    aCallback(gBrowser.contentWindow);
-  }, { capture: true, once: true });
-}
-
-function openAndLoadSubDialog(aURL, aFeatures = null, aParams = null, aClosingCallback = null) {
-  let promise = promiseLoadSubDialog(aURL);
-  content.gSubDialog.open(aURL, aFeatures, aParams, aClosingCallback);
-  return promise;
-}
-
 function promiseLoadSubDialog(aURL) {
   return new Promise((resolve, reject) => {
     content.gSubDialog._dialogStack.addEventListener("dialogopen", function dialogopen(aEvent) {
       if (aEvent.detail.dialog._frame.contentWindow.location == "about:blank")
         return;
       content.gSubDialog._dialogStack.removeEventListener("dialogopen", dialogopen);
 
       is(aEvent.detail.dialog._frame.contentWindow.location.toString(), aURL,
@@ -71,63 +73,16 @@ function promiseLoadSubDialog(aURL) {
 
       // Wait for the next event tick to make sure the remaining part of the
       // testcase runs after the dialog gets ready for input.
       executeSoon(() => resolve(aEvent.detail.dialog._frame.contentWindow));
     });
   });
 }
 
-/**
- * Waits a specified number of miliseconds for a specified event to be
- * fired on a specified element.
- *
- * Usage:
- *    let receivedEvent = waitForEvent(element, "eventName");
- *    // Do some processing here that will cause the event to be fired
- *    // ...
- *    // Now yield until the Promise is fulfilled
- *    yield receivedEvent;
- *    if (receivedEvent && !(receivedEvent instanceof Error)) {
- *      receivedEvent.msg == "eventName";
- *      // ...
- *    }
- *
- * @param aSubject the element that should receive the event
- * @param aEventName the event to wait for
- * @param aTimeoutMs the number of miliseconds to wait before giving up
- * @returns a Promise that resolves to the received event, or to an Error
- */
-function waitForEvent(aSubject, aEventName, aTimeoutMs, aTarget) {
-  let eventDeferred = Promise.defer();
-  let timeoutMs = aTimeoutMs || kDefaultWait;
-  let stack = new Error().stack;
-  let timerID = setTimeout(function wfe_canceller() {
-    aSubject.removeEventListener(aEventName, listener);
-    eventDeferred.reject(new Error(aEventName + " event timeout at " + stack));
-  }, timeoutMs);
-
-  var listener = function(aEvent) {
-    if (aTarget && aTarget !== aEvent.target)
-      return;
-
-    // stop the timeout clock and resume
-    clearTimeout(timerID);
-    eventDeferred.resolve(aEvent);
-  };
-
-  function cleanup(aEventOrError) {
-    // unhook listener in case of success or failure
-    aSubject.removeEventListener(aEventName, listener);
-    return aEventOrError;
-  }
-  aSubject.addEventListener(aEventName, listener);
-  return eventDeferred.promise.then(cleanup, cleanup);
-}
-
 function openPreferencesViaOpenPreferencesAPI(aPane, aOptions) {
   return new Promise(resolve => {
     let finalPrefPaneLoaded = TestUtils.topicObserved("sync-pane-loaded", () => true);
     gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
     openPreferences(aPane);
     let newTabBrowser = gBrowser.selectedBrowser;
 
     newTabBrowser.addEventListener("Initialized", function() {
@@ -139,28 +94,16 @@ function openPreferencesViaOpenPreferenc
           gBrowser.removeCurrentTab();
         resolve({ selectedPane });
       }, { once: true });
     }, { capture: true, once: true });
 
   });
 }
 
-function promiseWindowDialogOpen(buttonAction, url) {
-  return BrowserTestUtils.promiseAlertDialogOpen(buttonAction, url);
-}
-
-function promiseAlertDialogOpen(buttonAction) {
-  return BrowserTestUtils.promiseAlertDialogOpen(buttonAction);
-}
-
-function promiseSiteDataManagerSitesUpdated() {
-  return TestUtils.topicObserved("sitedatamanager:sites-updated", () => true);
-}
-
 function openSiteDataSettingsDialog() {
   let doc = gBrowser.selectedBrowser.contentDocument;
   let settingsBtn = doc.getElementById("siteDataSettings");
   let dialogOverlay = content.gSubDialog._preloadDialog._overlay;
   let dialogLoadPromise = promiseLoadSubDialog("chrome://browser/content/preferences/siteDataSettings.xul");
   let dialogInitPromise = TestUtils.topicObserved("sitedata-settings-init", () => true);
   let fullyLoadPromise = Promise.all([dialogLoadPromise, dialogInitPromise]).then(() => {
     is(dialogOverlay.style.visibility, "visible", "The Settings dialog should be visible");
@@ -179,38 +122,16 @@ function assertSitesListed(doc, hosts) {
   hosts.forEach(host => {
     let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
     ok(site, `Should list the site of ${host}`);
   });
   is(removeBtn.disabled, true, "Should disable the removeSelected button");
   is(removeAllBtn.disabled, false, "Should enable the removeAllBtn button");
 }
 
-async function evaluateSearchResults(keyword, searchReults) {
-  searchReults = Array.isArray(searchReults) ? searchReults : [searchReults];
-  searchReults.push("header-searchResults");
-
-  let searchInput = gBrowser.contentDocument.getElementById("searchInput");
-  searchInput.focus();
-  let searchCompletedPromise = BrowserTestUtils.waitForEvent(
-    gBrowser.contentWindow, "PreferencesSearchCompleted", evt => evt.detail == keyword);
-  EventUtils.sendString(keyword);
-  await searchCompletedPromise;
-
-  let mainPrefTag = gBrowser.contentDocument.getElementById("mainPrefPane");
-  for (let i = 0; i < mainPrefTag.childElementCount; i++) {
-    let child = mainPrefTag.children[i];
-    if (searchReults.includes(child.id)) {
-      is_element_visible(child, "Should be in search results");
-    } else if (child.id) {
-      is_element_hidden(child, "Should not be in search results");
-    }
-  }
-}
-
 const mockSiteDataManager = {
 
   _SiteDataManager: null,
   _originalQMS: null,
   _originalRemoveQuotaUsage: null,
 
   getUsage(onUsageResult) {
     let result = this.fakeSites.map(site => ({
@@ -224,18 +145,18 @@ const mockSiteDataManager = {
 
   _removeQuotaUsage(site) {
     var target = site.principals[0].URI.host;
     this.fakeSites = this.fakeSites.filter(fakeSite => {
       return fakeSite.principal.URI.host != target;
     });
   },
 
-  register(SiteDataManager, fakeSites) {
-    this._SiteDataManager = SiteDataManager;
+  register(siteDataManager, fakeSites) {
+    this._SiteDataManager = siteDataManager;
     this._originalQMS = this._SiteDataManager._qms;
     this._SiteDataManager._qms = this;
     this._originalRemoveQuotaUsage = this._SiteDataManager._removeQuotaUsage;
     this._SiteDataManager._removeQuotaUsage = this._removeQuotaUsage.bind(this);
     // Add some fake data.
     this.fakeSites = fakeSites;
     for (let site of fakeSites) {
       if (!site.principal) {
rename from browser/components/preferences/in-content/tests/offline/manifest.appcache
rename to browser/components/preferences/in-content/tests/siteData/offline/manifest.appcache
rename from browser/components/preferences/in-content/tests/offline/offline.html
rename to browser/components/preferences/in-content/tests/siteData/offline/offline.html
rename from browser/components/preferences/in-content/tests/service_worker_test.html
rename to browser/components/preferences/in-content/tests/siteData/service_worker_test.html
rename from browser/components/preferences/in-content/tests/service_worker_test.js
rename to browser/components/preferences/in-content/tests/siteData/service_worker_test.js
rename from browser/components/preferences/in-content/tests/site_data_test.html
rename to browser/components/preferences/in-content/tests/siteData/site_data_test.html
--- a/browser/components/preferences/moz.build
+++ b/browser/components/preferences/moz.build
@@ -4,17 +4,18 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DIRS += [
 	'in-content'
 ]
 
 BROWSER_CHROME_MANIFESTS += [
-    'in-content/tests/browser.ini'
+    'in-content/tests/browser.ini',
+    'in-content/tests/siteData/browser.ini'
 ]
 
 for var in ('MOZ_APP_NAME', 'MOZ_MACBUNDLE_NAME'):
     DEFINES[var] = CONFIG[var]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk3', 'cocoa'):
     DEFINES['HAVE_SHELL_SERVICE'] = 1