Bug 1509638 - Split browser_cookiePermission.js test, r=johannh
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 06 Mar 2019 10:24:10 +0000
changeset 520456 b25ed3efc1b313962d3d360db7cedf033dadd27e
parent 520455 0f706ba8fc8dd215149421cd278f400318e2a37b
child 520457 3f01af64f1bb74cf43ded6a381ae4c2a625fcf9a
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1509638
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509638 - Split browser_cookiePermission.js test, r=johannh Differential Revision: https://phabricator.services.mozilla.com/D22078
browser/base/content/test/sanitize/browser.ini
browser/base/content/test/sanitize/browser_cookiePermission.js
browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js
browser/base/content/test/sanitize/browser_cookiePermission_containers.js
browser/base/content/test/sanitize/browser_cookiePermission_subDomains.js
browser/base/content/test/sanitize/head.js
--- a/browser/base/content/test/sanitize/browser.ini
+++ b/browser/base/content/test/sanitize/browser.ini
@@ -7,8 +7,11 @@ support-files=
 [browser_purgehistory_clears_sh.js]
 [browser_sanitize-formhistory.js]
 [browser_sanitize-offlineData.js]
 [browser_sanitize-passwordDisabledHosts.js]
 [browser_sanitize-sitepermissions.js]
 [browser_sanitize-timespans.js]
 [browser_sanitizeDialog.js]
 [browser_cookiePermission.js]
