Bug 1593509 - Improvements to social tracking frontend test. r=xeonchen
authorNihanth Subramanya <nhnt11@gmail.com>
Mon, 04 Nov 2019 09:55:02 +0000
changeset 500338 02e649724d8194a7e86e5761d1fde3b4b1fb4b32
parent 500337 534738aa34c02f105cf747ba0eff4183b0274798
child 500339 d8b8aaa7e20253d2b79cd0506c305f2521f145a5
push id36763
push userrmaries@mozilla.com
push dateMon, 04 Nov 2019 21:44:06 +0000
treeherdermozilla-central@75a7a3400888 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxeonchen
bugs1593509
milestone72.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 1593509 - Improvements to social tracking frontend test. r=xeonchen Differential Revision: https://phabricator.services.mozilla.com/D51544
browser/base/content/test/trackingUI/browser_trackingUI_socialtracking.js
browser/base/content/test/trackingUI/head.js
browser/base/content/test/trackingUI/trackingAPI.js
--- a/browser/base/content/test/trackingUI/browser_trackingUI_socialtracking.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_socialtracking.js
@@ -1,40 +1,33 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const TRACKING_PAGE =
-  "http://example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
+  "http://example.com/browser/browser/base/content/test/trackingUI/trackingPage.html";
 
 const ST_PROTECTION_PREF = "privacy.trackingprotection.socialtracking.enabled";
 const ST_BLOCK_COOKIES_PREF = "privacy.socialtracking.block_cookies.enabled";
 
 add_task(async function setup() {
   await SpecialPowers.pushPrefEnv({
     set: [
-      [ST_PROTECTION_PREF, true],
       [ST_BLOCK_COOKIES_PREF, true],
       [
         "urlclassifier.features.socialtracking.blacklistHosts",
-        "socialtracking.example.com",
+        "social-tracking.example.org",
       ],
       [
         "urlclassifier.features.socialtracking.annotate.blacklistHosts",
-        "socialtracking.example.com",
+        "social-tracking.example.org",
       ],
       ["privacy.trackingprotection.enabled", false],
-      ["privacy.trackingprotection.annotate_channels", false],
-      ["privacy.trackingprotection.cryptomining.enabled", false],
-      ["urlclassifier.features.cryptomining.annotate.blacklistHosts", ""],
-      ["urlclassifier.features.cryptomining.annotate.blacklistTables", ""],
-      ["privacy.trackingprotection.fingerprinting.enabled", false],
-      ["urlclassifier.features.fingerprinting.annotate.blacklistHosts", ""],
-      ["urlclassifier.features.fingerprinting.annotate.blacklistTables", ""],
+      ["privacy.trackingprotection.annotate_channels", true],
     ],
   });
 });
 
 async function testIdentityState(hasException) {
   let promise = BrowserTestUtils.openNewForegroundTab({
     url: TRACKING_PAGE,
     gBrowser,
@@ -46,39 +39,47 @@ async function testIdentityState(hasExce
       tab.linkedBrowser,
       false,
       TRACKING_PAGE
     );
     gProtectionsHandler.disableForCurrentPage();
     await loaded;
   }
 
+  let categoryItem = document.getElementById(
+    "protections-popup-category-socialblock"
+  );
+
   ok(
-    !gProtectionsHandler._protectionsPopup.hasAttribute("detected"),
+    categoryItem.classList.contains("notFound"),
     "socialtrackings are not detected"
   );
 
   ok(
     BrowserTestUtils.is_visible(gProtectionsHandler.iconBox),
     "icon box is visible regardless the exception"
   );
 
-  promise = waitForContentBlockingEvent();
-
   await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
     content.postMessage("socialtracking", "*");
   });
 
-  await promise;
+  await TestUtils.waitForCondition(() => {
+    return !categoryItem.classList.contains("notFound");
+  });
 
   ok(
     gProtectionsHandler._protectionsPopup.hasAttribute("detected"),
     "trackers are detected"
   );
   ok(
+    !categoryItem.classList.contains("notFound"),
+    "social trackers are detected"
+  );
+  ok(
     BrowserTestUtils.is_visible(gProtectionsHandler.iconBox),
     "icon box is visible"
   );
   is(
     gProtectionsHandler.iconBox.hasAttribute("hasException"),
     hasException,
     "Shows an exception when appropriate"
   );
