Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit b09b868

Browse files
committed
Bug 1581409 - ensure SocialTracking enabled status is correct; r=johannh
- to check the enabled status, we must have: - TP or ETP is enabled - block social tracking cookies is enabled - Hide category item while not blocking social tracking cookies - sync behavior/tests from fingerprinter/cryptominer - check isAllowing/isBlocking without enabled status - add `testCategoryItem()` Differential Revision: https://phabricator.services.mozilla.com/D46161 --HG-- extra : moz-landing-system : lando
1 parent 885a031 commit b09b868

3 files changed

Lines changed: 125 additions & 15 deletions

File tree

browser/base/content/browser-siteProtections.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,10 @@ var ThirdPartyCookies = {
951951
};
952952

953953
var SocialTracking = {
954-
PREF_ENABLED: "privacy.socialtracking.block_cookies.enabled",
954+
PREF_STP_TP_ENABLED: "privacy.trackingprotection.socialtracking.enabled",
955+
PREF_STP_COOKIE_ENABLED: "privacy.socialtracking.block_cookies.enabled",
956+
PREF_COOKIE_BEHAVIOR: "network.cookie.cookieBehavior",
957+
reportBreakageLabel: "socialtracking",
955958

956959
strings: {
957960
get subViewBlocked() {
@@ -979,16 +982,43 @@ var SocialTracking = {
979982
init() {
980983
XPCOMUtils.defineLazyPreferenceGetter(
981984
this,
982-
"enabled",
983-
this.PREF_ENABLED,
985+
"socialTrackingProtectionEnabled",
986+
this.PREF_STP_TP_ENABLED,
987+
false,
988+
this.updateCategoryItem.bind(this)
989+
);
990+
XPCOMUtils.defineLazyPreferenceGetter(
991+
this,
992+
"rejectTrackingCookies",
993+
this.PREF_COOKIE_BEHAVIOR,
994+
false,
995+
this.updateCategoryItem.bind(this),
996+
val => val == Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER
997+
);
998+
XPCOMUtils.defineLazyPreferenceGetter(
999+
this,
1000+
"blockSocialTrackingCookies",
1001+
this.PREF_STP_COOKIE_ENABLED,
9841002
false,
9851003
this.updateCategoryItem.bind(this)
9861004
);
9871005
this.updateCategoryItem();
9881006
},
9891007

1008+
get enabled() {
1009+
return this.blockSocialTrackingCookies;
1010+
},
1011+
1012+
get blockingEnabled() {
1013+
return (
1014+
(this.socialTrackingProtectionEnabled || this.rejectTrackingCookies) &&
1015+
this.blockSocialTrackingCookies
1016+
);
1017+
},
1018+
9901019
updateCategoryItem() {
991-
this.categoryItem.classList.toggle("blocked", this.enabled);
1020+
this.categoryItem.hidden = !this.enabled;
1021+
this.categoryItem.classList.toggle("blocked", this.blockingEnabled);
9921022
},
9931023

9941024
isBlocking(state) {
@@ -1002,17 +1032,15 @@ var SocialTracking = {
10021032
(state & Ci.nsIWebProgressListener.STATE_LOADED_SOCIALTRACKING_CONTENT) !=
10031033
0;
10041034
return (
1005-
this.enabled &&
1006-
((socialtrackingContentLoaded && cookieTrackerBlocked) ||
1007-
socialtrackingContentBlocked)
1035+
(socialtrackingContentLoaded && cookieTrackerBlocked) ||
1036+
socialtrackingContentBlocked
10081037
);
10091038
},
10101039

10111040
isAllowing(state) {
10121041
return (
1013-
this.enabled &&
10141042
(state & Ci.nsIWebProgressListener.STATE_LOADED_SOCIALTRACKING_CONTENT) !=
1015-
0
1043+
0
10161044
);
10171045
},
10181046

@@ -1057,7 +1085,7 @@ var SocialTracking = {
10571085
this.subViewList.append(fragment);
10581086
this.subView.setAttribute(
10591087
"title",
1060-
this.enabled && !gProtectionsHandler.hasException
1088+
this.blockingEnabled && !gProtectionsHandler.hasException
10611089
? this.strings.subViewTitleBlocking
10621090
: this.strings.subViewTitleNotBlocking
10631091
);
@@ -1076,6 +1104,7 @@ var SocialTracking = {
10761104

10771105
let listItem = document.createXULElement("hbox");
10781106
listItem.className = "protections-popup-list-item";
1107+
listItem.classList.toggle("allowed", isAllowed);
10791108
// Repeat the host in the tooltip in case it's too long
10801109
// and overflows in our panel.
10811110
listItem.tooltipText = uri.host;

browser/base/content/test/trackingUI/browser_trackingUI_categories.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ const TP_PB_PREF = "privacy.trackingprotection.pbmode.enabled";
44
const TPC_PREF = "network.cookie.cookieBehavior";
55
const CM_PREF = "privacy.trackingprotection.cryptomining.enabled";
66
const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled";
7-
const ST_PREF = "privacy.socialtracking.block_cookies.enabled";
7+
const ST_PREF = "privacy.trackingprotection.socialtracking.enabled";
8+
const STC_PREF = "privacy.socialtracking.block_cookies.enabled";
89

910
ChromeUtils.import(
1011
"resource://testing-common/CustomizableUITestUtils.jsm",
1112
this
1213
);
1314

1415
registerCleanupFunction(function() {
16+
Services.prefs.clearUserPref(CAT_PREF);
1517
Services.prefs.clearUserPref(TP_PREF);
1618
Services.prefs.clearUserPref(TP_PB_PREF);
1719
Services.prefs.clearUserPref(TPC_PREF);
18-
Services.prefs.clearUserPref(CAT_PREF);
1920
Services.prefs.clearUserPref(CM_PREF);
2021
Services.prefs.clearUserPref(FP_PREF);
2122
Services.prefs.clearUserPref(ST_PREF);
23+
Services.prefs.clearUserPref(STC_PREF);
2224
});
2325

2426
add_task(async function testCookieCategoryLabels() {
@@ -162,7 +164,7 @@ let categoryItems = [
162164
"protections-popup-category-fingerprinters",
163165
].map(id => document.getElementById(id));
164166

165-
let categoryEnabledPrefs = [TP_PREF, ST_PREF, TPC_PREF, CM_PREF, FP_PREF];
167+
let categoryEnabledPrefs = [TP_PREF, STC_PREF, TPC_PREF, CM_PREF, FP_PREF];
166168

167169
let detectedStateFlags = [
168170
Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
@@ -184,6 +186,8 @@ async function waitForClass(item, className, shouldBePresent = true) {
184186
}
185187

186188
add_task(async function testCategorySections() {
189+
Services.prefs.setBoolPref(ST_PREF, true);
190+
187191
for (let pref of categoryEnabledPrefs) {
188192
if (pref == TPC_PREF) {
189193
Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT);

browser/base/content/test/trackingUI/browser_trackingUI_socialtracking.js

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
const TRACKING_PAGE =
77
"http://example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
88

9+
const ST_PROTECTION_PREF = "privacy.trackingprotection.socialtracking.enabled";
10+
const ST_BLOCK_COOKIES_PREF = "privacy.socialtracking.block_cookies.enabled";
11+
912
add_task(async function setup() {
1013
await SpecialPowers.pushPrefEnv({
1114
set: [
12-
["privacy.socialtracking.block_cookies.enabled", true],
13-
["privacy.trackingprotection.socialtracking.enabled", true],
15+
[ST_PROTECTION_PREF, true],
16+
[ST_BLOCK_COOKIES_PREF, true],
1417
[
1518
"urlclassifier.features.socialtracking.blacklistHosts",
1619
"socialtracking.example.com",
@@ -162,6 +165,78 @@ async function testSubview(hasException) {
162165
BrowserTestUtils.removeTab(tab);
163166
}
164167

168+
async function testCategoryItem() {
169+
Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, false);
170+
171+
let promise = BrowserTestUtils.openNewForegroundTab({
172+
url: TRACKING_PAGE,
173+
gBrowser,
174+
});
175+
let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]);
176+
177+
let categoryItem = document.getElementById(
178+
"protections-popup-category-socialblock"
179+
);
180+
181+
ok(
182+
!categoryItem.classList.contains("blocked"),
183+
"Category not marked as blocked"
184+
);
185+
ok(
186+
categoryItem.classList.contains("notFound"),
187+
"Category marked as not found"
188+
);
189+
Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, true);
190+
ok(categoryItem.classList.contains("blocked"), "Category marked as blocked");
191+
ok(
192+
categoryItem.classList.contains("notFound"),
193+
"Category marked as not found"
194+
);
195+
Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, false);
196+
ok(
197+
!categoryItem.classList.contains("blocked"),
198+
"Category not marked as blocked"
199+
);
200+
ok(
201+
categoryItem.classList.contains("notFound"),
202+
"Category marked as not found"
203+
);
204+
205+
promise = waitForContentBlockingEvent();
206+
207+
await ContentTask.spawn(tab.linkedBrowser, {}, function() {
208+
content.postMessage("socialtracking", "*");
209+
});
210+
211+
await promise;
212+
213+
ok(
214+
!categoryItem.classList.contains("blocked"),
215+
"Category not marked as blocked"
216+
);
217+
ok(
218+
!categoryItem.classList.contains("notFound"),
219+
"Category not marked as not found"
220+
);
221+
Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, true);
222+
ok(categoryItem.classList.contains("blocked"), "Category marked as blocked");
223+
ok(
224+
!categoryItem.classList.contains("notFound"),
225+
"Category not marked as not found"
226+
);
227+
Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, false);
228+
ok(
229+
!categoryItem.classList.contains("blocked"),
230+
"Category not marked as blocked"
231+
);
232+
ok(
233+
!categoryItem.classList.contains("notFound"),
234+
"Category not marked as not found"
235+
);
236+
237+
BrowserTestUtils.removeTab(tab);
238+
}
239+
165240
add_task(async function testIdentityUI() {
166241
requestLongerTimeout(2);
167242

@@ -170,4 +245,6 @@ add_task(async function testIdentityUI() {
170245

171246
await testSubview(false);
172247
await testSubview(true);
248+
249+
await testCategoryItem();
173250
});

0 commit comments

Comments
 (0)