+[browser_cookiePermission_aboutURL.js]
+[browser_cookiePermission_containers.js]
+[browser_cookiePermission_subDomains.js]
--- a/browser/base/content/test/sanitize/browser_cookiePermission.js
+++ b/browser/base/content/test/sanitize/browser_cookiePermission.js
@@ -1,400 +1,1 @@
-const {Sanitizer} = ChromeUtils.import("resource:///modules/Sanitizer.jsm");
-const {SiteDataTestUtils} = ChromeUtils.import("resource://testing-common/SiteDataTestUtils.jsm");
-
-function checkDataForAboutURL() {
-  return new Promise(resolve => {
-    let data = true;
-    let uri = Services.io.newURI("about:newtab");
-    let principal =
-      Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
-    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
-    request.onupgradeneeded = function(e) {
-      data = false;
-    };
-    request.onsuccess = function(e) {
-      resolve(data);
-    };
-  });
-}
-
-function createIndexedDB(host, originAttributes) {
-  let uri = Services.io.newURI("https://" + host);
-  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, originAttributes);
-  return SiteDataTestUtils.addToIndexedDB(principal.origin);
-}
-
-function checkIndexedDB(host, originAttributes) {
-  return new Promise(resolve => {
-    let data = true;
-    let uri = Services.io.newURI("https://" + host);
-    let principal =
-      Services.scriptSecurityManager.createCodebasePrincipal(uri,
-                                                             originAttributes);
-    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
-    request.onupgradeneeded = function(e) {
-      data = false;
-    };
-    request.onsuccess = function(e) {
-      resolve(data);
-    };
-  });
-}
-
-function createHostCookie(host, originAttributes) {
-  Services.cookies.add(host, "/test", "foo", "bar",
-    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
-    Ci.nsICookie2.SAMESITE_UNSET);
-}
-
-function createDomainCookie(host, originAttributes) {
-  Services.cookies.add("." + host, "/test", "foo", "bar",
-    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
-    Ci.nsICookie2.SAMESITE_UNSET);
-}
-
-function checkCookie(host, originAttributes) {
-  for (let cookie of Services.cookies.enumerator) {
-    if (ChromeUtils.isOriginAttributesEqual(originAttributes,
-                                            cookie.originAttributes) &&
-        cookie.host.includes(host)) {
-      return true;
-    }
-  }
-  return false;
-}
-
-async function deleteOnShutdown(opt) {
-  // Let's clean up all the data.
-  await new Promise(resolve => {
-    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", opt.lifetimePolicy],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Custom permission without considering OriginAttributes
-  if (opt.cookiePermission !== undefined) {
-    let uri = Services.io.newURI("https://www.example.com");
-    Services.perms.add(uri, "cookie", opt.cookiePermission);
-  }
-
-  // Let's create a tab with some data.
-  await opt.createData((opt.fullHost ? "www." : "") + "example.org",
-                       opt.originAttributes);
-  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
-                         opt.originAttributes),
-                         "We have data for www.example.org");
-  await opt.createData((opt.fullHost ? "www." : "") + "example.com",
-                       opt.originAttributes);
-  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
-                         opt.originAttributes),
-                         "We have data for www.example.com");
-
-  // Cleaning up.
-  await Sanitizer.runSanitizeOnShutdown();
-
-  // All gone!
-  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
-                            opt.originAttributes)),
-                            opt.expectedForOrg, "Do we have data for www.example.org?");
-  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
-                            opt.originAttributes)),
-                            opt.expectedForCom, "Do we have data for www.example.com?");
-
-  // Clean up.
-  await Sanitizer.sanitize([ "cookies", "offlineApps" ]);
-
-  if (opt.cookiePermission !== undefined) {
-    let uri = Services.io.newURI("https://www.example.com");
-    Services.perms.remove(uri, "cookie");
-  }
-}
-
-let tests = [
-  { name: "IDB",
-    createData: createIndexedDB,
-    checkData: checkIndexedDB },
-  { name: "Host Cookie",
-    createData: createHostCookie,
-    checkData: checkCookie },
-  { name: "Domain Cookie",
-    createData: createDomainCookie,
-    checkData: checkCookie },
-];
-
-let attributes = [
-  {name: "default", oa: {}},
-  {name: "container", oa: {userContextId: 1}},
-];
-
-// Delete all, no custom permission, data in example.com, cookie permission set
-// for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnShutdown() {
-      info(methods.name + ": Delete all, no custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: undefined,
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// Delete all, no custom permission, data in www.example.com, cookie permission
-// set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnShutdown() {
-      info(methods.name + ": Delete all, no custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: undefined,
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// All is session, but with ALLOW custom permission, data in example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageWithCustomPermission() {
-      info(methods.name + ": All is session, but with ALLOW custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
-          expectedForOrg: false,
-          expectedForCom: true,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// All is session, but with ALLOW custom permission, data in www.example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageWithCustomPermission() {
-      info(methods.name + ": All is session, but with ALLOW custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
-          expectedForOrg: false,
-          expectedForCom: true,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// All is default, but with SESSION custom permission, data in example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is default, but with SESSION custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
-          expectedForOrg: true,
-          // expected data just for example.com when using indexedDB because
-          // QuotaManager deletes for principal.
-          expectedForCom: false,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// All is default, but with SESSION custom permission, data in www.example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is default, but with SESSION custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
-          expectedForOrg: true,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// Session mode, but with unsupported custom permission, data in
-// www.example.com, cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is session only, but with unsupported custom custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: 123, // invalid cookie permission
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-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);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_SESSION],
-    ["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([ "cookies", "offlineApps" ]);
-
-  let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("about:newtab");
-  await new Promise(aResolve => {
-    let req = Services.qms.clearStoragesForPrincipal(principal);
-    req.callback = () => { aResolve(); };
-  });
-});
-
-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": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_NORMALLY],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Custom permission without considering OriginAttributes
-  let uri = Services.io.newURI("about:newtab");
-  Services.perms.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.createCodebasePrincipalFromOrigin("about:newtab");
-  await new Promise(aResolve => {
-    let req = Services.qms.clearStoragesForPrincipal(principal);
-    req.callback = () => { aResolve(); };
-  });
-
-  Services.perms.remove(uri, "cookie");
-});
-
-// 2 domains: www.mozilla.org (session-only) mozilla.org (allowed) - after the
-// cleanp, mozilla.org must have data.
-add_task(async function subDomains() {
-  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);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_NORMALLY ],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Domains and data
-  let uriA = Services.io.newURI("https://www.mozilla.org");
-  Services.perms.add(uriA, "cookie", Ci.nsICookiePermission.ACCESS_SESSION);
-
-  Services.cookies.add(uriA.host, "/test", "a", "b",
-    false, false, false, Date.now() + 24000 * 60 * 60, {},
-    Ci.nsICookie2.SAMESITE_UNSET);
-
-  await createIndexedDB(uriA.host, {});
-
-  let uriB = Services.io.newURI("https://mozilla.org");
-  Services.perms.add(uriB, "cookie", Ci.nsICookiePermission.ACCESS_ALLOW);
-
-  Services.cookies.add(uriB.host, "/test", "c", "d",
-    false, false, false, Date.now() + 24000 * 60 * 60, {},
-    Ci.nsICookie2.SAMESITE_UNSET);
-
-  await createIndexedDB(uriB.host, {});
-
-  // Check
-  ok(await checkCookie(uriA.host, {}), "We have cookies for URI: " + uriA.host);
-  ok(await checkIndexedDB(uriA.host, {}), "We have IDB for URI: " + uriA.host);
-  ok(await checkCookie(uriB.host, {}), "We have cookies for URI: " + uriB.host);
-  ok(await checkIndexedDB(uriB.host, {}), "We have IDB for URI: " + uriB.host);
-
-  // Cleaning up
-  await Sanitizer.runSanitizeOnShutdown();
-
-  // Check again
-  ok(!(await checkCookie(uriA.host, {})), "We should not have cookies for URI: " + uriA.host);
-  ok(!(await checkIndexedDB(uriA.host, {})), "We should not have IDB for URI: " + uriA.host);
-
-  // Note that cookies are stored per base domain...
-  ok(!(await checkCookie(uriB.host, {})), "We should not have cookies for URI: " + uriB.host);
-  ok(await checkIndexedDB(uriB.host, {}), "We should have IDB for URI: " + uriB.host);
-
-  // Cleaning up permissions
-  Services.perms.remove(uriA, "cookie");
-  Services.perms.remove(uriB, "cookie");
-});
+runAllCookiePermissionTests({name: "default", oa: {}});
copy from browser/base/content/test/sanitize/browser_cookiePermission.js
copy to browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js
--- a/browser/base/content/test/sanitize/browser_cookiePermission.js
+++ b/browser/base/content/test/sanitize/browser_cookiePermission_aboutURL.js
@@ -12,270 +12,16 @@ function checkDataForAboutURL() {
       data = false;
     };
     request.onsuccess = function(e) {
       resolve(data);
     };
   });
 }
 
