Bug 1525458 - Part 4: Add a test that verifies that when the top-level page is on the content blocking allow-list, we don't emit unexpected content blocking events inside the content blocking log; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 21 Feb 2019 16:57:28 -0500
changeset 519754 ca609968769496871058ab18a471b0c3be5c67ad
parent 519753 bfadbf643f32e259d45f8b5af88c0300dc17b68f
child 519755 0507c090702b82431521119b5d6f9873d8e0486f
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)
reviewersbaku
bugs1525458
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 1525458 - Part 4: Add a test that verifies that when the top-level page is on the content blocking allow-list, we don't emit unexpected content blocking events inside the content blocking log; r=baku Differential Revision: https://phabricator.services.mozilla.com/D20877
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_allowListNotifications.js
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -19,16 +19,19 @@ support-files =
   3rdPartyOpen.html
   3rdPartyOpenUI.html
   empty.js
   popup.html
   server.sjs
   storageAccessAPIHelpers.js
   !/browser/modules/test/browser/head.js
 
+[browser_allowListNotifications.js]
+skip-if = serviceworker_e10s
+support-files = subResources.sjs
 [browser_addonHostPermissionIgnoredInTP.js]
 [browser_allowListSeparationInPrivateAndNormalWindows.js]
 skip-if = os == "mac" && !debug # Bug 1503778
 [browser_backgroundImageAssertion.js]
 [browser_blockingCookies.js]
 [browser_blockingDOMCache.js]
 skip-if = (os == "win" && os_version == "6.1" && bits == 32 && !debug) # Bug 1491937
 [browser_blockingIndexedDb.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_allowListNotifications.js
@@ -0,0 +1,113 @@
+add_task(async function() {
+  info("Starting subResources test");
+
+  await SpecialPowers.flushPrefEnv();
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["browser.contentblocking.allowlist.annotations.enabled", true],
+    ["browser.contentblocking.allowlist.storage.enabled", true],
+    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+    ["privacy.trackingprotection.enabled", false],
+    ["privacy.trackingprotection.pbmode.enabled", false],
+    ["privacy.trackingprotection.annotate_channels", true],
+  ]});
+
+  await UrlClassifierTestUtils.addTestTrackers();
+
+  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);
+
+  ContentBlocking.disableForCurrentPage();
+
+  // The previous function reloads the browser, so wait for it to load again!
+  await BrowserTestUtils.browserLoaded(browser);
+
+  // Now load subresources from a few third-party origins.
+  // We should expect to see none of these origins in the content blocking log at the end.
+  await fetch("https://test1.example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=image")
+    .then(r => r.text())
+    .then(text => {
+      is(text, 0, "Cookies received for images");
+    });
+
+  await fetch("https://test2.example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=image")
+    .then(r => r.text())
+    .then(text => {
+      is(text, 0, "Cookies received for images");
+    });
+
+  info("Creating a 3rd party content");
+  await ContentTask.spawn(browser,
+                          { page: TEST_3RD_PARTY_PAGE,
+                            blockingCallback: (async _ => {}).toString(),
+                            nonBlockingCallback: (async _ => {}).toString(),
+                          },
+                          async function(obj) {
+    await new content.Promise(resolve => {
+      let ifr = content.document.createElement("iframe");
+      ifr.onload = function() {
+        info("Sending code to the 3rd party content");
+        ifr.contentWindow.postMessage(obj.blockingCallback, "*");
+      };
+
+      content.addEventListener("message", function msg(event) {
+        if (event.data.type == "finish") {
+          content.removeEventListener("message", msg);
+          resolve();
+          return;
+        }
+
+        if (event.data.type == "ok") {
+          ok(event.data.what, event.data.msg);
+          return;
+        }
+
+        if (event.data.type == "info") {
+          info(event.data.msg);
+          return;
+        }
+
+        ok(false, "Unknown message");
+      });
+
+      content.document.body.appendChild(ifr);
+      ifr.src = obj.page;
+    });
+  });
+
+  let expectTrackerFound = item => {
+    is(item[0], Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
+       "Correct blocking type reported");
+    is(item[1], true,
+       "Correct blocking status reported");
+    ok(item[2] >= 1,
+       "Correct repeat count reported");
+  };
+
+  let log = JSON.parse(await browser.getContentBlockingLog());
+  for (let trackerOrigin in log) {
+    is(trackerOrigin + "/", TEST_3RD_PARTY_DOMAIN, "Correct tracker origin must be reported");
+    let originLog = log[trackerOrigin];
+    is(originLog.length, 1, "We should have 1 entry in the compressed log");
+    expectTrackerFound(originLog[0]);
+  }
+
+  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);
+});
+
+add_task(async function() {
+  info("Cleaning up.");
+  await new Promise(resolve => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+  });
+});
+