Bug 1485182 - Part 2: Add a test case to ensure that http-on-modify-request will be dispatched by requests blocked by tracking protection; r=mayhemer
☠☠ backed out by 2f5f240834b0 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 22 Aug 2018 12:22:30 -0400
changeset 488020 4bf7cca192e7657ed0bdaa598b2a9ddb30ac5472
parent 488019 c7d62fc647ec1a96567a6266b51114fb7427cce9
child 488021 a7caa2f69479cee185e4a7caa9a9516ed1159298
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1485182
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 1485182 - Part 2: Add a test case to ensure that http-on-modify-request will be dispatched by requests blocked by tracking protection; r=mayhemer
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_onModifyRequestNotificationForTrackingResources.js
toolkit/components/antitracking/test/browser/embedder.html
toolkit/components/antitracking/test/browser/head.js
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -1,10 +1,11 @@
 [DEFAULT]
 support-files =
+  embedder.html
   head.js
   page.html
   3rdParty.html
   3rdPartySVG.html
   3rdPartyUI.html
   3rdPartyWO.html
   3rdPartyOpen.html
   3rdPartyOpenUI.html
@@ -17,12 +18,13 @@ support-files = server.sjs
 [browser_blockingIndexedDb.js]
 [browser_blockingStorage.js]
 [browser_blockingWorkers.js]
 [browser_blockingMessaging.js]
 [browser_blockingNoOpener.js]
 [browser_existingCookiesForSubresources.js]
 [browser_imageCache.js]
 support-files = image.sjs
+[browser_onModifyRequestNotificationForTrackingResources.js]
 [browser_subResources.js]
 support-files = subResources.sjs
 [browser_script.js]
 support-files = tracker.js
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_onModifyRequestNotificationForTrackingResources.js
@@ -0,0 +1,60 @@
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+/**
+ * This test ensures that http-on-modify-request is dispatched for channels that
+ * are blocked by tracking protection.  It sets up a page with a third-party script
+ * resource on it that is blocked by TP, and sets up an http-on-modify-request
+ * observer which waits to be notified about that resource.  The test would time out
+ * if the http-on-modify-request notification isn't dispatched before the channel is
+ * canceled.
+ */
+
+async function onModifyRequest() {
+  return new Promise((resolve, reject) => {
+    Services.obs.addObserver(function observer(subject, topic, data) {
+      let httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
+      let spec = httpChannel.URI.spec;
+      info("Observed channel for " + spec);
+      if (httpChannel.URI.prePath + "/" != TEST_3RD_PARTY_DOMAIN_TP) {
+        return;
+      }
+      ok(spec.endsWith("empty.js"), "Correct resource observed");
+      Services.obs.removeObserver(observer, "http-on-modify-request");
+      resolve();
+    }, "http-on-modify-request", false);
+  });
+}
+
+add_task(async function() {
+  info("Starting subResources test");
+
+  await SpecialPowers.flushPrefEnv();
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["browser.contentblocking.enabled", true],
+    ["privacy.trackingprotection.enabled", true],
+    // the test doesn't open a private window, so we don't care about this pref's value
+    ["privacy.trackingprotection.pbmode.enabled", false],
+    // tracking annotations aren't needed in this test, only TP is needed
+    ["privacy.trackingprotection.annotate_channels", false],
+    // prevent the content blocking on-boarding UI to start mid-way through the test!
+    ["privacy.trackingprotection.introCount", ContentBlocking.MAX_INTROS],
+  ]});
+
+  await UrlClassifierTestUtils.addTestTrackers();
+
+  let promise = onModifyRequest();
+
+  info("Creating a new tab");
+  let tab = BrowserTestUtils.addTab(gBrowser, TEST_EMBEDDER_PAGE);
+  gBrowser.selectedTab = tab;
+
+  let browser = gBrowser.getBrowserForTab(tab);
+  await BrowserTestUtils.browserLoaded(browser);
+
+  await promise;
+
+  info("Removing the tab");
+  BrowserTestUtils.removeTab(tab);
+
+  UrlClassifierTestUtils.cleanupTestTrackers();
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/embedder.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<script src="https://tracking.example.com/browser/toolkit/components/antitracking/test/browser/empty.js"></script>
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/head.js
@@ -1,14 +1,16 @@
 const TEST_DOMAIN = "http://example.net/";
 const TEST_3RD_PARTY_DOMAIN = "https://tracking.example.org/";
+const TEST_3RD_PARTY_DOMAIN_TP = "https://tracking.example.com/";
 
 const TEST_PATH = "browser/toolkit/components/antitracking/test/browser/";
 
 const TEST_TOP_PAGE = TEST_DOMAIN + TEST_PATH + "page.html";
+const TEST_EMBEDDER_PAGE = TEST_DOMAIN + TEST_PATH + "embedder.html";
 const TEST_POPUP_PAGE = TEST_DOMAIN + TEST_PATH + "popup.html";
 const TEST_3RD_PARTY_PAGE = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdParty.html";
 const TEST_3RD_PARTY_PAGE_WO = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdPartyWO.html";
 const TEST_3RD_PARTY_PAGE_UI = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdPartyUI.html";
 const TEST_3RD_PARTY_PAGE_WITH_SVG = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdPartySVG.html";
 
 var gFeatures = undefined;