Bug 1188443 - UITour: Add Tracking Protection "Enable protection" button as a UITour target. r=paolo
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 07 Aug 2015 13:06:12 -0700
changeset 256804 d0a1ddd01c1e2b6e67bce8272b0a512d43667293
parent 256803 96f128a9b4656aee393a3d022bb9d40a2a8c0384
child 256805 a4836b5699def75b78d6668d9929cde146f33170
push id14512
push usermozilla@noorenberghe.ca
push dateFri, 07 Aug 2015 20:16:50 +0000
treeherderfx-team@a4836b5699de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs1188443
milestone42.0a1
Bug 1188443 - UITour: Add Tracking Protection "Enable protection" button as a UITour target. r=paolo
browser/components/uitour/UITour.jsm
browser/components/uitour/test/browser_trackingProtection_tour.js
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -126,30 +126,18 @@ this.UITour = {
         panelPopup.removeEventListener("popupshown", aCallback);
       },
     }],
     ["backForward", {
       query: "#back-button",
       widgetName: "urlbar-container",
     }],
     ["bookmarks",   {query: "#bookmarks-menu-button"}],
-    ["controlCenter-trackingUnblock", {
-      infoPanelPosition: "rightcenter topleft",
-      query(aDocument) {
-        let popup = aDocument.defaultView.gIdentityHandler._identityPopup;
-        if (popup.state != "open") {
-          return null;
-        }
-        let buttonId =
-            PrivateBrowsingUtils.isWindowPrivate(aDocument.defaultView) ?
-            "tracking-action-unblock-private" : "tracking-action-unblock";
-        let element = aDocument.getElementById(buttonId);
-        return UITour.isElementVisible(element) ? element : null;
-      },
-    }],
+    ["controlCenter-trackingUnblock", controlCenterTrackingToggleTarget(true)],
+    ["controlCenter-trackingBlock", controlCenterTrackingToggleTarget(false)],
     ["customize",   {
       query: (aDocument) => {
         let customizeButton = aDocument.getElementById("PanelUI-customize");
         return aDocument.getAnonymousElementByAttribute(customizeButton,
                                                         "class",
                                                         "toolbarbutton-icon");
       },
       widgetName: "PanelUI-customize",
@@ -2076,16 +2064,40 @@ this.UITour = {
           params: params,
         };
         messageManager.sendAsyncMessage("UITour:SendPageNotification", detail);
       }
     }
   },
 };
 
+function controlCenterTrackingToggleTarget(aUnblock) {
+  return {
+    infoPanelPosition: "rightcenter topleft",
+    query(aDocument) {
+      let popup = aDocument.defaultView.gIdentityHandler._identityPopup;
+      if (popup.state != "open") {
+        return null;
+      }
+      let buttonId = null;
+      if (aUnblock) {
+        if (PrivateBrowsingUtils.isWindowPrivate(aDocument.defaultView)) {
+          buttonId = "tracking-action-unblock-private";
+        } else {
+          buttonId = "tracking-action-unblock";
+        }
+      } else {
+        buttonId = "tracking-action-block";
+      }
+      let element = aDocument.getElementById(buttonId);
+      return UITour.isElementVisible(element) ? element : null;
+    },
+  };
+}
+
 this.UITour.init();
 
 /**
  * UITour Health Report
  */
 /**
  * Public API to be called by the UITour code
  */
--- a/browser/components/uitour/test/browser_trackingProtection_tour.js
+++ b/browser/components/uitour/test/browser_trackingProtection_tour.js
@@ -20,49 +20,65 @@ let tests = [
     Services.prefs.setBoolPref("privacy.trackingprotection.enabled", true);
     yield UrlClassifierTestUtils.addTestTrackers();
 
     registerCleanupFunction(function() {
       UrlClassifierTestUtils.cleanupTestTrackers();
       Services.prefs.clearUserPref("privacy.trackingprotection.enabled");
     });
   }),
+
   taskify(function* test_unblock_target() {
-    let popup = document.getElementById("UITourTooltip");
-
-    yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
-      let doc = content.document;
-      let iframe = doc.createElement("iframe");
-      iframe.setAttribute("id", "tracking-element");
-      iframe.setAttribute("src", "https://tracking.example.com/");
-      doc.body.insertBefore(iframe, doc.body.firstChild);
-    });
-
-    let currentTarget = "controlCenter-trackingUnblock";
-
-    let testTargetAvailability = function* (expectedAvailable) {
-      let data = yield getConfigurationPromise("availableTargets");
-      let available = (data.targets.indexOf(currentTarget) != -1);
-      is(available, expectedAvailable, "Target has expected availability.");
-    }
-    yield testTargetAvailability(false);
+    yield* checkToggleTarget("controlCenter-trackingUnblock");
+  }),
 
-    yield showMenuPromise("controlCenter");
-    yield testTargetAvailability(true);
-
-    yield showInfoPromise(currentTarget, "This is " + currentTarget,
-                          "My arrow should be on the side");
-    is(popup.popupBoxObject.alignmentPosition, "end_before",
-       "Check " + currentTarget + " position");
+  taskify(function* setup_block_target() {
+    // Preparation for test_block_target. These are separate since the reload
+    // interferes with UITour as it does a teardown. All we really care about
+    // is the permission manager entry but UITour tests shouldn't rely on that
+    // implementation detail.
+    TrackingProtection.disableForCurrentPage();
+  }),
 
-    let hideMenuPromise =
-        promisePanelElementHidden(window, gIdentityHandler._identityPopup);
-    gContentAPI.hideMenu("controlCenter");
-    yield hideMenuPromise;
-
-    ok(!is_visible(popup), "The tooltip should now be hidden.");
-    yield testTargetAvailability(false);
-
-    yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
-      content.document.getElementById("tracking-element").remove();
-    });
+  taskify(function* test_block_target() {
+    yield* checkToggleTarget("controlCenter-trackingBlock");
+    TrackingProtection.enableForCurrentPage();
   }),
 ];
+
+
+function* checkToggleTarget(targetID) {
+  let popup = document.getElementById("UITourTooltip");
+
+  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
+    let doc = content.document;
+    let iframe = doc.createElement("iframe");
+    iframe.setAttribute("id", "tracking-element");
+    iframe.setAttribute("src", "https://tracking.example.com/");
+    doc.body.insertBefore(iframe, doc.body.firstChild);
+  });
+
+  let testTargetAvailability = function* (expectedAvailable) {
+    let data = yield getConfigurationPromise("availableTargets");
+    let available = (data.targets.indexOf(targetID) != -1);
+    is(available, expectedAvailable, "Target has expected availability.");
+  };
+  yield testTargetAvailability(false);
+  yield showMenuPromise("controlCenter");
+  yield testTargetAvailability(true);
+
+  yield showInfoPromise(targetID, "This is " + targetID,
+                        "My arrow should be on the side");
+  is(popup.popupBoxObject.alignmentPosition, "end_before",
+     "Check " + targetID + " position");
+
+  let hideMenuPromise =
+        promisePanelElementHidden(window, gIdentityHandler._identityPopup);
+  gContentAPI.hideMenu("controlCenter");
+  yield hideMenuPromise;
+
+  ok(!is_visible(popup), "The tooltip should now be hidden.");
+  yield testTargetAvailability(false);
+
+  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
+    content.document.getElementById("tracking-element").remove();
+  });
+}