Bug 1538684 - Add reportBreakage labels and report prefs for fingerprinters and cryptominers. r=ewright
authorJohann Hofmann <jhofmann@mozilla.com>
Fri, 29 Mar 2019 18:51:33 +0000
changeset 466806 c8b4e1f72505d4133af45789ca32a99d5fe78e48
parent 466805 47064bce86937fe84664fe713e20071670915def
child 466807 bd03a5a96bde1398d881c364c96cc06ec7d30de7
push id35780
push useropoprus@mozilla.com
push dateFri, 29 Mar 2019 21:53:01 +0000
treeherdermozilla-central@414f37afbe07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersewright
bugs1538684
milestone68.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 1538684 - Add reportBreakage labels and report prefs for fingerprinters and cryptominers. r=ewright Differential Revision: https://phabricator.services.mozilla.com/D24695
browser/base/content/browser-contentblocking.js
browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js
--- a/browser/base/content/browser-contentblocking.js
+++ b/browser/base/content/browser-contentblocking.js
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var Fingerprinting = {
   PREF_ENABLED: "privacy.trackingprotection.fingerprinting.enabled",
+  reportBreakageLabel: "fingerprinting",
   telemetryIdentifier: "fp",
 
   strings: {
     get subViewBlocked() {
       delete this.subViewBlocked;
       return this.subViewBlocked =
         gNavigatorBundle.getString("contentBlocking.fingerprintersView.blocked.label");
     },
@@ -111,16 +112,17 @@ var Fingerprinting = {
     }
 
     return listItem;
   },
 };
 
 var Cryptomining = {
   PREF_ENABLED: "privacy.trackingprotection.cryptomining.enabled",
+  reportBreakageLabel: "cryptomining",
   telemetryIdentifier: "cm",
 
   strings: {
     get subViewBlocked() {
       delete this.subViewBlocked;
       return this.subViewBlocked =
         gNavigatorBundle.getString("contentBlocking.cryptominersView.blocked.label");
     },
@@ -979,16 +981,18 @@ var ContentBlocking = {
     body += `${TrackingProtection.PREF_ENABLED_GLOBALLY}: ${Services.prefs.getBoolPref(TrackingProtection.PREF_ENABLED_GLOBALLY)}\n`;
     body += `${TrackingProtection.PREF_ENABLED_IN_PRIVATE_WINDOWS}: ${Services.prefs.getBoolPref(TrackingProtection.PREF_ENABLED_IN_PRIVATE_WINDOWS)}\n`;
     body += `urlclassifier.trackingTable: ${Services.prefs.getStringPref("urlclassifier.trackingTable")}\n`;
     body += `network.http.referer.defaultPolicy: ${Services.prefs.getIntPref("network.http.referer.defaultPolicy")}\n`;
     body += `network.http.referer.defaultPolicy.pbmode: ${Services.prefs.getIntPref("network.http.referer.defaultPolicy.pbmode")}\n`;
     body += `${ThirdPartyCookies.PREF_ENABLED}: ${Services.prefs.getIntPref(ThirdPartyCookies.PREF_ENABLED)}\n`;
     body += `network.cookie.lifetimePolicy: ${Services.prefs.getIntPref("network.cookie.lifetimePolicy")}\n`;
     body += `privacy.restrict3rdpartystorage.expiration: ${Services.prefs.getIntPref("privacy.restrict3rdpartystorage.expiration")}\n`;
+    body += `${Fingerprinting.PREF_ENABLED}: ${Services.prefs.getBoolPref(Fingerprinting.PREF_ENABLED)}\n`;
+    body += `${Cryptomining.PREF_ENABLED}: ${Services.prefs.getBoolPref(Cryptomining.PREF_ENABLED)}\n`;
 
     let comments = document.getElementById("identity-popup-breakageReportView-collection-comments");
     body += "\n**Comments**\n" + comments.value;
 
     formData.set("body", body);
 
     let activatedBlockers = [];
     for (let blocker of this.blockers) {
--- a/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js
@@ -2,33 +2,55 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
 const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
 const COOKIE_PAGE = "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookiePage.html";
 
+const CM_PREF = "privacy.trackingprotection.cryptomining.enabled";
+const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled";
 const TP_PREF = "privacy.trackingprotection.enabled";
+
 const PREF_REPORT_BREAKAGE_ENABLED = "browser.contentblocking.reportBreakage.enabled";
 const PREF_REPORT_BREAKAGE_URL = "browser.contentblocking.reportBreakage.url";
 
 let {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 let {CommonUtils} = ChromeUtils.import("resource://services-common/utils.js");
 let {Preferences} = ChromeUtils.import("resource://gre/modules/Preferences.jsm");
 
 add_task(async function setup() {
   await UrlClassifierTestUtils.addTestTrackers();
 
   let oldCanRecord = Services.telemetry.canRecordExtended;
   Services.telemetry.canRecordExtended = true;
 
   registerCleanupFunction(() => {
     Services.telemetry.canRecordExtended = oldCanRecord;
+
+    // Clear prefs that are touched in this test again for sanity.
+    Services.prefs.clearUserPref(TP_PREF);
+    Services.prefs.clearUserPref(FP_PREF);
+    Services.prefs.clearUserPref(CM_PREF);
+    Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED);
+    Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL);
+
+    UrlClassifierTestUtils.cleanupTestTrackers();
   });
+
+  await SpecialPowers.pushPrefEnv({set: [
+    [ ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS ],
+    [ "privacy.trackingprotection.fingerprinting.annotate.enabled", true ],
+    [ "urlclassifier.features.fingerprinting.blacklistHosts", "fingerprinting.example.com" ],
+    [ "urlclassifier.features.fingerprinting.annotate.blacklistHosts", "fingerprinting.example.com" ],
+    [ "privacy.trackingprotection.cryptomining.enabled", true ],
+    [ "urlclassifier.features.cryptomining.blacklistHosts", "cryptomining.example.com" ],
+    [ "urlclassifier.features.cryptomining.annotate.blacklistHosts", "cryptomining.example.com" ],
+  ]});
 });
 
 add_task(async function testReportBreakageVisibility() {
   let scenarios = [
     {
       url: TRACKING_PAGE,
       prefs: {
         "privacy.trackingprotection.enabled": true,
@@ -129,108 +151,139 @@ add_task(async function testReportBreaka
 
     ok(true, "Main view was shown");
   });
 
   Services.prefs.clearUserPref(TP_PREF);
   Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED);
 });
 
-add_task(async function testReportBreakage() {
+add_task(async function testTP() {
+  Services.prefs.setBoolPref(TP_PREF, true);
+  // Make sure that we correctly strip the query.
+  let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
+  await BrowserTestUtils.withNewTab(url, async function() {
+    await testReportBreakage(TRACKING_PAGE, "trackingprotection");
+  });
+
+  Services.prefs.clearUserPref(TP_PREF);
+});
+
+add_task(async function testFP() {
+  Services.prefs.setBoolPref(FP_PREF, true);
+  // Make sure that we correctly strip the query.
+  let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
+  await BrowserTestUtils.withNewTab(url, async function(browser) {
+    await ContentTask.spawn(browser, {}, function() {
+      content.postMessage("fingerprinting", "*");
+    });
+
+    // Without TP, we will have a cookie restrictions entry for trackertest.org.
+    await testReportBreakage(TRACKING_PAGE, "cookierestrictions,fingerprinting");
+  });
+
+  Services.prefs.clearUserPref(FP_PREF);
+});
+
+add_task(async function testCM() {
+  Services.prefs.setBoolPref(CM_PREF, true);
+  // Make sure that we correctly strip the query.
+  let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
+  await BrowserTestUtils.withNewTab(url, async function(browser) {
+    await ContentTask.spawn(browser, {}, function() {
+      content.postMessage("cryptomining", "*");
+    });
+
+    // Without TP, we will have a cookie restrictions entry for trackertest.org.
+    await testReportBreakage(TRACKING_PAGE, "cookierestrictions,cryptomining");
+  });
+
+  Services.prefs.clearUserPref(CM_PREF);
+});
+
+async function testReportBreakage(url, tags) {
   // Setup a mock server for receiving breakage reports.
   let server = new HttpServer();
   server.start(-1);
   let i = server.identity;
   let path = i.primaryScheme + "://" + i.primaryHost + ":" + i.primaryPort + "/";
 
-  Services.prefs.setBoolPref(TP_PREF, true);
   Services.prefs.setBoolPref(PREF_REPORT_BREAKAGE_ENABLED, true);
   Services.prefs.setStringPref(PREF_REPORT_BREAKAGE_URL, path);
 
-  // Make sure that we correctly strip the query.
-  let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊";
-  await BrowserTestUtils.withNewTab(url, async function() {
-    await openIdentityPopup();
+  await openIdentityPopup();
 
-    let reportBreakageButton = document.getElementById("identity-popup-content-blocking-report-breakage");
-    ok(BrowserTestUtils.is_visible(reportBreakageButton), "report breakage button is visible");
-    let reportBreakageView = document.getElementById("identity-popup-breakageReportView");
-    let viewShown = BrowserTestUtils.waitForEvent(reportBreakageView, "ViewShown");
-    reportBreakageButton.click();
-    await viewShown;
+  let reportBreakageButton = document.getElementById("identity-popup-content-blocking-report-breakage");
+  await TestUtils.waitForCondition(() => BrowserTestUtils.is_visible(reportBreakageButton),
+    "report breakage button is visible");
+  let reportBreakageView = document.getElementById("identity-popup-breakageReportView");
+  let viewShown = BrowserTestUtils.waitForEvent(reportBreakageView, "ViewShown");
+  reportBreakageButton.click();
+  await viewShown;
 
-    let submitButton = document.getElementById("identity-popup-breakageReportView-submit");
-    let reportURL = document.getElementById("identity-popup-breakageReportView-collection-url").value;
+  let submitButton = document.getElementById("identity-popup-breakageReportView-submit");
+  let reportURL = document.getElementById("identity-popup-breakageReportView-collection-url").value;
 
-    is(reportURL, TRACKING_PAGE, "Shows the correct URL in the report UI.");
+  is(reportURL, url, "Shows the correct URL in the report UI.");
 
-    // Make sure that sending the report closes the identity popup.
-    let popuphidden = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popuphidden");
+  // Make sure that sending the report closes the identity popup.
+  let popuphidden = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popuphidden");
 
-    // Check that we're receiving a good report.
-    await new Promise(resolve => {
-      server.registerPathHandler("/", async (request, response) => {
-        is(request.method, "POST", "request was a post");
+  // Check that we're receiving a good report.
+  await new Promise(resolve => {
+    server.registerPathHandler("/", async (request, response) => {
+      is(request.method, "POST", "request was a post");
 
-        // Extract and "parse" the form data in the request body.
-        let body = CommonUtils.readBytesFromInputStream(request.bodyInputStream);
-        let boundary = request.getHeader("Content-Type").match(/boundary=-+([^-]*)/i)[1];
-        let regex = new RegExp("-+" + boundary + "-*\\s+");
-        let sections = body.split(regex);
+      // Extract and "parse" the form data in the request body.
+      let body = CommonUtils.readBytesFromInputStream(request.bodyInputStream);
+      let boundary = request.getHeader("Content-Type").match(/boundary=-+([^-]*)/i)[1];
+      let regex = new RegExp("-+" + boundary + "-*\\s+");
+      let sections = body.split(regex);
 
-        let prefs = [
-          "privacy.trackingprotection.enabled",
-          "privacy.trackingprotection.pbmode.enabled",
-          "urlclassifier.trackingTable",
-          "network.http.referer.defaultPolicy",
-          "network.http.referer.defaultPolicy.pbmode",
-          "network.cookie.cookieBehavior",
-          "network.cookie.lifetimePolicy",
-          "privacy.restrict3rdpartystorage.expiration",
-        ];
-        let prefsBody = "";
-
-        for (let pref of prefs) {
-          prefsBody += `${pref}: ${Preferences.get(pref)}\r\n`;
-        }
+      let prefs = [
+        "privacy.trackingprotection.enabled",
+        "privacy.trackingprotection.pbmode.enabled",
+        "urlclassifier.trackingTable",
+        "network.http.referer.defaultPolicy",
+        "network.http.referer.defaultPolicy.pbmode",
+        "network.cookie.cookieBehavior",
+        "network.cookie.lifetimePolicy",
+        "privacy.restrict3rdpartystorage.expiration",
+        "privacy.trackingprotection.fingerprinting.enabled",
+        "privacy.trackingprotection.cryptomining.enabled",
+      ];
+      let prefsBody = "";
 
-        Assert.deepEqual(sections, [
-          "",
-          "Content-Disposition: form-data; name=\"title\"\r\n\r\ntracking.example.org\r\n",
-          "Content-Disposition: form-data; name=\"body\"\r\n\r\n" +
-          `Full URL: ${reportURL + "?"}\r\n` +
-          `userAgent: ${navigator.userAgent}\r\n\r\n` +
-          "**Preferences**\r\n" +
-          `${prefsBody}\r\n` +
-          "**Comments**\r\n" +
-          "This is a comment\r\n",
-          "Content-Disposition: form-data; name=\"labels\"\r\n\r\n" +
-          "trackingprotection\r\n",
-          "",
-        ], "Should send the correct form data");
+      for (let pref of prefs) {
+        prefsBody += `${pref}: ${Preferences.get(pref)}\r\n`;
+      }
 
-        resolve();
-      });
+      Assert.deepEqual(sections, [
+        "",
+        "Content-Disposition: form-data; name=\"title\"\r\n\r\ntracking.example.org\r\n",
+        "Content-Disposition: form-data; name=\"body\"\r\n\r\n" +
+        `Full URL: ${reportURL + "?"}\r\n` +
+        `userAgent: ${navigator.userAgent}\r\n\r\n` +
+        "**Preferences**\r\n" +
+        `${prefsBody}\r\n` +
+        "**Comments**\r\n" +
+        "This is a comment\r\n",
+        "Content-Disposition: form-data; name=\"labels\"\r\n\r\n" +
+        `${tags}\r\n`,
+        "",
+      ], "Should send the correct form data");
 
-      let comments = document.getElementById("identity-popup-breakageReportView-collection-comments");
-      comments.value = "This is a comment";
-      submitButton.click();
+      resolve();
     });
 
-    await popuphidden;
+    let comments = document.getElementById("identity-popup-breakageReportView-collection-comments");
+    comments.value = "This is a comment";
+    submitButton.click();
   });
 
+  await popuphidden;
+
   // Stop the server.
   await new Promise(r => server.stop(r));
 
-  Services.prefs.clearUserPref(TP_PREF);
   Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED);
   Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL);
-});
-
-add_task(async function cleanup() {
-  // Clear prefs that are touched in this test again for sanity.
-  Services.prefs.clearUserPref(TP_PREF);
-  Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED);
-  Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL);
-
-  UrlClassifierTestUtils.cleanupTestTrackers();
-});
+}