From c6e5a886d1ed0397a0256b2bb73affb5aba31d10 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Tue, 6 Jun 2017 17:14:55 +0800 Subject: [PATCH] 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 --- .../test/browser/browser.ini | 3 + .../test/browser/browser_navigator.js | 122 ++++++++++++++++++ .../browser_roundedWindow_newWindow.js | 2 +- .../browser/browser_roundedWindow_open_max.js | 2 +- .../browser/browser_roundedWindow_open_mid.js | 2 +- .../browser/browser_roundedWindow_open_min.js | 2 +- ...browser_roundedWindow_windowSetting_max.js | 2 +- ...browser_roundedWindow_windowSetting_mid.js | 2 +- ...browser_roundedWindow_windowSetting_min.js | 2 +- .../test/browser/browser_timezone.js | 2 +- .../test/browser/file_navigator.html | 33 +++++ .../test/browser/file_navigatorWorker.js | 19 +++ .../resistfingerprinting/test/browser/head.js | 2 +- 13 files changed, 186 insertions(+), 9 deletions(-) create mode 100644 browser/components/resistfingerprinting/test/browser/browser_navigator.js create mode 100644 browser/components/resistfingerprinting/test/browser/file_navigator.html create mode 100644 browser/components/resistfingerprinting/test/browser/file_navigatorWorker.js diff --git a/browser/components/resistfingerprinting/test/browser/browser.ini b/browser/components/resistfingerprinting/test/browser/browser.ini index 05801c9c19bb..5f7fda69b1f7 100644 --- a/browser/components/resistfingerprinting/test/browser/browser.ini +++ b/browser/components/resistfingerprinting/test/browser/browser.ini @@ -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] diff --git a/browser/components/resistfingerprinting/test/browser/browser_navigator.js b/browser/components/resistfingerprinting/test/browser/browser_navigator.js new file mode 100644 index 000000000000..6a67d7a84baa --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_navigator.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(); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js index 8a278ec95260..3e572d10ee73 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js @@ -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; diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js index a1738fe67b1a..2cf9f5a4c1fb 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js @@ -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; diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js index e623e49242fe..fea81803d361 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js @@ -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; diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js index 3dcdd30a8ebd..50b655c42e30 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js @@ -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; diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js index c06dc568f8b9..112df4eeb872 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js @@ -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; diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js index c3deb1500bfd..a406a2411ce0 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js @@ -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; diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js index 098c32c1df55..a18a52a2b9f0 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js @@ -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; diff --git a/browser/components/resistfingerprinting/test/browser/browser_timezone.js b/browser/components/resistfingerprinting/test/browser/browser_timezone.js index 966b3589f916..c75778ddd9d3 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_timezone.js +++ b/browser/components/resistfingerprinting/test/browser/browser_timezone.js @@ -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": diff --git a/browser/components/resistfingerprinting/test/browser/file_navigator.html b/browser/components/resistfingerprinting/test/browser/file_navigator.html new file mode 100644 index 000000000000..6c9b1d18c9ba --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_navigator.html @@ -0,0 +1,33 @@ + + +Test page for navigator object + + + + +

+ + diff --git a/browser/components/resistfingerprinting/test/browser/file_navigatorWorker.js b/browser/components/resistfingerprinting/test/browser/file_navigatorWorker.js new file mode 100644 index 000000000000..703e4afd9181 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_navigatorWorker.js @@ -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(); +}; diff --git a/browser/components/resistfingerprinting/test/browser/head.js b/browser/components/resistfingerprinting/test/browser/head.js index d8a5ed0fcf6b..5810966f25bf 100644 --- a/browser/components/resistfingerprinting/test/browser/head.js +++ b/browser/components/resistfingerprinting/test/browser/head.js @@ -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) {