Bug 1486185 - Part 2: Ensure that anti-tracking tests are run in a mode where blocking is active but the top-level site is white-listed for content blocking; r=baku
☠☠ backed out by 028c9eeaf27e ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 25 Aug 2018 01:59:28 -0400
changeset 433469 fc7618dd27c9812296e00fe7f5c91f32ce5b222e
parent 433468 83388bace8ff0150e4811777180e51c24ddcbbc4
child 433470 028c9eeaf27e553883ada6ef5f591917a2bc4524
push id107081
push usereakhgari@mozilla.com
push dateMon, 27 Aug 2018 14:05:12 +0000
treeherdermozilla-inbound@fc7618dd27c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1486185
milestone63.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 1486185 - Part 2: Ensure that anti-tracking tests are run in a mode where blocking is active but the top-level site is white-listed for content blocking; r=baku
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_imageCache1.js
toolkit/components/antitracking/test/browser/browser_imageCache2.js
toolkit/components/antitracking/test/browser/browser_imageCache3.js
toolkit/components/antitracking/test/browser/browser_imageCache4.js
toolkit/components/antitracking/test/browser/head.js
toolkit/components/antitracking/test/browser/imageCacheWorker.js
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -21,14 +21,15 @@ support-files = server.sjs
 [browser_blockingStorage.js]
 [browser_blockingWorkers.js]
 [browser_blockingMessaging.js]
 [browser_blockingNoOpener.js]
 [browser_existingCookiesForSubresources.js]
 [browser_imageCache1.js]
 [browser_imageCache2.js]
 [browser_imageCache3.js]
+[browser_imageCache4.js]
 [browser_onBeforeRequestNotificationForTrackingResources.js]
 [browser_onModifyRequestNotificationForTrackingResources.js]
 [browser_subResources.js]
 support-files = subResources.sjs
 [browser_script.js]
 support-files = tracker.js
--- a/toolkit/components/antitracking/test/browser/browser_imageCache1.js
+++ b/toolkit/components/antitracking/test/browser/browser_imageCache1.js
@@ -1,12 +1,13 @@
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 let blockingByCookieBehavior = true;
 let blockingByContentBlocking = false;
+let blockingByAllowList = false;
 
 let rootDir = getRootDirectory(gTestPath);
 let jar = getJar(rootDir);
 if (jar) {
   let tmpdir = extractJarToTmp(jar);
   rootDir = "file://" + tmpdir.path + "/";
 }
 /* import-globals-from imageCacheWorker.js */
--- a/toolkit/components/antitracking/test/browser/browser_imageCache2.js
+++ b/toolkit/components/antitracking/test/browser/browser_imageCache2.js
@@ -1,12 +1,13 @@
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 let blockingByCookieBehavior = false;
 let blockingByContentBlocking = true;
+let blockingByAllowList = false;
 
 let rootDir = getRootDirectory(gTestPath);
 let jar = getJar(rootDir);
 if (jar) {
   let tmpdir = extractJarToTmp(jar);
   rootDir = "file://" + tmpdir.path + "/";
 }
 /* import-globals-from imageCacheWorker.js */
--- a/toolkit/components/antitracking/test/browser/browser_imageCache3.js
+++ b/toolkit/components/antitracking/test/browser/browser_imageCache3.js
@@ -1,12 +1,13 @@
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 let blockingByCookieBehavior = false;
 let blockingByContentBlocking = false;