-function createIndexedDB(host, originAttributes) {
-  let uri = Services.io.newURI("https://" + host);
-  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, originAttributes);
-  return SiteDataTestUtils.addToIndexedDB(principal.origin);
-}
-
-function checkIndexedDB(host, originAttributes) {
-  return new Promise(resolve => {
-    let data = true;
-    let uri = Services.io.newURI("https://" + host);
-    let principal =
-      Services.scriptSecurityManager.createCodebasePrincipal(uri,
-                                                             originAttributes);
-    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
-    request.onupgradeneeded = function(e) {
-      data = false;
-    };
-    request.onsuccess = function(e) {
-      resolve(data);
-    };
-  });
-}
-
-function createHostCookie(host, originAttributes) {
-  Services.cookies.add(host, "/test", "foo", "bar",
-    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
-    Ci.nsICookie2.SAMESITE_UNSET);
-}
-
-function createDomainCookie(host, originAttributes) {
-  Services.cookies.add("." + host, "/test", "foo", "bar",
-    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
-    Ci.nsICookie2.SAMESITE_UNSET);
-}
-
-function checkCookie(host, originAttributes) {
-  for (let cookie of Services.cookies.enumerator) {
-    if (ChromeUtils.isOriginAttributesEqual(originAttributes,
-                                            cookie.originAttributes) &&
-        cookie.host.includes(host)) {
-      return true;
-    }
-  }
-  return false;
-}
-
-async function deleteOnShutdown(opt) {
-  // Let's clean up all the data.
-  await new Promise(resolve => {
-    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", opt.lifetimePolicy],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Custom permission without considering OriginAttributes
-  if (opt.cookiePermission !== undefined) {
-    let uri = Services.io.newURI("https://www.example.com");
-    Services.perms.add(uri, "cookie", opt.cookiePermission);
-  }
-
-  // Let's create a tab with some data.
-  await opt.createData((opt.fullHost ? "www." : "") + "example.org",
-                       opt.originAttributes);
-  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
-                         opt.originAttributes),
-                         "We have data for www.example.org");
-  await opt.createData((opt.fullHost ? "www." : "") + "example.com",
-                       opt.originAttributes);
-  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
-                         opt.originAttributes),
-                         "We have data for www.example.com");
-
-  // Cleaning up.
-  await Sanitizer.runSanitizeOnShutdown();
-
-  // All gone!
-  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
-                            opt.originAttributes)),
-                            opt.expectedForOrg, "Do we have data for www.example.org?");
-  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
-                            opt.originAttributes)),
-                            opt.expectedForCom, "Do we have data for www.example.com?");
-
-  // Clean up.
-  await Sanitizer.sanitize([ "cookies", "offlineApps" ]);
-
-  if (opt.cookiePermission !== undefined) {
-    let uri = Services.io.newURI("https://www.example.com");
-    Services.perms.remove(uri, "cookie");
-  }
-}
-
-let tests = [
-  { name: "IDB",
-    createData: createIndexedDB,
-    checkData: checkIndexedDB },
-  { name: "Host Cookie",
-    createData: createHostCookie,
-    checkData: checkCookie },
-  { name: "Domain Cookie",
-    createData: createDomainCookie,
-    checkData: checkCookie },
-];
-
-let attributes = [
-  {name: "default", oa: {}},
-  {name: "container", oa: {userContextId: 1}},
-];
-
-// Delete all, no custom permission, data in example.com, cookie permission set
-// for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnShutdown() {
-      info(methods.name + ": Delete all, no custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: undefined,
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// Delete all, no custom permission, data in www.example.com, cookie permission
-// set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnShutdown() {
-      info(methods.name + ": Delete all, no custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: undefined,
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// All is session, but with ALLOW custom permission, data in example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageWithCustomPermission() {
-      info(methods.name + ": All is session, but with ALLOW custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
-          expectedForOrg: false,
-          expectedForCom: true,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// All is session, but with ALLOW custom permission, data in www.example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageWithCustomPermission() {
-      info(methods.name + ": All is session, but with ALLOW custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
-          expectedForOrg: false,
-          expectedForCom: true,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// All is default, but with SESSION custom permission, data in example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is default, but with SESSION custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
-          expectedForOrg: true,
-          // expected data just for example.com when using indexedDB because
-          // QuotaManager deletes for principal.
-          expectedForCom: false,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// All is default, but with SESSION custom permission, data in www.example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is default, but with SESSION custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
-          expectedForOrg: true,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// Session mode, but with unsupported custom permission, data in
-// www.example.com, cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is session only, but with unsupported custom custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: 123, // invalid cookie permission
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
 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);
   });
 
@@ -337,64 +83,8 @@ add_task(async function deleteStorageOnl
   let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("about:newtab");
   await new Promise(aResolve => {
     let req = Services.qms.clearStoragesForPrincipal(principal);
     req.callback = () => { aResolve(); };
   });
 
   Services.perms.remove(uri, "cookie");
 });
