Bug 1470020 - Part 2 - Add specific states for when the user has added a TP exception to the TP section of the identity popup. r=florian

We used to give this all the same "tracking-loaded" state, but now we want to differentiate between:

- Tracking loaded because TP is off
- Tracking loaded because of an exception
- Tracking not loaded but the site has an exception, which we want to allow the user to remove (if TP is on)

MozReview-Commit-ID: E9j0Roq1bsH

--HG--
extra : rebase_source : 70992e27b91bfed3cce0b868b63ce3a8c0afc5d0
This commit is contained in:
Johann Hofmann 2018-06-21 02:10:02 +02:00
Родитель eea47c667c
Коммит e338329576
6 изменённых файлов: 86 добавлений и 24 удалений

Просмотреть файл

@ -144,24 +144,6 @@ var TrackingProtection = {
let isBlocking = state & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT; let isBlocking = state & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT;
let isAllowing = state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT; let isAllowing = state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT;
if (isBlocking && this.enabled) {
this.icon.setAttribute("tooltiptext", this.activeTooltipText);
this.icon.setAttribute("state", "blocked-tracking-content");
this.content.setAttribute("state", "blocked-tracking-content");
this.content.removeAttribute("hasException");
// Open the tracking protection introduction panel, if applicable.
if (this.enabledGlobally) {
let introCount = Services.prefs.getIntPref("privacy.trackingprotection.introCount");
if (introCount < TrackingProtection.MAX_INTROS) {
Services.prefs.setIntPref("privacy.trackingprotection.introCount", ++introCount);
Services.prefs.savePrefFile(null);
this.showIntroPanel();
}
}
this.shieldHistogramAdd(2);
} else if (isAllowing) {
// Check whether the user has added an exception for this site. // Check whether the user has added an exception for this site.
let hasException = false; let hasException = false;
if (PrivateBrowsingUtils.isBrowserPrivate(gBrowser.selectedBrowser)) { if (PrivateBrowsingUtils.isBrowserPrivate(gBrowser.selectedBrowser)) {
@ -177,6 +159,23 @@ var TrackingProtection = {
this.content.removeAttribute("hasException"); this.content.removeAttribute("hasException");
} }
if (isBlocking && this.enabled) {
this.icon.setAttribute("tooltiptext", this.activeTooltipText);
this.icon.setAttribute("state", "blocked-tracking-content");
this.content.setAttribute("state", "blocked-tracking-content");
// Open the tracking protection introduction panel, if applicable.
if (this.enabledGlobally) {
let introCount = Services.prefs.getIntPref("privacy.trackingprotection.introCount");
if (introCount < TrackingProtection.MAX_INTROS) {
Services.prefs.setIntPref("privacy.trackingprotection.introCount", ++introCount);
Services.prefs.savePrefFile(null);
this.showIntroPanel();
}
}
this.shieldHistogramAdd(2);
} else if (isAllowing) {
// Only show the shield when TP is enabled for now. // Only show the shield when TP is enabled for now.
if (this.enabled) { if (this.enabled) {
this.icon.setAttribute("tooltiptext", this.disabledTooltipText); this.icon.setAttribute("tooltiptext", this.disabledTooltipText);
@ -194,7 +193,6 @@ var TrackingProtection = {
this.icon.removeAttribute("tooltiptext"); this.icon.removeAttribute("tooltiptext");
this.icon.removeAttribute("state"); this.icon.removeAttribute("state");
this.content.removeAttribute("state"); this.content.removeAttribute("state");
this.content.removeAttribute("hasException");
// We didn't show the shield // We didn't show the shield
this.shieldHistogramAdd(0); this.shieldHistogramAdd(0);

Просмотреть файл

@ -50,6 +50,7 @@ function testTrackingPage(window) {
// Make sure that the blocked tracking elements message appears // Make sure that the blocked tracking elements message appears
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden"); ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden"); ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(hidden("#tracking-loaded-exception"), "labelTrackingLoadedException is hidden");
ok(!hidden("#tracking-blocked"), "labelTrackingBlocked is visible"); ok(!hidden("#tracking-blocked"), "labelTrackingBlocked is visible");
} }
@ -67,7 +68,7 @@ function testTrackingPageUnblocked() {
// Make sure that the blocked tracking elements message appears // Make sure that the blocked tracking elements message appears
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden"); ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(!hidden("#tracking-loaded"), "labelTrackingLoaded is visible"); ok(!hidden("#tracking-loaded-exception"), "labelTrackingLoadedException is visible");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden"); ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
} }

Просмотреть файл

@ -65,6 +65,27 @@ function testBenignPage() {
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden"); ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
} }
function testBenignPageWithException() {
info("Non-tracking content must not be blocked");
ok(!TrackingProtection.container.hidden, "The container is visible");
ok(!TrackingProtection.content.hasAttribute("state"), "content: no state");
ok(!TrackingProtection.icon.hasAttribute("state"), "icon: no state");
ok(!TrackingProtection.icon.hasAttribute("tooltiptext"), "icon: no tooltip");
ok(hidden("#tracking-protection-icon"), "icon is hidden");
is(!hidden("#tracking-action-block"), TrackingProtection.enabled,
"blockButton is visible if TP is on");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#tracking-protection-preferences-button"), "preferences button is visible");
is(!hidden("#tracking-not-detected-exception"), TrackingProtection.enabled,
"labelNoTrackingException is visible if TP is on");
is(hidden("#tracking-not-detected"), TrackingProtection.enabled,
"labelNoTracking is visible if TP is off");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
}
function testTrackingPage(window) { function testTrackingPage(window) {
info("Tracking content must be blocked"); info("Tracking content must be blocked");
ok(!TrackingProtection.container.hidden, "The container is visible"); ok(!TrackingProtection.container.hidden, "The container is visible");
@ -91,6 +112,7 @@ function testTrackingPage(window) {
// Make sure that the blocked tracking elements message appears // Make sure that the blocked tracking elements message appears
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden"); ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden"); ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(hidden("#tracking-loaded-exception"), "labelTrackingLoadedException is hidden");
ok(!hidden("#tracking-blocked"), "labelTrackingBlocked is visible"); ok(!hidden("#tracking-blocked"), "labelTrackingBlocked is visible");
} }
@ -113,15 +135,38 @@ function testTrackingPageUnblocked() {
// Make sure that the blocked tracking elements message appears // Make sure that the blocked tracking elements message appears
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden"); ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(!hidden("#tracking-loaded"), "labelTrackingLoaded is visible"); is(hidden("#tracking-loaded"), TrackingProtection.enabled,
"labelTrackingLoaded is visible if TP is off");
is(!hidden("#tracking-loaded-exception"), TrackingProtection.enabled,
"labelTrackingLoadedException is visible if TP is on");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden"); ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
} }
async function testTrackingProtectionEnabled(tab) { async function testTrackingProtectionEnabled(tab) {
info("Testing with Tracking Protection ENABLED.");
info("Load a test page not containing tracking elements"); info("Load a test page not containing tracking elements");
await promiseTabLoadEvent(tab, BENIGN_PAGE); await promiseTabLoadEvent(tab, BENIGN_PAGE);
testBenignPage(); testBenignPage();
info("Load a test page not containing tracking elements which has an exception.");
let isPrivateBrowsing = PrivateBrowsingUtils.isWindowPrivate(tab.ownerGlobal);
let uri = Services.io.newURI("https://example.org/");
if (isPrivateBrowsing) {
PrivateBrowsingUtils.addToTrackingAllowlist(uri);
} else {
Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION);
}
await promiseTabLoadEvent(tab, uri.spec);
testBenignPageWithException();
if (isPrivateBrowsing) {
PrivateBrowsingUtils.removeFromTrackingAllowlist(uri);
} else {
Services.perms.remove(uri, "trackingprotection");
}
info("Load a test page containing tracking elements"); info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE); await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPage(tab.ownerGlobal); testTrackingPage(tab.ownerGlobal);
@ -140,10 +185,19 @@ async function testTrackingProtectionEnabled(tab) {
} }
async function testTrackingProtectionDisabled(tab) { async function testTrackingProtectionDisabled(tab) {
info("Testing with Tracking Protection DISABLED.");
info("Load a test page not containing tracking elements"); info("Load a test page not containing tracking elements");
await promiseTabLoadEvent(tab, BENIGN_PAGE); await promiseTabLoadEvent(tab, BENIGN_PAGE);
testBenignPage(); testBenignPage();
info("Load a test page not containing tracking elements which has an exception.");
let uri = Services.io.newURI("https://example.org/");
Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION);
await promiseTabLoadEvent(tab, uri.spec);
testBenignPageWithException();
Services.perms.remove(uri, "trackingprotection");
info("Load a test page containing tracking elements"); info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE); await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPageUnblocked(); testTrackingPageUnblocked();