@@ -135,17 +136,17 @@ async function testSubview(hasException)
   await viewShown;
 
   let listItems = subview.querySelectorAll(".protections-popup-list-item");
   is(listItems.length, 1, "We have 1 item in the list");
   let listItem = listItems[0];
   ok(BrowserTestUtils.is_visible(listItem), "List item is visible");
   is(
     listItem.querySelector("label").value,
-    "socialtracking.example.com",
+    "social-tracking.example.org",
     "Has the correct host"
   );
 
   let mainView = document.getElementById("protections-popup-mainView");
   viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown");
   let backButton = subview.querySelector(".subviewbutton-back");
   backButton.click();
   await viewShown;
@@ -160,18 +161,21 @@ async function testSubview(hasException)
     );
     gProtectionsHandler.enableForCurrentPage();
     await loaded;
   }
 
   BrowserTestUtils.removeTab(tab);
 }
 
-async function testCategoryItem() {
-  Services.prefs.setBoolPref(ST_PROTECTION_PREF, false);
+async function testCategoryItem(blockLoads) {
+  if (blockLoads) {
+    Services.prefs.setBoolPref(ST_PROTECTION_PREF, true);
+  }
+
   Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, false);
 
   let promise = BrowserTestUtils.openNewForegroundTab({
     url: TRACKING_PAGE,
     gBrowser,
   });
   let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]);
 
@@ -183,49 +187,48 @@ async function testCategoryItem() {
     !categoryItem.classList.contains("blocked"),
     "Category not marked as blocked"
   );
   ok(
     categoryItem.classList.contains("notFound"),
     "Category marked as not found"
   );
 
-  Services.prefs.setBoolPref(ST_PROTECTION_PREF, true);
   Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, true);
 
   ok(categoryItem.classList.contains("blocked"), "Category marked as blocked");
   ok(
     categoryItem.classList.contains("notFound"),
     "Category marked as not found"
   );
 
-  promise = waitForContentBlockingEvent();
-
   await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
     content.postMessage("socialtracking", "*");
   });
 
-  await promise;
+  await TestUtils.waitForCondition(() => {
+    return !categoryItem.classList.contains("notFound");
+  });
 
   ok(categoryItem.classList.contains("blocked"), "Category marked as blocked");
 
-  await TestUtils.waitForCondition(() => {
-    return !categoryItem.classList.contains("notFound");
-  });
   ok(
     !categoryItem.classList.contains("notFound"),
     "Category not marked as not found"
   );
 
   BrowserTestUtils.removeTab(tab);
+
+  Services.prefs.clearUserPref(ST_PROTECTION_PREF);
 }
 
 add_task(async function testIdentityUI() {
   requestLongerTimeout(2);
 
   await testIdentityState(false);
   await testIdentityState(true);
 
   await testSubview(false);
   await testSubview(true);
 
-  await testCategoryItem();
+  await testCategoryItem(false);
+  await testCategoryItem(true);
 });
--- a/browser/base/content/test/trackingUI/head.js
+++ b/browser/base/content/test/trackingUI/head.js
@@ -79,20 +79,20 @@ function waitForSecurityChange(numChange
 
 function waitForContentBlockingEvent(numChanges = 1, win = null) {
   if (!win) {
     win = window;
   }
   return new Promise(resolve => {
     let n = 0;
     let listener = {
-      onContentBlockingEvent() {
+      onContentBlockingEvent(webProgress, request, event) {
         n = n + 1;
         info(
-          "Received onContentBlockingEvent event " + n + " of " + numChanges
+          `Received onContentBlockingEvent event: ${event} (${n} of ${numChanges})`
         );
         if (n >= numChanges) {
           win.gBrowser.removeProgressListener(listener);
           resolve(n);
         }
       },
     };
     win.gBrowser.addProgressListener(listener);
--- a/browser/base/content/test/trackingUI/trackingAPI.js
+++ b/browser/base/content/test/trackingUI/trackingAPI.js
@@ -6,17 +6,17 @@ function createIframe(src) {
 
 onmessage = event => {
   switch (event.data) {
     case "tracking":
       createIframe("https://trackertest.org/");
       break;
     case "socialtracking":
       createIframe(
-        "http://socialtracking.example.com/browser/browser/base/content/test/trackingUI/cookieServer.sjs"
+        "https://social-tracking.example.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs"
       );
       break;
     case "cryptomining":
       createIframe("http://cryptomining.example.com/");
       break;
     case "fingerprinting":
       createIframe("https://fingerprinting.example.com/");
       break;