-
-// 2 domains: www.mozilla.org (session-only) mozilla.org (allowed) - after the
-// cleanp, mozilla.org must have data.
-add_task(async function subDomains() {
-  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);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_NORMALLY ],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Domains and data
-  let uriA = Services.io.newURI("https://www.mozilla.org");
-  Services.perms.add(uriA, "cookie", Ci.nsICookiePermission.ACCESS_SESSION);
-
-  Services.cookies.add(uriA.host, "/test", "a", "b",
-    false, false, false, Date.now() + 24000 * 60 * 60, {},
-    Ci.nsICookie2.SAMESITE_UNSET);
-
-  await createIndexedDB(uriA.host, {});
-
-  let uriB = Services.io.newURI("https://mozilla.org");
-  Services.perms.add(uriB, "cookie", Ci.nsICookiePermission.ACCESS_ALLOW);
-
-  Services.cookies.add(uriB.host, "/test", "c", "d",
-    false, false, false, Date.now() + 24000 * 60 * 60, {},
-    Ci.nsICookie2.SAMESITE_UNSET);
-
-  await createIndexedDB(uriB.host, {});
-
-  // Check
-  ok(await checkCookie(uriA.host, {}), "We have cookies for URI: " + uriA.host);
-  ok(await checkIndexedDB(uriA.host, {}), "We have IDB for URI: " + uriA.host);
-  ok(await checkCookie(uriB.host, {}), "We have cookies for URI: " + uriB.host);
-  ok(await checkIndexedDB(uriB.host, {}), "We have IDB for URI: " + uriB.host);
-
-  // Cleaning up
-  await Sanitizer.runSanitizeOnShutdown();
-
-  // Check again
-  ok(!(await checkCookie(uriA.host, {})), "We should not have cookies for URI: " + uriA.host);
-  ok(!(await checkIndexedDB(uriA.host, {})), "We should not have IDB for URI: " + uriA.host);
-
-  // Note that cookies are stored per base domain...
-  ok(!(await checkCookie(uriB.host, {})), "We should not have cookies for URI: " + uriB.host);
-  ok(await checkIndexedDB(uriB.host, {}), "We should have IDB for URI: " + uriB.host);
-
-  // Cleaning up permissions
-  Services.perms.remove(uriA, "cookie");
-  Services.perms.remove(uriB, "cookie");
-});
copy from browser/base/content/test/sanitize/browser_cookiePermission.js
copy to browser/base/content/test/sanitize/browser_cookiePermission_containers.js
--- a/browser/base/content/test/sanitize/browser_cookiePermission.js
+++ b/browser/base/content/test/sanitize/browser_cookiePermission_containers.js
@@ -1,400 +1,1 @@
-const {Sanitizer} = ChromeUtils.import("resource:///modules/Sanitizer.jsm");
-const {SiteDataTestUtils} = ChromeUtils.import("resource://testing-common/SiteDataTestUtils.jsm");
-
-function checkDataForAboutURL() {
-  return new Promise(resolve => {
-    let data = true;
-    let uri = Services.io.newURI("about:newtab");
-    let principal =
-      Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
-    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
-    request.onupgradeneeded = function(e) {
-      data = false;
-    };
-    request.onsuccess = function(e) {
-      resolve(data);
-    };
-  });
-}
-
-function createIndexedDB(host, originAttributes) {
-  let uri = Services.io.newURI("https://" + host);
-  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, originAttributes);
-  return SiteDataTestUtils.addToIndexedDB(principal.origin);
-}
-
-function checkIndexedDB(host, originAttributes) {
-  return new Promise(resolve => {
-    let data = true;
-    let uri = Services.io.newURI("https://" + host);
-    let principal =
-      Services.scriptSecurityManager.createCodebasePrincipal(uri,
-                                                             originAttributes);
-    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
-    request.onupgradeneeded = function(e) {
-      data = false;
-    };
-    request.onsuccess = function(e) {
-      resolve(data);
-    };
-  });
-}
-
-function createHostCookie(host, originAttributes) {
-  Services.cookies.add(host, "/test", "foo", "bar",
-    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
-    Ci.nsICookie2.SAMESITE_UNSET);
-}
-
-function createDomainCookie(host, originAttributes) {
-  Services.cookies.add("." + host, "/test", "foo", "bar",
-    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
-    Ci.nsICookie2.SAMESITE_UNSET);
-}
-
-function checkCookie(host, originAttributes) {
-  for (let cookie of Services.cookies.enumerator) {
-    if (ChromeUtils.isOriginAttributesEqual(originAttributes,
-                                            cookie.originAttributes) &&
-        cookie.host.includes(host)) {
-      return true;
-    }
-  }
-  return false;
-}
-
-async function deleteOnShutdown(opt) {
-  // Let's clean up all the data.
-  await new Promise(resolve => {
-    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", opt.lifetimePolicy],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Custom permission without considering OriginAttributes
-  if (opt.cookiePermission !== undefined) {
-    let uri = Services.io.newURI("https://www.example.com");
-    Services.perms.add(uri, "cookie", opt.cookiePermission);
-  }
-
-  // Let's create a tab with some data.
-  await opt.createData((opt.fullHost ? "www." : "") + "example.org",
-                       opt.originAttributes);
-  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
-                         opt.originAttributes),
-                         "We have data for www.example.org");
-  await opt.createData((opt.fullHost ? "www." : "") + "example.com",
-                       opt.originAttributes);
-  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
-                         opt.originAttributes),
-                         "We have data for www.example.com");
-
-  // Cleaning up.
-  await Sanitizer.runSanitizeOnShutdown();
-
-  // All gone!
-  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
-                            opt.originAttributes)),
-                            opt.expectedForOrg, "Do we have data for www.example.org?");
-  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
-                            opt.originAttributes)),
-                            opt.expectedForCom, "Do we have data for www.example.com?");
-
-  // Clean up.
-  await Sanitizer.sanitize([ "cookies", "offlineApps" ]);
-
-  if (opt.cookiePermission !== undefined) {
-    let uri = Services.io.newURI("https://www.example.com");
-    Services.perms.remove(uri, "cookie");
-  }
-}
-
-let tests = [
-  { name: "IDB",
-    createData: createIndexedDB,
-    checkData: checkIndexedDB },
-  { name: "Host Cookie",
-    createData: createHostCookie,
-    checkData: checkCookie },
-  { name: "Domain Cookie",
-    createData: createDomainCookie,
-    checkData: checkCookie },
-];
-
-let attributes = [
-  {name: "default", oa: {}},
-  {name: "container", oa: {userContextId: 1}},
-];
-
-// Delete all, no custom permission, data in example.com, cookie permission set
-// for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnShutdown() {
-      info(methods.name + ": Delete all, no custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: undefined,
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// Delete all, no custom permission, data in www.example.com, cookie permission
-// set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnShutdown() {
-      info(methods.name + ": Delete all, no custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: undefined,
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// All is session, but with ALLOW custom permission, data in example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageWithCustomPermission() {
-      info(methods.name + ": All is session, but with ALLOW custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
-          expectedForOrg: false,
-          expectedForCom: true,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// All is session, but with ALLOW custom permission, data in www.example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageWithCustomPermission() {
-      info(methods.name + ": All is session, but with ALLOW custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
-          expectedForOrg: false,
-          expectedForCom: true,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// All is default, but with SESSION custom permission, data in example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is default, but with SESSION custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
-          expectedForOrg: true,
-          // expected data just for example.com when using indexedDB because
-          // QuotaManager deletes for principal.
-          expectedForCom: false,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// All is default, but with SESSION custom permission, data in www.example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is default, but with SESSION custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
-          expectedForOrg: true,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// Session mode, but with unsupported custom permission, data in
-// www.example.com, cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is session only, but with unsupported custom custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: 123, // invalid cookie permission
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-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);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_SESSION],
-    ["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([ "cookies", "offlineApps" ]);
-
-  let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("about:newtab");
-  await new Promise(aResolve => {
-    let req = Services.qms.clearStoragesForPrincipal(principal);
-    req.callback = () => { aResolve(); };
-  });
-});
-
-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": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_NORMALLY],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Custom permission without considering OriginAttributes
-  let uri = Services.io.newURI("about:newtab");
-  Services.perms.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.createCodebasePrincipalFromOrigin("about:newtab");
-  await new Promise(aResolve => {
-    let req = Services.qms.clearStoragesForPrincipal(principal);
-    req.callback = () => { aResolve(); };
-  });
-
-  Services.perms.remove(uri, "cookie");
-});
-
-// 2 domains: www.mozilla.org (session-only) mozilla.org (allowed) - after the
-// cleanp, mozilla.org must have data.
-add_task(async function subDomains() {
-  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);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_NORMALLY ],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Domains and data
-  let uriA = Services.io.newURI("https://www.mozilla.org");
-  Services.perms.add(uriA, "cookie", Ci.nsICookiePermission.ACCESS_SESSION);
-
-  Services.cookies.add(uriA.host, "/test", "a", "b",
-    false, false, false, Date.now() + 24000 * 60 * 60, {},
-    Ci.nsICookie2.SAMESITE_UNSET);
-
-  await createIndexedDB(uriA.host, {});
-
-  let uriB = Services.io.newURI("https://mozilla.org");
-  Services.perms.add(uriB, "cookie", Ci.nsICookiePermission.ACCESS_ALLOW);
-
-  Services.cookies.add(uriB.host, "/test", "c", "d",
-    false, false, false, Date.now() + 24000 * 60 * 60, {},
-    Ci.nsICookie2.SAMESITE_UNSET);
-
-  await createIndexedDB(uriB.host, {});
-
-  // Check
-  ok(await checkCookie(uriA.host, {}), "We have cookies for URI: " + uriA.host);
-  ok(await checkIndexedDB(uriA.host, {}), "We have IDB for URI: " + uriA.host);
-  ok(await checkCookie(uriB.host, {}), "We have cookies for URI: " + uriB.host);
-  ok(await checkIndexedDB(uriB.host, {}), "We have IDB for URI: " + uriB.host);
-
-  // Cleaning up
-  await Sanitizer.runSanitizeOnShutdown();
-
-  // Check again
-  ok(!(await checkCookie(uriA.host, {})), "We should not have cookies for URI: " + uriA.host);
-  ok(!(await checkIndexedDB(uriA.host, {})), "We should not have IDB for URI: " + uriA.host);
-
-  // Note that cookies are stored per base domain...
-  ok(!(await checkCookie(uriB.host, {})), "We should not have cookies for URI: " + uriB.host);
-  ok(await checkIndexedDB(uriB.host, {}), "We should have IDB for URI: " + uriB.host);
-
-  // Cleaning up permissions
-  Services.perms.remove(uriA, "cookie");
-  Services.perms.remove(uriB, "cookie");
-});
+runAllCookiePermissionTests({name: "container", oa: {userContextId: 1}});
copy from browser/base/content/test/sanitize/browser_cookiePermission.js
copy to browser/base/content/test/sanitize/browser_cookiePermission_subDomains.js
--- a/browser/base/content/test/sanitize/browser_cookiePermission.js
+++ b/browser/base/content/test/sanitize/browser_cookiePermission_subDomains.js
@@ -1,353 +1,11 @@
 const {Sanitizer} = ChromeUtils.import("resource:///modules/Sanitizer.jsm");
 const {SiteDataTestUtils} = ChromeUtils.import("resource://testing-common/SiteDataTestUtils.jsm");
 
-function checkDataForAboutURL() {
-  return new Promise(resolve => {
-    let data = true;
-    let uri = Services.io.newURI("about:newtab");
-    let principal =
-      Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
-    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
-    request.onupgradeneeded = function(e) {
-      data = false;
-    };
-    request.onsuccess = function(e) {
-      resolve(data);
-    };
-  });
-}
-
-function createIndexedDB(host, originAttributes) {
-  let uri = Services.io.newURI("https://" + host);
-  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, originAttributes);
-  return SiteDataTestUtils.addToIndexedDB(principal.origin);
-}
-
-function checkIndexedDB(host, originAttributes) {
-  return new Promise(resolve => {
-    let data = true;
-    let uri = Services.io.newURI("https://" + host);
-    let principal =
-      Services.scriptSecurityManager.createCodebasePrincipal(uri,
-                                                             originAttributes);
-    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
-    request.onupgradeneeded = function(e) {
-      data = false;
-    };
-    request.onsuccess = function(e) {
-      resolve(data);
-    };
-  });
-}
-
-function createHostCookie(host, originAttributes) {
-  Services.cookies.add(host, "/test", "foo", "bar",
-    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
-    Ci.nsICookie2.SAMESITE_UNSET);
-}
-
-function createDomainCookie(host, originAttributes) {
-  Services.cookies.add("." + host, "/test", "foo", "bar",
-    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
-    Ci.nsICookie2.SAMESITE_UNSET);
-}
-
-function checkCookie(host, originAttributes) {
-  for (let cookie of Services.cookies.enumerator) {
-    if (ChromeUtils.isOriginAttributesEqual(originAttributes,
-                                            cookie.originAttributes) &&
-        cookie.host.includes(host)) {
-      return true;
-    }
-  }
-  return false;
-}
-
-async function deleteOnShutdown(opt) {
-  // Let's clean up all the data.
-  await new Promise(resolve => {
-    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", opt.lifetimePolicy],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Custom permission without considering OriginAttributes
-  if (opt.cookiePermission !== undefined) {
-    let uri = Services.io.newURI("https://www.example.com");
-    Services.perms.add(uri, "cookie", opt.cookiePermission);
-  }
-
-  // Let's create a tab with some data.
-  await opt.createData((opt.fullHost ? "www." : "") + "example.org",
-                       opt.originAttributes);
-  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
-                         opt.originAttributes),
-                         "We have data for www.example.org");
-  await opt.createData((opt.fullHost ? "www." : "") + "example.com",
-                       opt.originAttributes);
-  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
-                         opt.originAttributes),
-                         "We have data for www.example.com");
-
-  // Cleaning up.
-  await Sanitizer.runSanitizeOnShutdown();
-
-  // All gone!
-  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
-                            opt.originAttributes)),
-                            opt.expectedForOrg, "Do we have data for www.example.org?");
-  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
-                            opt.originAttributes)),
-                            opt.expectedForCom, "Do we have data for www.example.com?");
-
-  // Clean up.
-  await Sanitizer.sanitize([ "cookies", "offlineApps" ]);
-
-  if (opt.cookiePermission !== undefined) {
-    let uri = Services.io.newURI("https://www.example.com");
-    Services.perms.remove(uri, "cookie");
-  }
-}
-
-let tests = [
-  { name: "IDB",
-    createData: createIndexedDB,
-    checkData: checkIndexedDB },
-  { name: "Host Cookie",
-    createData: createHostCookie,
-    checkData: checkCookie },
-  { name: "Domain Cookie",
-    createData: createDomainCookie,
-    checkData: checkCookie },
-];
-
-let attributes = [
-  {name: "default", oa: {}},
-  {name: "container", oa: {userContextId: 1}},
-];
-
-// Delete all, no custom permission, data in example.com, cookie permission set
-// for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnShutdown() {
-      info(methods.name + ": Delete all, no custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: undefined,
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// Delete all, no custom permission, data in www.example.com, cookie permission
-// set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnShutdown() {
-      info(methods.name + ": Delete all, no custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: undefined,
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// All is session, but with ALLOW custom permission, data in example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageWithCustomPermission() {
-      info(methods.name + ": All is session, but with ALLOW custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
-          expectedForOrg: false,
-          expectedForCom: true,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// All is session, but with ALLOW custom permission, data in www.example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageWithCustomPermission() {
-      info(methods.name + ": All is session, but with ALLOW custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
-          expectedForOrg: false,
-          expectedForCom: true,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// All is default, but with SESSION custom permission, data in example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is default, but with SESSION custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
-          expectedForOrg: true,
-          // expected data just for example.com when using indexedDB because
-          // QuotaManager deletes for principal.
-          expectedForCom: false,
-          fullHost: false,
-        });
-    });
-  });
-});
-
-// All is default, but with SESSION custom permission, data in www.example.com,
-// cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is default, but with SESSION custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
-          expectedForOrg: true,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-// Session mode, but with unsupported custom permission, data in
-// www.example.com, cookie permission set for www.example.com
-tests.forEach(methods => {
-  attributes.forEach(originAttributes => {
-    add_task(async function deleteStorageOnlyCustomPermission() {
-      info(methods.name + ": All is session only, but with unsupported custom custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
-      await deleteOnShutdown(
-        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
-          createData: methods.createData,
-          checkData: methods.checkData,
-          originAttributes: originAttributes.oa,
-          cookiePermission: 123, // invalid cookie permission
-          expectedForOrg: false,
-          expectedForCom: false,
-          fullHost: true,
-        });
-    });
-  });
-});
-
-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);
-  });
-
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_SESSION],
-    ["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([ "cookies", "offlineApps" ]);
-
-  let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("about:newtab");
-  await new Promise(aResolve => {
-    let req = Services.qms.clearStoragesForPrincipal(principal);
-    req.callback = () => { aResolve(); };
-  });
-});
-
-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": [
-    ["network.cookie.lifetimePolicy", Ci.nsICookieService.ACCEPT_NORMALLY],
-    ["browser.sanitizer.loglevel", "All"],
-  ]});
-
-  // Custom permission without considering OriginAttributes
-  let uri = Services.io.newURI("about:newtab");
-  Services.perms.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.createCodebasePrincipalFromOrigin("about:newtab");
-  await new Promise(aResolve => {
-    let req = Services.qms.clearStoragesForPrincipal(principal);
-    req.callback = () => { aResolve(); };
-  });
-
-  Services.perms.remove(uri, "cookie");
-});
-
 // 2 domains: www.mozilla.org (session-only) mozilla.org (allowed) - after the
 // cleanp, mozilla.org must have data.
 add_task(async function subDomains() {
   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);
--- a/browser/base/content/test/sanitize/head.js
+++ b/browser/base/content/test/sanitize/head.js
@@ -1,9 +1,246 @@
 var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   Downloads: "resource://gre/modules/Downloads.jsm",
   FormHistory: "resource://gre/modules/FormHistory.jsm",
   PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
   Sanitizer: "resource:///modules/Sanitizer.jsm",
+  SiteDataTestUtils: "resource://testing-common/SiteDataTestUtils.jsm",
 });
 