+let blockingByAllowList = false;
 
 let rootDir = getRootDirectory(gTestPath);
 let jar = getJar(rootDir);
 if (jar) {
   let tmpdir = extractJarToTmp(jar);
   rootDir = "file://" + tmpdir.path + "/";
 }
 /* import-globals-from imageCacheWorker.js */
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_imageCache4.js
@@ -0,0 +1,15 @@
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+let blockingByCookieBehavior = true;
+let blockingByContentBlocking = true;
+let blockingByAllowList = true;
+
+let rootDir = getRootDirectory(gTestPath);
+let jar = getJar(rootDir);
+if (jar) {
+  let tmpdir = extractJarToTmp(jar);
+  rootDir = "file://" + tmpdir.path + "/";
+}
+/* import-globals-from imageCacheWorker.js */
+Services.scriptloader.loadSubScript(rootDir + "imageCacheWorker.js", this);
+
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/head.js
@@ -14,17 +14,17 @@ const TEST_3RD_PARTY_PAGE_WITH_SVG = TES
 
 var gFeatures = undefined;
 
 let {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
 
 this.AntiTracking = {
   runTest(name, callbackTracking, callbackNonTracking, cleanupFunction, extraPrefs, windowOpenTest = true, userInteractionTest = true) {
     // Here we want to test that a 3rd party context is simply blocked.
-    this._createTask(name, true, true, callbackTracking, extraPrefs);
+    this._createTask(name, true, true, false, callbackTracking, extraPrefs);
     this._createCleanupTask(cleanupFunction);
 
     if (callbackNonTracking) {
       let runExtraTests = true;
       let options = {};
       if (typeof callbackNonTracking == "object") {
         callbackNonTracking = callbackNonTracking.callback;
         runExtraTests = callbackNonTracking.runExtraTests;
@@ -35,36 +35,47 @@ this.AntiTracking = {
           options.blockingByCookieBehavior = false;
         }
         if ("blockingByContentBlocking" in callbackNonTracking) {
           options.blockingByContentBlocking =
             callbackNonTracking.blockingByContentBlocking;
         } else {
           options.blockingByContentBlocking = false;
         }
+        if ("blockingByAllowList" in callbackNonTracking) {
+          options.blockingByAllowList =
+            callbackNonTracking.blockingByAllowList;
+        } else {
+          options.blockingByAllowList = false;
+        }
       }
 
       // Phase 1: Here we want to test that a 3rd party context is not blocked if pref is off.
       if (runExtraTests) {
-        // There are three ways in which the third-party context may be blocked:
+        // There are four ways in which the third-party context may be blocked:
         //   * If the cookieBehavior pref causes it to not be blocked.
         //   * If the contentBlocking pref causes it to not be blocked.
         //   * If both of these prefs cause it to not be blocked.
+        //   * If the top-level page is on the content blocking allow list.
         // All of these cases are tested here.
-        this._createTask(name, false, true, callbackNonTracking);
+        this._createTask(name, false, true, false, callbackNonTracking);
         this._createCleanupTask(cleanupFunction);
 
-        this._createTask(name, true, false, callbackNonTracking);
+        this._createTask(name, true, false, false, callbackNonTracking);
         this._createCleanupTask(cleanupFunction);
 
-        this._createTask(name, false, false, callbackNonTracking);
+        this._createTask(name, false, false, false, callbackNonTracking);
+        this._createCleanupTask(cleanupFunction);
+
+        this._createTask(name, true, true, true, callbackNonTracking);
         this._createCleanupTask(cleanupFunction);
       } else {
         this._createTask(name, options.blockingByCookieBehavior,
                          options.blockingByContentBlocking,
+                         options.blockingByAllowList,
                          callbackNonTracking);
         this._createCleanupTask(cleanupFunction);
       }
 
       // Phase 2: Here we want to test that a third-party context doesn't
       // get blocked with when the same origin is opened through window.open().
       if (windowOpenTest) {
         this._createWindowOpenTask(name, callbackTracking, callbackNonTracking, extraPrefs);
@@ -83,39 +94,50 @@ this.AntiTracking = {
   async _setupTest(blockingByCookieBehavior, blockingByContentBlocking, extraPrefs) {
     await SpecialPowers.flushPrefEnv();
     await SpecialPowers.pushPrefEnv({"set": [
       ["browser.contentblocking.enabled", blockingByContentBlocking],
       ["network.cookie.cookieBehavior", blockingByCookieBehavior ? Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER : Ci.nsICookieService.BEHAVIOR_ACCEPT],
       ["privacy.trackingprotection.enabled", false],
       ["privacy.trackingprotection.pbmode.enabled", false],
       ["privacy.trackingprotection.annotate_channels", blockingByCookieBehavior],
+      [ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS],
     ]});
 
     if (extraPrefs && Array.isArray(extraPrefs) && extraPrefs.length) {
       await SpecialPowers.pushPrefEnv({"set": extraPrefs });
     }
 
     await UrlClassifierTestUtils.addTestTrackers();
   },
 
-  _createTask(name, blockingByCookieBehavior, blockingByContentBlocking, callback, extraPrefs) {
+  _createTask(name, blockingByCookieBehavior, blockingByContentBlocking,
+              allowList, callback, extraPrefs) {
     add_task(async function() {
       info("Starting " + (blockingByCookieBehavior ? "blocking" : "non-blocking") + " cookieBehavior and " +
-                         (blockingByContentBlocking ? "blocking" : "non-blocking") + " contentBlocking test " + name);
+                         (blockingByContentBlocking ? "blocking" : "non-blocking") + " contentBlocking with" +
+                         (allowList ? "" : "out") + " allow list test " + name);
 
       await AntiTracking._setupTest(blockingByCookieBehavior, blockingByContentBlocking, extraPrefs);
 
       info("Creating a new tab");
       let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
       gBrowser.selectedTab = tab;
 
       let browser = gBrowser.getBrowserForTab(tab);
       await BrowserTestUtils.browserLoaded(browser);
 
+      if (allowList) {
+        info("Disabling content blocking for this page");
+        ContentBlocking.disableForCurrentPage();
+
+        // The previous function reloads the browser, so wait for it to load again!
+        await BrowserTestUtils.browserLoaded(browser);
+      }
+
       info("Creating a 3rd party content");
       await ContentTask.spawn(browser,
                               { page: TEST_3RD_PARTY_PAGE,
                                 callback: callback.toString() },
                               async function(obj) {
         await new content.Promise(resolve => {
           let ifr = content.document.createElement("iframe");
           ifr.onload = function() {
@@ -143,16 +165,24 @@ this.AntiTracking = {
             ok(false, "Unknown message");
           });
 
           content.document.body.appendChild(ifr);
           ifr.src = obj.page;
         });
       });
 
+      if (allowList) {
+        info("Enabling content blocking for this page");
+        ContentBlocking.enableForCurrentPage();
+
+        // The previous function reloads the browser, so wait for it to load again!
+        await BrowserTestUtils.browserLoaded(browser);
+      }
+
       info("Removing the tab");
       BrowserTestUtils.removeTab(tab);
 
       UrlClassifierTestUtils.cleanupTestTrackers();
     });
   },
 
   _createCleanupTask(cleanupFunction) {
--- a/toolkit/components/antitracking/test/browser/imageCacheWorker.js
+++ b/toolkit/components/antitracking/test/browser/imageCacheWorker.js
@@ -19,16 +19,17 @@ AntiTracking.runTest("Image cache - shou
     ok(true, "Image 2 loaded");
   },
 
   // non-blocking callback
   {
     runExtraTests: false,
     blockingByCookieBehavior,
     blockingByContentBlocking,
+    blockingByAllowList,
     callback: async _ => {
       // Let's load the image twice here as well.
       let img = document.createElement("img");
       document.body.appendChild(img);
       img.src = "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs",
       await new Promise(resolve => { img.onload = resolve; });
       ok(true, "Image 3 loaded");