Bug 1524674 - Cleanup site data with custom permissions per subdomains - Tests. r=johannh a=lizzard
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 04 Feb 2019 14:25:51 +0000
changeset 515765 6e1b209f1fd83d990cbfff4740579544e9e88fcf
parent 515764 ea1d5311b285dcdb93b1b1748dc5d9905fda7993
child 515766 3330d6764f480f5a27517df67a3a500f60e71dd1
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, lizzard
bugs1524674
milestone66.0
Bug 1524674 - Cleanup site data with custom permissions per subdomains - Tests. r=johannh a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D18498
browser/base/content/test/sanitize/browser_cookiePermission.js
--- a/browser/base/content/test/sanitize/browser_cookiePermission.js
+++ b/browser/base/content/test/sanitize/browser_cookiePermission.js
@@ -61,21 +61,22 @@ function checkCookie(host, originAttribu
     }
   }
   return false;
 }
 
 async function deleteOnShutdown(opt) {
   // Let's clean up all the data.
   await new Promise(resolve => {
-    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => 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);
   }
 
@@ -270,21 +271,22 @@ tests.forEach(methods => {
   });
 });
 
 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, value => 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.
@@ -302,21 +304,22 @@ add_task(async function deleteStorageInA
   });
 });
 
 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, value => 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", {});
@@ -334,8 +337,64 @@ 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");
+});