+function createIndexedDB(host, originAttributes) {
+  let uri = Services.io.newURI("https://" + host);
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, originAttributes);
+  return SiteDataTestUtils.addToIndexedDB(principal.origin);
+}
+
+function checkIndexedDB(host, originAttributes) {
+  return new Promise(resolve => {
+    let data = true;
+    let uri = Services.io.newURI("https://" + host);
+    let principal =
+      Services.scriptSecurityManager.createCodebasePrincipal(uri,
+                                                             originAttributes);
+    let request = indexedDB.openForPrincipal(principal, "TestDatabase", 1);
+    request.onupgradeneeded = function(e) {
+      data = false;
+    };
+    request.onsuccess = function(e) {
+      resolve(data);
+    };
+  });
+}
+
+function createHostCookie(host, originAttributes) {
+  Services.cookies.add(host, "/test", "foo", "bar",
+    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
+    Ci.nsICookie2.SAMESITE_UNSET);
+}
+
+function createDomainCookie(host, originAttributes) {
+  Services.cookies.add("." + host, "/test", "foo", "bar",
+    false, false, false, Date.now() + 24000 * 60 * 60, originAttributes,
+    Ci.nsICookie2.SAMESITE_UNSET);
+}
+
+function checkCookie(host, originAttributes) {
+  for (let cookie of Services.cookies.enumerator) {
+    if (ChromeUtils.isOriginAttributesEqual(originAttributes,
+                                            cookie.originAttributes) &&
+        cookie.host.includes(host)) {
+      return true;
+    }
+  }
+  return false;
+}
+
+async function deleteOnShutdown(opt) {
+  // Let's clean up all the data.
+  await new Promise(resolve => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
+  });
+
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["network.cookie.lifetimePolicy", opt.lifetimePolicy],
+    ["browser.sanitizer.loglevel", "All"],
+  ]});
+
+  // Custom permission without considering OriginAttributes
+  if (opt.cookiePermission !== undefined) {
+    let uri = Services.io.newURI("https://www.example.com");
+    Services.perms.add(uri, "cookie", opt.cookiePermission);
+  }
+
+  // Let's create a tab with some data.
+  await opt.createData((opt.fullHost ? "www." : "") + "example.org",
+                       opt.originAttributes);
+  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
+                         opt.originAttributes),
+                         "We have data for www.example.org");
+  await opt.createData((opt.fullHost ? "www." : "") + "example.com",
+                       opt.originAttributes);
+  ok(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
+                         opt.originAttributes),
+                         "We have data for www.example.com");
+
+  // Cleaning up.
+  await Sanitizer.runSanitizeOnShutdown();
+
+  // All gone!
+  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.org",
+                            opt.originAttributes)),
+                            opt.expectedForOrg, "Do we have data for www.example.org?");
+  is(!!(await opt.checkData((opt.fullHost ? "www." : "") + "example.com",
+                            opt.originAttributes)),
+                            opt.expectedForCom, "Do we have data for www.example.com?");
+
+  // Clean up.
+  await Sanitizer.sanitize([ "cookies", "offlineApps" ]);
+
+  if (opt.cookiePermission !== undefined) {
+    let uri = Services.io.newURI("https://www.example.com");
+    Services.perms.remove(uri, "cookie");
+  }
+}
+
+function runAllCookiePermissionTests(originAttributes) {
+  let tests = [
+    { name: "IDB",
+      createData: createIndexedDB,
+      checkData: checkIndexedDB },
+    { name: "Host Cookie",
+      createData: createHostCookie,
+      checkData: checkCookie },
+    { name: "Domain Cookie",
+      createData: createDomainCookie,
+      checkData: checkCookie },
+  ];
+
+  // Delete all, no custom permission, data in example.com, cookie permission set
+  // for www.example.com
+  tests.forEach(methods => {
+    add_task(async function deleteStorageOnShutdown() {
+      info(methods.name + ": Delete all, no custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
+      await deleteOnShutdown(
+        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
+          createData: methods.createData,
+          checkData: methods.checkData,
+          originAttributes: originAttributes.oa,
+          cookiePermission: undefined,
+          expectedForOrg: false,
+          expectedForCom: false,
+          fullHost: false,
+        });
+    });
+  });
+
+  // Delete all, no custom permission, data in www.example.com, cookie permission
+  // set for www.example.com
+  tests.forEach(methods => {
+    add_task(async function deleteStorageOnShutdown() {
+      info(methods.name + ": Delete all, no custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
+      await deleteOnShutdown(
+        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
+          createData: methods.createData,
+          checkData: methods.checkData,
+          originAttributes: originAttributes.oa,
+          cookiePermission: undefined,
+          expectedForOrg: false,
+          expectedForCom: false,
+          fullHost: true,
+        });
+    });
+  });
+
+  // All is session, but with ALLOW custom permission, data in example.com,
+  // cookie permission set for www.example.com
+  tests.forEach(methods => {
+    add_task(async function deleteStorageWithCustomPermission() {
+      info(methods.name + ": All is session, but with ALLOW custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
+      await deleteOnShutdown(
+        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
+          createData: methods.createData,
+          checkData: methods.checkData,
+          originAttributes: originAttributes.oa,
+          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
+          expectedForOrg: false,
+          expectedForCom: true,
+          fullHost: false,
+        });
+    });
+  });
+
+  // All is session, but with ALLOW custom permission, data in www.example.com,
+  // cookie permission set for www.example.com
+  tests.forEach(methods => {
+    add_task(async function deleteStorageWithCustomPermission() {
+      info(methods.name + ": All is session, but with ALLOW custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
+      await deleteOnShutdown(
+        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
+          createData: methods.createData,
+          checkData: methods.checkData,
+          originAttributes: originAttributes.oa,
+          cookiePermission: Ci.nsICookiePermission.ACCESS_ALLOW,
+          expectedForOrg: false,
+          expectedForCom: true,
+          fullHost: true,
+        });
+    });
+  });
+
+  // All is default, but with SESSION custom permission, data in example.com,
+  // cookie permission set for www.example.com
+  tests.forEach(methods => {
+    add_task(async function deleteStorageOnlyCustomPermission() {
+      info(methods.name + ": All is default, but with SESSION custom permission, data in example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
+      await deleteOnShutdown(
+        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
+          createData: methods.createData,
+          checkData: methods.checkData,
+          originAttributes: originAttributes.oa,
+          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
+          expectedForOrg: true,
+          // expected data just for example.com when using indexedDB because
+          // QuotaManager deletes for principal.
+          expectedForCom: false,
+          fullHost: false,
+        });
+    });
+  });
+
+  // All is default, but with SESSION custom permission, data in www.example.com,
+  // cookie permission set for www.example.com
+  tests.forEach(methods => {
+    add_task(async function deleteStorageOnlyCustomPermission() {
+      info(methods.name + ": All is default, but with SESSION custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
+      await deleteOnShutdown(
+        { lifetimePolicy: Ci.nsICookieService.ACCEPT_NORMALLY,
+          createData: methods.createData,
+          checkData: methods.checkData,
+          originAttributes: originAttributes.oa,
+          cookiePermission: Ci.nsICookiePermission.ACCESS_SESSION,
+          expectedForOrg: true,
+          expectedForCom: false,
+          fullHost: true,
+        });
+    });
+  });
+
+  // Session mode, but with unsupported custom permission, data in
+  // www.example.com, cookie permission set for www.example.com
+  tests.forEach(methods => {
+    add_task(async function deleteStorageOnlyCustomPermission() {
+      info(methods.name + ": All is session only, but with unsupported custom custom permission, data in www.example.com, cookie permission set for www.example.com - OA: " + originAttributes.name);
+      await deleteOnShutdown(
+        { lifetimePolicy: Ci.nsICookieService.ACCEPT_SESSION,
+          createData: methods.createData,
+          checkData: methods.checkData,
+          originAttributes: originAttributes.oa,
+          cookiePermission: 123, // invalid cookie permission
+          expectedForOrg: false,
+          expectedForCom: false,
+          fullHost: true,
+        });
+    });
+  });
+}