зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1333651 - Part 3: Add a test case to verify that Navigator object has been spoofed/disabled correctly when 'privacy.resistFingerprinting' is true. r=arthuredelstein,Ehsan
This patch adds a brower chrome test to verify the navigator object when 'privacy.resistFingerprinting' is true. This test will also test worker navigator to check that whether it has been correctly spoofed/disabled. MozReview-Commit-ID: 17FvdlmLMjP --HG-- extra : rebase_source : 584abc9de089b5c9b08a85f419905f7412d1ed80
This commit is contained in:
Родитель
b6286c46af
Коммит
c6e5a886d1
|
@ -2,9 +2,12 @@
|
|||
tags = resistfingerprinting
|
||||
support-files =
|
||||
file_dummy.html
|
||||
file_navigator.html
|
||||
file_navigatorWorker.js
|
||||
file_workerPerformance.js
|
||||
head.js
|
||||
|
||||
[browser_navigator.js]
|
||||
[browser_performanceAPI.js]
|
||||
[browser_roundedWindow_dialogWindow.js]
|
||||
[browser_roundedWindow_newWindow.js]
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
* Bug 1333651 - A test case for making sure the navigator object has been
|
||||
* spoofed/disabled correctly.
|
||||
*/
|
||||
|
||||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const TEST_PATH = "http://example.net/browser/browser/" +
|
||||
"components/resistfingerprinting/test/browser/"
|
||||
|
||||
var spoofedUserAgent;
|
||||
|
||||
const SPOOFED_APPNAME = "Netscape";
|
||||
const SPOOFED_APPVERSION = "5.0 (Windows)";
|
||||
const SPOOFED_PLATFORM = "Win32";
|
||||
const SPOOFED_OSCPU = "Windows NT 6.1";
|
||||
const SPOOFED_BUILDID = "20100101";
|
||||
const SPOOFED_HW_CONCURRENCY = 2;
|
||||
|
||||
const CONST_APPCODENAME = "Mozilla";
|
||||
const CONST_PRODUCT = "Gecko";
|
||||
const CONST_PRODUCTSUB = "20100101";
|
||||
const CONST_VENDOR = "";
|
||||
const CONST_VENDORSUB = "";
|
||||
|
||||
async function testNavigator() {
|
||||
// Open a tab to collect result.
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser, TEST_PATH + "file_navigator.html");
|
||||
|
||||
let result = await ContentTask.spawn(tab.linkedBrowser, null, function() {
|
||||
return content.document.getElementById("result").innerHTML;
|
||||
});
|
||||
|
||||
result = JSON.parse(result);
|
||||
|
||||
is(result.appName, SPOOFED_APPNAME, "Navigator.appName is correctly spoofed.");
|
||||
is(result.appVersion, SPOOFED_APPVERSION, "Navigator.appVersion is correctly spoofed.");
|
||||
is(result.platform, SPOOFED_PLATFORM, "Navigator.platform is correctly spoofed.");
|
||||
is(result.userAgent, spoofedUserAgent, "Navigator.userAgent is correctly spoofed.");
|
||||
is(result.mimeTypesLength, 0, "Navigator.mimeTypes has a length of 0.");
|
||||
is(result.pluginsLength, 0, "Navigator.plugins has a length of 0.");
|
||||
is(result.oscpu, SPOOFED_OSCPU, "Navigator.oscpu is correctly spoofed.");
|
||||
is(result.buildID, SPOOFED_BUILDID, "Navigator.buildID is correctly spoofed.");
|
||||
is(result.hardwareConcurrency, SPOOFED_HW_CONCURRENCY, "Navigator.hardwareConcurrency is correctly spoofed.")
|
||||
|
||||
is(result.appCodeName, CONST_APPCODENAME, "Navigator.appCodeName reports correct constant value.");
|
||||
is(result.product, CONST_PRODUCT, "Navigator.product reports correct constant value.");
|
||||
is(result.productSub, CONST_PRODUCTSUB, "Navigator.productSub reports correct constant value.");
|
||||
is(result.vendor, CONST_VENDOR, "Navigator.vendor reports correct constant value.");
|
||||
is(result.vendorSub, CONST_VENDORSUB, "Navigator.vendorSub reports correct constant value.");
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
|
||||
async function testWorkerNavigator() {
|
||||
// Open a tab to collect result from worker.
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser, TEST_PATH + "file_dummy.html");
|
||||
|
||||
let result = await ContentTask.spawn(tab.linkedBrowser, null, async function() {
|
||||
let worker = new content.SharedWorker("file_navigatorWorker.js", "WorkerNavigatorTest");
|
||||
|
||||
let res = await new Promise(resolve => {
|
||||
worker.port.onmessage = function(e) {
|
||||
resolve(e.data);
|
||||
};
|
||||
});
|
||||
|
||||
return res;
|
||||
});
|
||||
|
||||
result = JSON.parse(result);
|
||||
|
||||
is(result.appName, SPOOFED_APPNAME, "Navigator.appName is correctly spoofed.");
|
||||
is(result.appVersion, SPOOFED_APPVERSION, "Navigator.appVersion is correctly spoofed.");
|
||||
is(result.platform, SPOOFED_PLATFORM, "Navigator.platform is correctly spoofed.");
|
||||
is(result.userAgent, spoofedUserAgent, "Navigator.userAgent is correctly spoofed.");
|
||||
is(result.hardwareConcurrency, SPOOFED_HW_CONCURRENCY, "Navigator.hardwareConcurrency is correctly spoofed.")
|
||||
|
||||
is(result.appCodeName, CONST_APPCODENAME, "Navigator.appCodeName reports correct constant value.");
|
||||
is(result.product, CONST_PRODUCT, "Navigator.product reports correct constant value.");
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({"set":
|
||||
[["privacy.resistFingerprinting", true]]
|
||||
});
|
||||
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
|
||||
let appVersion = parseInt(appInfo.version);
|
||||
let spoofedVersion = appVersion - (appVersion % 10);
|
||||
spoofedUserAgent = `Mozilla/5.0 (Windows NT 6.1; rv:${spoofedVersion}.0) Gecko/20100101 Firefox/${spoofedVersion}.0`;
|
||||
});
|
||||
|
||||
add_task(async function runNavigatorTest() {
|
||||
await testNavigator();
|
||||
});
|
||||
|
||||
add_task(async function runWorkerNavigatorTest() {
|
||||
await testWorkerNavigator();
|
||||
});
|
||||
|
||||
// This tests that 'general.*.override' should not override spoofed values.
|
||||
add_task(async function runOverrideTest() {
|
||||
await SpecialPowers.pushPrefEnv({"set":
|
||||
[
|
||||
["general.appname.override", "appName overridden"],
|
||||
["general.appversion.override", "appVersion overridden"],
|
||||
["general.platform.override", "platform overridden"],
|
||||
["general.useragent.override", "userAgent overridden"],
|
||||
["general.oscpu.override", "oscpu overridden"],
|
||||
["general.buildID.override", "buildID overridden"],
|
||||
]
|
||||
});
|
||||
|
||||
await testNavigator();
|
||||
|
||||
await testWorkerNavigator();
|
||||
});
|
|
@ -6,7 +6,7 @@
|
|||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
|
||||
|
||||
let gMaxAvailWidth;
|
||||
let gMaxAvailHeight;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
|
||||
|
||||
let gMaxAvailWidth;
|
||||
let gMaxAvailHeight;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
|
||||
|
||||
let gMaxAvailWidth;
|
||||
let gMaxAvailHeight;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
|
||||
|
||||
let gMaxAvailWidth;
|
||||
let gMaxAvailHeight;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
|
||||
|
||||
let gMaxAvailWidth;
|
||||
let gMaxAvailHeight;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
|
||||
|
||||
let gMaxAvailWidth;
|
||||
let gMaxAvailHeight;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
|
||||
|
||||
let gMaxAvailWidth;
|
||||
let gMaxAvailHeight;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
|
||||
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
|
||||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({"set":
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Test page for navigator object</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
|
||||
<script>
|
||||
// This page will collect information from the navigator object and store
|
||||
// the result at a paragraph in the page.
|
||||
function collect() {
|
||||
let result = {};
|
||||
|
||||
result["appCodeName"] = navigator.appCodeName;
|
||||
result["appName"] = navigator.appName;
|
||||
result["appVersion"] = navigator.appVersion;
|
||||
result["platform"] = navigator.platform;
|
||||
result["userAgent"] = navigator.userAgent;
|
||||
result["product"] = navigator.product;
|
||||
result["productSub"] = navigator.productSub;
|
||||
result["vendor"] = navigator.vendor;
|
||||
result["vendorSub"] = navigator.vendorSub;
|
||||
result["mimeTypesLength"] = navigator.mimeTypes.length;
|
||||
result["pluginsLength"] = navigator.plugins.length;
|
||||
result["oscpu"] = navigator.oscpu;
|
||||
result["buildID"] = navigator.buildID;
|
||||
result["hardwareConcurrency"] = navigator.hardwareConcurrency;
|
||||
|
||||
document.getElementById("result").innerHTML = JSON.stringify(result);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="collect();">
|
||||
<p id="result"></p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,19 @@
|
|||
/* eslint-env worker */
|
||||
|
||||
onconnect = function(e) {
|
||||
let port = e.ports[0];
|
||||
|
||||
let navigatorObj = self.navigator;
|
||||
let result = {};
|
||||
|
||||
result["appCodeName"] = navigatorObj.appCodeName;
|
||||
result["appName"] = navigatorObj.appName;
|
||||
result["appVersion"] = navigatorObj.appVersion;
|
||||
result["platform"] = navigatorObj.platform;
|
||||
result["userAgent"] = navigatorObj.userAgent;
|
||||
result["product"] = navigatorObj.product;
|
||||
result["hardwareConcurrency"] = navigatorObj.hardwareConcurrency;
|
||||
|
||||
port.postMessage(JSON.stringify(result));
|
||||
port.start();
|
||||
};
|
|
@ -11,7 +11,7 @@ async function calcMaximumAvailSize(aChromeWidth, aChromeHeight) {
|
|||
let chromeUIWidth;
|
||||
let chromeUIHeight;
|
||||
let testPath = "http://example.net/browser/browser/" +
|
||||
"components/resistFingerprinting/test/browser/"
|
||||
"components/resistfingerprinting/test/browser/"
|
||||
|
||||
// If the chrome UI dimensions is not given, we will calculate it.
|
||||
if (!aChromeWidth || !aChromeHeight) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче