Bug 1774739 - Update ETP preferences section for TCP in standard mode. r=anti-tracking-reviewers,preferences-reviewers,Gijs,bvandersloot

Differential Revision: https://phabricator.services.mozilla.com/D150364
This commit is contained in:
Paul Zuehlcke 2022-06-28 10:24:49 +00:00
parent 81a4459a03
commit 89fa1fe1f2
7 changed files with 222 additions and 17 deletions

View File

@ -1798,9 +1798,12 @@ pref("network.cookie.cookieBehavior", 4 /* BEHAVIOR_REJECT_TRACKER */);
// Total Cookie Protection (dFPI) in standard mode.
pref("privacy.restrict3rdpartystorage.rollout.preferences.TCPToggleInStandard", false);
// Target URL for the learn more link of the TCP in standard mode section.
// Target URL for the learn more link of the TCP in standard mode rollout section.
pref("privacy.restrict3rdpartystorage.rollout.preferences.learnMoreURLSuffix", "total-cookie-protection");
// Target URL for the learn more link of the TCP in standard mode section.
pref("privacy.restrict3rdpartystorage.preferences.learnMoreURLSuffix", "total-cookie-protection");
// Enable Dynamic First-Party Isolation in the private browsing mode.
pref("network.cookie.cookieBehavior.pbmode", 5 /* BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN */);

View File

@ -112,6 +112,15 @@
<label class="content-blocking-label" data-l10n-id="content-blocking-fingerprinters"/>
</hbox>
</vbox>
<vbox id="etpStandardTCPBox" class="content-blocking-warning info-box-container">
<hbox>
<label class="content-blocking-warning-title" data-l10n-id="content-blocking-etp-standard-tcp-title"/>
</hbox>
<description>
<html:span class="tail-with-learn-more" data-l10n-id="content-blocking-etp-standard-tcp-rollout-description"></html:span>
<label id="tcp-learn-more-link" class="learnMore" data-l10n-id="content-blocking-etp-standard-tcp-rollout-learn-more" is="text-link"/>
</description>
</vbox>
<vbox id="etpStandardTCPRolloutBox" class="content-blocking-warning info-box-container">
<hbox>
<checkbox id="etpStandardTCPRollout"

View File

