Bug 1646136 - Isolate preload channels per first-party when privacy.partition.network_state is set to true, r=mayhemer
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 24 Jun 2020 15:34:33 +0000
changeset 537206 8d5bc317935c4ae68dcb14fab6f027d1aa247c10
parent 537205 baa45f675f4cb872342c5ac92bbd0411bd2701e6
child 537207 5c0784fac661220f7e763df2ef24147331862fce
push id119845
push useramarchesini@mozilla.com
push dateWed, 24 Jun 2020 15:35:15 +0000
treeherderautoland@8d5bc317935c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1646136
milestone79.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 1646136 - Isolate preload channels per first-party when privacy.partition.network_state is set to true, r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D80047
toolkit/components/antitracking/test/xpcshell/test_staticPartition_preload.js
toolkit/components/antitracking/test/xpcshell/xpcshell.ini
copy from toolkit/components/antitracking/test/xpcshell/test_staticPartition_prefetch.js
copy to toolkit/components/antitracking/test/xpcshell/test_staticPartition_preload.js
--- a/toolkit/components/antitracking/test/xpcshell/test_staticPartition_prefetch.js
+++ b/toolkit/components/antitracking/test/xpcshell/test_staticPartition_preload.js
@@ -43,80 +43,94 @@ async function checkCache(originAttribut
     // need to use Services.cache2.memoryCacheStorage() here.
     let storage = Services.cache2.diskCacheStorage(loadContextInfo, false);
     storage.asyncVisitStorage(cacheVisitor, true);
   });
 
   let foundEntryCount = countMatchingCacheEntries(
     data,
     "example.org",
-    "image.png"
+    "style.css"
   );
   ok(
     foundEntryCount > 0,
-    `Cache entries expected for image.png and OA=${originAttributes}`
+    `Cache entries expected for style.css and OA=${originAttributes}`
   );
 }
 
 add_task(async () => {
   do_get_profile();
 
-  Services.prefs.setBoolPref("network.prefetch-next", true);
+  Services.prefs.setBoolPref("network.preload", true);
   Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
 
   const server = CookieXPCShellUtils.createServer({
     hosts: ["example.org", "foo.com"],
   });
 
-  server.registerPathHandler("/image.png", (metadata, response) => {
+  server.registerPathHandler("/empty", (metadata, response) => {
+    var body = "<h1>Hello!</h1>";
+    response.bodyOutputStream.write(body, body.length);
+  });
+
+  server.registerPathHandler("/style.css", (metadata, response) => {
     gHints++;
     response.setHeader("Cache-Control", "max-age=10000", false);
     response.setStatusLine(metadata.httpVersion, 200, "OK");
-    response.setHeader("Content-Type", "image/png", false);
-    var body =
-      "iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAEUlEQVQImWP4z8AAQTAamQkAhpcI+DeMzFcAAAAASUVORK5CYII=";
+    response.setHeader("Access-Control-Allow-Origin", "*", false);
+    var body = "* { color: red }";
     response.bodyOutputStream.write(body, body.length);
   });
 
-  server.registerPathHandler("/prefetch", (metadata, response) => {
+  server.registerPathHandler("/preload", (metadata, response) => {
     response.setStatusLine(metadata.httpVersion, 200, "OK");
     response.setHeader("Content-Type", "text/html", false);
     var body = `<html><head></head><body><script>
       const link = document.createElement("link")
-      link.setAttribute("rel", "prefetch");
-      link.setAttribute("href", "http://example.org/image.png");
+      link.setAttribute("rel", "preload");
+      link.setAttribute("as", "style");
+      link.setAttribute("href", "http://example.org/style.css");
       document.head.appendChild(link);
       link.onload = () => {
-        const img = document.createElement("IMG");
-        img.src = "http://example.org/image.png";
-        document.body.appendChild(img);
         fetch("/done").then(() => {});
-      }
+      };
     </script></body></html>`;
     response.bodyOutputStream.write(body, body.length);
   });
 
   const tests = [
     {
-      hints: 2,
+      prefValue: true,
       originAttributes: { partitionKey: "(http,example.org)" },
-      prefValue: true,
+      hints: 2,
     },
     {
+      prefValue: false,
       hints: 1,
       originAttributes: {},
-      prefValue: false,
     },
   ];
 
   for (let test of tests) {
     await new Promise(resolve =>
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve)
     );
 
+    info("Reset the shared sheets");
+    let contentPage = await CookieXPCShellUtils.loadContentPage(
+      "http://example.org/empty"
+    );
+
+    await contentPage.spawn(null, () =>
+      // eslint-disable-next-line no-undef
+      content.windowUtils.clearSharedStyleSheetCache()
+    );
+
+    await contentPage.close();
+
     info("Reset the counter");
     gHints = 0;
 
     info("Enabling network state partitioning");
     Services.prefs.setBoolPref(
       "privacy.partition.network_state",
       test.prefValue
     );
@@ -128,18 +142,18 @@ add_task(async () => {
         response.setHeader("Content-Type", "text/html", false);
         var body = "OK";
         response.bodyOutputStream.write(body, body.length);
         resolve();
       });
     });
 
     info("Let's load a page with origin A");
-    let contentPage = await CookieXPCShellUtils.loadContentPage(
-      "http://example.org/prefetch"
+    contentPage = await CookieXPCShellUtils.loadContentPage(
+      "http://example.org/preload"
     );
 
     await complete;
     await checkCache(test.originAttributes);
     await contentPage.close();
 
     complete = new Promise(resolve => {
       server.registerPathHandler("/done", (metadata, response) => {
@@ -149,17 +163,17 @@ add_task(async () => {
         var body = "OK";
         response.bodyOutputStream.write(body, body.length);
         resolve();
       });
     });
 
     info("Let's load a page with origin B");
     contentPage = await CookieXPCShellUtils.loadContentPage(
-      "http://foo.com/prefetch"
+      "http://foo.com/preload"
     );
 
     await complete;
     await checkCache(test.originAttributes);
     await contentPage.close();
 
     Assert.equal(
       gHints,
--- a/toolkit/components/antitracking/test/xpcshell/xpcshell.ini
+++ b/toolkit/components/antitracking/test/xpcshell/xpcshell.ini
@@ -8,8 +8,10 @@ head = head.js ../../../../components/ur
 [test_rejectForeignAllowList.js]
 skip-if = toolkit == 'android' # Bug 1567341
 [test_staticPartition_image.js]
 skip-if = toolkit == 'android' # Bug 1567341
 [test_staticPartition_authhttp.js]
 skip-if = toolkit == 'android' # Bug 1567341
 [test_staticPartition_prefetch.js]
 skip-if = toolkit == 'android' # Bug 1567341
+[test_staticPartition_preload.js]
+skip-if = toolkit == 'android' # Bug 1567341