Bug 1945142: Backout D234215. r=tjr

Differential Revision: https://phabricator.services.mozilla.com/D236356
This commit is contained in:
Fatih Kilic
2025-02-01 01:40:20 +00:00
parent 617f609e3c
commit 2d1654201c
19 changed files with 148 additions and 190 deletions

View File

@@ -8,6 +8,7 @@ support-files = [
"file_keyBoardEvent.sjs",
"file_navigator.html",
"file_navigator.worker.js",
"file_workerNetInfo.js",
"file_workerPerformance.js",
"head.js",
"file_canvascompare_aboutblank_iframee.html",
@@ -80,8 +81,6 @@ https_first_disabled = true
["browser_canvascompare_popups_data.js"]
["browser_color_scheme.js"]
["browser_cross_origin_isolated_animation_api.js"]
["browser_cross_origin_isolated_performance_api.js"]
@@ -138,6 +137,9 @@ https_first_disabled = true
["browser_navigator_iframes.js"]
https_first_disabled = true
["browser_netInfo.js"]
https_first_disabled = true
["browser_performanceAPI.js"]
["browser_performanceAPIWorkers.js"]
@@ -158,3 +160,5 @@ https_first_disabled = true
["browser_spoofing_keyboard_event.js"]
["browser_timezone.js"]
["browser_color_scheme.js"]

View File

@@ -346,7 +346,6 @@ add_task(async function setupRFPExemptions() {
set: [
["privacy.resistFingerprinting", true],
["privacy.resistFingerprinting.exemptedDomains", "example.net"],
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
});
@@ -442,10 +441,7 @@ add_task(async function setupETPToggleExemptions() {
add_task(async function setupResistFingerprinting() {
await SpecialPowers.pushPrefEnv({
set: [
["privacy.resistFingerprinting", true],
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
set: [["privacy.resistFingerprinting", true]],
});
let spoofedGeckoTrail = SPOOFED_UA_GECKO_TRAIL[AppConstants.platform];

View File

@@ -0,0 +1,64 @@
/**
* Bug 1372072 - A test case for check whether network information API has been
* spoofed correctly when 'privacy.resistFingerprinting' is true;
*/
async function testWindow() {
// Open a tab to test network information in a content.
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "file_dummy.html"
);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
ok("connection" in content.navigator, "navigator.connection should exist");
is(
content.navigator.connection.type,
"unknown",
"The connection type is spoofed correctly"
);
});
BrowserTestUtils.removeTab(tab);
}
async function testWorker() {
// Open a tab to test network information in a worker.
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "file_dummy.html"
);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
await new Promise(resolve => {
let worker = new content.Worker("file_workerNetInfo.js");
worker.onmessage = function (e) {
if (e.data.type == "status") {
ok(e.data.status, e.data.msg);
} else if (e.data.type == "finish") {
resolve();
} else {
ok(false, "Unknown message type");
resolve();
}
};
worker.postMessage({ type: "runTests" });
});
});
BrowserTestUtils.removeTab(tab);
}
add_task(async function runTest() {
await SpecialPowers.pushPrefEnv({
set: [
["privacy.resistFingerprinting", true],
["dom.netinfo.enabled", true],
],
});
await testWindow();
await testWorker();
});

View File

@@ -34,24 +34,23 @@ add_task(async function test_new_window() {
tab.linkedBrowser,
[{ gMaxAvailWidth, gMaxAvailHeight }],
async function (input) {
let windowWaived = content.wrappedJSObject.window;
is(
windowWaived.screen.width,
content.screen.width,
input.gMaxAvailWidth,
"The screen.width has a correct rounded value"
);
is(
windowWaived.screen.height,
content.screen.height,
input.gMaxAvailHeight,
"The screen.height has a correct rounded value"
);
is(
windowWaived.innerWidth,
content.innerWidth,
input.gMaxAvailWidth,
"The window.innerWidth has a correct rounded value"
);
is(
windowWaived.innerHeight,
content.innerHeight,
input.gMaxAvailHeight,
"The window.innerHeight has a correct rounded value"
);

View File

@@ -7,8 +7,7 @@
let targetWidth = Services.prefs.getIntPref("privacy.window.maxInnerWidth");
let targetHeight = Services.prefs.getIntPref("privacy.window.maxInnerHeight");
OpenTest.run(
[
OpenTest.run([
{
settingWidth: targetWidth + 25,
settingHeight: targetHeight + 50,
@@ -27,7 +26,4 @@ OpenTest.run(
targetWidth,
targetHeight,
},
],
undefined,
[["privacy.resistFingerprinting.principalCheckEnabled", false]]
);
]);

View File

@@ -4,8 +4,7 @@
* middle values.
*/
OpenTest.run(
[
OpenTest.run([
{
settingWidth: 600,
settingHeight: 600,
@@ -24,7 +23,4 @@ OpenTest.run(
targetWidth: 600,
targetHeight: 600,
},
],
undefined,
[["privacy.resistFingerprinting.principalCheckEnabled", false]]
);
]);

View File

@@ -4,8 +4,7 @@
* minimum values.
*/
OpenTest.run(
[
OpenTest.run([
{
settingWidth: 199,
settingHeight: 99,
@@ -18,7 +17,4 @@ OpenTest.run(
targetWidth: 200,
targetHeight: 100,
},
],
undefined,
[["privacy.resistFingerprinting.principalCheckEnabled", false]]
);
]);

View File

@@ -2119,11 +2119,7 @@ function eventConsumer(aEvent) {
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["privacy.resistFingerprinting", true],
// Disable the principal check because synthesizeKey is system privileged.
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
set: [["privacy.resistFingerprinting", true]],
});
});

View File

@@ -555,11 +555,11 @@ async function testWindowSizeSetting(
class RoundedWindowTest {
// testOuter is optional. run() can be invoked with only 1 parameter.
static run(testCases, testOuter, extraPrefs = []) {
static run(testCases, testOuter) {
// "this" is the calling class itself.
// e.g. when invoked by RoundedWindowTest.run(), "this" is "class RoundedWindowTest".
let test = new this(testCases);
add_task(async () => test.setup(extraPrefs));
add_task(async () => test.setup());
add_task(async () => {
if (testOuter == undefined) {
// If testOuter is not given, do tests for both inner and outer.
@@ -575,9 +575,9 @@ class RoundedWindowTest {
this.testCases = testCases;
}
async setup(extraPrefs) {
async setup() {
await SpecialPowers.pushPrefEnv({
set: [["privacy.resistFingerprinting", true], ...extraPrefs],
set: [["privacy.resistFingerprinting", true]],
});
// Calculate the popup window's chrome UI size for tests of outerWidth/Height.
@@ -668,15 +668,7 @@ async function runActualTest(uri, testFunction, expectedResults, extraData) {
browserWin = openedWin.gBrowser;
}
// This is hacky, but since we added IsJSContextCurrentlyChromePrivileged(),
// we ended up disabling RFP for this tab because the test suite
// has the system principal when it opens it. So we disable the
// principal check for a brief moment.
await SpecialPowers.pushPrefEnv({
set: [["privacy.resistFingerprinting.principalCheckEnabled", false]],
});
let tab = await BrowserTestUtils.openNewForegroundTab(browserWin, uri);
await SpecialPowers.popPrefEnv();
if ("etp_reload" in extraData) {
ContentBlockingAllowList.add(tab.linkedBrowser);
@@ -710,13 +702,11 @@ async function runActualTest(uri, testFunction, expectedResults, extraData) {
tab.linkedBrowser,
[IFRAME_DOMAIN, CROSS_ORIGIN_DOMAIN, filterExtraData(extraData)],
async function (iframe_domain_, cross_origin_domain_, extraData_) {
return content.wrappedJSObject.eval(`
runTheTest(
${JSON.stringify(iframe_domain_)},
${JSON.stringify(cross_origin_domain_)},
${JSON.stringify(extraData_)}
return content.wrappedJSObject.runTheTest(
iframe_domain_,
cross_origin_domain_,
extraData_
);
`);
}
);
@@ -731,7 +721,7 @@ async function runActualTest(uri, testFunction, expectedResults, extraData) {
popup_tab.linkedBrowser,
[],
async function () {
let r = content.wrappedJSObject.eval("give_result()");
let r = content.wrappedJSObject.give_result();
return r;
}
);

View File

@@ -4,7 +4,6 @@ tags = "resistfingerprinting"
support-files = [
"file_animation_api.html",
"file_workerNetInfo.js",
"worker_child.js",
"worker_grandchild.js",
"!/dom/tests/mochitest/geolocation/network_geolocation.sjs",
@@ -19,8 +18,6 @@ support-files = ["decode_error.mp4"]
["test_bug1382499_touch_api.html"]
["test_bug1885101_screenwindow_sizes.html"]
["test_device_sensor_event.html"]
["test_geolocation.html"]
@@ -32,11 +29,10 @@ support-files = ["test_hide_gamepad_info_iframe.html"]
["test_keyboard_event.html"]
["test_netInfo.html"]
https_first_disabled = true
["test_pointer_event.html"]
support-files = ["../../../../../dom/events/test/pointerevents/mochitest_support_external.js"]
["test_speech_synthesis.html"]
skip-if = ["verify"]
["test_bug1885101_screenwindow_sizes.html"]

View File

@@ -1,41 +0,0 @@
<!DOCTYPE html>
<meta charset="utf8">
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script>
/* global SimpleTest SpecialPowers */
SimpleTest.waitForExplicitFinish();
document.addEventListener("DOMContentLoaded", function() {
SpecialPowers.pushPrefEnv({
set: [
["dom.netinfo.enabled", true],
["privacy.resistFingerprinting", true],
],
}, async function() {
ok("connection" in navigator, "navigator.connection should exist");
is(
navigator.connection.type,
"unknown",
"The connection type is spoofed correctly"
);
await new Promise(resolve => {
let worker = new Worker("file_workerNetInfo.js");
worker.onmessage = function (e) {
if (e.data.type == "status") {
ok(e.data.status, e.data.msg);
} else if (e.data.type == "finish") {
resolve();
} else {
ok(false, "Unknown message type");
resolve();
}
};
worker.postMessage({ type: "runTests" });
});
SimpleTest.finish();
});
});
</script>

View File

@@ -21,10 +21,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1333641
isnot(window.speechSynthesis.getVoices().length, 0, "Voices added");
SimpleTest.waitForFocus(() => {
SpecialPowers.pushPrefEnv({"set":
[
["privacy.resistFingerprinting", true],
["privacy.resistFingerprinting.principalCheckEnabled", false]
],
[["privacy.resistFingerprinting", true]],
}, doGetVoicesTest);
}, window);
}, {once: true});

View File

@@ -2367,13 +2367,8 @@ bool ChromeUtils::ShouldResistFingerprinting(
// This global object appears to be the global window, not for individual
// sites so to exempt individual sites (instead of just PBM/Not-PBM windows)
// more work would be needed to get the correct context.
// We set aSkipChromePrincipalCheck to true because ChromeUtils is only
// called from chrome code where we are system principal.
// We only want to check document's properties and not JS context's
// properties.
return nsRFPService::IsRFPEnabledFor(isPBM, target,
overriddenFingerprintingSettings,
/* aSkipChromePrincipalCheck */ true);
overriddenFingerprintingSettings);
}
/* static */

View File

@@ -8,10 +8,6 @@ do_get_profile();
add_task(async function test_clear_fingerprinting_protection_state() {
info("Enabling fingerprinting randomization");
Services.prefs.setBoolPref("privacy.resistFingerprinting", true);
Services.prefs.setBoolPref(
"privacy.resistFingerprinting.principalCheckEnabled",
false
);
let uri = Services.io.newURI("https://example.com");
let principal = Services.scriptSecurityManager.createContentPrincipal(
@@ -163,19 +159,12 @@ add_task(async function test_clear_fingerprinting_protection_state() {
);
Services.prefs.clearUserPref("privacy.resistFingerprinting");
Services.prefs.clearUserPref(
"privacy.resistFingerprinting.principalCheckEnabled"
);
});
add_task(
async function test_clear_fingerprinting_protection_state_by_site_and_pattern() {
info("Enabling fingerprinting randomization");
Services.prefs.setBoolPref("privacy.resistFingerprinting", true);
Services.prefs.setBoolPref(
"privacy.resistFingerprinting.principalCheckEnabled",
false
);
let uri = Services.io.newURI("https://example.com");
let principal = Services.scriptSecurityManager.createContentPrincipal(
@@ -256,8 +245,5 @@ add_task(
);
Services.prefs.clearUserPref("privacy.resistFingerprinting");
Services.prefs.clearUserPref(
"privacy.resistFingerprinting.principalCheckEnabled"
);
}
);

View File

@@ -313,7 +313,7 @@ bool nsRFPService::IsRFPEnabledFor(
}
#endif
if (!aSkipChromePrincipalCheck && IsJSContextCurrentlyChromePrivileged()) {
if (IsJSContextCurrentlyChromePrivileged()) {
return false;
}

View File

@@ -424,7 +424,6 @@ async function runTest(enabled) {
["privacy.fingerprintingProtection.pbmode", true],
["privacy.fingerprintingProtection.overrides", RFPOverrides],
["privacy.resistFingerprinting", false],
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
});

View File

@@ -170,7 +170,6 @@ async function runTest(enabled) {
["privacy.fingerprintingProtection.pbmode", true],
["privacy.fingerprintingProtection.overrides", RFPOverrides],
["privacy.resistFingerprinting", false],
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
});

View File

@@ -213,10 +213,7 @@ add_task(async function test_randomization_disabled_with_rfp_disabled() {
// Test the fingerprinting randomization key generation.
add_task(async function test_generate_randomization_key() {
await SpecialPowers.pushPrefEnv({
set: [
["privacy.resistFingerprinting", true],
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
set: [["privacy.resistFingerprinting", true]],
});
for (let testPrivateWin of [true, false]) {
@@ -307,10 +304,7 @@ add_task(async function test_generate_randomization_key() {
// ends.
add_task(async function test_reset_key_after_pbm_session_ends() {
await SpecialPowers.pushPrefEnv({
set: [
["privacy.resistFingerprinting", true],
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
set: [["privacy.resistFingerprinting", true]],
});
let privateWin = await BrowserTestUtils.openNewBrowserWindow({
@@ -368,7 +362,6 @@ add_task(async function test_randomization_with_exempted_normal_window() {
["privacy.resistFingerprinting.pbmode", true],
["privacy.fingerprintingProtection", false],
["privacy.fingerprintingProtection.pbmode", false],
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
});
@@ -433,10 +426,7 @@ add_task(async function test_randomization_with_exempted_normal_window() {
add_task(async function test_reset_random_key_when_clear_site_data() {
// Enable fingerprinting randomization key generation.
await SpecialPowers.pushPrefEnv({
set: [
["privacy.resistFingerprinting", true],
["privacy.resistFingerprinting.principalCheckEnabled", false],
],
set: [["privacy.resistFingerprinting", true]],
});
// Open a tab and get randomization key from the test domain.