@ -292,6 +292,31 @@ function setUpContentBlockingWarnings() {
}
}
function initTCPStandardSection() {
document
.getElementById("tcp-learn-more-link")
.setAttribute(
"href",
Services.urlFormatter.formatURLPref("app.support.baseURL") +
Services.prefs.getStringPref(
"privacy.restrict3rdpartystorage.preferences.learnMoreURLSuffix"
)
);
let cookieBehaviorPref = Preferences.get("network.cookie.cookieBehavior");
let updateTCPSectionVisibilityState = () => {
document.getElementById("etpStandardTCPBox").hidden =
// Hide this section if we show the rollout section already.
!document.getElementById("etpStandardTCPRolloutBox").hidden ||
cookieBehaviorPref.value !=
Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
};
cookieBehaviorPref.on("change", updateTCPSectionVisibilityState);
updateTCPSectionVisibilityState();
}
function initTCPRolloutSection() {
document
.getElementById("tcp-rollout-learn-more-link")
@ -954,6 +979,7 @@ var gPrivacyPane = {
setUpContentBlockingWarnings();
initTCPRolloutSection();
initTCPStandardSection();
},
populateCategoryContents() {

View File

@ -69,6 +69,7 @@ skip-if = (verify && debug && (os == 'linux' || os == 'mac'))
[browser_contentblocking.js]
skip-if = socketprocess_networking
[browser_contentblocking_standard_tcp_toggle.js]
[browser_contentblocking_standard_tcp_section.js]
[browser_cookies_exceptions.js]
[browser_defaultbrowser_alwayscheck.js]
[browser_homepages_filter_aboutpreferences.js]

View File

@ -0,0 +1,152 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests the TCP info box in the ETP standard section of about:preferences#privacy.
*/
ChromeUtils.defineModuleGetter(
this,
"Preferences",
"resource://gre/modules/Preferences.jsm"
);
const COOKIE_BEHAVIOR_PREF = "network.cookie.cookieBehavior";
const CAT_PREF = "browser.contentblocking.category";
const LEARN_MORE_URL =
Services.urlFormatter.formatURLPref("app.support.baseURL") +
Services.prefs.getStringPref(
"privacy.restrict3rdpartystorage.preferences.learnMoreURLSuffix"
);
const {
BEHAVIOR_REJECT_TRACKER,
BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN,
} = Ci.nsICookieService;
async function testTCPSection({ dFPIEnabled }) {
info(
"Testing TCP preferences section in standard " +
JSON.stringify({ dFPIEnabled })
);
// In order to test the "standard" category we need to set the default value
// for the cookie behavior pref. A user value would get cleared as soon as we
// switch to "standard".
Services.prefs
.getDefaultBranch("")
.setIntPref(
COOKIE_BEHAVIOR_PREF,
dFPIEnabled
? BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN
: BEHAVIOR_REJECT_TRACKER
);
// Setting to standard category explicitly, since changing the default cookie
// behavior still switches us to custom initially.
await SpecialPowers.pushPrefEnv({
set: [[CAT_PREF, "standard"]],
});
const uiEnabled =
Services.prefs.getIntPref(COOKIE_BEHAVIOR_PREF) ==
BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
let doc = gBrowser.contentDocument;
let standardRadioOption = doc.getElementById("standardRadio");
let strictRadioOption = doc.getElementById("strictRadio");
let customRadioOption = doc.getElementById("customRadio");
ok(standardRadioOption.selected, "Standard category is selected");
let etpStandardTCPBox = doc.getElementById("etpStandardTCPBox");
is(
BrowserTestUtils.is_visible(etpStandardTCPBox),
uiEnabled,
`TCP section in standard is ${uiEnabled ? " " : "not "}visible.`
);
if (uiEnabled) {
// If visible, test the TCP section elements.
let learnMoreLink = etpStandardTCPBox.querySelector("#tcp-learn-more-link");
ok(learnMoreLink, "Should have a learn more link");
BrowserTestUtils.is_visible(
learnMoreLink,
"Learn more link should be visible."
);
ok(
learnMoreLink.href && !learnMoreLink.href.startsWith("about:blank"),
"Learn more link should be valid."
);
is(
learnMoreLink.href,
LEARN_MORE_URL,
"Learn more link should have the correct target."
);
let description = etpStandardTCPBox.querySelector(".tail-with-learn-more");
ok(description, "Should have a description element.");
BrowserTestUtils.is_visible(description, "Description should be visible.");
let title = etpStandardTCPBox.querySelector(
".content-blocking-warning-title"
);
ok(title, "Should have a title element.");
BrowserTestUtils.is_visible(title, "Title should be visible.");
}
info("Switch to ETP strict.");
let categoryPrefChange = waitForAndAssertPrefState(CAT_PREF, "strict");
strictRadioOption.click();
await categoryPrefChange;
ok(
!BrowserTestUtils.is_visible(etpStandardTCPBox),
"When strict is selected TCP UI is not visible."
);
info("Switch to ETP custom.");
categoryPrefChange = waitForAndAssertPrefState(CAT_PREF, "custom");
customRadioOption.click();
await categoryPrefChange;
ok(
!BrowserTestUtils.is_visible(etpStandardTCPBox),
"When custom is selected TCP UI is not visible."
);
info("Switch back to standard and ensure we show the TCP UI again.");
categoryPrefChange = waitForAndAssertPrefState(CAT_PREF, "standard");
standardRadioOption.click();
await categoryPrefChange;
is(
BrowserTestUtils.is_visible(etpStandardTCPBox),
uiEnabled,
`TCP section in standard is ${uiEnabled ? " " : "not "}visible.`
);
gBrowser.removeCurrentTab();
await SpecialPowers.popPrefEnv();
Services.prefs.setStringPref(CAT_PREF, "standard");
}
add_setup(async function() {
// Register cleanup function to restore default cookie behavior.
const defaultPrefs = Services.prefs.getDefaultBranch("");
const previousDefaultCB = defaultPrefs.getIntPref(COOKIE_BEHAVIOR_PREF);
registerCleanupFunction(function() {
defaultPrefs.setIntPref(COOKIE_BEHAVIOR_PREF, previousDefaultCB);
});
});
// Clients which don't have dFPI enabled should not see the
// preferences section.
add_task(async function test_dfpi_disabled() {
await testTCPSection({ dFPIEnabled: false });
});
add_task(async function test_dfpi_enabled() {
await testTCPSection({ dFPIEnabled: true });
});

View File

@ -53,22 +53,6 @@ function testTelemetryState(optIn) {
);
}
/**
* Waits for preference to be set and asserts the value.
* @param {string} pref - Preference key.
* @param {*} expectedValue - Expected value of the preference.
* @param {string} message - Assertion message.
*/
async function waitForAndAssertPrefState(pref, expectedValue, message) {
await TestUtils.waitForPrefChange(pref, value => {
if (value != expectedValue) {
return false;
}
is(value, expectedValue, message);
return true;
});
}
add_setup(async function() {
const defaultPrefs = Services.prefs.getDefaultBranch("");
const previousDefaultCB = defaultPrefs.getIntPref(COOKIE_BEHAVIOR_PREF);
@ -146,6 +130,20 @@ async function testRolloutUI({
`Rollout UI in standard is ${uiEnabled ? " " : "not "}visible.`
);
// Ensure that the regular TCP standard section is only visible if we don't show the rollout section.
let etpStandardTCPBox = doc.getElementById("etpStandardTCPBox");
let tcpSectionEnabled =
!uiEnabled &&
Services.prefs.getIntPref(COOKIE_BEHAVIOR_PREF) ==
BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
is(
BrowserTestUtils.is_visible(etpStandardTCPBox),
tcpSectionEnabled,
`Non-rollout TCP section in standard is ${
tcpSectionEnabled ? " " : "not "
}visible.`
);
if (uiEnabled) {
// Test the TCP rollout section.
let learnMoreLink = etpStandardTCPRolloutBox.querySelector(

View File

@ -273,3 +273,19 @@ function createObserveAllPromise(observances) {
Services.obs.addObserver(permObserver, "perm-changed");
});
}
/**
* Waits for preference to be set and asserts the value.
* @param {string} pref - Preference key.
* @param {*} expectedValue - Expected value of the preference.
* @param {string} message - Assertion message.
*/
async function waitForAndAssertPrefState(pref, expectedValue, message) {
await TestUtils.waitForPrefChange(pref, value => {
if (value != expectedValue) {
return false;
}
is(value, expectedValue, message);
return true;
});
}