Просмотреть файл

@ -78,6 +78,10 @@
crop="end">&trackingProtection.detectedNotBlocked4;</description> crop="end">&trackingProtection.detectedNotBlocked4;</description>
<description id="tracking-not-detected" <description id="tracking-not-detected"
crop="end">&trackingProtection.notDetected4;</description> crop="end">&trackingProtection.notDetected4;</description>
<description id="tracking-loaded-exception"
crop="end">&trackingProtection.detectedException;</description>
<description id="tracking-not-detected-exception"
crop="end">&trackingProtection.notDetectedException;</description>
<description id="tracking-reload-required" <description id="tracking-reload-required"
crop="end">&trackingProtection.reloadRequired;</description> crop="end">&trackingProtection.reloadRequired;</description>

Просмотреть файл

@ -909,6 +909,9 @@ you can use these alternative items. Otherwise, their values should be empty. -
<!ENTITY trackingProtection.detectedBlocked3 "&brandShortName; is blocking parts of the page that may track your browsing."> <!ENTITY trackingProtection.detectedBlocked3 "&brandShortName; is blocking parts of the page that may track your browsing.">
<!ENTITY trackingProtection.detectedNotBlocked4 "Trackers have been detected on this webpage."> <!ENTITY trackingProtection.detectedNotBlocked4 "Trackers have been detected on this webpage.">
<!ENTITY trackingProtection.notDetected4 "No trackers detected on this page."> <!ENTITY trackingProtection.notDetected4 "No trackers detected on this page.">
<!ENTITY trackingProtection.detectedException "&brandShortName; has detected elements that may track your browsing. You have disabled protection for this site.">
<!ENTITY trackingProtection.notDetectedException "No tracking elements detected on this page. You have disabled protection for this site.">
<!ENTITY trackingProtection.reloadRequired "You have enabled Tracking Protection. To block all trackers please reload the current webpage."> <!ENTITY trackingProtection.reloadRequired "You have enabled Tracking Protection. To block all trackers please reload the current webpage.">
<!-- LOCALIZATION NOTE (trackingProtection.unblock.label, trackingProtection.unblock.accesskey): <!-- LOCALIZATION NOTE (trackingProtection.unblock.label, trackingProtection.unblock.accesskey):
The associated button with this label and accesskey is only shown when opening the control The associated button with this label and accesskey is only shown when opening the control

