From aa4d1c87ee341e26918d015d106b841c0545a596 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Fri, 7 Aug 2015 13:06:12 -0700 Subject: [PATCH] Bug 1188443 - UITour: Add Tracking Protection "Enable protection" button as a UITour target. r=paolo --- browser/components/uitour/UITour.jsm | 40 ++++++--- .../test/browser_trackingProtection_tour.js | 88 +++++++++++-------- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/browser/components/uitour/UITour.jsm b/browser/components/uitour/UITour.jsm index 9c143ff1a8a..e18ed204d1d 100644 --- a/browser/components/uitour/UITour.jsm +++ b/browser/components/uitour/UITour.jsm @@ -131,20 +131,8 @@ this.UITour = { 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"); @@ -2081,6 +2069,30 @@ this.UITour = { }, }; +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(); /** diff --git a/browser/components/uitour/test/browser_trackingProtection_tour.js b/browser/components/uitour/test/browser_trackingProtection_tour.js index 1fbe606f2d3..3de53d8c75c 100644 --- a/browser/components/uitour/test/browser_trackingProtection_tour.js +++ b/browser/components/uitour/test/browser_trackingProtection_tour.js @@ -25,44 +25,60 @@ let tests = [ Services.prefs.clearUserPref("privacy.trackingprotection.enabled"); }); }), + taskify(function* test_unblock_target() { - let popup = document.getElementById("UITourTooltip"); + yield* checkToggleTarget("controlCenter-trackingUnblock"); + }), - 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); - }); + 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 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 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"); - - 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(); + }); +}