Просмотреть файл

@ -341,7 +341,8 @@ description#identity-popup-content-verifier,
/* Show the right tracking descriptions and buttons for the corresponding state. */ /* Show the right tracking descriptions and buttons for the corresponding state. */
/* Default state / Tracking not detected */ /* Default state / Tracking not detected */
#tracking-protection-content:not([state]) > #tracking-not-detected, #tracking-protection-content:not([state]):-moz-any([enabled="false"], :not([hasException])) > #tracking-not-detected,
#tracking-protection-content:not([state])[enabled="true"][hasException] > #tracking-not-detected-exception,
/* Blocking tracking, offer buttons to unblock (depending on PBM). */ /* Blocking tracking, offer buttons to unblock (depending on PBM). */
#tracking-protection-content[state="blocked-tracking-content"] > #tracking-blocked, #tracking-protection-content[state="blocked-tracking-content"] > #tracking-blocked,
#main-window:not([privatebrowsingmode]) #tracking-protection-content[state="blocked-tracking-content"] > #tracking-action-unblock, #main-window:not([privatebrowsingmode]) #tracking-protection-content[state="blocked-tracking-content"] > #tracking-action-unblock,
@ -349,8 +350,9 @@ description#identity-popup-content-verifier,
/* Enabled and no exception but trackers loaded, probably needs a reload */ /* Enabled and no exception but trackers loaded, probably needs a reload */
#tracking-protection-content[enabled="true"]:not([hasException])[state="loaded-tracking-content"] > #tracking-reload-required, #tracking-protection-content[enabled="true"]:not([hasException])[state="loaded-tracking-content"] > #tracking-reload-required,
#tracking-protection-content[enabled="true"]:not([hasException])[state="loaded-tracking-content"] > #tracking-action-reload, #tracking-protection-content[enabled="true"]:not([hasException])[state="loaded-tracking-content"] > #tracking-action-reload,
/* Disabled or has an exception, offer to block the site. */ /* Tracking Loaded */
#tracking-protection-content[state="loaded-tracking-content"]:-moz-any([enabled="false"],[hasException]) > #tracking-loaded, #tracking-protection-content[state="loaded-tracking-content"][enabled="false"] > #tracking-loaded,
#tracking-protection-content[state="loaded-tracking-content"][enabled="true"][hasException] > #tracking-loaded-exception,
/* Has an exception, offer to block the site again. */ /* Has an exception, offer to block the site again. */
#tracking-protection-content[enabled="true"][hasException] > #tracking-action-block { #tracking-protection-content[enabled="true"][hasException] > #tracking-action-block {
display: -moz-box; display: -moz-box;