diff options
Diffstat (limited to '')
65 files changed, 8515 insertions, 0 deletions
diff --git a/browser/components/resistfingerprinting/test/browser/browser.ini b/browser/components/resistfingerprinting/test/browser/browser.ini new file mode 100644 index 0000000000..67d329691c --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser.ini @@ -0,0 +1,79 @@ +[DEFAULT] +tags = resistfingerprinting +support-files = + coop_header.sjs + file_dummy.html + file_keyBoardEvent.sjs + file_navigator.html + file_navigatorWorker.js + file_workerNetInfo.js + file_workerPerformance.js + head.js + file_navigator_header.sjs + file_navigator_iframer.html + file_navigator_iframee.html + file_navigator_iframe_worker.sjs + file_reduceTimePrecision_iframer.html + file_reduceTimePrecision_iframee.html + file_reduceTimePrecision_iframe_worker.sjs + file_animationapi_iframer.html + file_animationapi_iframee.html + +[browser_block_mozAddonManager.js] +[browser_animationapi_iframes.js] +[browser_cross_origin_isolated_animation_api.js] +[browser_cross_origin_isolated_performance_api.js] +[browser_cross_origin_isolated_reduce_time_precision.js] +[browser_dynamical_window_rounding.js] +https_first_disabled = true +skip-if = + (os == "mac") #Bug 1570812 + os == 'linux' && bits == 64 && !debug # Bug 1570812 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_math.js] +[browser_navigator.js] +https_first_disabled = true +skip-if = + os == "win" && bits == 32 # fails on win10-32 +[browser_navigator_iframes.js] +https_first_disabled = true +skip-if = + os == "win" && bits == 32 # fails on win10-32 also +[browser_netInfo.js] +https_first_disabled = true +[browser_performanceAPI.js] +[browser_performanceAPIWorkers.js] +[browser_reduceTimePrecision_iframes.js] +https_first_disabled = true +[browser_roundedWindow_dialogWindow.js] +[browser_roundedWindow_newWindow.js] +[browser_roundedWindow_open_max_inner.js] +[browser_roundedWindow_open_mid_inner.js] +[browser_roundedWindow_open_min_inner.js] +[browser_roundedWindow_windowSetting_max_inner.js] +skip-if = + os == 'linux' && socketprocess_networking + os == "linux" && fission && !swgl # high frequency intermittent +[browser_roundedWindow_windowSetting_max_outer.js] +skip-if = + os == 'linux' && socketprocess_networking + os == "linux" && fission && !swgl # high frequency intermittent +[browser_roundedWindow_windowSetting_mid_inner.js] +skip-if = + os == 'linux' && socketprocess_networking + os == "linux" && fission && !swgl # high frequency intermittent +[browser_roundedWindow_windowSetting_mid_outer.js] +skip-if = os == "linux" && bits == 64 && os_version == "18.04" +[browser_roundedWindow_windowSetting_min_inner.js] +skip-if = + os == 'linux' && socketprocess_networking + os == "linux" && fission && !swgl # high frequency intermittent +[browser_roundedWindow_windowSetting_min_outer.js] +skip-if = + os == 'linux' && socketprocess_networking + os == "linux" && fission && !swgl # high frequency intermittent +[browser_spoofing_keyboard_event.js] +skip-if = (debug || asan) && os == "linux" && bits == 64 #Bug 1518179 +[browser_timezone.js] +[browser_bug1369357_site_specific_zoom_level.js] +https_first_disabled = true diff --git a/browser/components/resistfingerprinting/test/browser/browser_animationapi_iframes.js b/browser/components/resistfingerprinting/test/browser/browser_animationapi_iframes.js new file mode 100644 index 0000000000..188cfb8973 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_animationapi_iframes.js @@ -0,0 +1,263 @@ +/** + * This test only tests values in the iframe, it does not test them on the framer + * + * Covers the following cases: + * - RFP is disabled entirely + * - RFP is enabled entirely + + * - (A) RFP is exempted on the framer and framee + * - (B) RFP is exempted on the framer and framee + + * - (C) RFP is exempted on the framer but not the framee + * - (D) RFP is exempted on the framer but not the framee + + * - (E) RFP is not exempted on the framer nor the framee + * - (F) RFP is not exempted on the framer nor the framee + * + * - (G) RFP is not exempted on the framer but is on the framee + * - (H) RFP is not exempted on the framer but is on the framee + */ + +"use strict"; + +requestLongerTimeout(3); + +ChromeUtils.defineModuleGetter( + this, + "AppConstants", + "resource://gre/modules/AppConstants.jsm" +); + +// ============================================================================================= +// ============================================================================================= + +async function testTimePrecision(results, expectedResults, extraData) { + let testDesc = extraData.testDesc; + let precision = undefined; + + if (!expectedResults.shouldRFPApply) { + precision = extraData.Unconditional_Precision; + } else { + precision = extraData.RFP_Precision; + } + + for (let result of results) { + if ("error" in result) { + ok(false, result.error); + continue; + } + + let isRounded = isTimeValueRounded(result.value, precision); + + ok( + isRounded, + "Test: " + + testDesc + + " - '" + + "'" + + result.name + + "' should be rounded to nearest " + + precision + + " ms; saw " + + result.value + ); + } +} + +const RFP_TIME_ATOM_MS = 16.667; +const framer_domain = "example.com"; +const iframe_domain = "example.org"; +const cross_origin_domain = "example.net"; +const uri = `https://${framer_domain}/browser/browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html`; + +// The first three variables are defined here; and then set for test banks below. +let extraData = {}; +let extraPrefs = {}; +let precision = 100; +let expectedResults = {}; // In this test, we don't have explicit expected values, but rather we expect them to be rounded + +// ======================================================================================================================== +// Create a function that defines all the tests +function addAllTests(extraData_, extraPrefs_) { + add_task( + partial( + defaultsTest, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + add_task( + partial( + simpleRFPTest, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource + add_task( + partial( + testA, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource + add_task( + partial( + testB, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource + add_task( + partial( + testC, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource + add_task( + partial( + testD, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource + add_task( + partial( + testE, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource + add_task( + partial( + testF, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource + add_task( + partial( + testG, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource + add_task( + partial( + testH, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); +} + +// ======================================================================================================================== +// First we run through all the tests with RTP's precision set to 100 ms and 133 ms. +// Animation does _not_ obey RTP's timestamp, instead it falls back to the unconditional +// rounding which is 20 microseconds. +extraData = { + RFP_Precision: 100, + Unconditional_Precision: 0.02, +}; + +extraPrefs = [ + [ + "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", + extraData.RFP_Precision * 1000, + ], + ["dom.animations-api.timelines.enabled", true], +]; + +addAllTests(extraData, extraPrefs); + +extraData = { + RFP_Precision: 133, + Unconditional_Precision: 0.02, +}; + +extraPrefs = [ + [ + "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", + extraData.RFP_Precision * 1000, + ], + ["dom.animations-api.timelines.enabled", true], +]; + +addAllTests(extraData, extraPrefs); + +// ======================================================================================================================== +// Then we run through all the tests with the precision set to its normal value. +// This will mean that in some cases we expect RFP to apply and in some we don't. +extraData = { + RFP_Precision: RFP_TIME_ATOM_MS, + Unconditional_Precision: 0.02, +}; +extraPrefs = [["dom.animations-api.timelines.enabled", true]]; +addAllTests(extraData, extraPrefs); diff --git a/browser/components/resistfingerprinting/test/browser/browser_block_mozAddonManager.js b/browser/components/resistfingerprinting/test/browser/browser_block_mozAddonManager.js new file mode 100644 index 0000000000..eca83dd1dd --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_block_mozAddonManager.js @@ -0,0 +1,43 @@ +/** + * Bug 1384330 - A test case for making sure the navigator.mozAddonManager will + * be blocked when pref 'privacy.resistFingerprinting.block_mozAddonManager' is true. + */ + +const HTTPS_TEST_PATH = + "https://example.com/browser/browser/" + + "components/resistfingerprinting/test/browser/"; + +add_task(async function test() { + await SpecialPowers.pushPrefEnv({ + set: [["extensions.webapi.testing", true]], + }); + + for (let pref of [false, true]) { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting.block_mozAddonManager", pref]], + }); + + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + HTTPS_TEST_PATH + "file_dummy.html" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [pref], function(aPref) { + if (aPref) { + is( + content.navigator.mozAddonManager, + undefined, + "The navigator.mozAddonManager should not exist when the pref is on." + ); + } else { + ok( + content.navigator.mozAddonManager, + "The navigator.mozAddonManager should exist when the pref is off." + ); + } + }); + + BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); + } +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_bug1369357_site_specific_zoom_level.js b/browser/components/resistfingerprinting/test/browser/browser_bug1369357_site_specific_zoom_level.js new file mode 100644 index 0000000000..711fb3ad48 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_bug1369357_site_specific_zoom_level.js @@ -0,0 +1,40 @@ +"use strict"; + +const testPage = + "http://example.net/browser/browser/components/resistFingerprinting/test/browser/file_dummy.html"; + +add_task(async function() { + let tab1, tab1Zoom, tab2, tab2Zoom, tab3, tab3Zoom; + + tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, testPage); + await FullZoom.enlarge(); + tab1Zoom = ZoomManager.getZoomForBrowser(tab1.linkedBrowser); + + tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, testPage); + tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser); + + is( + tab2Zoom, + tab1Zoom, + "privacy.resistFingerprinting is false, site-specific zoom level should be enabled" + ); + + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]], + }); + + tab3 = await BrowserTestUtils.openNewForegroundTab(gBrowser, testPage); + tab3Zoom = ZoomManager.getZoomForBrowser(tab3.linkedBrowser); + + isnot( + tab3Zoom, + tab1Zoom, + "privacy.resistFingerprinting is true, site-specific zoom level should be disabled" + ); + + await FullZoom.reset(); + + BrowserTestUtils.removeTab(tab1); + BrowserTestUtils.removeTab(tab2); + BrowserTestUtils.removeTab(tab3); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_animation_api.js b/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_animation_api.js new file mode 100644 index 0000000000..db474c200b --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_animation_api.js @@ -0,0 +1,119 @@ +/** + * Bug 1621677 - A test for making sure getting the correct (higher) precision + * when it's cross-origin-isolated on animation APIs. + */ + +// ================================================================================================ +// ================================================================================================ +// This test case is mostly copy-and-paste from the test case for window in +// test_animation_api.html. The main difference is this test case +// verifies animation has more precsion when it's in cross-origin-isolated and +// cross-origin-isolated doesn't affect RFP. +add_task(async function runRTPTestAnimation() { + let runTests = async function(data) { + function waitForCondition(aCond, aCallback, aErrorMsg) { + var tries = 0; + var interval = content.setInterval(() => { + if (tries >= 30) { + ok(false, aErrorMsg); + moveOn(); + return; + } + var conditionPassed; + try { + conditionPassed = aCond(); + } catch (e) { + ok(false, `${e}\n${e.stack}`); + conditionPassed = false; + } + if (conditionPassed) { + moveOn(); + } + tries++; + }, 100); + var moveOn = () => { + content.clearInterval(interval); + aCallback(); + }; + } + + let expectedPrecision = data.precision; + // eslint beleives that isrounded is available in this scope, but if you + // remove the assignment, you will see it is not + // eslint-disable-next-line + let isRounded = eval(data.isRoundedFunc); + + const testDiv = content.document.getElementById("testDiv"); + const animation = testDiv.animate({ opacity: [0, 1] }, 100000); + animation.play(); + + let done; + let promise = new Promise(resolve => { + done = resolve; + }); + + waitForCondition( + () => animation.currentTime > 100, + () => { + // We have disabled Time Precision Reduction for CSS Animations, so we + // expect those tests to fail. + // If we are testing that preference, we accept either rounded or not + // rounded values as A-OK. + var maybeAcceptEverything = function(value) { + if (data.reduceTimerPrecision && !data.resistFingerprinting) { + return true; + } + + return value; + }; + + ok( + maybeAcceptEverything( + isRounded(animation.startTime, expectedPrecision) + ), + `Animation.startTime with precision ${expectedPrecision} is not ` + + `rounded: ${animation.startTime}` + ); + ok( + maybeAcceptEverything( + isRounded(animation.currentTime, expectedPrecision) + ), + `Animation.currentTime with precision ${expectedPrecision} is ` + + `not rounded: ${animation.currentTime}` + ); + ok( + maybeAcceptEverything( + isRounded(animation.timeline.currentTime, expectedPrecision) + ), + `Animation.timeline.currentTime with precision ` + + `${expectedPrecision} is not rounded: ` + + `${animation.timeline.currentTime}` + ); + if (content.document.timeline) { + ok( + maybeAcceptEverything( + isRounded( + content.document.timeline.currentTime, + expectedPrecision + ) + ), + `Document.timeline.currentTime with precision ` + + `${expectedPrecision} is not rounded: ` + + `${content.document.timeline.currentTime}` + ); + } + done(); + }, + "animation failed to start" + ); + + await promise; + }; + + await setupAndRunCrossOriginIsolatedTest(true, true, true, 100, runTests); + await setupAndRunCrossOriginIsolatedTest(true, false, true, 50, runTests); + await setupAndRunCrossOriginIsolatedTest(true, false, true, 0.1, runTests); + await setupAndRunCrossOriginIsolatedTest(true, true, true, 0.013, runTests); + + await setupAndRunCrossOriginIsolatedTest(false, true, true, 0.005, runTests); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_performance_api.js b/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_performance_api.js new file mode 100644 index 0000000000..f3552de0d1 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_performance_api.js @@ -0,0 +1,174 @@ +/** + * Bug 1621677 - A test for making sure getting the correct (higher) precision + * when it's cross-origin-isolated for performance APIs. + */ + +// ================================================================================================ +// ================================================================================================ +// This test case is mostly copy-and-paste from the forth test case in +// browser_performanceAPI.js. The main difference is this test case verifies +// performance API have more precsion when it's in cross-origin-isolated and +// cross-origin-isolated doesn't affect RFP. +let runWorkerTest = async function(data) { + let expectedPrecision = data.precision; + await new Promise(resolve => { + // eslint beleives that isrounded is available in this scope, but if you + // remove the assignment, you will see it is not + // eslint-disable-next-line + let isRounded = eval(data.isRoundedFunc); + + let worker = new content.Worker( + "coop_header.sjs?crossOriginIsolated=true&worker=true" + ); + + worker.postMessage({ + type: "runCmdAndGetResult", + cmd: `performance.timeOrigin`, + }); + + const expectedAllEntriesLength = data.workerCall == "runRPTests" ? 0 : 3; + const expectedResourceEntriesLength = + data.workerCall == "runRPTests" ? 0 : 2; + const expectedTestAndMarkEntriesLength = + data.workerCall == "runRPTests" ? 0 : 1; + + worker.onmessage = function(e) { + if (e.data.type == "result") { + if (e.data.resultOf == "performance.timeOrigin") { + ok( + isRounded(e.data.result, expectedPrecision), + `In a worker, for reduceTimerPrecision, performance.timeOrigin is` + + ` not correctly rounded: ${e.data.result}` + ); + + worker.postMessage({ + type: "runCmds", + cmds: [ + `performance.mark("Test");`, + `performance.mark("Test-End");`, + `performance.measure("Test-Measure", "Test", "Test-End");`, + ], + }); + } else if (e.data.resultOf == "entriesLength") { + is( + e.data.result, + expectedAllEntriesLength, + `In a worker, for reduceTimerPrecision: Incorrect number of ` + + `entries for performance.getEntries() for workers: ` + + `${e.data.result}` + ); + + if (data.workerCall == "runRTPTests") { + worker.postMessage({ + type: "getResult", + resultOf: "startTimeAndDuration", + num: 0, + }); + } else { + worker.postMessage({ + type: "getResult", + resultOf: "getEntriesByTypeLength", + }); + } + } else if (e.data.resultOf == "startTimeAndDuration") { + let index = e.data.result.index; + let startTime = e.data.result.startTime; + let duration = e.data.result.duration; + ok( + isRounded(startTime, expectedPrecision), + `In a worker, for reduceTimerPrecision(${expectedPrecision}, ` + + `performance.getEntries(${index}).startTime is not rounded: ` + + `${startTime}` + ); + ok( + isRounded(duration, expectedPrecision), + `In a worker, for reduceTimerPrecision(${expectedPrecision}), ` + + `performance.getEntries(${index}).duration is not rounded: ` + + `${duration}` + ); + + if (index < 2) { + worker.postMessage({ + type: "getResult", + resultOf: "startTimeAndDuration", + num: index + 1, + }); + } else { + worker.postMessage({ + type: "getResult", + resultOf: "getEntriesByTypeLength", + }); + } + } else if (e.data.resultOf == "entriesByTypeLength") { + is( + e.data.result.markLength, + expectedResourceEntriesLength, + `In a worker, for reduceTimerPrecision: Incorrect number of ` + + `entries for performance.getEntriesByType() for workers: ` + + `${e.data.result.resourceLength}` + ); + is( + e.data.result.testAndMarkLength, + expectedTestAndMarkEntriesLength, + `In a worker, for reduceTimerPrecision: Incorrect number of ` + + `entries for performance.getEntriesByName() for workers: ` + + `${e.data.result.testAndMarkLength}` + ); + + worker.terminate(); + resolve(); + } + } else { + ok(false, `Unknown message type got ${e.data.type}`); + worker.terminate(); + resolve(); + } + }; + }); +}; + +add_task(async function runTestsForWorker() { + // RFP + await setupAndRunCrossOriginIsolatedTest( + true, + true, + true, + 100, + runWorkerTest, + "runRPTests" + ); + await setupAndRunCrossOriginIsolatedTest( + true, + false, + true, + 13, + runWorkerTest, + "runRPTests" + ); + await setupAndRunCrossOriginIsolatedTest( + true, + true, + true, + 0.13, + runWorkerTest, + "runRPTests" + ); + + // RTP + await setupAndRunCrossOriginIsolatedTest( + false, + true, + false, + 0.13, + runWorkerTest, + "runRTPTests" + ); + await setupAndRunCrossOriginIsolatedTest( + false, + true, + true, + 0.005, + runWorkerTest, + "runRTPTests" + ); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_reduce_time_precision.js b/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_reduce_time_precision.js new file mode 100644 index 0000000000..6d15729cbd --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_cross_origin_isolated_reduce_time_precision.js @@ -0,0 +1,173 @@ +/** + * Bug 1621677 - A test for making sure getting the correct (higher) precision + * when it's cross-origin-isolated. + */ + +// ================================================================================================ +// ================================================================================================ +// This test case is mostly copy-and-paste from the test case for window in +// test_reduce_time_precision.html. The main difference is this test case +// verifies DOM API has more precsion when it's in cross-origin-isolated and +// cross-origin-isolated doesn't affect RFP. +add_task(async function runRTPTestDOM() { + let runTests = async function(data) { + let expectedPrecision = data.precision; + // eslint beleives that isrounded is available in this scope, but if you + // remove the assignment, you will see it is not + // eslint-disable-next-line + let isRounded = eval(data.isRoundedFunc); + + // Prepare for test of AudioContext.currentTime + // eslint-disable-next-line + let audioContext = new content.AudioContext(); + + // Known ways to generate time stamps, in milliseconds + const timeStampCodes = [ + "content.performance.now()", + "new content.Date().getTime()", + 'new content.Event("").timeStamp', + 'new content.File([], "").lastModified', + ]; + // These are measured in seconds, so we need to scale them up + var timeStampCodesDOM = timeStampCodes.concat([ + "audioContext.currentTime * 1000", + ]); + + // Loop through each timeStampCode, evaluate it, + // and check if it is rounded + for (let timeStampCode of timeStampCodesDOM) { + // eslint-disable-next-line + let timeStamp = eval(timeStampCode); + + // Audio Contexts increment in intervals of (minimum) 5.4ms, so we don't + // clamp/jitter if the timer precision is les than that. + // (Technically on MBPs they increment in intervals of 2.6 but this is + // non-standard and will eventually be changed. We don't cover this situation + // because we don't really support arbitrary Timer Precision, especially in + // the 2.6 - 5.4ms interval.) + if (timeStampCode.includes("audioContext") && expectedPrecision < 5.4) { + continue; + } + + ok( + isRounded(timeStamp, expectedPrecision), + `Should be rounded to nearest ${expectedPrecision} ms; saw ${timeStamp}` + ); + } + }; + + // RFP + await setupAndRunCrossOriginIsolatedTest(true, true, true, 100, runTests); + await setupAndRunCrossOriginIsolatedTest(true, false, true, 13, runTests); + await setupAndRunCrossOriginIsolatedTest(true, false, true, 0.13, runTests); + + // RTP + await setupAndRunCrossOriginIsolatedTest(false, true, false, 0.13, runTests); + await setupAndRunCrossOriginIsolatedTest(false, true, true, 0.005, runTests); +}); + +// ================================================================================================ +// ================================================================================================ +// This test case is mostly copy-and-paste from the test case for worker in +// test_reduce_time_precision.html. The main difference is this test case +// verifies DOM API has more precsion when it's in cross-origin-isolated and +// cross-origin-isolated doesn't affect RFP. +let runWorkerTest = async function(data) { + let expectedPrecision = data.precision; + await new Promise(resolve => { + // eslint beleives that isrounded is available in this scope, but if you + // remove the assignment, you will see it is not + // eslint-disable-next-line + let isRounded = eval(data.isRoundedFunc); + + let worker = new content.Worker( + "coop_header.sjs?crossOriginIsolated=true&worker=true" + ); + + // Known ways to generate time stamps, in milliseconds + const timeStampCodes = [ + "performance.now()", + "new Date().getTime()", + 'new Event("").timeStamp', + 'new File([], "").lastModified', + ]; + + let promises = []; + for (let timeStampCode of timeStampCodes) { + promises.push( + new Promise(res => { + worker.postMessage({ + type: "runCmdAndGetResult", + cmd: timeStampCode, + }); + + worker.addEventListener("message", function(e) { + if (e.data.type == "result") { + if (e.data.resultOf == timeStampCode) { + ok( + isRounded(e.data.result, expectedPrecision), + `The result of ${e.data.resultOf} should be rounded to ` + + ` nearest ${expectedPrecision} ms in workers; saw ` + + `${e.data.result}` + ); + worker.removeEventListener("message", this); + res(); + } + + return; + } + + ok(false, `Unknown message type. Got ${e.data.type}`); + res(); + }); + }) + ); + } + + Promise.all(promises).then(_ => { + worker.terminate(); + resolve(); + }); + }); +}; + +add_task(async function runRTPTestsForWorker() { + // RFP + await setupAndRunCrossOriginIsolatedTest( + true, + true, + true, + 100, + runWorkerTest + ); + await setupAndRunCrossOriginIsolatedTest( + true, + false, + true, + 13, + runWorkerTest + ); + await setupAndRunCrossOriginIsolatedTest( + true, + false, + true, + 0.13, + runWorkerTest + ); + + // RTP + await setupAndRunCrossOriginIsolatedTest( + false, + true, + false, + 0.13, + runWorkerTest + ); + await setupAndRunCrossOriginIsolatedTest( + false, + true, + true, + 0.005, + runWorkerTest + ); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_dynamical_window_rounding.js b/browser/components/resistfingerprinting/test/browser/browser_dynamical_window_rounding.js new file mode 100644 index 0000000000..3c5dc5e745 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_dynamical_window_rounding.js @@ -0,0 +1,397 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Bug 1407366 - A test case for reassuring the size of the content viewport is + * rounded if the window is resized when letterboxing is enabled. + * + * A helpful note: if this test starts randomly failing; it may be because the + * zoom level was not reset by an earlier-run test. See Bug 1407366 for an + * example. + */ + +const { RFPHelper } = ChromeUtils.import( + "resource://gre/modules/RFPHelper.jsm" +); + +// A set of test cases which defines the width and the height of the outer window. +const TEST_CASES = [ + { width: 1250, height: 1000 }, + { width: 1500, height: 1050 }, + { width: 1120, height: 760 }, + { width: 800, height: 600 }, + { width: 640, height: 400 }, + { width: 500, height: 350 }, +]; + +function getPlatform() { + const { OS } = Services.appinfo; + if (OS == "WINNT") { + return "win"; + } else if (OS == "Darwin") { + return "mac"; + } + return "linux"; +} + +function handleOSFuzziness(aContent, aTarget) { + /* + * On Windows, we observed off-by-one pixel differences that + * couldn't be expained. When manually setting the window size + * to try to reproduce it; it did not occur. + */ + if (getPlatform() == "win") { + return Math.abs(aContent - aTarget) <= 1; + } + return aContent == aTarget; +} + +function checkForDefaultSetting( + aContentWidth, + aContentHeight, + aRealWidth, + aRealHeight +) { + // We can get the rounded size by subtracting twice the margin. + let targetWidth = aRealWidth - 2 * RFPHelper.steppedRange(aRealWidth); + let targetHeight = aRealHeight - 2 * RFPHelper.steppedRange(aRealHeight); + + // This platform-specific code is explained in the large comment below. + if (getPlatform() != "linux") { + ok( + handleOSFuzziness(aContentWidth, targetWidth), + `Default Dimensions: The content window width is correctly rounded into. ${aRealWidth}px -> ${aContentWidth}px should equal ${targetWidth}px` + ); + + ok( + handleOSFuzziness(aContentHeight, targetHeight), + `Default Dimensions: The content window height is correctly rounded into. ${aRealHeight}px -> ${aContentHeight}px should equal ${targetHeight}px` + ); + + // Using ok() above will cause Win/Mac to fail on even the first test, we don't need to repeat it, return true so waitForCondition ends + return true; + } + // Returning true or false depending on if the test succeeded will cause Linux to repeat until it succeeds. + return ( + handleOSFuzziness(aContentWidth, targetWidth) && + handleOSFuzziness(aContentHeight, targetHeight) + ); +} + +async function test_dynamical_window_rounding(aWindow, aCheckFunc) { + // We need to wait for the updating the margins for the newly opened tab, or + // it will affect the following tests. + let promiseForTheFirstRounding = TestUtils.topicObserved( + "test:letterboxing:update-margin-finish" + ); + + info("Open a content tab for testing."); + let tab = await BrowserTestUtils.openNewForegroundTab( + aWindow.gBrowser, + TEST_PATH + "file_dummy.html" + ); + + info("Wait until the margins are applied for the opened tab."); + await promiseForTheFirstRounding; + + let getContainerSize = aTab => { + let browserContainer = aWindow.gBrowser.getBrowserContainer( + aTab.linkedBrowser + ); + return { + containerWidth: browserContainer.clientWidth, + containerHeight: browserContainer.clientHeight, + }; + }; + + for (let { width, height } of TEST_CASES) { + let caseString = "Case " + width + "x" + height + ": "; + // Create a promise for waiting for the margin update. + let promiseRounding = TestUtils.topicObserved( + "test:letterboxing:update-margin-finish" + ); + + let { containerWidth, containerHeight } = getContainerSize(tab); + + info( + caseString + + "Resize the window and wait until resize event happened (currently " + + containerWidth + + "x" + + containerHeight + + ")" + ); + await new Promise(resolve => { + ({ containerWidth, containerHeight } = getContainerSize(tab)); + info( + caseString + + "Resizing (currently " + + containerWidth + + "x" + + containerHeight + + ")" + ); + + aWindow.onresize = () => { + ({ containerWidth, containerHeight } = getContainerSize(tab)); + info( + caseString + + "Resized (currently " + + containerWidth + + "x" + + containerHeight + + ")" + ); + if (getPlatform() == "linux" && containerWidth != width) { + /* + * We observed frequent test failures that resulted from receiving an onresize + * event where the browser was resized to an earlier requested dimension. This + * resize event happens on Linux only, and is an artifact of the asynchronous + * resizing. (See more discussion on 1407366#53) + * + * We cope with this problem in two ways. + * + * 1: If we detect that the browser was resized to the wrong value; we + * redo the resize. (This is the lines of code immediately following this + * comment) + * 2: We repeat the test until it works using waitForCondition(). But we still + * test Win/Mac more thoroughly: they do not loop in waitForCondition more + * than once, and can fail the test on the first attempt (because their + * check() functions use ok() while on Linux, we do not all ok() and instead + * rely on waitForCondition to fail). + * + * The logging statements in this test, and RFPHelper.jsm, help narrow down and + * illustrate the issue. + */ + info(caseString + "We hit the weird resize bug. Resize it again."); + aWindow.resizeTo(width, height); + } else { + resolve(); + } + }; + aWindow.resizeTo(width, height); + }); + + ({ containerWidth, containerHeight } = getContainerSize(tab)); + info( + caseString + + "Waiting until margin has been updated on browser element. (currently " + + containerWidth + + "x" + + containerHeight + + ")" + ); + await promiseRounding; + + info(caseString + "Get innerWidth/Height from the content."); + await BrowserTestUtils.waitForCondition(async () => { + let { contentWidth, contentHeight } = await SpecialPowers.spawn( + tab.linkedBrowser, + [], + () => { + return { + contentWidth: content.innerWidth, + contentHeight: content.innerHeight, + }; + } + ); + + info(caseString + "Check the result."); + return aCheckFunc( + contentWidth, + contentHeight, + containerWidth, + containerHeight + ); + }, "Default Dimensions: The content window width is correctly rounded into."); + } + + BrowserTestUtils.removeTab(tab); +} + +async function test_customize_width_and_height(aWindow) { + const test_dimensions = `120x80, 200x143, 335x255, 600x312, 742x447, 813x558, + 990x672, 1200x733, 1470x858`; + + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting.letterboxing.dimensions", test_dimensions], + ], + }); + + let dimensions_set = test_dimensions.split(",").map(item => { + let sizes = item.split("x").map(size => parseInt(size, 10)); + + return { + width: sizes[0], + height: sizes[1], + }; + }); + + let checkDimension = ( + aContentWidth, + aContentHeight, + aRealWidth, + aRealHeight + ) => { + let matchingArea = aRealWidth * aRealHeight; + let minWaste = Number.MAX_SAFE_INTEGER; + let targetDimensions = undefined; + + // Find the dimensions which waste the least content area. + for (let dim of dimensions_set) { + if (dim.width > aRealWidth || dim.height > aRealHeight) { + continue; + } + + let waste = matchingArea - dim.width * dim.height; + + if (waste >= 0 && waste < minWaste) { + targetDimensions = dim; + minWaste = waste; + } + } + + // This platform-specific code is explained in the large comment above. + if (getPlatform() != "linux") { + ok( + handleOSFuzziness(aContentWidth, targetDimensions.width), + `Custom Dimension: The content window width is correctly rounded into. ${aRealWidth}px -> ${aContentWidth}px should equal ${targetDimensions.width}` + ); + + ok( + handleOSFuzziness(aContentHeight, targetDimensions.height), + `Custom Dimension: The content window height is correctly rounded into. ${aRealHeight}px -> ${aContentHeight}px should equal ${targetDimensions.height}` + ); + + // Using ok() above will cause Win/Mac to fail on even the first test, we don't need to repeat it, return true so waitForCondition ends + return true; + } + // Returning true or false depending on if the test succeeded will cause Linux to repeat until it succeeds. + return ( + handleOSFuzziness(aContentWidth, targetDimensions.width) && + handleOSFuzziness(aContentHeight, targetDimensions.height) + ); + }; + + await test_dynamical_window_rounding(aWindow, checkDimension); + + await SpecialPowers.popPrefEnv(); +} + +async function test_no_rounding_for_chrome(aWindow) { + // First, resize the window to a size which is not rounded. + await new Promise(resolve => { + aWindow.onresize = () => resolve(); + aWindow.resizeTo(700, 450); + }); + + // open a chrome privilege tab, like about:config. + let tab = await BrowserTestUtils.openNewForegroundTab( + aWindow.gBrowser, + "about:config" + ); + + // Check that the browser element should not have a margin. + is( + tab.linkedBrowser.style.margin, + "", + "There is no margin around chrome tab." + ); + + BrowserTestUtils.removeTab(tab); +} + +// Tests that the findbar opening and closing causes a margin update. +async function test_findbar(aWindow) { + // First, resize the window to a size which is not rounded. + await new Promise(resolve => { + aWindow.onresize = () => resolve(); + aWindow.resizeTo(701, 451); + }); + + let tab = await BrowserTestUtils.openNewForegroundTab( + aWindow.gBrowser, + TEST_PATH + "file_dummy.html" + ); + + let promiseRounding = TestUtils.topicObserved( + "test:letterboxing:update-margin-finish" + ); + + let findBarOpenPromise = BrowserTestUtils.waitForEvent( + aWindow, + "findbaropen" + ); + EventUtils.synthesizeKey("F", { accelKey: true }, aWindow); + await findBarOpenPromise; + await promiseRounding; + + ok(true, "Margin updated when findbar opened"); + + promiseRounding = TestUtils.topicObserved( + "test:letterboxing:update-margin-finish" + ); + + let findBarClosePromise = BrowserTestUtils.waitForEvent( + aWindow, + "findbarclose" + ); + EventUtils.synthesizeKey("KEY_Escape", {}, aWindow); + await findBarClosePromise; + await promiseRounding; + + ok(true, "Margin updated when findbar closed"); + + BrowserTestUtils.removeTab(tab); +} + +add_setup(async function() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting.letterboxing", true], + ["privacy.resistFingerprinting.letterboxing.testing", true], + ], + }); +}); + +add_task(async function do_tests() { + // Store the original window size before testing. + let originalOuterWidth = window.outerWidth; + let originalOuterHeight = window.outerHeight; + + info("Run test for the default window rounding."); + await test_dynamical_window_rounding(window, checkForDefaultSetting); + + info("Run test for the window rounding with customized dimensions."); + await test_customize_width_and_height(window); + + info("Run test for no margin around tab with the chrome privilege."); + await test_no_rounding_for_chrome(window); + + await test_findbar(window); + + // Restore the original window size. + window.outerWidth = originalOuterWidth; + window.outerHeight = originalOuterHeight; + + // Testing that whether the dynamical rounding works for new windows. + let win = await BrowserTestUtils.openNewBrowserWindow(); + + info("Run test for the default window rounding in new window."); + await test_dynamical_window_rounding(win, checkForDefaultSetting); + + info( + "Run test for the window rounding with customized dimensions in new window." + ); + await test_customize_width_and_height(win); + + info( + "Run test for no margin around tab with the chrome privilege in new window." + ); + await test_no_rounding_for_chrome(win); + + await test_findbar(win); + + await BrowserTestUtils.closeWindow(win); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_math.js b/browser/components/resistfingerprinting/test/browser/browser_math.js new file mode 100644 index 0000000000..66a7114590 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_math.js @@ -0,0 +1,107 @@ +/** + * Bug 531915 - A test for verifying that the JS Math fingerprint is constant + * when using fdlibm for Math.sin, Math.cos, and Math.tan. + */ + +async function test_math(rfp_pref, fdlibm_pref) { + await SpecialPowers.pushPrefEnv({ + set: [ + ["javascript.options.use_fdlibm_for_sin_cos_tan", fdlibm_pref], + ["privacy.resistFingerprinting", rfp_pref], + ], + }); + + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TEST_PATH + "file_dummy.html" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function() { + // override is to check strict equality like we would do in a JS ref test. + function strictly_is(a, b) { + ok(a === b); + } + + // + // Tests adapted from https://github.com/arkenfox/TZP/blob/5e3f5ff2c64b4edc7beecd8308aa4f7a3efb49e3/tests/math.html#L158-L319 + // + strictly_is(Math.cos(1e251), -0.37419577499634155); + strictly_is(Math.cos(1e140), -0.7854805190645291); + strictly_is(Math.cos(1e12), 0.7914463018528902); + strictly_is(Math.cos(1e130), -0.767224894221913); + strictly_is(Math.cos(1e272), -0.7415825695514536); + strictly_is(Math.cos(1), 0.5403023058681398); + strictly_is(Math.cos(1e284), 0.7086865671674247); + strictly_is(Math.cos(1e75), -0.7482651726250321); + strictly_is(Math.cos(Math.PI), -1); + strictly_is(Math.cos(-1e308), -0.8913089376870335); + strictly_is(Math.cos(13 * Math.E), -0.7108118501064332); + strictly_is(Math.cos(57 * Math.E), -0.536911695749024); + strictly_is(Math.cos(21 * Math.LN2), -0.4067775970251724); + strictly_is(Math.cos(51 * Math.LN2), -0.7017203400855446); + strictly_is(Math.cos(21 * Math.LOG2E), 0.4362848063618998); + strictly_is(Math.cos(25 * Math.SQRT2), -0.6982689820462377); + strictly_is(Math.cos(50 * Math.SQRT1_2), -0.6982689820462377); + strictly_is(Math.cos(21 * Math.SQRT1_2), -0.6534063185820198); + strictly_is(Math.cos(17 * Math.LOG10E), 0.4537557425982784); + strictly_is(Math.cos(2 * Math.LOG10E), 0.6459044007438142); + + strictly_is(Math.sin(1e251), -0.9273497301314576); + strictly_is(Math.sin(1e140), -0.6188863822787813); + strictly_is(Math.sin(1e12), -0.6112387023768895); + strictly_is(Math.sin(1e130), 0.6413781736901984); + strictly_is(Math.sin(1e272), 0.6708616046081811); + strictly_is(Math.sin(1), 0.8414709848078965); + strictly_is(Math.sin(1e284), -0.7055234578073583); + strictly_is(Math.sin(1e75), 0.66339975236386); + strictly_is(Math.sin(Math.PI), 1.2246467991473532e-16); + strictly_is(Math.sin(39 * Math.E), -0.7181630308570678); + strictly_is(Math.sin(35 * Math.LN2), -0.765996413898051); + strictly_is(Math.sin(110 * Math.LOG2E), 0.9989410140273757); + strictly_is(Math.sin(7 * Math.LOG10E), 0.10135692924965616); + strictly_is(Math.sin(35 * Math.SQRT1_2), -0.3746357547858202); + strictly_is(Math.sin(21 * Math.SQRT2), -0.9892668187780497); + + strictly_is(Math.tan(1e251), 2.478247463217681); + strictly_is(Math.tan(1e140), 0.7879079967710036); + strictly_is(Math.tan(1e12), -0.7723059681318761); + strictly_is(Math.tan(1e130), -0.8359715365344825); + strictly_is(Math.tan(1e272), -0.904635076595654); + strictly_is(Math.tan(1), 1.5574077246549023); + strictly_is(Math.tan(1e284), -0.9955366596368418); + strictly_is(Math.tan(1e75), -0.8865837628611647); + strictly_is(Math.tan(-1e308), 0.5086861259107568); + strictly_is(Math.tan(Math.PI), -1.2246467991473532e-16); + strictly_is(Math.tan(6 * Math.E), 0.6866761546452431); + strictly_is(Math.tan(6 * Math.LN2), 1.6182817135715877); + strictly_is(Math.tan(10 * Math.LOG2E), -3.3537128705376014); + strictly_is(Math.tan(17 * Math.SQRT2), -1.9222955461799982); + strictly_is(Math.tan(34 * Math.SQRT1_2), -1.9222955461799982); + strictly_is(Math.tan(10 * Math.LOG10E), 2.5824856130712432); + + // + // Tests adapted from https://github.com/fingerprintjs/fingerprintjs/blob/7096a5589af495f1f46067963e13ad27d887d185/src/sources/math.ts#L32-L64 + // + strictly_is(Math.acos(0.123124234234234242), 1.4473588658278522); + strictly_is(Math.acosh(1e308), 709.889355822726); + strictly_is(Math.asin(0.123124234234234242), 0.12343746096704435); + strictly_is(Math.asinh(1), 0.881373587019543); + strictly_is(Math.atanh(0.5), 0.5493061443340548); + strictly_is(Math.atan(0.5), 0.4636476090008061); + strictly_is(Math.sin(-1e300), 0.8178819121159085); + strictly_is(Math.sinh(1), 1.1752011936438014); + strictly_is(Math.cos(10.000000000123), -0.8390715290095377); + strictly_is(Math.cosh(1), 1.5430806348152437); + strictly_is(Math.tan(-1e300), -1.4214488238747245); + strictly_is(Math.tanh(1), 0.7615941559557649); + strictly_is(Math.exp(1), 2.718281828459045); + strictly_is(Math.expm1(1), 1.718281828459045); + strictly_is(Math.log1p(10), 2.3978952727983707); + }); + + BrowserTestUtils.removeTab(tab); +} + +add_task(test_math.bind(null, false, true)); +add_task(test_math.bind(null, true, false)); +add_task(test_math.bind(null, true, true)); 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 0000000000..68f624cb51 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_navigator.js @@ -0,0 +1,471 @@ +/** + * Bug 1333651 - A test case for making sure the navigator object has been + * spoofed/disabled correctly. + */ + +"use strict"; + +const CC = Components.Constructor; + +const { AppConstants } = ChromeUtils.importESModule( + "resource://gre/modules/AppConstants.sys.mjs" +); + +ChromeUtils.defineModuleGetter( + this, + "WindowsVersionInfo", + "resource://gre/modules/components-utils/WindowsVersionInfo.jsm" +); + +let expectedResults; + +let osVersion = Services.sysinfo.get("version"); +if (AppConstants.platform == "macosx") { + // Convert Darwin version to macOS version: 19.x.x -> 10.15 etc. + // https://en.wikipedia.org/wiki/Darwin_%28operating_system%29 + let DarwinVersionParts = osVersion.split("."); + let DarwinMajorVersion = +DarwinVersionParts[0]; + let macOsMinorVersion = DarwinMajorVersion - 4; + if (macOsMinorVersion > 15) { + macOsMinorVersion = 15; + } + osVersion = `10.${macOsMinorVersion}`; +} + +const DEFAULT_APPVERSION = { + linux: "5.0 (X11)", + win: "5.0 (Windows)", + macosx: "5.0 (Macintosh)", + android: `5.0 (Android ${osVersion})`, + other: "5.0 (X11)", +}; + +const SPOOFED_APPVERSION = { + linux: "5.0 (X11)", + win: "5.0 (Windows)", + macosx: "5.0 (Macintosh)", + android: "5.0 (Android 10)", + other: "5.0 (X11)", +}; + +let cpuArch = Services.sysinfo.get("arch"); +if (cpuArch == "x86-64") { + // Convert CPU arch "x86-64" to "x86_64" used in Linux and Android UAs. + cpuArch = "x86_64"; +} + +const DEFAULT_PLATFORM = { + linux: `Linux ${cpuArch}`, + win: "Win32", + macosx: "MacIntel", + android: `Linux ${cpuArch}`, + other: `Linux ${cpuArch}`, +}; + +const SPOOFED_PLATFORM = { + linux: "Linux x86_64", + win: "Win32", + macosx: "MacIntel", + android: "Linux aarch64", + other: "Linux x86_64", +}; + +// If comparison with the WindowsOscpu value fails in the future, it's time to +// evaluate if exposing a new Windows version to the Web is appropriate. See +// https://bugzilla.mozilla.org/show_bug.cgi?id=1693295 +let WindowsOscpu = null; +if (AppConstants.platform == "win") { + let isWin11 = WindowsVersionInfo.get().buildNumber >= 22000; + WindowsOscpu = + cpuArch == "x86_64" || (cpuArch == "aarch64" && isWin11) + ? `Windows NT ${osVersion}; Win64; x64` + : `Windows NT ${osVersion}`; +} + +const DEFAULT_OSCPU = { + linux: `Linux ${cpuArch}`, + win: WindowsOscpu, + macosx: `Intel Mac OS X ${osVersion}`, + android: `Linux ${cpuArch}`, + other: `Linux ${cpuArch}`, +}; + +const SPOOFED_OSCPU = { + linux: "Linux x86_64", + win: "Windows NT 10.0; Win64; x64", + macosx: "Intel Mac OS X 10.15", + android: "Linux aarch64", + other: "Linux x86_64", +}; + +const DEFAULT_UA_OS = { + linux: `X11; Linux ${cpuArch}`, + win: WindowsOscpu, + macosx: `Macintosh; Intel Mac OS X ${osVersion}`, + android: `Android ${osVersion}; Mobile`, + other: `X11; Linux ${cpuArch}`, +}; + +const SPOOFED_UA_NAVIGATOR_OS = { + linux: "X11; Linux x86_64", + win: "Windows NT 10.0; Win64; x64", + macosx: "Macintosh; Intel Mac OS X 10.15", + android: "Android 10; Mobile", + other: "X11; Linux x86_64", +}; +const SPOOFED_UA_HTTPHEADER_OS = { + linux: "Windows NT 10.0", + win: "Windows NT 10.0", + macosx: "Windows NT 10.0", + android: "Android 10; Mobile", + other: "Windows NT 10.0", +}; +const SPOOFED_HW_CONCURRENCY = 2; + +const CONST_APPCODENAME = "Mozilla"; +const CONST_APPNAME = "Netscape"; +const CONST_PRODUCT = "Gecko"; +const CONST_PRODUCTSUB = "20100101"; +const CONST_VENDOR = ""; +const CONST_VENDORSUB = ""; + +const appVersion = parseInt(Services.appinfo.version); +const rvVersion = + parseInt( + Services.prefs.getIntPref("network.http.useragent.forceRVOnly", 0), + 0 + ) || appVersion; +const spoofedVersion = AppConstants.platform == "android" ? "102" : appVersion; + +const LEGACY_UA_GECKO_TRAIL = "20100101"; + +const DEFAULT_UA_GECKO_TRAIL = { + linux: LEGACY_UA_GECKO_TRAIL, + win: LEGACY_UA_GECKO_TRAIL, + macosx: LEGACY_UA_GECKO_TRAIL, + android: `${appVersion}.0`, + other: LEGACY_UA_GECKO_TRAIL, +}; + +const SPOOFED_UA_GECKO_TRAIL = { + linux: LEGACY_UA_GECKO_TRAIL, + win: LEGACY_UA_GECKO_TRAIL, + macosx: LEGACY_UA_GECKO_TRAIL, + android: `${spoofedVersion}.0`, + other: LEGACY_UA_GECKO_TRAIL, +}; + +async function testUserAgentHeader() { + const BASE = + "http://mochi.test:8888/browser/browser/components/resistfingerprinting/test/browser/"; + const TEST_TARGET_URL = `${BASE}file_navigator_header.sjs?`; + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TEST_TARGET_URL + ); + + let result = await SpecialPowers.spawn(tab.linkedBrowser, [], function() { + return content.document.body.textContent; + }); + + is( + result, + expectedResults.userAgentHeader, + `Checking ${expectedResults.testDesc} User Agent HTTP Header.` + ); + + BrowserTestUtils.removeTab(tab); +} + +async function testNavigator() { + // Open a tab to collect result. + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TEST_PATH + "file_navigator.html" + ); + + let result = await SpecialPowers.spawn(tab.linkedBrowser, [], function() { + return content.document.getElementById("result").innerHTML; + }); + + result = JSON.parse(result); + + let testDesc = expectedResults.testDesc; + + is( + result.appVersion, + expectedResults.appVersion, + `Checking ${testDesc} navigator.appVersion.` + ); + is( + result.platform, + expectedResults.platform, + `Checking ${testDesc} navigator.platform.` + ); + is( + result.userAgent, + expectedResults.userAgentNavigator, + `Checking ${testDesc} navigator.userAgent.` + ); + is( + result.mimeTypesLength, + expectedResults.mimeTypesLength, + `Navigator.mimeTypes has a length of ${expectedResults.mimeTypesLength}.` + ); + is( + result.pluginsLength, + expectedResults.pluginsLength, + `Navigator.plugins has a length of ${expectedResults.pluginsLength}.` + ); + is( + result.oscpu, + expectedResults.oscpu, + `Checking ${testDesc} navigator.oscpu.` + ); + is( + result.hardwareConcurrency, + expectedResults.hardwareConcurrency, + `Checking ${testDesc} navigator.hardwareConcurrency.` + ); + + is( + result.appCodeName, + CONST_APPCODENAME, + "Navigator.appCodeName reports correct constant value." + ); + is( + result.appName, + CONST_APPNAME, + "Navigator.appName 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." + ); + + 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 SpecialPowers.spawn( + tab.linkedBrowser, + [], + 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); + + let testDesc = expectedResults.testDesc; + + is( + result.appVersion, + expectedResults.appVersion, + `Checking ${testDesc} worker navigator.appVersion.` + ); + is( + result.platform, + expectedResults.platform, + `Checking ${testDesc} worker navigator.platform.` + ); + is( + result.userAgent, + expectedResults.userAgentNavigator, + `Checking ${testDesc} worker navigator.userAgent.` + ); + is( + result.hardwareConcurrency, + expectedResults.hardwareConcurrency, + `Checking ${testDesc} worker navigator.hardwareConcurrency.` + ); + + is( + result.appCodeName, + CONST_APPCODENAME, + "worker Navigator.appCodeName reports correct constant value." + ); + is( + result.appName, + CONST_APPNAME, + "worker Navigator.appName reports correct constant value." + ); + is( + result.product, + CONST_PRODUCT, + "worker Navigator.product reports correct constant value." + ); + + BrowserTestUtils.removeTab(tab); + + // Ensure the content process is shut down entirely before we start the next + // test in Fission. + if (SpecialPowers.useRemoteSubframes) { + await new Promise(resolve => { + let observer = (subject, topic, data) => { + if (topic === "ipc:content-shutdown") { + Services.obs.removeObserver(observer, "ipc:content-shutdown"); + resolve(); + } + }; + Services.obs.addObserver(observer, "ipc:content-shutdown"); + }); + } +} + +add_task(async function setupDefaultUserAgent() { + let defaultUserAgent = `Mozilla/5.0 (${ + DEFAULT_UA_OS[AppConstants.platform] + }; rv:${rvVersion}.0) Gecko/${ + DEFAULT_UA_GECKO_TRAIL[AppConstants.platform] + } Firefox/${appVersion}.0`; + expectedResults = { + testDesc: "default", + appVersion: DEFAULT_APPVERSION[AppConstants.platform], + hardwareConcurrency: navigator.hardwareConcurrency, + mimeTypesLength: 2, + oscpu: DEFAULT_OSCPU[AppConstants.platform], + platform: DEFAULT_PLATFORM[AppConstants.platform], + pluginsLength: 5, + userAgentNavigator: defaultUserAgent, + userAgentHeader: defaultUserAgent, + }; + + await testNavigator(); + + await testUserAgentHeader(); + + await testWorkerNavigator(); +}); + +add_task(async function setupRFPExemptions() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.net, mochi.test", + ], + ], + }); + + let defaultUserAgent = `Mozilla/5.0 (${ + DEFAULT_UA_OS[AppConstants.platform] + }; rv:${rvVersion}.0) Gecko/${ + DEFAULT_UA_GECKO_TRAIL[AppConstants.platform] + } Firefox/${appVersion}.0`; + + expectedResults = { + testDesc: "RFP Exempted Domain", + appVersion: DEFAULT_APPVERSION[AppConstants.platform], + hardwareConcurrency: navigator.hardwareConcurrency, + mimeTypesLength: 2, + oscpu: DEFAULT_OSCPU[AppConstants.platform], + platform: DEFAULT_PLATFORM[AppConstants.platform], + pluginsLength: 5, + userAgentNavigator: defaultUserAgent, + userAgentHeader: defaultUserAgent, + }; + + await testNavigator(); + + await testUserAgentHeader(); + + await testWorkerNavigator(); + + // Pop exempted domains + await SpecialPowers.popPrefEnv(); +}); + +add_task(async function setupResistFingerprinting() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]], + }); + + let spoofedGeckoTrail = SPOOFED_UA_GECKO_TRAIL[AppConstants.platform]; + + let spoofedUserAgentNavigator = `Mozilla/5.0 (${ + SPOOFED_UA_NAVIGATOR_OS[AppConstants.platform] + }; rv:${spoofedVersion}.0) Gecko/${spoofedGeckoTrail} Firefox/${spoofedVersion}.0`; + + let spoofedUserAgentHeader = `Mozilla/5.0 (${ + SPOOFED_UA_HTTPHEADER_OS[AppConstants.platform] + }; rv:${spoofedVersion}.0) Gecko/${spoofedGeckoTrail} Firefox/${spoofedVersion}.0`; + + expectedResults = { + testDesc: "spoofed", + appVersion: SPOOFED_APPVERSION[AppConstants.platform], + hardwareConcurrency: SPOOFED_HW_CONCURRENCY, + mimeTypesLength: 2, + oscpu: SPOOFED_OSCPU[AppConstants.platform], + platform: SPOOFED_PLATFORM[AppConstants.platform], + pluginsLength: 5, + userAgentNavigator: spoofedUserAgentNavigator, + userAgentHeader: spoofedUserAgentHeader, + }; + + await testNavigator(); + + await testUserAgentHeader(); + + 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"], + ], + }); + + await testNavigator(); + + await testWorkerNavigator(); + + await testUserAgentHeader(); + + // Pop general.appname.override etc + await SpecialPowers.popPrefEnv(); + + // Pop privacy.resistFingerprinting + await SpecialPowers.popPrefEnv(); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_navigator_iframes.js b/browser/components/resistfingerprinting/test/browser/browser_navigator_iframes.js new file mode 100644 index 0000000000..1cdcaea7a9 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_navigator_iframes.js @@ -0,0 +1,487 @@ +/** + * Bug 1737829 and Bug 1770498 - A test case for making sure the navigator object has been + * spoofed/disabled correctly respecting cross-origin resources, iframes + * and exemption behavior. + * + * This test only tests values in the iframe, it does not test them on the framer + * + * Covers the following cases: + * - RFP is disabled entirely + * - RFP is enabled entirely + + * - (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource + * - (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource + + * - (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource + * - (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource + + * - (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource + * - (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource + * + * - (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource + * - (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource + */ + +"use strict"; + +ChromeUtils.defineESModuleGetters(this, { + AppConstants: "resource://gre/modules/AppConstants.sys.mjs", +}); + +ChromeUtils.defineModuleGetter( + this, + "WindowsVersionInfo", + "resource://gre/modules/components-utils/WindowsVersionInfo.jsm" +); + +let osVersion = Services.sysinfo.get("version"); +if (AppConstants.platform == "macosx") { + // Convert Darwin version to macOS version: 19.x.x -> 10.15 etc. + // https://en.wikipedia.org/wiki/Darwin_%28operating_system%29 + let DarwinVersionParts = osVersion.split("."); + let DarwinMajorVersion = +DarwinVersionParts[0]; + let macOsMinorVersion = DarwinMajorVersion - 4; + if (macOsMinorVersion > 15) { + macOsMinorVersion = 15; + } + osVersion = `10.${macOsMinorVersion}`; +} + +const DEFAULT_APPVERSION = { + linux: "5.0 (X11)", + win: "5.0 (Windows)", + macosx: "5.0 (Macintosh)", + android: `5.0 (Android ${osVersion})`, + other: "5.0 (X11)", +}; + +const SPOOFED_APPVERSION = { + linux: "5.0 (X11)", + win: "5.0 (Windows)", + macosx: "5.0 (Macintosh)", + android: "5.0 (Android 10)", + other: "5.0 (X11)", +}; + +let cpuArch = Services.sysinfo.get("arch"); +if (cpuArch == "x86-64") { + // Convert CPU arch "x86-64" to "x86_64" used in Linux and Android UAs. + cpuArch = "x86_64"; +} + +const DEFAULT_PLATFORM = { + linux: `Linux ${cpuArch}`, + win: "Win32", + macosx: "MacIntel", + android: `Linux ${cpuArch}`, + other: `Linux ${cpuArch}`, +}; + +const SPOOFED_PLATFORM = { + linux: "Linux x86_64", + win: "Win32", + macosx: "MacIntel", + android: "Linux aarch64", + other: "Linux x86_64", +}; + +// If comparison with the WindowsOscpu value fails in the future, it's time to +// evaluate if exposing a new Windows version to the Web is appropriate. See +// https://bugzilla.mozilla.org/show_bug.cgi?id=1693295 +let WindowsOscpu = null; +if (AppConstants.platform == "win") { + let isWin11 = WindowsVersionInfo.get().buildNumber >= 22000; + WindowsOscpu = + cpuArch == "x86_64" || (cpuArch == "aarch64" && isWin11) + ? `Windows NT ${osVersion}; Win64; x64` + : `Windows NT ${osVersion}`; +} + +const DEFAULT_OSCPU = { + linux: `Linux ${cpuArch}`, + win: WindowsOscpu, + macosx: `Intel Mac OS X ${osVersion}`, + android: `Linux ${cpuArch}`, + other: `Linux ${cpuArch}`, +}; + +const SPOOFED_OSCPU = { + linux: "Linux x86_64", + win: "Windows NT 10.0; Win64; x64", + macosx: "Intel Mac OS X 10.15", + android: "Linux aarch64", + other: "Linux x86_64", +}; + +const DEFAULT_UA_OS = { + linux: `X11; Linux ${cpuArch}`, + win: WindowsOscpu, + macosx: `Macintosh; Intel Mac OS X ${osVersion}`, + android: `Android ${osVersion}; Mobile`, + other: `X11; Linux ${cpuArch}`, +}; + +const SPOOFED_UA_NAVIGATOR_OS = { + linux: "X11; Linux x86_64", + win: "Windows NT 10.0; Win64; x64", + macosx: "Macintosh; Intel Mac OS X 10.15", + android: "Android 10; Mobile", + other: "X11; Linux x86_64", +}; +const SPOOFED_UA_HTTPHEADER_OS = { + linux: "Windows NT 10.0", + win: "Windows NT 10.0", + macosx: "Windows NT 10.0", + android: "Android 10; Mobile", + other: "Windows NT 10.0", +}; +const SPOOFED_HW_CONCURRENCY = 2; + +const CONST_APPCODENAME = "Mozilla"; +const CONST_APPNAME = "Netscape"; +const CONST_PRODUCT = "Gecko"; +const CONST_PRODUCTSUB = "20100101"; +const CONST_VENDOR = ""; +const CONST_VENDORSUB = ""; + +const appVersion = parseInt(Services.appinfo.version); +const rvVersion = + parseInt( + Services.prefs.getIntPref("network.http.useragent.forceRVOnly", 0), + 0 + ) || appVersion; +const spoofedVersion = AppConstants.platform == "android" ? "102" : appVersion; + +const LEGACY_UA_GECKO_TRAIL = "20100101"; + +const DEFAULT_UA_GECKO_TRAIL = { + linux: LEGACY_UA_GECKO_TRAIL, + win: LEGACY_UA_GECKO_TRAIL, + macosx: LEGACY_UA_GECKO_TRAIL, + android: `${appVersion}.0`, + other: LEGACY_UA_GECKO_TRAIL, +}; + +const SPOOFED_UA_GECKO_TRAIL = { + linux: LEGACY_UA_GECKO_TRAIL, + win: LEGACY_UA_GECKO_TRAIL, + macosx: LEGACY_UA_GECKO_TRAIL, + android: `${spoofedVersion}.0`, + other: LEGACY_UA_GECKO_TRAIL, +}; + +const DEFAULT_HARDWARE_CONCURRENCY = navigator.hardwareConcurrency; + +// ============================================================================================= +// ============================================================================================= + +async function testNavigator(result, expectedResults, extraData) { + let testDesc = extraData.testDesc; + + is( + result.appVersion, + expectedResults.appVersion, + `Checking ${testDesc} navigator.appVersion.` + ); + is( + result.platform, + expectedResults.platform, + `Checking ${testDesc} navigator.platform.` + ); + is( + result.userAgent, + expectedResults.userAgentNavigator, + `Checking ${testDesc} navigator.userAgent.` + ); + is( + result.userAgentHTTPHeader, + expectedResults.userAgentHTTPHeader, + `Checking ${testDesc} userAgentHTTPHeader.` + ); + is( + result.framer_crossOrigin_userAgentHTTPHeader, + expectedResults.framer_crossOrigin_userAgentHTTPHeader, + `Checking ${testDesc} framer contacting cross-origin userAgentHTTPHeader.` + ); + is( + result.framee_crossOrigin_userAgentHTTPHeader, + expectedResults.framee_crossOrigin_userAgentHTTPHeader, + `Checking ${testDesc} framee contacting cross-origin userAgentHTTPHeader.` + ); + is( + result.mimeTypesLength, + expectedResults.mimeTypesLength, + `Navigator.mimeTypes has a length of ${expectedResults.mimeTypesLength}.` + ); + is( + result.pluginsLength, + expectedResults.pluginsLength, + `Navigator.plugins has a length of ${expectedResults.pluginsLength}.` + ); + is( + result.oscpu, + expectedResults.oscpu, + `Checking ${testDesc} navigator.oscpu.` + ); + is( + result.hardwareConcurrency, + expectedResults.hardwareConcurrency, + `Checking ${testDesc} navigator.hardwareConcurrency.` + ); + + is( + result.appCodeName, + CONST_APPCODENAME, + "Navigator.appCodeName reports correct constant value." + ); + is( + result.appName, + CONST_APPNAME, + "Navigator.appName 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." + ); + + is( + result.worker_appVersion, + expectedResults.appVersion, + `Checking ${testDesc} worker navigator.appVersion.` + ); + is( + result.worker_platform, + expectedResults.platform, + `Checking ${testDesc} worker navigator.platform.` + ); + is( + result.worker_userAgent, + expectedResults.userAgentNavigator, + `Checking ${testDesc} worker navigator.userAgent.` + ); + is( + result.worker_hardwareConcurrency, + expectedResults.hardwareConcurrency, + `Checking ${testDesc} worker navigator.hardwareConcurrency.` + ); + + is( + result.worker_appCodeName, + CONST_APPCODENAME, + "worker Navigator.appCodeName reports correct constant value." + ); + is( + result.worker_appName, + CONST_APPNAME, + "worker Navigator.appName reports correct constant value." + ); + is( + result.worker_product, + CONST_PRODUCT, + "worker Navigator.product reports correct constant value." + ); +} + +const defaultUserAgent = `Mozilla/5.0 (${ + DEFAULT_UA_OS[AppConstants.platform] +}; rv:${rvVersion}.0) Gecko/${ + DEFAULT_UA_GECKO_TRAIL[AppConstants.platform] +} Firefox/${appVersion}.0`; + +const spoofedUserAgentNavigator = `Mozilla/5.0 (${ + SPOOFED_UA_NAVIGATOR_OS[AppConstants.platform] +}; rv:${appVersion}.0) Gecko/${ + SPOOFED_UA_GECKO_TRAIL[AppConstants.platform] +} Firefox/${appVersion}.0`; + +const spoofedUserAgentHeader = `Mozilla/5.0 (${ + SPOOFED_UA_HTTPHEADER_OS[AppConstants.platform] +}; rv:${appVersion}.0) Gecko/${ + SPOOFED_UA_GECKO_TRAIL[AppConstants.platform] +} Firefox/${appVersion}.0`; + +// The following are convenience objects that allow you to quickly see what is +// and is not modified from a logical set of values. +// Be sure to always use `let expectedResults = JSON.parse(JSON.stringify(allNotSpoofed))` to do a +// deep copy and avoiding corrupting the original 'const' object +const allNotSpoofed = { + appVersion: DEFAULT_APPVERSION[AppConstants.platform], + hardwareConcurrency: navigator.hardwareConcurrency, + mimeTypesLength: 2, + oscpu: DEFAULT_OSCPU[AppConstants.platform], + platform: DEFAULT_PLATFORM[AppConstants.platform], + pluginsLength: 5, + userAgentNavigator: defaultUserAgent, + userAgentHTTPHeader: defaultUserAgent, + framer_crossOrigin_userAgentHTTPHeader: defaultUserAgent, + framee_crossOrigin_userAgentHTTPHeader: defaultUserAgent, +}; +const allSpoofed = { + appVersion: SPOOFED_APPVERSION[AppConstants.platform], + hardwareConcurrency: SPOOFED_HW_CONCURRENCY, + mimeTypesLength: 2, + oscpu: SPOOFED_OSCPU[AppConstants.platform], + platform: SPOOFED_PLATFORM[AppConstants.platform], + pluginsLength: 5, + userAgentNavigator: spoofedUserAgentNavigator, + userAgentHTTPHeader: spoofedUserAgentHeader, + framer_crossOrigin_userAgentHTTPHeader: spoofedUserAgentHeader, + framee_crossOrigin_userAgentHTTPHeader: spoofedUserAgentHeader, +}; + +const framer_domain = "example.com"; +const iframe_domain = "example.org"; +const cross_origin_domain = "example.net"; +const uri = `https://${framer_domain}/browser/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html`; + +requestLongerTimeout(2); + +let expectedResults = {}; + +expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); +add_task( + partial( + defaultsTest, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +expectedResults = JSON.parse(JSON.stringify(allSpoofed)); +add_task( + partial( + simpleRFPTest, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +// (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource +expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); +add_task( + partial( + testA, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +// (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource +expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); +add_task( + partial( + testB, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +// (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource +expectedResults = JSON.parse(JSON.stringify(allSpoofed)); +expectedResults.framer_crossOrigin_userAgentHTTPHeader = defaultUserAgent; +expectedResults.framee_crossOrigin_userAgentHTTPHeader = spoofedUserAgentHeader; +add_task( + partial( + testC, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +// (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource +expectedResults = JSON.parse(JSON.stringify(allSpoofed)); +expectedResults.framer_crossOrigin_userAgentHTTPHeader = defaultUserAgent; +expectedResults.framee_crossOrigin_userAgentHTTPHeader = spoofedUserAgentHeader; +add_task( + partial( + testD, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +// (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource +expectedResults = JSON.parse(JSON.stringify(allSpoofed)); +add_task( + partial( + testE, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +// (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource +expectedResults = JSON.parse(JSON.stringify(allSpoofed)); +add_task( + partial( + testF, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +// (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource +expectedResults = JSON.parse(JSON.stringify(allSpoofed)); +add_task( + partial( + testG, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); + +// (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource +expectedResults = JSON.parse(JSON.stringify(allSpoofed)); +add_task( + partial( + testH, + uri, + iframe_domain, + cross_origin_domain, + testNavigator, + expectedResults + ) +); diff --git a/browser/components/resistfingerprinting/test/browser/browser_netInfo.js b/browser/components/resistfingerprinting/test/browser/browser_netInfo.js new file mode 100644 index 0000000000..cdce9dd2d5 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_netInfo.js @@ -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(); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js b/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js new file mode 100644 index 0000000000..3f1561c057 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js @@ -0,0 +1,213 @@ +// ================================================================================================ +// ================================================================================================ +add_task(async function runRPTests() { + let runTests = async function(data) { + let timerlist = data.list; + let expectedPrecision = data.precision; + // eslint beleives that isrounded is available in this scope, but if you + // remove the assignment, you will see it is not + // eslint-disable-next-line + let isRounded = eval(data.isRoundedFunc); + + ok( + isRounded(content.performance.timeOrigin, expectedPrecision), + `For resistFingerprinting, performance.timeOrigin is not correctly rounded: ` + + content.performance.timeOrigin + ); + + // Check that the performance timing API is correctly spoofed. In + // particular, check if domainLookupStart and domainLookupEnd return + // fetchStart, and if everything else is clamped to the expected precision. + for (let time of timerlist) { + if (time == "domainLookupStart" || time == "domainLookupEnd") { + is( + content.performance.timing[time], + content.performance.timing.fetchStart, + `For resistFingerprinting, the timing(${time}) is not correctly spoofed.` + ); + } else { + ok( + isRounded(content.performance.timing[time], expectedPrecision), + `For resistFingerprinting with expected precision ` + + expectedPrecision + + `, the timing(${time}) is not correctly rounded: ` + + content.performance.timing[time] + ); + } + } + + // Try to add some entries. + content.performance.mark("Test"); + content.performance.mark("Test-End"); + content.performance.measure("Test-Measure", "Test", "Test-End"); + + // Check that no entries for performance.getEntries/getEntriesByType/getEntriesByName. + is( + content.performance.getEntries().length, + 0, + "For resistFingerprinting, there should be no entries for performance.getEntries()" + ); + is( + content.performance.getEntriesByType("resource").length, + 0, + "For resistFingerprinting, there should be no entries for performance.getEntriesByType()" + ); + is( + content.performance.getEntriesByName("Test", "mark").length, + 0, + "For resistFingerprinting, there should be no entries for performance.getEntriesByName()" + ); + }; + + await setupPerformanceAPISpoofAndDisableTest( + true, + true, + false, + 200, + runTests + ); + await setupPerformanceAPISpoofAndDisableTest( + true, + true, + false, + 100, + runTests + ); + await setupPerformanceAPISpoofAndDisableTest( + true, + false, + false, + 13, + runTests + ); + await setupPerformanceAPISpoofAndDisableTest( + true, + false, + false, + 0.13, + runTests + ); + await setupPerformanceAPISpoofAndDisableTest(true, true, true, 100, runTests); + await setupPerformanceAPISpoofAndDisableTest(true, false, true, 13, runTests); + await setupPerformanceAPISpoofAndDisableTest( + true, + false, + true, + 0.13, + runTests + ); +}); + +// ================================================================================================ +// ================================================================================================ +add_task(async function runRTPTests() { + let runTests = async function(data) { + let timerlist = data.list; + let expectedPrecision = data.precision; + // eslint beleives that isrounded is available in this scope, but if you + // remove the assignment, you will see it is not + // eslint-disable-next-line + let isRounded = eval(data.isRoundedFunc); + + ok( + isRounded(content.performance.timeOrigin, expectedPrecision), + `For reduceTimerPrecision, performance.timeOrigin is not correctly rounded: ` + + content.performance.timeOrigin + ); + + // Check that whether the performance timing API is correctly spoofed. + for (let time of timerlist) { + ok( + isRounded(content.performance.timing[time], expectedPrecision), + `For reduceTimerPrecision(` + + expectedPrecision + + `), the timing(${time}) is not correctly rounded: ` + + content.performance.timing[time] + ); + } + + // Try to add some entries. + content.performance.mark("Test"); + content.performance.mark("Test-End"); + content.performance.measure("Test-Measure", "Test", "Test-End"); + + // Check the entries for performance.getEntries/getEntriesByType/getEntriesByName. + await new Promise(resolve => { + const paintObserver = new content.PerformanceObserver(() => { + resolve(); + }); + paintObserver.observe({ type: "paint", buffered: true }); + }); + + is( + content.performance.getEntries().length, + 5, + "For reduceTimerPrecision, there should be 4 entries for performance.getEntries()" + // PerformancePaintTiming, PerformanceNavigationTiming, PerformanceMark, PerformanceMark, PerformanceMeasure + ); + for (var i = 0; i < 5; i++) { + let startTime = content.performance.getEntries()[i].startTime; + let duration = content.performance.getEntries()[i].duration; + ok( + isRounded(startTime, expectedPrecision), + "For reduceTimerPrecision(" + + expectedPrecision + + "), performance.getEntries(" + + i + + ").startTime is not rounded: " + + startTime + ); + ok( + isRounded(duration, expectedPrecision), + "For reduceTimerPrecision(" + + expectedPrecision + + "), performance.getEntries(" + + i + + ").duration is not rounded: " + + duration + ); + } + is( + content.performance.getEntriesByType("mark").length, + 2, + "For reduceTimerPrecision, there should be 2 entries for performance.getEntriesByType()" + ); + is( + content.performance.getEntriesByName("Test", "mark").length, + 1, + "For reduceTimerPrecision, there should be 1 entry for performance.getEntriesByName()" + ); + content.performance.clearMarks(); + content.performance.clearMeasures(); + content.performance.clearResourceTimings(); + }; + + await setupPerformanceAPISpoofAndDisableTest( + false, + true, + false, + 100, + runTests + ); + await setupPerformanceAPISpoofAndDisableTest( + false, + true, + false, + 13, + runTests + ); + await setupPerformanceAPISpoofAndDisableTest( + false, + true, + false, + 0.13, + runTests + ); + await setupPerformanceAPISpoofAndDisableTest( + false, + true, + true, + 0.005, + runTests + ); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_performanceAPIWorkers.js b/browser/components/resistfingerprinting/test/browser/browser_performanceAPIWorkers.js new file mode 100644 index 0000000000..1385daaf6e --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_performanceAPIWorkers.js @@ -0,0 +1,79 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// ================================================================================================ +// ================================================================================================ +let runWorkerTest = async function(data) { + let expectedPrecision = data.precision; + let workerCall = data.workerCall; + await new Promise(resolve => { + let worker = new content.Worker("file_workerPerformance.js"); + worker.onmessage = function(e) { + if (e.data.type == "status") { + ok(e.data.status, e.data.msg); + } else if (e.data.type == "finish") { + worker.terminate(); + resolve(); + } else { + ok(false, "Unknown message type"); + worker.terminate(); + resolve(); + } + }; + worker.postMessage({ type: workerCall, precision: expectedPrecision }); + }); +}; + +add_task(async function runRPTestsForWorker() { + await setupPerformanceAPISpoofAndDisableTest( + true, + true, + false, + 100, + runWorkerTest, + "runRPTests" + ); + await setupPerformanceAPISpoofAndDisableTest( + true, + false, + false, + 13, + runWorkerTest, + "runRPTests" + ); + await setupPerformanceAPISpoofAndDisableTest( + true, + true, + false, + 0.13, + runWorkerTest, + "runRPTests" + ); +}); + +add_task(async function runRTPTestsForWorker() { + await setupPerformanceAPISpoofAndDisableTest( + false, + true, + false, + 100, + runWorkerTest, + "runRTPTests" + ); + await setupPerformanceAPISpoofAndDisableTest( + false, + true, + false, + 13, + runWorkerTest, + "runRTPTests" + ); + await setupPerformanceAPISpoofAndDisableTest( + false, + true, + false, + 0.13, + runWorkerTest, + "runRTPTests" + ); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_reduceTimePrecision_iframes.js b/browser/components/resistfingerprinting/test/browser/browser_reduceTimePrecision_iframes.js new file mode 100644 index 0000000000..bb0a967224 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_reduceTimePrecision_iframes.js @@ -0,0 +1,270 @@ +/** + * This test only tests values in the iframe, it does not test them on the framer + * + * Covers the following cases: + * - RFP is disabled entirely + * - RFP is enabled entirely + + * - (A) RFP is exempted on the framer and framee + * - (B) RFP is exempted on the framer and framee + + * - (C) RFP is exempted on the framer but not the framee + * - (D) RFP is exempted on the framer but not the framee + + * - (E) RFP is not exempted on the framer nor the framee + * - (F) RFP is not exempted on the framer nor the framee + * + * - (G) RFP is not exempted on the framer but is on the framee + * - (H) RFP is not exempted on the framer but is on the framee + */ + +"use strict"; + +requestLongerTimeout(3); + +ChromeUtils.defineModuleGetter( + this, + "AppConstants", + "resource://gre/modules/AppConstants.jsm" +); + +// ============================================================================================= +// ============================================================================================= + +async function testTimePrecision(results, expectedResults, extraData) { + let testDesc = extraData.testDesc; + let precision = undefined; + + if (!expectedResults.shouldRFPApply) { + precision = extraData.RTP_Precision; + } else { + precision = extraData.RFP_Precision; + } + + for (let result of results) { + let isRounded = isTimeValueRounded(result.value, precision); + + ok( + isRounded, + "Test: " + + testDesc + + " - '" + + "'" + + result.name + + "' should be rounded to nearest " + + precision + + " ms; saw " + + result.value + ); + } +} + +const RFP_TIME_ATOM_MS = 16.667; +const framer_domain = "example.com"; +const iframe_domain = "example.org"; +const cross_origin_domain = "example.net"; +const uri = `https://${framer_domain}/browser/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html`; + +// The first three variables are defined here; and then set for test banks below. +let extraData = {}; +let extraPrefs = {}; +let precision = 100; +let expectedResults = {}; // In this test, we don't have explicit expected values, but rather we expect them to be rounded + +// ======================================================================================================================== +// Create a function that defines all the tests +function addAllTests(extraData_, extraPrefs_) { + add_task( + partial( + defaultsTest, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + add_task( + partial( + simpleRFPTest, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource + add_task( + partial( + testA, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource + add_task( + partial( + testB, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource + add_task( + partial( + testC, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource + add_task( + partial( + testD, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource + add_task( + partial( + testE, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource + add_task( + partial( + testF, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource + add_task( + partial( + testG, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); + + // (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource + add_task( + partial( + testH, + uri, + iframe_domain, + cross_origin_domain, + testTimePrecision, + expectedResults, + extraData_, + extraPrefs_ + ) + ); +} + +// ======================================================================================================================== +// First we run through all the tests with RTP's precision set to 100 ms and 133 ms. +// Because 100ms and 133ms are >= RFP's precision of 100ms, _all_ tests results should +// be rounded. +precision = 100; +extraData = { + RFP_Precision: precision, + RTP_Precision: precision, +}; +extraPrefs = [ + [ + "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", + precision * 1000, + ], +]; +addAllTests(extraData, extraPrefs); + +precision = 133; +extraData = { + RFP_Precision: precision, + RTP_Precision: precision, +}; +extraPrefs = [ + [ + "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", + precision * 1000, + ], +]; +addAllTests(extraData, extraPrefs); + +// ======================================================================================================================== +// Then we run through all the tests with the precision set to its normal value. +// This will mean that in some cases we expect RFP to apply and in some we don't. + +precision = RFP_TIME_ATOM_MS; +extraData = { + RFP_Precision: precision, + RTP_Precision: 1, +}; +extraPrefs = []; +addAllTests(extraData, extraPrefs); + +// ======================================================================================================================== +// Finally we run through all the tests with the precision set to an unusual value +// This will mean that in some cases we expect RFP to apply and in some we don't. + +precision = RFP_TIME_ATOM_MS; +extraData = { + RFP_Precision: RFP_TIME_ATOM_MS, + RTP_Precision: 7, +}; +extraPrefs = [ + ["privacy.resistFingerprinting.reduceTimerPrecision.microseconds", 7 * 1000], +]; +addAllTests(extraData, extraPrefs); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_dialogWindow.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_dialogWindow.js new file mode 100644 index 0000000000..57f60f4153 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_dialogWindow.js @@ -0,0 +1,51 @@ +/** + * Bug 1352305 - A test case for dialog windows that it should not be rounded + * even after fingerprinting resistance is enabled. + */ + +async function test_dialog_window() { + let diagWin; + + await new Promise(resolve => { + // Open a dialog window which is not rounded size. + diagWin = window.openDialog( + "about:blank", + null, + "innerWidth=250,innerHeight=350" + ); + + diagWin.addEventListener( + "load", + function() { + resolve(); + }, + { once: true } + ); + }); + + is(diagWin.innerWidth, 250, "The dialog window doesn't have a rounded size."); + is( + diagWin.innerHeight, + 350, + "The dialog window doesn't have a rounded size." + ); + + await BrowserTestUtils.closeWindow(diagWin); +} + +add_setup(async function() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]], + }); +}); + +add_task(test_dialog_window); + +add_task(async function test_dialog_window_without_resistFingerprinting() { + // Test dialog windows with 'privacy.resistFingerprinting' is false. + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", false]], + }); + + await test_dialog_window(); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js new file mode 100644 index 0000000000..aa7290a900 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js @@ -0,0 +1,62 @@ +/* + * Bug 1330882 - A test case for opening new windows as rounded size when + * fingerprinting resistance is enabled. + */ + +const CC = Components.Constructor; + +let gMaxAvailWidth; +let gMaxAvailHeight; + +add_setup(async function() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]], + }); + + // Calculate the maximum available size. + let maxAvailSize = await calcMaximumAvailSize(); + + gMaxAvailWidth = maxAvailSize.maxAvailWidth; + gMaxAvailHeight = maxAvailSize.maxAvailHeight; +}); + +add_task(async function test_new_window() { + // Open a new window. + let win = await BrowserTestUtils.openNewBrowserWindow(); + + // Load a page and verify its window size. + let tab = await BrowserTestUtils.openNewForegroundTab( + win.gBrowser, + TEST_PATH + "file_dummy.html" + ); + + await SpecialPowers.spawn( + tab.linkedBrowser, + [{ gMaxAvailWidth, gMaxAvailHeight }], + async function(input) { + is( + content.screen.width, + input.gMaxAvailWidth, + "The screen.width has a correct rounded value" + ); + is( + content.screen.height, + input.gMaxAvailHeight, + "The screen.height has a correct rounded value" + ); + is( + content.innerWidth, + input.gMaxAvailWidth, + "The window.innerWidth has a correct rounded value" + ); + is( + content.innerHeight, + input.gMaxAvailHeight, + "The window.innerHeight has a correct rounded value" + ); + } + ); + + BrowserTestUtils.removeTab(tab); + await BrowserTestUtils.closeWindow(win); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max_inner.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max_inner.js new file mode 100644 index 0000000000..5d8ed74580 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max_inner.js @@ -0,0 +1,26 @@ +/* + * Bug 1330882 - A test case for opening new windows through window.open() as + * rounded size when fingerprinting resistance is enabled. This test is for + * maximum values. + */ + +OpenTest.run([ + { + settingWidth: 1025, + settingHeight: 1050, + targetWidth: 1000, + targetHeight: 1000, + }, + { + settingWidth: 9999, + settingHeight: 9999, + targetWidth: 1000, + targetHeight: 1000, + }, + { + settingWidth: 999, + settingHeight: 999, + targetWidth: 1000, + targetHeight: 1000, + }, +]); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid_inner.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid_inner.js new file mode 100644 index 0000000000..a3a41829e0 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid_inner.js @@ -0,0 +1,26 @@ +/* + * Bug 1330882 - A test case for opening new windows through window.open() as + * rounded size when fingerprinting resistance is enabled. This test is for + * middle values. + */ + +OpenTest.run([ + { + settingWidth: 600, + settingHeight: 600, + targetWidth: 600, + targetHeight: 600, + }, + { + settingWidth: 599, + settingHeight: 599, + targetWidth: 600, + targetHeight: 600, + }, + { + settingWidth: 401, + settingHeight: 501, + targetWidth: 600, + targetHeight: 600, + }, +]); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min_inner.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min_inner.js new file mode 100644 index 0000000000..f016a560ba --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min_inner.js @@ -0,0 +1,20 @@ +/* + * Bug 1330882 - A test case for opening new windows through window.open() as + * rounded size when fingerprinting resistance is enabled. This test is for + * minimum values. + */ + +OpenTest.run([ + { + settingWidth: 199, + settingHeight: 99, + targetWidth: 200, + targetHeight: 100, + }, + { + settingWidth: 10, + settingHeight: 10, + targetWidth: 200, + targetHeight: 100, + }, +]); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max_inner.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max_inner.js new file mode 100644 index 0000000000..c0147be3fc --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max_inner.js @@ -0,0 +1,34 @@ +/* + * Bug 1330882 - A test case for setting window size through window.innerWidth/Height + * when fingerprinting resistance is enabled. This test is for maximum values. + */ + +WindowSettingTest.run( + [ + { + settingWidth: 1025, + settingHeight: 1050, + targetWidth: 1000, + targetHeight: 1000, + initWidth: 200, + initHeight: 100, + }, + { + settingWidth: 9999, + settingHeight: 9999, + targetWidth: 1000, + targetHeight: 1000, + initWidth: 200, + initHeight: 100, + }, + { + settingWidth: 999, + settingHeight: 999, + targetWidth: 1000, + targetHeight: 1000, + initWidth: 200, + initHeight: 100, + }, + ], + false +); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max_outer.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max_outer.js new file mode 100644 index 0000000000..d06a55b5d2 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max_outer.js @@ -0,0 +1,34 @@ +/* + * Bug 1330882 - A test case for setting window size through window.outerWidth/Height + * when fingerprinting resistance is enabled. This test is for maximum values. + */ + +WindowSettingTest.run( + [ + { + settingWidth: 1025, + settingHeight: 1050, + targetWidth: 1000, + targetHeight: 1000, + initWidth: 200, + initHeight: 100, + }, + { + settingWidth: 9999, + settingHeight: 9999, + targetWidth: 1000, + targetHeight: 1000, + initWidth: 200, + initHeight: 100, + }, + { + settingWidth: 999, + settingHeight: 999, + targetWidth: 1000, + targetHeight: 1000, + initWidth: 200, + initHeight: 100, + }, + ], + true +); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid_inner.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid_inner.js new file mode 100644 index 0000000000..097e911f44 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid_inner.js @@ -0,0 +1,34 @@ +/* + * Bug 1330882 - A test case for setting window size through window.innerWidth/Height + * when fingerprinting resistance is enabled. This test is for middle values. + */ + +WindowSettingTest.run( + [ + { + settingWidth: 600, + settingHeight: 600, + targetWidth: 600, + targetHeight: 600, + initWidth: 200, + initHeight: 100, + }, + { + settingWidth: 599, + settingHeight: 599, + targetWidth: 600, + targetHeight: 600, + initWidth: 200, + initHeight: 100, + }, + { + settingWidth: 401, + settingHeight: 501, + targetWidth: 600, + targetHeight: 600, + initWidth: 200, + initHeight: 100, + }, + ], + false +); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid_outer.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid_outer.js new file mode 100644 index 0000000000..b50d30b33f --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid_outer.js @@ -0,0 +1,34 @@ +/* + * Bug 1330882 - A test case for setting window size through window.outerWidth/Height + * when fingerprinting resistance is enabled. This test is for middle values. + */ + +WindowSettingTest.run( + [ + { + settingWidth: 600, + settingHeight: 600, + targetWidth: 600, + targetHeight: 600, + initWidth: 200, + initHeight: 100, + }, + { + settingWidth: 599, + settingHeight: 599, + targetWidth: 600, + targetHeight: 600, + initWidth: 200, + initHeight: 100, + }, + { + settingWidth: 401, + settingHeight: 501, + targetWidth: 600, + targetHeight: 600, + initWidth: 200, + initHeight: 100, + }, + ], + true +); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min_inner.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min_inner.js new file mode 100644 index 0000000000..f79e46e78f --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min_inner.js @@ -0,0 +1,26 @@ +/* + * Bug 1330882 - A test case for setting window size through window.innerWidth/Height + * when fingerprinting resistance is enabled. This test is for minimum values. + */ + +WindowSettingTest.run( + [ + { + settingWidth: 199, + settingHeight: 99, + targetWidth: 200, + targetHeight: 100, + initWidth: 1000, + initHeight: 1000, + }, + { + settingWidth: 10, + settingHeight: 10, + targetWidth: 200, + targetHeight: 100, + initWidth: 1000, + initHeight: 1000, + }, + ], + false +); diff --git a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min_outer.js b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min_outer.js new file mode 100644 index 0000000000..76b5e40f82 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min_outer.js @@ -0,0 +1,26 @@ +/* + * Bug 1330882 - A test case for setting window size through window.outerWidth/Height + * when fingerprinting resistance is enabled. This test is for minimum values. + */ + +WindowSettingTest.run( + [ + { + settingWidth: 199, + settingHeight: 99, + targetWidth: 200, + targetHeight: 100, + initWidth: 1000, + initHeight: 1000, + }, + { + settingWidth: 10, + settingHeight: 10, + targetWidth: 200, + targetHeight: 100, + initWidth: 1000, + initHeight: 1000, + }, + ], + true +); diff --git a/browser/components/resistfingerprinting/test/browser/browser_spoofing_keyboard_event.js b/browser/components/resistfingerprinting/test/browser/browser_spoofing_keyboard_event.js new file mode 100644 index 0000000000..9703fca055 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_spoofing_keyboard_event.js @@ -0,0 +1,2268 @@ +/** + * Bug 1222285 - A test case for testing whether keyboard events be spoofed correctly + * when fingerprinting resistance is enable. + */ + +const SHOULD_DELIVER_KEYDOWN = 0x1; +const SHOULD_DELIVER_KEYPRESS = 0x2; +const SHOULD_DELIVER_KEYUP = 0x4; +const SHOULD_DELIVER_ALL_FOR_PRINTABLE = + SHOULD_DELIVER_KEYDOWN | SHOULD_DELIVER_KEYPRESS | SHOULD_DELIVER_KEYUP; +const SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE = + SHOULD_DELIVER_KEYDOWN | SHOULD_DELIVER_KEYUP; + +// The test cases for english content. +const TEST_CASES_EN = [ + { + key: "KEY_ArrowDown", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "ArrowDown", + code: "ArrowDown", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_DOWN, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_ArrowLeft", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "ArrowLeft", + code: "ArrowLeft", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_LEFT, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_ArrowRight", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "ArrowRight", + code: "ArrowRight", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_RIGHT, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_ArrowUp", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "ArrowUp", + code: "ArrowUp", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_UP, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_CapsLock", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_KEYDOWN, + result: { + key: "CapsLock", + code: "CapsLock", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_CAPS_LOCK, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_End", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "End", + code: "End", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_END, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_Enter", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "Enter", + code: "Enter", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_RETURN, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_Escape", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "Escape", + code: "Escape", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_ESCAPE, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_Home", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "Home", + code: "Home", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_HOME, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_Meta", + modifiers: { location: KeyboardEvent.DOM_KEY_LOCATION_LEFT, metaKey: true }, + expectedKeyEvent: SHOULD_DELIVER_KEYDOWN, + result: { + key: "Meta", + code: "OSLeft", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_WIN, + location: KeyboardEvent.DOM_KEY_LOCATION_LEFT, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_Meta", + modifiers: { + location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT, + metaKey: true, + }, + expectedKeyEvent: SHOULD_DELIVER_KEYDOWN, + result: { + key: "Meta", + code: "OSRight", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_WIN, + location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_OS", + modifiers: { location: KeyboardEvent.DOM_KEY_LOCATION_LEFT, osKey: true }, + expectedKeyEvent: SHOULD_DELIVER_KEYDOWN, + result: { + key: "OS", + code: "OSLeft", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_WIN, + location: KeyboardEvent.DOM_KEY_LOCATION_LEFT, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_OS", + modifiers: { location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT, osKey: true }, + expectedKeyEvent: SHOULD_DELIVER_KEYDOWN, + result: { + key: "OS", + code: "OSRight", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_WIN, + location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_PageDown", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "PageDown", + code: "PageDown", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_PAGE_DOWN, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_PageUp", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "PageUp", + code: "PageUp", + charCode: 0, + keyCode: KeyboardEvent.DOM_VK_PAGE_UP, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: " ", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: " ", + code: "Space", + charCode: 32, + keyCode: KeyboardEvent.DOM_VK_SPACE, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: ",", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: ",", + code: "Comma", + charCode: 44, + keyCode: KeyboardEvent.DOM_VK_COMMA, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "<", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "<", + code: "Comma", + charCode: 60, + keyCode: KeyboardEvent.DOM_VK_COMMA, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "[", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "[", + code: "BracketLeft", + charCode: 91, + keyCode: KeyboardEvent.DOM_VK_OPEN_BRACKET, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "{", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "{", + code: "BracketLeft", + charCode: 123, + keyCode: KeyboardEvent.DOM_VK_OPEN_BRACKET, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "]", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "]", + code: "BracketRight", + charCode: 93, + keyCode: KeyboardEvent.DOM_VK_CLOSE_BRACKET, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "}", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "}", + code: "BracketRight", + charCode: 125, + keyCode: KeyboardEvent.DOM_VK_CLOSE_BRACKET, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "\\", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "\\", + code: "Backslash", + charCode: 92, + keyCode: KeyboardEvent.DOM_VK_BACK_SLASH, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "|", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "|", + code: "Backslash", + charCode: 124, + keyCode: KeyboardEvent.DOM_VK_BACK_SLASH, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: ";", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: ";", + code: "Semicolon", + charCode: 59, + keyCode: KeyboardEvent.DOM_VK_SEMICOLON, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: ":", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: ":", + code: "Semicolon", + charCode: 58, + keyCode: KeyboardEvent.DOM_VK_SEMICOLON, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: ".", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: ".", + code: "Period", + charCode: 46, + keyCode: KeyboardEvent.DOM_VK_PERIOD, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: ">", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: ">", + code: "Period", + charCode: 62, + keyCode: KeyboardEvent.DOM_VK_PERIOD, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "/", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "/", + code: "Slash", + charCode: 47, + keyCode: KeyboardEvent.DOM_VK_SLASH, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "?", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "?", + code: "Slash", + charCode: 63, + keyCode: KeyboardEvent.DOM_VK_SLASH, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "'", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "'", + code: "Quote", + charCode: 39, + keyCode: KeyboardEvent.DOM_VK_QUOTE, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: '"', + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: '"', + code: "Quote", + charCode: 34, + keyCode: KeyboardEvent.DOM_VK_QUOTE, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "-", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "-", + code: "Minus", + charCode: 45, + keyCode: KeyboardEvent.DOM_VK_HYPHEN_MINUS, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "_", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "_", + code: "Minus", + charCode: 95, + keyCode: KeyboardEvent.DOM_VK_HYPHEN_MINUS, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "=", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "=", + code: "Equal", + charCode: 61, + keyCode: KeyboardEvent.DOM_VK_EQUALS, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "+", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "+", + code: "Equal", + charCode: 43, + keyCode: KeyboardEvent.DOM_VK_EQUALS, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "a", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "a", + code: "KeyA", + charCode: 97, + keyCode: KeyboardEvent.DOM_VK_A, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "A", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "A", + code: "KeyA", + charCode: 65, + keyCode: KeyboardEvent.DOM_VK_A, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "b", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "b", + code: "KeyB", + charCode: 98, + keyCode: KeyboardEvent.DOM_VK_B, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "B", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "B", + code: "KeyB", + charCode: 66, + keyCode: KeyboardEvent.DOM_VK_B, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "c", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "c", + code: "KeyC", + charCode: 99, + keyCode: KeyboardEvent.DOM_VK_C, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "C", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "C", + code: "KeyC", + charCode: 67, + keyCode: KeyboardEvent.DOM_VK_C, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "d", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "d", + code: "KeyD", + charCode: 100, + keyCode: KeyboardEvent.DOM_VK_D, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "D", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "D", + code: "KeyD", + charCode: 68, + keyCode: KeyboardEvent.DOM_VK_D, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "e", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "e", + code: "KeyE", + charCode: 101, + keyCode: KeyboardEvent.DOM_VK_E, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "E", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "E", + code: "KeyE", + charCode: 69, + keyCode: KeyboardEvent.DOM_VK_E, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "f", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "f", + code: "KeyF", + charCode: 102, + keyCode: KeyboardEvent.DOM_VK_F, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "F", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "F", + code: "KeyF", + charCode: 70, + keyCode: KeyboardEvent.DOM_VK_F, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "g", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "g", + code: "KeyG", + charCode: 103, + keyCode: KeyboardEvent.DOM_VK_G, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "G", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "G", + code: "KeyG", + charCode: 71, + keyCode: KeyboardEvent.DOM_VK_G, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "h", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "h", + code: "KeyH", + charCode: 104, + keyCode: KeyboardEvent.DOM_VK_H, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "H", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "H", + code: "KeyH", + charCode: 72, + keyCode: KeyboardEvent.DOM_VK_H, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "i", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "i", + code: "KeyI", + charCode: 105, + keyCode: KeyboardEvent.DOM_VK_I, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "I", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "I", + code: "KeyI", + charCode: 73, + keyCode: KeyboardEvent.DOM_VK_I, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "j", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "j", + code: "KeyJ", + charCode: 106, + keyCode: KeyboardEvent.DOM_VK_J, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "J", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "J", + code: "KeyJ", + charCode: 74, + keyCode: KeyboardEvent.DOM_VK_J, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "k", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "k", + code: "KeyK", + charCode: 107, + keyCode: KeyboardEvent.DOM_VK_K, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "K", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "K", + code: "KeyK", + charCode: 75, + keyCode: KeyboardEvent.DOM_VK_K, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "l", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "l", + code: "KeyL", + charCode: 108, + keyCode: KeyboardEvent.DOM_VK_L, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "L", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "L", + code: "KeyL", + charCode: 76, + keyCode: KeyboardEvent.DOM_VK_L, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "m", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "m", + code: "KeyM", + charCode: 109, + keyCode: KeyboardEvent.DOM_VK_M, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "M", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "M", + code: "KeyM", + charCode: 77, + keyCode: KeyboardEvent.DOM_VK_M, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "n", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "n", + code: "KeyN", + charCode: 110, + keyCode: KeyboardEvent.DOM_VK_N, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "N", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "N", + code: "KeyN", + charCode: 78, + keyCode: KeyboardEvent.DOM_VK_N, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "o", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "o", + code: "KeyO", + charCode: 111, + keyCode: KeyboardEvent.DOM_VK_O, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "O", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "O", + code: "KeyO", + charCode: 79, + keyCode: KeyboardEvent.DOM_VK_O, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "p", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "p", + code: "KeyP", + charCode: 112, + keyCode: KeyboardEvent.DOM_VK_P, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "P", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "P", + code: "KeyP", + charCode: 80, + keyCode: KeyboardEvent.DOM_VK_P, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "q", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "q", + code: "KeyQ", + charCode: 113, + keyCode: KeyboardEvent.DOM_VK_Q, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "Q", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "Q", + code: "KeyQ", + charCode: 81, + keyCode: KeyboardEvent.DOM_VK_Q, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "r", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "r", + code: "KeyR", + charCode: 114, + keyCode: KeyboardEvent.DOM_VK_R, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "R", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "R", + code: "KeyR", + charCode: 82, + keyCode: KeyboardEvent.DOM_VK_R, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "s", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "s", + code: "KeyS", + charCode: 115, + keyCode: KeyboardEvent.DOM_VK_S, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "S", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "S", + code: "KeyS", + charCode: 83, + keyCode: KeyboardEvent.DOM_VK_S, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "t", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "t", + code: "KeyT", + charCode: 116, + keyCode: KeyboardEvent.DOM_VK_T, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "T", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "T", + code: "KeyT", + charCode: 84, + keyCode: KeyboardEvent.DOM_VK_T, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "u", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "u", + code: "KeyU", + charCode: 117, + keyCode: KeyboardEvent.DOM_VK_U, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "U", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "U", + code: "KeyU", + charCode: 85, + keyCode: KeyboardEvent.DOM_VK_U, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "v", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "v", + code: "KeyV", + charCode: 118, + keyCode: KeyboardEvent.DOM_VK_V, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "V", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "V", + code: "KeyV", + charCode: 86, + keyCode: KeyboardEvent.DOM_VK_V, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "w", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "w", + code: "KeyW", + charCode: 119, + keyCode: KeyboardEvent.DOM_VK_W, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "W", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "W", + code: "KeyW", + charCode: 87, + keyCode: KeyboardEvent.DOM_VK_W, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "x", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "x", + code: "KeyX", + charCode: 120, + keyCode: KeyboardEvent.DOM_VK_X, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "X", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "X", + code: "KeyX", + charCode: 88, + keyCode: KeyboardEvent.DOM_VK_X, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "y", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "y", + code: "KeyY", + charCode: 121, + keyCode: KeyboardEvent.DOM_VK_Y, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "Y", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "Y", + code: "KeyY", + charCode: 89, + keyCode: KeyboardEvent.DOM_VK_Y, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "z", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "z", + code: "KeyZ", + charCode: 122, + keyCode: KeyboardEvent.DOM_VK_Z, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "Z", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "Z", + code: "KeyZ", + charCode: 90, + keyCode: KeyboardEvent.DOM_VK_Z, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "0", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "0", + code: "Digit0", + charCode: 48, + keyCode: KeyboardEvent.DOM_VK_0, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "1", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "1", + code: "Digit1", + charCode: 49, + keyCode: KeyboardEvent.DOM_VK_1, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "2", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "2", + code: "Digit2", + charCode: 50, + keyCode: KeyboardEvent.DOM_VK_2, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "3", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "3", + code: "Digit3", + charCode: 51, + keyCode: KeyboardEvent.DOM_VK_3, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "4", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "4", + code: "Digit4", + charCode: 52, + keyCode: KeyboardEvent.DOM_VK_4, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "5", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "5", + code: "Digit5", + charCode: 53, + keyCode: KeyboardEvent.DOM_VK_5, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "6", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "6", + code: "Digit6", + charCode: 54, + keyCode: KeyboardEvent.DOM_VK_6, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "7", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "7", + code: "Digit7", + charCode: 55, + keyCode: KeyboardEvent.DOM_VK_7, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "8", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "8", + code: "Digit8", + charCode: 56, + keyCode: KeyboardEvent.DOM_VK_8, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "9", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "9", + code: "Digit9", + charCode: 57, + keyCode: KeyboardEvent.DOM_VK_9, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: ")", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: ")", + code: "Digit0", + charCode: 41, + keyCode: KeyboardEvent.DOM_VK_0, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "!", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "!", + code: "Digit1", + charCode: 33, + keyCode: KeyboardEvent.DOM_VK_1, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "@", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "@", + code: "Digit2", + charCode: 64, + keyCode: KeyboardEvent.DOM_VK_2, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "#", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "#", + code: "Digit3", + charCode: 35, + keyCode: KeyboardEvent.DOM_VK_3, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "$", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "$", + code: "Digit4", + charCode: 36, + keyCode: KeyboardEvent.DOM_VK_4, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "%", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "%", + code: "Digit5", + charCode: 37, + keyCode: KeyboardEvent.DOM_VK_5, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "^", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "^", + code: "Digit6", + charCode: 94, + keyCode: KeyboardEvent.DOM_VK_6, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "&", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "&", + code: "Digit7", + charCode: 38, + keyCode: KeyboardEvent.DOM_VK_7, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "*", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "*", + code: "Digit8", + charCode: 42, + keyCode: KeyboardEvent.DOM_VK_8, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "(", + modifiers: { shiftKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "(", + code: "Digit9", + charCode: 40, + keyCode: KeyboardEvent.DOM_VK_9, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: true, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F1", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F1", + code: "F1", + charCode: 112, + keyCode: KeyboardEvent.DOM_VK_F1, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F2", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F2", + code: "F2", + charCode: 113, + keyCode: KeyboardEvent.DOM_VK_F2, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F3", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F3", + code: "F3", + charCode: 114, + keyCode: KeyboardEvent.DOM_VK_F3, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F4", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F4", + code: "F4", + charCode: 115, + keyCode: KeyboardEvent.DOM_VK_F4, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F5", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F5", + code: "F5", + charCode: 116, + keyCode: KeyboardEvent.DOM_VK_F5, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F7", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F7", + code: "F7", + charCode: 118, + keyCode: KeyboardEvent.DOM_VK_F7, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F8", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F8", + code: "F8", + charCode: 119, + keyCode: KeyboardEvent.DOM_VK_F8, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F9", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F9", + code: "F9", + charCode: 120, + keyCode: KeyboardEvent.DOM_VK_F9, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F10", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F10", + code: "F10", + charCode: 121, + keyCode: KeyboardEvent.DOM_VK_F10, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F11", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F11", + code: "F11", + charCode: 122, + keyCode: KeyboardEvent.DOM_VK_F11, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "KEY_F12", + modifiers: {}, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "F12", + code: "F12", + charCode: 123, + keyCode: KeyboardEvent.DOM_VK_F12, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, + { + key: "a", + modifiers: { ctrlKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "a", + code: "KeyA", + charCode: 97, + keyCode: KeyboardEvent.DOM_VK_A, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: true, + altGraphKey: false, + }, + }, + { + key: "a", + modifiers: { altKey: true }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE, + result: { + key: "a", + code: "KeyA", + charCode: 97, + keyCode: KeyboardEvent.DOM_VK_A, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }, +]; + +async function testKeyEvent(aTab, aTestCase) { + // Prepare all expected key events. + let testEvents = []; + + if (aTestCase.expectedKeyEvent & SHOULD_DELIVER_KEYDOWN) { + testEvents.push("keydown"); + } + + if (aTestCase.expectedKeyEvent & SHOULD_DELIVER_KEYPRESS) { + testEvents.push("keypress"); + } + + if (aTestCase.expectedKeyEvent & SHOULD_DELIVER_KEYUP) { + testEvents.push("keyup"); + } + + let allKeyEventPromises = []; + + for (let testEvent of testEvents) { + let keyEventPromise = ContentTask.spawn( + aTab.linkedBrowser, + { testEvent, result: aTestCase.result }, + async aInput => { + function verifyKeyboardEvent( + aEvent, + aResult, + aSameKeyCodeAndCharCodeValue + ) { + is( + aEvent.key, + aResult.key, + "KeyboardEvent.key is correctly spoofed." + ); + is( + aEvent.code, + aResult.code, + "KeyboardEvent.code is correctly spoofed." + ); + is( + aEvent.location, + aResult.location, + "KeyboardEvent.location is correctly spoofed." + ); + is( + aEvent.altKey, + aResult.altKey, + "KeyboardEvent.altKey is correctly spoofed." + ); + is( + aEvent.shiftKey, + aResult.shiftKey, + "KeyboardEvent.shiftKey is correctly spoofed." + ); + is( + aEvent.ctrlKey, + aResult.ctrlKey, + "KeyboardEvent.ctrlKey is correctly spoofed." + ); + + // If the charCode is not 0, this is a character. The keyCode will be remained as 0. + // Otherwise, we should check the keyCode. + if (!aSameKeyCodeAndCharCodeValue) { + if (aEvent.charCode != 0) { + is( + aEvent.keyCode, + 0, + "KeyboardEvent.keyCode should be 0 for this case." + ); + is( + aEvent.charCode, + aResult.charCode, + "KeyboardEvent.charCode is correctly spoofed." + ); + } else { + is( + aEvent.keyCode, + aResult.keyCode, + "KeyboardEvent.keyCode is correctly spoofed." + ); + is( + aEvent.charCode, + 0, + "KeyboardEvent.charCode should be 0 for this case." + ); + } + } else if (aResult.charCode) { + is( + aEvent.keyCode, + aResult.charCode, + "KeyboardEvent.keyCode should be same as expected charCode for this case." + ); + is( + aEvent.charCode, + aResult.charCode, + "KeyboardEvent.charCode is correctly spoofed." + ); + } else { + is( + aEvent.keyCode, + aResult.keyCode, + "KeyboardEvent.keyCode is correctly spoofed." + ); + is( + aEvent.charCode, + aResult.keyCode, + "KeyboardEvent.charCode should be same as expected keyCode for this case." + ); + } + + // Check getModifierState(). + is( + aEvent.modifierState.Alt, + aResult.altKey, + "KeyboardEvent.getModifierState() reports a correctly spoofed value for 'Alt'." + ); + is( + aEvent.modifierState.AltGraph, + aResult.altGraphKey, + "KeyboardEvent.getModifierState() reports a correctly spoofed value for 'AltGraph'." + ); + is( + aEvent.modifierState.Shift, + aResult.shiftKey, + `KeyboardEvent.getModifierState() reports a correctly spoofed value for 'Shift'.` + ); + is( + aEvent.modifierState.Control, + aResult.ctrlKey, + `KeyboardEvent.getModifierState() reports a correctly spoofed value for 'Control'.` + ); + } + + let { testEvent: eventType, result } = aInput; + let inputBox = content.document.getElementById("test"); + + // We need to put the real access of event object into the content page instead of + // here, ContentTask.spawn, since the script running here is under chrome privilege. + // So the fingerprinting resistance won't work here. + let resElement = content.document.getElementById("result-" + eventType); + + // First, try to focus on the input box. + await new Promise(resolve => { + if (content.document.activeElement == inputBox) { + // the input box already got focused. + resolve(); + } else { + inputBox.onfocus = () => { + resolve(); + }; + inputBox.focus(); + } + }); + + // Once the result of the keyboard event ready, the content page will send + // a custom event 'resultAvailable' for informing the script to check the + // result. + await new Promise(resolve => { + function eventHandler(aEvent) { + verifyKeyboardEvent( + JSON.parse(resElement.value), + result, + eventType == "keypress" + ); + resElement.removeEventListener( + "resultAvailable", + eventHandler, + true + ); + resolve(); + } + + resElement.addEventListener("resultAvailable", eventHandler, true); + }); + } + ); + + allKeyEventPromises.push(keyEventPromise); + } + + // Send key event to the tab. + BrowserTestUtils.synthesizeKey( + aTestCase.key, + aTestCase.modifiers, + aTab.linkedBrowser + ); + + await Promise.all(allKeyEventPromises); +} + +function eventConsumer(aEvent) { + aEvent.preventDefault(); +} + +add_setup(async function() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]], + }); +}); + +add_task(async function runTestsForEnglishContent() { + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TEST_PATH + "file_keyBoardEvent.sjs?language=en-US" + ); + + // Prevent shortcut keys. + gBrowser.addEventListener("keypress", eventConsumer, true); + + for (let test of TEST_CASES_EN) { + await testKeyEvent(tab, test); + } + + // Test a key which doesn't exist in US English keyboard layout. + await testKeyEvent(tab, { + key: "\u00DF", + modifiers: { code: "Minus", keyCode: 63 }, + expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE, + result: { + key: "\u00DF", + code: "", + charCode: 223, + keyCode: 0, + location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, + altKey: false, + shiftKey: false, + ctrlKey: false, + altGraphKey: false, + }, + }); + + gBrowser.removeEventListener("keypress", eventConsumer, true); + + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function runTestForSuppressModifierKeys() { + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TEST_PATH + "file_keyBoardEvent.sjs?language=en-US" + ); + + // Prevent Alt key to trigger the menu item. + gBrowser.addEventListener("keydown", eventConsumer, true); + + for (let eventType of ["keydown", "keyup"]) { + for (let modifierKey of ["Alt", "Shift", "Control"]) { + let testPromise = ContentTask.spawn( + tab.linkedBrowser, + eventType, + async aEventType => { + let inputBox = content.document.getElementById("test"); + + // First, try to focus on the input box. + await new Promise(resolve => { + if (content.document.activeElement == inputBox) { + // the input box already got focused. + resolve(); + } else { + inputBox.onfocus = () => { + resolve(); + }; + inputBox.focus(); + } + }); + + let event = await new Promise(resolve => { + inputBox.addEventListener( + aEventType, + aEvent => { + resolve(aEvent); + }, + { once: true } + ); + }); + + is( + event.key, + "x", + "'x' should be seen and the modifier key should be suppressed" + ); + } + ); + + let modifierState; + + if (modifierKey === "Alt") { + modifierState = { altKey: true }; + } else if (modifierKey === "Shift") { + modifierState = { shiftKey: true }; + } else { + modifierState = { ctrlKey: true }; + } + + // Generate a Alt or Shift key event. + BrowserTestUtils.synthesizeKey( + `KEY_${modifierKey}`, + modifierState, + tab.linkedBrowser + ); + + // Generate a dummy "x" key event that will only be handled if + // modifier key is successfully suppressed. + BrowserTestUtils.synthesizeKey("x", {}, tab.linkedBrowser); + + await testPromise; + } + } + + gBrowser.removeEventListener("keydown", eventConsumer, true); + + BrowserTestUtils.removeTab(tab); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_timezone.js b/browser/components/resistfingerprinting/test/browser/browser_timezone.js new file mode 100644 index 0000000000..5baa13124e --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_timezone.js @@ -0,0 +1,60 @@ +/** + * Bug 1330890 - A test case for verifying Date() object of javascript will use + * UTC timezone after fingerprinting resistance is enabled. + */ + +add_setup(async function() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]], + }); +}); + +add_task(async function test_timezone() { + // Load a page and verify the timezone. + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TEST_PATH + "file_dummy.html" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function() { + let dateObj = new Date(); + let dateString = dateObj.toString(); + + ok( + dateString.endsWith("(Coordinated Universal Time)"), + "The date string is in UTC timezone." + ); + is( + dateObj.getFullYear(), + dateObj.getUTCFullYear(), + "The full year reports in UTC timezone." + ); + is( + dateObj.getMonth(), + dateObj.getUTCMonth(), + "The month reports in UTC timezone." + ); + is( + dateObj.getDate(), + dateObj.getUTCDate(), + "The month reports in UTC timezone." + ); + is( + dateObj.getDay(), + dateObj.getUTCDay(), + "The day reports in UTC timezone." + ); + is( + dateObj.getHours(), + dateObj.getUTCHours(), + "The hours reports in UTC timezone." + ); + is( + dateObj.getTimezoneOffset(), + 0, + "The difference with UTC timezone is 0." + ); + }); + + BrowserTestUtils.removeTab(tab); +}); diff --git a/browser/components/resistfingerprinting/test/browser/coop_header.sjs b/browser/components/resistfingerprinting/test/browser/coop_header.sjs new file mode 100644 index 0000000000..16c8eded66 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/coop_header.sjs @@ -0,0 +1,77 @@ +const HTML_DATA = ` + <!DOCTYPE HTML> + <html> + <head> + <title>Dummy test page</title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta> + </head> + <body> + <p>Dummy test page</p> + <div id="testDiv">test</div> + </body> + </html> + `; + +const WORKER = ` + self.onmessage = function(e) { + if (e.data.type == "runCmdAndGetResult") { + let result = eval(e.data.cmd); + + postMessage({ type: "result", resultOf: e.data.cmd, result: result }); + return; + } else if (e.data.type == "runCmds") { + for (let cmd of e.data.cmds) { + eval(cmd); + } + + postMessage({ type: "result", resultOf: "entriesLength", result: performance.getEntries().length }); + return; + } else if (e.data.type == "getResult") { + if (e.data.resultOf == "startTimeAndDuration") { + postMessage({ type: "result", + resultOf: "startTimeAndDuration", + result: { + index: e.data.num, + startTime: performance.getEntries()[e.data.num].startTime, + duration: performance.getEntries()[e.data.num].duration, + } + }); + return; + } else if (e.data.resultOf == "getEntriesByTypeLength") { + postMessage({ + type: "result", + resultOf: "entriesByTypeLength", + result: { + markLength: performance.getEntriesByType("mark").length, + resourceLength: performance.getEntriesByType("resource").length, + testAndMarkLength: performance.getEntriesByName("Test", "mark").length, + } + }); + return; + } + } + + postMessage({ type: "unexpectedMessageType", data: e.data.type }); + }; + `; + +function handleRequest(request, response) { + Cu.importGlobalProperties(["URLSearchParams"]); + let query = new URLSearchParams(request.queryString); + + if (query.get("crossOriginIsolated") === "true") { + response.setHeader("Cross-Origin-Opener-Policy", "same-origin", false); + response.setHeader("Cross-Origin-Embedder-Policy", "require-corp", false); + } + + if (query.get("worker")) { + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "application/javascript"); + response.write(WORKER); + return; + } + + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "text/html", false); + response.write(HTML_DATA); +} diff --git a/browser/components/resistfingerprinting/test/browser/file_animationapi_iframee.html b/browser/components/resistfingerprinting/test/browser/file_animationapi_iframee.html new file mode 100644 index 0000000000..da86656bd4 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_animationapi_iframee.html @@ -0,0 +1,85 @@ +<!DOCTYPE html> +<head> +<meta charset="utf8"> +<script> +function waitForCondition(aCond, aCallback, aErrorMsg) { + var tries = 0; + var interval = setInterval(() => { + if (tries >= 30) { + result.push({ + 'error': `Exceeded 30 tries waiting for animation` + }) + clearInterval(interval); + parent.postMessage(result, "*"); + return; + } + + var conditionPassed; + try { + conditionPassed = aCond(); + } catch (e) { + result.push({ + 'error': `${e}\n${e.stack}` + }) + clearInterval(interval); + parent.postMessage(result, "*") + return; + } + + if (conditionPassed) { + clearInterval(interval); + aCallback(); + } + + tries++; + }, 100); + } + +window.onload = async () => { + parent.postMessage("ready", "*"); +} + +var result = []; + +window.addEventListener("message", async function listener(event) { + if (event.data[0] == "gimme") { + + const testDiv = document.getElementById("testDiv"); + const animation = testDiv.animate({ opacity: [0, 1] }, 100000); + animation.play(); + + waitForCondition( + () => animation.currentTime > 100, + () => { + + result.push({ + 'name': 'animation.startTime', + 'value': animation.startTime + }); + result.push({ + 'name': 'animation.currentTime', + 'value': animation.currentTime + }); + result.push({ + 'name': 'animation.timeline.currentTime', + 'value': animation.timeline.currentTime + }); + + if (document.timeline) { + result.push({ + 'name': 'document.timeline.currentTime', + 'value': document.timeline.currentTime + }); + } + + parent.postMessage(result, "*") + }, + "animation failed to start"); + } +}); +</script> +</head> +<body> +<div id="testDiv">test</div> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html b/browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html new file mode 100644 index 0000000000..ece07357e1 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title></title> +<script> +function waitForMessage(aMsg, aOrigin) { + return new Promise(resolve => { + window.addEventListener("message", function listener(event) { + if (event.data == "ready" && event.origin == aOrigin) { + window.removeEventListener("message", listener); + resolve(); + } + }); + }); +} + +async function runTheTest(iframe_domain, cross_origin_domain, extraData) { + const iframes = document.querySelectorAll("iframe"); + iframes[0].src = `https://${iframe_domain}/browser/browser/components/resistfingerprinting/test/browser/file_animationapi_iframee.html`; + await waitForMessage("ready", `https://${iframe_domain}`); + + const promiseForRFPTest = new Promise(resolve => { + window.addEventListener("message", event => { + if(event.origin != `https://${iframe_domain}`) { + throw new Error(`origin should be ${iframe_domain}`); + } + resolve(event.data); + }, { once: true }); + }); + iframes[0].contentWindow.postMessage({0: "gimme", 1: cross_origin_domain}, "*"); + var result = await promiseForRFPTest; + + return result; +} +</script> +</head> +<body> +<iframe width=100></iframe> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/browser/file_dummy.html b/browser/components/resistfingerprinting/test/browser/file_dummy.html new file mode 100644 index 0000000000..1a87e28408 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_dummy.html @@ -0,0 +1,9 @@ +<html> +<head> +<title>Dummy test page</title> +<meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta> +</head> +<body> +<p>Dummy test page</p> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/browser/file_keyBoardEvent.sjs b/browser/components/resistfingerprinting/test/browser/file_keyBoardEvent.sjs new file mode 100644 index 0000000000..5e3c0e2e57 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_keyBoardEvent.sjs @@ -0,0 +1,64 @@ +"use strict"; + +Cu.importGlobalProperties(["URLSearchParams"]); + +const HTML_DATA = ` + <!DOCTYPE HTML> + <html> + <head> + <meta charset="utf-8"> + <title>Test for Bug 1222285</title> + <script type="application/javascript"> + function populateKeyEventResult(aEvent) { + let result = document.getElementById("result-" + aEvent.type); + let data = { + key: aEvent.key, + code: aEvent.code, + location: aEvent.location, + altKey: aEvent.altKey, + shiftKey: aEvent.shiftKey, + ctrlKey: aEvent.ctrlKey, + charCode: aEvent.charCode, + keyCode: aEvent.keyCode, + modifierState: { + Alt: aEvent.getModifierState("Alt"), + AltGraph: aEvent.getModifierState("AltGraph"), + Shift: aEvent.getModifierState("Shift"), + Control: aEvent.getModifierState("Control") + } + }; + + result.value = JSON.stringify(data); + result.dispatchEvent(new CustomEvent("resultAvailable")); + } + + window.onload = () => { + for (event of ["keydown", "keypress", "keyup"]) { + document.getElementById("test") + .addEventListener(event, populateKeyEventResult); + } + } + </script> + </head> + <body> + <input id="test"/> + <input id="result-keydown"/> + <input id="result-keypress"/> + <input id="result-keyup"/> + </body> + </html>`; + +function handleRequest(request, response) { + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "text/html", false); + + let queryString = new URLSearchParams(request.queryString); + + let language = queryString.get("language"); + + if (language) { + response.setHeader("Content-Language", language, false); + } + + response.write(HTML_DATA); +} 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 0000000000..73029a2168 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_navigator.html @@ -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.hardwareConcurrency = navigator.hardwareConcurrency; + + // eslint-disable-next-line no-unsanitized/property + document.getElementById("result").innerHTML = JSON.stringify(result); + } +</script> +</head> +<body onload="collect();"> +<p id="result"></p> +</body> +</html> 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 0000000000..353aa849d0 --- /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/file_navigator_header.sjs b/browser/components/resistfingerprinting/test/browser/file_navigator_header.sjs new file mode 100644 index 0000000000..0afa1f1b41 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_navigator_header.sjs @@ -0,0 +1,12 @@ +"use strict"; + +function handleRequest(request, response) { + response.setHeader("Content-Type", "text/plain; charset=UTF-8", false); + response.setHeader("Access-Control-Allow-Origin", "*", false); + + if (request.hasHeader("user-agent")) { + response.write(request.getHeader("user-agent")); + } else { + response.write("no user agent header"); + } +} diff --git a/browser/components/resistfingerprinting/test/browser/file_navigator_iframe_worker.sjs b/browser/components/resistfingerprinting/test/browser/file_navigator_iframe_worker.sjs new file mode 100644 index 0000000000..cbb54d06bc --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_navigator_iframe_worker.sjs @@ -0,0 +1,25 @@ +"use strict"; + +function handleRequest(request, response) { + response.setHeader("Content-Type", "application/javascript"); + + let content = `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(result); + port.start(); + };`; + + response.write(content); +} diff --git a/browser/components/resistfingerprinting/test/browser/file_navigator_iframee.html b/browser/components/resistfingerprinting/test/browser/file_navigator_iframee.html new file mode 100644 index 0000000000..8e312d1d7b --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_navigator_iframee.html @@ -0,0 +1,60 @@ +<!DOCTYPE html> +<meta charset="utf8"> +<script> +window.onload = async () => { + parent.postMessage("ready", "*"); +} + +window.addEventListener("message", async function listener(event) { + if (event.data[0] == "gimme") { + let cross_origin_domain = event.data[1]; + var 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.hardwareConcurrency = navigator.hardwareConcurrency; + result.userAgentHTTPHeader = "unknown"; + + let worker = new SharedWorker("file_navigator_iframe_worker.sjs"); + let worker_result = await new Promise(resolve => { + worker.port.onmessage = function(e) { + resolve(e.data); + }; + }); + + result.worker_appCodeName = worker_result.appCodeName; + result.worker_appName = worker_result.appName; + result.worker_appVersion = worker_result.appVersion; + result.worker_platform = worker_result.platform; + result.worker_userAgent = worker_result.userAgent; + result.worker_product = worker_result.product; + result.worker_hardwareConcurrency = worker_result.hardwareConcurrency; + + var one = fetch("file_navigator_header.sjs?") + .then((response) => { return response.text(); }) + .then((content) => { + result.userAgentHTTPHeader = content; + }); + + var two = fetch(`https://${cross_origin_domain}/browser/browser/components/resistfingerprinting/test/browser/file_navigator_header.sjs?`) + .then((response) => { return response.text(); }) + .then((content) => { + result.framee_crossOrigin_userAgentHTTPHeader = content; + }); + + Promise.all([one, two]).then((values) => { + parent.postMessage(result, "*") + }); + } +}); +</script> diff --git a/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html b/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html new file mode 100644 index 0000000000..e01027b07e --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html @@ -0,0 +1,47 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title></title> +<script> +function waitForMessage(aMsg, aOrigin) { + return new Promise(resolve => { + window.addEventListener("message", function listener(event) { + if (event.data == "ready" && event.origin == aOrigin) { + window.removeEventListener("message", listener); + resolve(); + } + }); + }); +} + +async function runTheTest(iframe_domain, cross_origin_domain) { + const iframes = document.querySelectorAll("iframe"); + iframes[0].src = `https://${iframe_domain}/browser/browser/components/resistfingerprinting/test/browser/file_navigator_iframee.html`; + await waitForMessage("ready", `https://${iframe_domain}`); + + const promiseForRFPTest = new Promise(resolve => { + window.addEventListener("message", event => { + if(event.origin != `https://${iframe_domain}`) { + throw new Error(`origin should be ${iframe_domain}`); + } + resolve(event.data); + }, { once: true }); + }); + iframes[0].contentWindow.postMessage({0: "gimme", 1: cross_origin_domain}, "*"); + var result = await promiseForRFPTest; + + await fetch(`https://${cross_origin_domain}/browser/browser/components/resistfingerprinting/test/browser/file_navigator_header.sjs?`) + .then((response) => { return response.text(); }) + .then((content) => { + result.framer_crossOrigin_userAgentHTTPHeader = content; + }); + + return result; +} +</script> +</head> +<body> +<iframe width=100></iframe> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframe_worker.sjs b/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframe_worker.sjs new file mode 100644 index 0000000000..7791c05c06 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframe_worker.sjs @@ -0,0 +1,34 @@ +"use strict"; + +function handleRequest(request, response) { + response.setHeader("Content-Type", "application/javascript"); + + let content = `onconnect = function(e) { + let port = e.ports[0]; + + let navigatorObj = self.navigator; + let result = []; + + // Known ways to generate time stamps, in milliseconds + const timeStampCodes = [ + 'performance.now()', + 'new Date().getTime()', + 'new Event("").timeStamp', + 'new File([], "").lastModified', + ]; + + for (let timeStampCode of timeStampCodes) { + let timeStamp = eval(timeStampCode); + + result.push({ + 'name': 'worker ' + timeStampCode, + 'value': timeStamp + }); + } + + port.postMessage(result); + port.start(); + };`; + + response.write(content); +} diff --git a/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframee.html b/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframee.html new file mode 100644 index 0000000000..d336fa8d85 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframee.html @@ -0,0 +1,52 @@ +<!DOCTYPE html> +<meta charset="utf8"> +<script> +window.onload = async () => { + parent.postMessage("ready", "*"); +} + +window.addEventListener("message", async function listener(event) { + if (event.data[0] == "gimme") { + var result = []; + + // Prepare for test of AudioContext.currentTime + // eslint-disable-next-line + let audioContext = new AudioContext(); + + // Known ways to generate time stamps, in milliseconds + const timeStampCodes = [ + "performance.now()", + "new Date().getTime()", + "new Event(\"\").timeStamp", + "new File([], \"\").lastModified", + ]; + // These are measured in seconds, so we need to scale them up + var timeStampCodesDOM = timeStampCodes.concat([ + "audioContext.currentTime * 1000", + ]); + + for (let timeStampCode of timeStampCodesDOM) { + // eslint-disable-next-line no-eval + let timeStamp = eval(timeStampCode); + + result.push({ + 'name': timeStampCode, + 'value': timeStamp + }); + } + + let worker = new SharedWorker("file_reduceTimePrecision_iframe_worker.sjs"); + let worker_result = await new Promise(resolve => { + worker.port.onmessage = function(e) { + resolve(e.data); + }; + }); + + for (let item of worker_result) { + result.push(item); + } + + parent.postMessage(result, "*") + } +}); +</script> diff --git a/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html b/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html new file mode 100644 index 0000000000..454cc8d3b2 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title></title> +<script> +function waitForMessage(aMsg, aOrigin) { + return new Promise(resolve => { + window.addEventListener("message", function listener(event) { + if (event.data == "ready" && event.origin == aOrigin) { + window.removeEventListener("message", listener); + resolve(); + } + }); + }); +} + +async function runTheTest(iframe_domain, cross_origin_domain, extraData) { + const iframes = document.querySelectorAll("iframe"); + iframes[0].src = `https://${iframe_domain}/browser/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframee.html`; + await waitForMessage("ready", `https://${iframe_domain}`); + + const promiseForRFPTest = new Promise(resolve => { + window.addEventListener("message", event => { + if(event.origin != `https://${iframe_domain}`) { + throw new Error(`origin should be ${iframe_domain}`); + } + resolve(event.data); + }, { once: true }); + }); + iframes[0].contentWindow.postMessage({0: "gimme", 1: cross_origin_domain}, "*"); + var result = await promiseForRFPTest; + + return result; +} +</script> +</head> +<body> +<iframe width=100></iframe> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/browser/file_workerNetInfo.js b/browser/components/resistfingerprinting/test/browser/file_workerNetInfo.js new file mode 100644 index 0000000000..219db4f41c --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_workerNetInfo.js @@ -0,0 +1,30 @@ +function ok(a, msg) { + postMessage({ type: "status", status: !!a, msg }); +} + +function is(a, b, msg) { + ok(a === b, msg); +} + +function finish() { + postMessage({ type: "finish" }); +} + +function runTests() { + ok("connection" in navigator, "navigator.connection should exist"); + is( + navigator.connection.type, + "unknown", + "The connection type is spoofed correctly" + ); + + finish(); +} + +self.onmessage = function(e) { + if (e.data.type === "runTests") { + runTests(); + } else { + ok(false, "Unknown message type"); + } +}; diff --git a/browser/components/resistfingerprinting/test/browser/file_workerPerformance.js b/browser/components/resistfingerprinting/test/browser/file_workerPerformance.js new file mode 100644 index 0000000000..15398d9fc6 --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/file_workerPerformance.js @@ -0,0 +1,156 @@ +function ok(a, msg) { + postMessage({ type: "status", status: !!a, msg }); +} + +function is(a, b, msg) { + ok(a === b, msg); +} + +function finish() { + postMessage({ type: "finish" }); +} + +let isRounded = (x, expectedPrecision) => { + let rounded = Math.floor(x / expectedPrecision) * expectedPrecision; + // First we do the perfectly normal check that should work just fine + if (rounded === x || x === 0) { + return true; + } + + // When we're diving by non-whole numbers, we may not get perfect + // multiplication/division because of floating points. + // When dealing with ms since epoch, a double's precision is on the order + // of 1/5 of a microsecond, so we use a value a little higher than that as + // our epsilon. + // To be clear, this error is introduced in our re-calculation of 'rounded' + // above in JavaScript. + if (Math.abs(rounded - x + expectedPrecision) < 0.0005) { + return true; + } else if (Math.abs(rounded - x) < 0.0005) { + return true; + } + + // Then we handle the case where you're sub-millisecond and the timer is not + // We check that the timer is not sub-millisecond by assuming it is not if it + // returns an even number of milliseconds + if (expectedPrecision < 1 && Math.round(x) == x) { + if (Math.round(rounded) == x) { + return true; + } + } + + ok( + false, + "Looming Test Failure, Additional Debugging Info: Expected Precision: " + + expectedPrecision + + " Measured Value: " + + x + + " Rounded Vaue: " + + rounded + + " Fuzzy1: " + + Math.abs(rounded - x + expectedPrecision) + + " Fuzzy 2: " + + Math.abs(rounded - x) + ); + + return false; +}; + +function runRPTests(expectedPrecision) { + ok( + isRounded(performance.timeOrigin, expectedPrecision), + `In a worker, for resistFingerprinting, performance.timeOrigin is not correctly rounded: ` + + performance.timeOrigin + ); + + // Try to add some entries. + performance.mark("Test"); + performance.mark("Test-End"); + performance.measure("Test-Measure", "Test", "Test-End"); + + // Check that no entries for performance.getEntries/getEntriesByType/getEntriesByName. + is( + performance.getEntries().length, + 0, + "In a worker, for resistFingerprinting: No entries for performance.getEntries() for workers" + ); + is( + performance.getEntriesByType("resource").length, + 0, + "In a worker, for resistFingerprinting: No entries for performance.getEntriesByType() for workers" + ); + is( + performance.getEntriesByName("Test", "mark").length, + 0, + "In a worker, for resistFingerprinting: No entries for performance.getEntriesByName() for workers" + ); + + finish(); +} + +function runRTPTests(expectedPrecision) { + ok( + isRounded(performance.timeOrigin, expectedPrecision), + `In a worker, for reduceTimerPrecision, performance.timeOrigin is not correctly rounded: ` + + performance.timeOrigin + ); + + // Try to add some entries. + performance.mark("Test"); + performance.mark("Test-End"); + performance.measure("Test-Measure", "Test", "Test-End"); + + // Check the entries in performance.getEntries/getEntriesByType/getEntriesByName. + is( + performance.getEntries().length, + 3, + "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntries() for workers: " + + performance.getEntries().length + ); + for (var i = 0; i < 3; i++) { + let startTime = performance.getEntries()[i].startTime; + let duration = performance.getEntries()[i].duration; + ok( + isRounded(startTime, expectedPrecision), + "In a worker, for reduceTimerPrecision(" + + expectedPrecision + + "), performance.getEntries(" + + i.toString() + + ").startTime is not rounded: " + + startTime.toString() + ); + ok( + isRounded(duration, expectedPrecision), + "In a worker, for reduceTimerPrecision(" + + expectedPrecision + + "), performance.getEntries(" + + i.toString() + + ").duration is not rounded: " + + duration.toString() + ); + } + is( + performance.getEntriesByType("mark").length, + 2, + "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntriesByType() for workers: " + + performance.getEntriesByType("resource").length + ); + is( + performance.getEntriesByName("Test", "mark").length, + 1, + "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntriesByName() for workers: " + + performance.getEntriesByName("Test", "mark").length + ); + + finish(); +} + +self.onmessage = function(e) { + if (e.data.type === "runRPTests") { + runRPTests(e.data.precision); + } else if (e.data.type === "runRTPTests") { + runRTPTests(e.data.precision); + } else { + ok(false, "Unknown message type"); + } +}; diff --git a/browser/components/resistfingerprinting/test/browser/head.js b/browser/components/resistfingerprinting/test/browser/head.js new file mode 100644 index 0000000000..ffc8134d9e --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/head.js @@ -0,0 +1,975 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const TEST_PATH = + "http://example.net/browser/browser/" + + "components/resistfingerprinting/test/browser/"; + +const PERFORMANCE_TIMINGS = [ + "navigationStart", + "unloadEventStart", + "unloadEventEnd", + "redirectStart", + "redirectEnd", + "fetchStart", + "domainLookupStart", + "domainLookupEnd", + "connectStart", + "connectEnd", + "secureConnectionStart", + "requestStart", + "responseStart", + "responseEnd", + "domLoading", + "domInteractive", + "domContentLoadedEventStart", + "domContentLoadedEventEnd", + "domComplete", + "loadEventStart", + "loadEventEnd", +]; + +/** + * Sets up tests for making sure that performance APIs have been correctly + * spoofed or disabled. + */ +let setupPerformanceAPISpoofAndDisableTest = async function( + resistFingerprinting, + reduceTimerPrecision, + crossOriginIsolated, + expectedPrecision, + runTests, + workerCall +) { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", resistFingerprinting], + ["privacy.reduceTimerPrecision", reduceTimerPrecision], + [ + "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", + expectedPrecision * 1000, + ], + ["browser.tabs.remote.useCrossOriginOpenerPolicy", crossOriginIsolated], + ["browser.tabs.remote.useCrossOriginEmbedderPolicy", crossOriginIsolated], + ], + }); + + let url = crossOriginIsolated + ? `https://example.com/browser/browser/components/resistfingerprinting` + + `/test/browser/coop_header.sjs?crossOriginIsolated=${crossOriginIsolated}` + : TEST_PATH + "file_dummy.html"; + + let win = await BrowserTestUtils.openNewBrowserWindow(); + let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, url); + + // No matter what we set the precision to, if we're in ResistFingerprinting + // mode we use the larger of the precision pref and the RFP time-atom constant + if (resistFingerprinting) { + const RFP_TIME_ATOM_MS = 16.667; + expectedPrecision = Math.max(RFP_TIME_ATOM_MS, expectedPrecision); + } + await SpecialPowers.spawn( + tab.linkedBrowser, + [ + { + list: PERFORMANCE_TIMINGS, + precision: expectedPrecision, + isRoundedFunc: isTimeValueRounded.toString(), + workerCall, + }, + ], + runTests + ); + + if (crossOriginIsolated) { + let remoteType = tab.linkedBrowser.remoteType; + ok( + remoteType.startsWith(E10SUtils.WEB_REMOTE_COOP_COEP_TYPE_PREFIX), + `${remoteType} expected to be coop+coep` + ); + } + + await BrowserTestUtils.closeWindow(win); +}; + +let isTimeValueRounded = (x, expectedPrecision) => { + const nearestExpected = Math.round(x / expectedPrecision) * expectedPrecision; + // First we do the perfectly normal check that should work just fine + if (x === nearestExpected) { + return true; + } + + // When we're dividing by non-whole numbers, we may not get perfect + // multiplication/division because of floating points. + // When dealing with ms since epoch, a double's precision is on the order + // of 1/5 of a microsecond, so we use a value a little higher than that as + // our epsilon. + // To be clear, this error is introduced in our re-calculation of 'rounded' + // above in JavaScript. + const error = Math.abs(x - nearestExpected); + if (Math.abs(error) < 0.0005) { + return true; + } + + // Then we handle the case where you're sub-millisecond and the timer is not + // We check that the timer is not sub-millisecond by assuming it is not if it + // returns an even number of milliseconds + if ( + Math.round(expectedPrecision) != expectedPrecision && + Math.round(x) == x + ) { + let acceptableIntRounding = false; + acceptableIntRounding |= Math.floor(nearestExpected) == x; + acceptableIntRounding |= Math.ceil(nearestExpected) == x; + if (acceptableIntRounding) { + return true; + } + } + + ok( + false, + "Looming Test Failure, Additional Debugging Info: Expected Precision: " + + expectedPrecision + + " Measured Value: " + + x + + " Nearest Expected Vaue: " + + nearestExpected + + " Error: " + + error + ); + + return false; +}; + +let setupAndRunCrossOriginIsolatedTest = async function( + resistFingerprinting, + reduceTimerPrecision, + crossOriginIsolated, + expectedPrecision, + runTests, + workerCall +) { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", resistFingerprinting], + ["privacy.reduceTimerPrecision", reduceTimerPrecision], + [ + "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", + expectedPrecision * 1000, + ], + ["browser.tabs.remote.useCrossOriginOpenerPolicy", crossOriginIsolated], + ["browser.tabs.remote.useCrossOriginEmbedderPolicy", crossOriginIsolated], + ], + }); + + let win = await BrowserTestUtils.openNewBrowserWindow(); + let tab = await BrowserTestUtils.openNewForegroundTab( + win.gBrowser, + `https://example.com/browser/browser/components/resistfingerprinting` + + `/test/browser/coop_header.sjs?crossOriginIsolated=${crossOriginIsolated}` + ); + + // No matter what we set the precision to, if we're in ResistFingerprinting + // mode we use the larger of the precision pref and the RFP time-atom constant + if (resistFingerprinting) { + const RFP_TIME_ATOM_MS = 16.667; + expectedPrecision = Math.max(RFP_TIME_ATOM_MS, expectedPrecision); + } + await SpecialPowers.spawn( + tab.linkedBrowser, + [ + { + precision: expectedPrecision, + isRoundedFunc: isTimeValueRounded.toString(), + workerCall, + resistFingerprinting, + reduceTimerPrecision, + }, + ], + runTests + ); + + if (crossOriginIsolated) { + let remoteType = tab.linkedBrowser.remoteType; + ok( + remoteType.startsWith(E10SUtils.WEB_REMOTE_COOP_COEP_TYPE_PREFIX), + `${remoteType} expected to be coop+coep` + ); + } + + await BrowserTestUtils.closeWindow(win); +}; + +// This function calculates the maximum available window dimensions and returns +// them as an object. +async function calcMaximumAvailSize(aChromeWidth, aChromeHeight) { + let chromeUIWidth; + let chromeUIHeight; + let testPath = + "http://example.net/browser/browser/" + + "components/resistfingerprinting/test/browser/"; + + // If the chrome UI dimensions is not given, we will calculate it. + if (!aChromeWidth || !aChromeHeight) { + let win = await BrowserTestUtils.openNewBrowserWindow(); + + let tab = await BrowserTestUtils.openNewForegroundTab( + win.gBrowser, + testPath + "file_dummy.html" + ); + + let contentSize = await SpecialPowers.spawn( + tab.linkedBrowser, + [], + async function() { + let result = { + width: content.innerWidth, + height: content.innerHeight, + }; + + return result; + } + ); + + // Calculate the maximum available window size which is depending on the + // available screen space. + chromeUIWidth = win.outerWidth - contentSize.width; + chromeUIHeight = win.outerHeight - contentSize.height; + + BrowserTestUtils.removeTab(tab); + await BrowserTestUtils.closeWindow(win); + } else { + chromeUIWidth = aChromeWidth; + chromeUIHeight = aChromeHeight; + } + + let availWidth = window.screen.availWidth; + let availHeight = window.screen.availHeight; + + // Ideally, we would round the window size as 1000x1000. But the available + // screen space might not suffice. So, we decide the size according to the + // available screen size. + let availContentWidth = Math.min(1000, availWidth - chromeUIWidth); + let availContentHeight; + + // If it is GTK window, we would consider the system decorations when we + // calculating avail content height since the system decorations won't be + // reported when we get available screen dimensions. + if (AppConstants.MOZ_WIDGET_GTK) { + availContentHeight = Math.min(1000, -40 + availHeight - chromeUIHeight); + } else { + availContentHeight = Math.min(1000, availHeight - chromeUIHeight); + } + + // Rounded the desire size to the nearest 200x100. + let maxAvailWidth = availContentWidth - (availContentWidth % 200); + let maxAvailHeight = availContentHeight - (availContentHeight % 100); + + return { maxAvailWidth, maxAvailHeight }; +} + +async function calcPopUpWindowChromeUISize() { + let testPath = + "http://example.net/browser/browser/" + + "components/resistFingerprinting/test/browser/"; + // open a popup window to acquire the chrome UI size of it. + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + testPath + "file_dummy.html" + ); + + let result = await SpecialPowers.spawn( + tab.linkedBrowser, + [], + async function() { + let win; + + await new Promise(resolve => { + win = content.open("about:blank", "", "width=1000,height=1000"); + win.onload = () => resolve(); + }); + + let res = { + chromeWidth: win.outerWidth - win.innerWidth, + chromeHeight: win.outerHeight - win.innerHeight, + }; + + win.close(); + + return res; + } + ); + + BrowserTestUtils.removeTab(tab); + + return result; +} + +async function testWindowOpen( + aBrowser, + aSettingWidth, + aSettingHeight, + aTargetWidth, + aTargetHeight, + aMaxAvailWidth, + aMaxAvailHeight, + aPopupChromeUIWidth, + aPopupChromeUIHeight +) { + // If the target size is greater than the maximum available content size, + // we set the target size to it. + if (aTargetWidth > aMaxAvailWidth) { + aTargetWidth = aMaxAvailWidth; + } + + if (aTargetHeight > aMaxAvailHeight) { + aTargetHeight = aMaxAvailHeight; + } + + // Create the testing window features. + let winFeatures = "width=" + aSettingWidth + ",height=" + aSettingHeight; + + let testParams = { + winFeatures, + targetWidth: aTargetWidth, + targetHeight: aTargetHeight, + }; + + await SpecialPowers.spawn(aBrowser, [testParams], async function(input) { + // Call window.open() with window features. + await new Promise(resolve => { + let win = content.open("http://example.net/", "", input.winFeatures); + + win.onload = () => { + is( + win.screen.width, + input.targetWidth, + "The screen.width has a correct rounded value" + ); + is( + win.screen.height, + input.targetHeight, + "The screen.height has a correct rounded value" + ); + is( + win.innerWidth, + input.targetWidth, + "The window.innerWidth has a correct rounded value" + ); + is( + win.innerHeight, + input.targetHeight, + "The window.innerHeight has a correct rounded value" + ); + + win.close(); + resolve(); + }; + }); + }); +} + +async function testWindowSizeSetting( + aBrowser, + aSettingWidth, + aSettingHeight, + aTargetWidth, + aTargetHeight, + aInitWidth, + aInitHeight, + aTestOuter, + aMaxAvailWidth, + aMaxAvailHeight, + aPopupChromeUIWidth, + aPopupChromeUIHeight +) { + // If the target size is greater than the maximum available content size, + // we set the target size to it. + if (aTargetWidth > aMaxAvailWidth) { + aTargetWidth = aMaxAvailWidth; + } + + if (aTargetHeight > aMaxAvailHeight) { + aTargetHeight = aMaxAvailHeight; + } + + let testParams = { + initWidth: aInitWidth, + initHeight: aInitHeight, + settingWidth: aSettingWidth + (aTestOuter ? aPopupChromeUIWidth : 0), + settingHeight: aSettingHeight + (aTestOuter ? aPopupChromeUIHeight : 0), + targetWidth: aTargetWidth, + targetHeight: aTargetHeight, + testOuter: aTestOuter, + }; + + await SpecialPowers.spawn(aBrowser, [testParams], async function(input) { + let win; + // Open a new window and wait until it loads. + await new Promise(resolve => { + // Given a initial window size which should be different from target + // size. We need this to trigger 'onresize' event. + let initWinFeatures = + "width=" + input.initWidth + ",height=" + input.initHeight; + win = content.open("http://example.net/", "", initWinFeatures); + win.onload = () => resolve(); + }); + + // Test inner/outerWidth. + await new Promise(resolve => { + win.addEventListener( + "resize", + () => { + is( + win.screen.width, + input.targetWidth, + "The screen.width has a correct rounded value" + ); + is( + win.innerWidth, + input.targetWidth, + "The window.innerWidth has a correct rounded value" + ); + + resolve(); + }, + { once: true } + ); + + if (input.testOuter) { + win.outerWidth = input.settingWidth; + } else { + win.innerWidth = input.settingWidth; + } + }); + + win.close(); + // Open a new window and wait until it loads. + await new Promise(resolve => { + // Given a initial window size which should be different from target + // size. We need this to trigger 'onresize' event. + let initWinFeatures = + "width=" + input.initWidth + ",height=" + input.initHeight; + win = content.open("http://example.net/", "", initWinFeatures); + win.onload = () => resolve(); + }); + + // Test inner/outerHeight. + await new Promise(resolve => { + win.addEventListener( + "resize", + () => { + is( + win.screen.height, + input.targetHeight, + "The screen.height has a correct rounded value" + ); + is( + win.innerHeight, + input.targetHeight, + "The window.innerHeight has a correct rounded value" + ); + + resolve(); + }, + { once: true } + ); + + if (input.testOuter) { + win.outerHeight = input.settingHeight; + } else { + win.innerHeight = input.settingHeight; + } + }); + + win.close(); + }); +} + +class RoundedWindowTest { + // testOuter is optional. run() can be invoked with only 1 parameter. + 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()); + add_task(async () => { + if (testOuter == undefined) { + // If testOuter is not given, do tests for both inner and outer. + await test.doTests(false); + await test.doTests(true); + } else { + await test.doTests(testOuter); + } + }); + } + + constructor(testCases) { + this.testCases = testCases; + } + + async setup() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]], + }); + + // Calculate the popup window's chrome UI size for tests of outerWidth/Height. + let popUpChromeUISize = await calcPopUpWindowChromeUISize(); + + this.popupChromeUIWidth = popUpChromeUISize.chromeWidth; + this.popupChromeUIHeight = popUpChromeUISize.chromeHeight; + + // Calculate the maximum available size. + let maxAvailSize = await calcMaximumAvailSize( + this.popupChromeUIWidth, + this.popupChromeUIHeight + ); + + this.maxAvailWidth = maxAvailSize.maxAvailWidth; + this.maxAvailHeight = maxAvailSize.maxAvailHeight; + } + + async doTests(testOuter) { + // Open a tab to test. + this.tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TEST_PATH + "file_dummy.html" + ); + + for (let test of this.testCases) { + await this.doTest(test, testOuter); + } + + BrowserTestUtils.removeTab(this.tab); + } + + async doTest() { + throw new Error("RoundedWindowTest.doTest must be overridden."); + } +} + +class WindowSettingTest extends RoundedWindowTest { + async doTest(test, testOuter) { + await testWindowSizeSetting( + this.tab.linkedBrowser, + test.settingWidth, + test.settingHeight, + test.targetWidth, + test.targetHeight, + test.initWidth, + test.initHeight, + testOuter, + this.maxAvailWidth, + this.maxAvailHeight, + this.popupChromeUIWidth, + this.popupChromeUIHeight + ); + } +} + +class OpenTest extends RoundedWindowTest { + async doTest(test) { + await testWindowOpen( + this.tab.linkedBrowser, + test.settingWidth, + test.settingHeight, + test.targetWidth, + test.targetHeight, + this.maxAvailWidth, + this.maxAvailHeight, + this.popupChromeUIWidth, + this.popupChromeUIHeight + ); + } +} + +// ============================================================ +const partial = (func, ...args) => (...rest) => func(...args, ...rest); + +async function runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData +) { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain, extraData], + async function(iframe_domain_, cross_origin_domain_, extraData_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_, + extraData_ + ); + } + ); + + testFunction(result, expectedResults, extraData); + } + ); +} + +async function defaultsTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "default"; + expectedResults.shouldRFPApply = false; + if (extraPrefs != undefined) { + await SpecialPowers.pushPrefEnv({ + set: extraPrefs, + }); + } + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + if (extraPrefs != undefined) { + await SpecialPowers.popPrefEnv(); + } +} + +async function simpleRFPTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "simple RFP enabled"; + expectedResults.shouldRFPApply = true; + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} + +// (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource +async function testA( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "test (A)"; + expectedResults.shouldRFPApply = false; + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.com, example.org, example.net", + ], + ].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} + +// (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource +async function testB( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "test (B)"; + expectedResults.shouldRFPApply = false; + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.com, example.org", + ], + ].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} + +// (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource +async function testC( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "test (C)"; + expectedResults.shouldRFPApply = true; + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.com, example.net", + ], + ].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} + +// (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource +async function testD( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "test (D)"; + expectedResults.shouldRFPApply = true; + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + ["privacy.resistFingerprinting.exemptedDomains", "example.com"], + ].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} + +// (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource +async function testE( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "test (E)"; + expectedResults.shouldRFPApply = true; + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + ["privacy.resistFingerprinting.exemptedDomains", "example.net"], + ].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} + +// (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource +async function testF( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "test (F)"; + expectedResults.shouldRFPApply = true; + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + ["privacy.resistFingerprinting.exemptedDomains", ""], + ].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} + +// (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource +async function testG( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "test (G)"; + expectedResults.shouldRFPApply = true; + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.org, example.net", + ], + ].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} + +// (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource +async function testH( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData, + extraPrefs +) { + if (extraData == undefined) { + extraData = {}; + } + extraData.testDesc = "test (H)"; + expectedResults.shouldRFPApply = true; + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + ["privacy.resistFingerprinting.exemptedDomains", "example.org"], + ].concat(extraPrefs || []), + }); + + await runActualTest( + uri, + iframe_domain, + cross_origin_domain, + testFunction, + expectedResults, + extraData + ); + + await SpecialPowers.popPrefEnv(); +} diff --git a/browser/components/resistfingerprinting/test/chrome/chrome.ini b/browser/components/resistfingerprinting/test/chrome/chrome.ini new file mode 100644 index 0000000000..e177136ad6 --- /dev/null +++ b/browser/components/resistfingerprinting/test/chrome/chrome.ini @@ -0,0 +1 @@ +[test_bug1409973_date_time_format.html] diff --git a/browser/components/resistfingerprinting/test/chrome/test_bug1409973_date_time_format.html b/browser/components/resistfingerprinting/test/chrome/test_bug1409973_date_time_format.html new file mode 100644 index 0000000000..a507b65397 --- /dev/null +++ b/browser/components/resistfingerprinting/test/chrome/test_bug1409973_date_time_format.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +<script> + /* globals SpecialPowers, SimpleTest */ + SimpleTest.waitForExplicitFinish(); + + const originalAvailable = Services.locale.availableLocales; + const originalRequested = Services.locale.requestedLocales; + Services.locale.availableLocales = ["ko-KR"]; + Services.locale.requestedLocales = ["ko-KR"]; + + // First be sure we have a non-UTC timezone and a non en-US locale. + var setTimeZone = SpecialPowers.Cu.getJSTestingFunctions().setTimeZone; + setTimeZone("EST5EDT"); + // Now sanity check the defaults + let date = new Date(2003, 4, 6, 2, 30, 15); + // These tests should pass, but we don't enable them because every time CLDR data changed, + // the test would start failing. We leave them here for future debugging. + // SimpleTest.is(date.toLocaleString(), "2003. 5. 6. ì˜¤ì „ 2:30:15", "Sanity Check of toLocaleString"); + // SimpleTest.is(date.toString(), "Tue May 06 2003 02:30:15 GMT-0400 (EDT)", "Sanity check of control timezone failed."); + + let defaultOptions = new Intl.DateTimeFormat(undefined, { + month: "numeric", day: "numeric", year: "numeric", hour: "numeric", minute: "numeric", second: "numeric", + timeZoneName: "long", + }).resolvedOptions(); + SimpleTest.is(defaultOptions.locale, "ko-KR", "defaultOptions Intl.DateTimeFormat.format.locale"); + SimpleTest.is(defaultOptions.timeZone, "EST5EDT", "defaultOptions Intl.DateTimeFormat.format.timeZone"); + SimpleTest.is(defaultOptions.timeZoneName, "long", "defaultOptions Intl.DateTimeFormat.format.timeZoneName"); + + // Then create output it as UTC en-US date string; which should be constant + const referenceLocaleString = date.toLocaleString("en-US", {timeZone: "UTC", timeZoneName: "long"}); + let sanityCheck = new Intl.DateTimeFormat("en-us", {timeZone: "UTC", timeZoneName: "long"}).resolvedOptions(); + SimpleTest.is(sanityCheck.locale, "en-US", "Sanity Check of Intl.DateTimeFormat.format.locale"); + SimpleTest.is(sanityCheck.timeZone, "UTC", "Sanity Check of Intl.DateTimeFormat.format.timeZone"); + SimpleTest.is(sanityCheck.timeZoneName, "long", "Sanity Check of Intl.DateTimeFormat.format.timeZoneName"); + + // Set preferences. + SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + // In real world, this will be set if the user decides to spoof preferred languages by en-US. + ["javascript.use_us_english_locale", true], + ], + }, function() { + // Now confirm that calling toLocaleString with no arguements gives us UTC + SimpleTest.is(date.toLocaleString(undefined, {timeZoneName: "long"}), referenceLocaleString, "Date.toLocaleString"); + // And that a no-options Intl.DateTimeFormat formatter looks correct too + let options = new Intl.DateTimeFormat(undefined, { + month: "numeric", day: "numeric", year: "numeric", hour: "numeric", minute: "numeric", second: "numeric", + timeZoneName: "long", + }).resolvedOptions(); + SimpleTest.is(options.locale, "en-US", "Resist Fingerprinting Intl.DateTimeFormat.format.locale"); + SimpleTest.is(options.timeZone, "UTC", "Resist Fingerprinting Intl.DateTimeFormat.format.timeZone"); + SimpleTest.is(options.timeZoneName, "long", "Resist Fingerprinting Intl.DateTimeFormat.format.timeZoneName"); + + // Cleanup + Services.locale.requestedLocales = originalRequested; + Services.locale.availableLocales = originalAvailable; + SimpleTest.finish(); + }); +</script> diff --git a/browser/components/resistfingerprinting/test/mochitest/.eslintrc.js b/browser/components/resistfingerprinting/test/mochitest/.eslintrc.js new file mode 100644 index 0000000000..16ee78885f --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + rules: { + "no-eval": "off", + }, +}; diff --git a/browser/components/resistfingerprinting/test/mochitest/decode_error.mp4 b/browser/components/resistfingerprinting/test/mochitest/decode_error.mp4 Binary files differnew file mode 100644 index 0000000000..ee72e2dd75 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/decode_error.mp4 diff --git a/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html b/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html new file mode 100644 index 0000000000..376fddf343 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html @@ -0,0 +1,104 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1382545</title> +<script> + function waitForCondition(aCond, aCallback, aErrorMsg) { + var tries = 0; + var interval = setInterval(() => { + if (tries >= 30) { + opener.ok(false, aErrorMsg); + moveOn(); + return; + } + var conditionPassed; + try { + conditionPassed = aCond(); + } catch (e) { + opener.ok(false, `${e}\n${e.stack}`); + conditionPassed = false; + } + if (conditionPassed) { + moveOn(); + } + tries++; + }, 100); + var moveOn = () => { clearInterval(interval); aCallback(); }; + } + + function runTest() { + let expectedPrecision = opener.expectedPrecision / 1000; + let isRounded = (x) => { + let rounded = (Math.floor(x / expectedPrecision) * expectedPrecision); + // First we do the perfectly normal check that should work just fine + if (rounded === x || x === 0) + return true; + + // When we're diving by non-whole numbers, we may not get perfect + // multiplication/division because of floating points. + // When dealing with ms since epoch, a double's precision is on the order + // of 1/5 of a microsecond, so we use a value a little higher than that as + // our epsilon. + // To be clear, this error is introduced in our re-calculation of 'rounded' + // above in JavaScript. + if (Math.abs(rounded - x + expectedPrecision) < .0005) { + return true; + } else if (Math.abs(rounded - x) < .0005) { + return true; + } + + // Then we handle the case where you're sub-millisecond and the timer is not + // We check that the timer is not sub-millisecond by assuming it is not if it + // returns an even number of milliseconds + if (expectedPrecision < 1 && Math.round(x) == x) { + if (Math.round(rounded) == x) { + return true; + } + } + + // We are temporarily disabling this extra debugging failure because we expect to return false in some instances + // When we correct things we will re-enable it for debugging assistance + // opener.ok(false, "Looming Test Failure, Additional Debugging Info: Expected Precision: " + expectedPrecision + " Measured Value: " + x + + // " Rounded Vaue: " + rounded + " Fuzzy1: " + Math.abs(rounded - x + expectedPrecision) + + // " Fuzzy 2: " + Math.abs(rounded - x)); + + return false; + }; + const testDiv = document.getElementById("testDiv"); + const animation = testDiv.animate({ opacity: [0, 1] }, 100000); + animation.play(); + + waitForCondition( + () => animation.currentTime > 100, + () => { + // We have disabled Time Precision Reduction for CSS Animations, so we expect those tests to fail. + // If we are testing that preference, we accept either rounded or not rounded values as A-OK. + var maybeAcceptEverything = function(value) { + if (opener.prefName.includes("privacy.reduceTimerPrecision") && + !opener.prefName.includes("privacy.resistFingerprinting")) + return true; + return value; + }; + + opener.ok(maybeAcceptEverything(isRounded(animation.startTime)), + "pref: " + opener.prefName + " - animation.startTime with precision " + expectedPrecision + " is not rounded: " + animation.startTime); + opener.ok(maybeAcceptEverything(isRounded(animation.currentTime)), + "pref: " + opener.prefName + " - animation.currentTime with precision " + expectedPrecision + " is not rounded: " + animation.currentTime); + opener.ok(maybeAcceptEverything(isRounded(animation.timeline.currentTime)), + "pref: " + opener.prefName + " - animation.timeline.currentTime with precision " + expectedPrecision + " is not rounded: " + animation.timeline.currentTime); + if (document.timeline) { + opener.ok(maybeAcceptEverything(isRounded(document.timeline.currentTime)), + "pref: " + opener.prefName + " - document.timeline.currentTime with precision " + expectedPrecision + " is not rounded: " + document.timeline.currentTime); + } + opener.done(); + window.close(); + }, + "animation failed to start"); + } +</script> +</head> +<body onload="runTest();"> +<div id="testDiv">test</div> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/mochitest/mochitest.ini b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini new file mode 100644 index 0000000000..2ebbc0382f --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini @@ -0,0 +1,29 @@ +[DEFAULT] +skip-if = toolkit == 'android' # bug 1730213 +tags = resistfingerprinting + +support-files = + file_animation_api.html + worker_child.js + worker_grandchild.js + !/dom/tests/mochitest/geolocation/network_geolocation.sjs + +[test_animation_api.html] +[test_device_sensor_event.html] +[test_geolocation.html] +scheme = https +fail-if = xorigin +[test_hide_gamepad_info.html] +scheme = https +support-files = test_hide_gamepad_info_iframe.html +[test_iframe.html] +[test_keyboard_event.html] +[test_pointer_event.html] + support-files = + ../../../../../dom/events/test/pointerevents/mochitest_support_external.js +[test_speech_synthesis.html] +skip-if = verify +[test_bug1382499_touch_api.html] +[test_bug863246_resource_uri.html] +[test_bug1354633_media_error.html] +support-files = decode_error.mp4 diff --git a/browser/components/resistfingerprinting/test/mochitest/test_animation_api.html b/browser/components/resistfingerprinting/test/mochitest/test_animation_api.html new file mode 100644 index 0000000000..74f6f3083e --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_animation_api.html @@ -0,0 +1,78 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1382545 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1382545</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript"> + + /** Test for Bug 1382545 **/ + SimpleTest.waitForExplicitFinish(); + + // Used by file_animation_api.html + var prefName = ""; + var expectedPrecision = 0; + var resistFingerprinting = false; + var reduceTimerPrecision = false; + + function runTest() { + // No matter what we set the precision to, if we're in ResistFingerprinting mode + // we use the larger of the precision pref and the constant RFP time-atom + if (resistFingerprinting) { + const RFP_TIME_ATOM_MS = 16.667; + expectedPrecision = Math.max(1000*RFP_TIME_ATOM_MS, expectedPrecision); + } + window.open("file_animation_api.html"); + } + + function setupTest(rfp, rtp, ep) { + // Set globals + expectedPrecision = ep; + resistFingerprinting = rfp; + reduceTimerPrecision = rtp; + prefName = ""; + prefName += resistFingerprinting ? "privacy.resistFingerprinting " : ""; + prefName += reduceTimerPrecision ? "privacy.reduceTimerPrecision " : ""; + SpecialPowers.pushPrefEnv({"set": + [ + ["dom.animations-api.timelines.enabled", true], + ["privacy.resistFingerprinting", resistFingerprinting], + ["privacy.reduceTimerPrecision", reduceTimerPrecision], + ["privacy.resistFingerprinting.reduceTimerPrecision.microseconds", expectedPrecision], + ], + }, runTest); + } + + var testIndx = 0; + var testSequence = [ + [true, false, 100000], + [false, true, 100000], + [true, false, 50000], + [false, true, 50000], + [true, false, 100], + [false, true, 100], + [true, true, 13], + [false, true, 13], + ]; + + window.onload = () => { + setupTest(testSequence[testIndx][0], testSequence[testIndx][1], testSequence[testIndx][2]); + }; + + function done() { + testIndx++; + if (testIndx == testSequence.length) { + SimpleTest.finish(); + } else { + setupTest(testSequence[testIndx][0], testSequence[testIndx][1], testSequence[testIndx][2]); + } + } + </script> +</head> +<body> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_bug1354633_media_error.html b/browser/components/resistfingerprinting/test/mochitest/test_bug1354633_media_error.html new file mode 100644 index 0000000000..a53a3ad34a --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_bug1354633_media_error.html @@ -0,0 +1,53 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script> +/* global SimpleTest SpecialPowers */ + +let errorMessageMap = {}; + +let testPromise = (resistFingerprinting, src, whitelist) => new Promise(resolve => { + let video = document.createElement("video"); + video.src = src; + video.controls = "true"; + video.onerror = () => { + let message = video.error.message; + if (!resistFingerprinting) { + SimpleTest.isnot(message, "", "Message should not be blank"); + SimpleTest.info(src + ": " + message); + errorMessageMap[src] = message; + } else if (whitelist) { + SimpleTest.is(message, whitelist, "Error message in whitelist: " + whitelist); + } else { + SimpleTest.is(message, "", "Blank error message: " + errorMessageMap[src]); + } + resolve(); + }; + document.body.appendChild(video); +}); + +async function testBody(resistFingerprinting) { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", resistFingerprinting], + ], + }); + await testPromise( + resistFingerprinting, + "load_error.mp4", + "404: Not Found" // whitelist + ); + await testPromise( + resistFingerprinting, + "decode_error.mp4", + false // whitelist + ); +} + +SimpleTest.waitForExplicitFinish(); +document.addEventListener("DOMContentLoaded", async () => { + await testBody(false); + await testBody(true); + SimpleTest.finish(); +}); +</script> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_bug1382499_touch_api.html b/browser/components/resistfingerprinting/test/mochitest/test_bug1382499_touch_api.html new file mode 100644 index 0000000000..45743f3dc3 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_bug1382499_touch_api.html @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<link rel="stylesheet" href="/tests/SimpleTest/test.css"/> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="/tests/SimpleTest/EventUtils.js"></script> +<script> +/* global SimpleTest SpecialPowers synthesizeTouch */ + +SimpleTest.waitForExplicitFinish(); + +function promiseEvent(target, eventName) { + return new Promise(resolve => { + target.addEventListener(eventName, resolve, {once: true}); + }); +} + +function promiseTouchEvent(target, type, offsetX, offsetY, params) { + let touchEventPromise = promiseEvent(target, type); + params.type = type; + synthesizeTouch(target, offsetX, offsetY, params); + return touchEventPromise; +} + +document.addEventListener("DOMContentLoaded", async () => { + const target0 = document.getElementById("target0"); + const touchParams = {force: 1.0, angle: 1.0, rx: 2, ry: 3}; + await SpecialPowers.pushPrefEnv({set: [["dom.w3c_touch_events.enabled", 1]]}); + for (let resist of [false, true]) { + await SpecialPowers.pushPrefEnv({set: [["privacy.resistFingerprinting", resist]]}); + info("starting test with fingerprinting resistance " + (resist ? "on" : "off")); + let touchEvent = await promiseTouchEvent(target0, "touchstart", 5, 5, touchParams); + info("touch event received"); + let touch = touchEvent.touches[0]; + if (resist) { + is(touch.screenX, touch.clientX, "touch.screenX should be the same as touch.clientX"); + is(touch.screenY, touch.clientY, "touch.screenY should be the same as touch.clientY"); + // radiusX/radiusY may differ from the original rx/ry because of AppUnitsPerCSSPixel and AppUnitsPerDevPixel. + // So only check if the values are spoofed. + is(touch.radiusX, 0, "touch.radiusX"); + is(touch.radiusY, 0, "touch.radiusY"); + } + is(touch.force, resist ? 0.0 : touchParams.force, "touch.force"); + is(touch.rotationAngle, resist ? 0 : touchParams.angle, "touch.rotationAngle"); + } + SimpleTest.finish(); +}); +</script> +<div id="target0">target 0</div> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_bug863246_resource_uri.html b/browser/components/resistfingerprinting/test/mochitest/test_bug863246_resource_uri.html new file mode 100644 index 0000000000..fda1c04200 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_bug863246_resource_uri.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<meta charset="utf8"> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script> +/* global SimpleTest SpecialPowers add_task */ + +function testResourceUri(aTest, aUri, aContentAccessible) { + return new Promise((aResolve) => { + let link = document.createElement("link"); + link.rel = "stylesheet"; + link.onload = () => { + SimpleTest.ok(aContentAccessible, aTest); + aResolve(); + }; + link.onerror = () => { + SimpleTest.ok(!aContentAccessible, aTest); + aResolve(); + }; + link.href = aUri; + document.head.appendChild(link); + }); +} + +add_task(async function() { + await testResourceUri( + "resource://content-accessible is content-accessible", + "resource://content-accessible/viewsource.css", + true); + await testResourceUri( + "resource://gre-resources is not content-accessible", + "resource://gre-resources/html.css", + false); + await SpecialPowers.pushPrefEnv({ + set: [ + ["security.all_resource_uri_content_accessible", true], + ], + }); + await testResourceUri( + "security.all_resource_uri_content_accessible = true, resource://gre-resources is now content-accessible", + "resource://gre-resources/html.css", + true); +}); +</script> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_device_sensor_event.html b/browser/components/resistfingerprinting/test/mochitest/test_device_sensor_event.html new file mode 100644 index 0000000000..afc6bbfb40 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_device_sensor_event.html @@ -0,0 +1,50 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1369319 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1369319</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript"> + + /** Test for Bug 1369319 **/ + SimpleTest.waitForExplicitFinish(); + window.onload = () => { + SimpleTest.waitForFocus(() => { + SpecialPowers.pushPrefEnv({"set": + [ + ["device.sensors.test.events", true], + ["privacy.resistFingerprinting", true], + ], + }, doTest); + }, window); + }; + + function doTest() { + window.addEventListener("devicemotion", () => { + ok(false, "The device motion event should not be fired."); + }, {once: true}); + + window.addEventListener("TestEvent", () => { + // If we receive this event without receiving a 'devicemotion' event, this means + // the device sensor event has been blocked correctly. + ok(true, "Got the 'TestEvent' event."); + SimpleTest.finish(); + }, {once: true}); + + window.dispatchEvent(new CustomEvent("TestEvent")); + } + </script> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"></pre> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_geolocation.html b/browser/components/resistfingerprinting/test/mochitest/test_geolocation.html new file mode 100644 index 0000000000..7dc2059dd9 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_geolocation.html @@ -0,0 +1,68 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1372069 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1372069</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript"> + + const BASE_GEO_URL = "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"; + + /** Test for Bug 1372069 **/ + /** Modified for Bug 1441295 **/ + SimpleTest.waitForExplicitFinish(); + window.onload = () => { + SimpleTest.waitForFocus(() => { + SpecialPowers.pushPrefEnv({"set": + [ + ["privacy.resistFingerprinting", true], + ["geo.prompt.testing", true], + ["geo.prompt.testing.allow", true], + ["geo.provider.network.url", BASE_GEO_URL], + ], + }, doTest_getCurrentPosition); + }, window); + }; + + function doTest_getCurrentPosition() { + navigator.geolocation.getCurrentPosition( + (position) => { + ok(true, "Success callback is expected to be called"); + doTest_watchPosition(); + }, + (error) => { + ok(false, "Should be able to call success callback, Got error. code = " + error.code); + doTest_watchPosition(); + } + ); + } + + function doTest_watchPosition() { + let wid = navigator.geolocation.watchPosition( + (position) => { + ok(true, "Success callback is expected to be called"); + navigator.geolocation.clearWatch(wid); + SimpleTest.finish(); + }, + (error) => { + ok(false, "Should be able to call success callback, Got error. code = " + error.code); + navigator.geolocation.clearWatch(wid); + SimpleTest.finish(); + } + ); + } + </script> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"></pre> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info.html b/browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info.html new file mode 100644 index 0000000000..08fdb0c852 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info.html @@ -0,0 +1,23 @@ +<!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.gamepad.test.enabled", true], + ["privacy.resistFingerprinting", true], + ], + }, function() { + // This test loads in an iframe, to ensure that the navigator instance is + // loaded with the correct value of the preference. + var iframe = document.createElement("iframe"); + iframe.allow = "gamepad"; + iframe.src = "test_hide_gamepad_info_iframe.html"; + document.body.appendChild(iframe); + }); +}); +</script> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info_iframe.html b/browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info_iframe.html new file mode 100644 index 0000000000..5946e1ce6e --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info_iframe.html @@ -0,0 +1,45 @@ +<!DOCTYPE html> +<meta charset="utf8"> +<!--<script src="/tests/SimpleTest/SimpleTest.js"></script>--> +<script> +var SimpleTest = window.parent.SimpleTest; + +function forceFail() { + SimpleTest.ok( + false, + "privacy.resistFingerprinting is true, should not receive any gamepad events" + ); +} + +window.addEventListener("gamepadconnected", forceFail); +window.addEventListener("gamepaddisconnected", forceFail); +window.addEventListener("gamepadbuttondown", forceFail); + +window.addEventListener("load", async () => { + const service = navigator.requestGamepadServiceTest(); + const buttonIndex = await service.addGamepad( + "test gamepad", // id + service.standardMapping, + service.noHand, + 4, // buttons + 2, + 0, + 0, + 0 + ); + + // Press a button to make the gamepad visible to the page. + await service.newButtonEvent(buttonIndex, 0, true, true); + + const { length } = navigator.getGamepads(); + SimpleTest.is( + length, + 0, + "privacy.resistFingerprinting is true, navigator.getGamepads() should always return an empty array" + ); + + // Attempt to force gamepad events to be fired, by simulating gamepad disconnect + await service.removeGamepad(buttonIndex); + SimpleTest.finish(); +}); +</script> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_iframe.html b/browser/components/resistfingerprinting/test/mochitest/test_iframe.html new file mode 100644 index 0000000000..f01809b28c --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_iframe.html @@ -0,0 +1,18 @@ +<!doctype html> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" href="/tests/SimpleTest/test.css"/> +<body> +<script> + add_task(async function() { + await SpecialPowers.pushPrefEnv({ + "set": [["privacy.resistFingerprinting", true]], + }); + is(screen.width, window.innerWidth, "Width should be spoofed"); + is(screen.height, window.innerHeight, "Height should be spoofed"); + let iframe = document.createElement("iframe"); + document.body.appendChild(iframe); + is(iframe.contentWindow.screen.width, iframe.contentWindow.innerWidth, "Width should be spoofed in iframe"); + is(iframe.contentWindow.screen.height, iframe.contentWindow.innerHeight, "Height should be spoofed in iframe"); + }); +</script> +</body> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_keyboard_event.html b/browser/components/resistfingerprinting/test/mochitest/test_keyboard_event.html new file mode 100644 index 0000000000..f2ef7107f8 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_keyboard_event.html @@ -0,0 +1,61 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1222285 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1222285</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/EventUtils.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript"> + + /** Test for Bug 1222285 **/ + SimpleTest.waitForExplicitFinish(); + + window.onload = () => { + SpecialPowers.pushPrefEnv({"set": + [ + ["privacy.resistFingerprinting", true], + ], + }, doTestForSystemEventGroup); + }; + + // This test makes sure that system event group will still get real keyboard event. + function doTestForSystemEventGroup() { + SpecialPowers.addSystemEventListener(document, "keydown", + function eventHandler(aEvent) { + SpecialPowers.removeSystemEventListener(document, + "keydown", eventHandler, true); + + is(aEvent.code, "Minus", "The system group event should get real code."); + is(aEvent.keyCode, 63, "The system group event should get real keyCode."); + + doTestModifiersForSystemEventGroup(); + }, true); + + // Send key event to the system group. + synthesizeKey("\u00DF", {code: "Minus", keyCode: 63}); + } + + // Test that will system group event still get suppressed modifier keys + function doTestModifiersForSystemEventGroup() { + SpecialPowers.addSystemEventListener(document, "keydown", + function eventHandler(aEvent) { + SpecialPowers.removeSystemEventListener(document, + "keydown", eventHandler, true); + is(aEvent.key, "Alt", "The system group event get the suppressed keyboard event."); + + SimpleTest.finish(); + }, true); + + // Send key event to the system group. + synthesizeKey("KEY_Alt", {altKey: true}); + } + + </script> +</head> +<body> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_pointer_event.html b/browser/components/resistfingerprinting/test/mochitest/test_pointer_event.html new file mode 100644 index 0000000000..49c83910b0 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_pointer_event.html @@ -0,0 +1,242 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1363508 +--> +<head> + <meta charset="utf-8"> + <title>Test for Pointer Events spoofing</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/EventUtils.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<div id="target0" style="width: 50px; height: 50px; background: green"></div> +<div id="target1" style="width: 50px; height: 50px; background: black"></div> +<script type="application/javascript"> + + /** Test for Bug 1363508 **/ + SimpleTest.waitForExplicitFinish(); + + var target0 = window.document.getElementById("target0"); + var target1 = window.document.getElementById("target1"); + var utils = SpecialPowers.Ci.nsIDOMWindowUtils; + + // A helper function to check that whether the pointer is spoofed correctly. + function checkPointerEvent(aEvent) { + is(aEvent.pointerId, utils.DEFAULT_MOUSE_POINTER_ID, + "The spoofed pointer event should always have the mouse pointer id."); + is(aEvent.width, 1, "The spoofed pointer event should always have width as 1."); + is(aEvent.height, 1, "The spoofed pointer event should always have width as 1."); + if (aEvent.buttons === 0) { + is(aEvent.pressure, 0.0, + "The spoofed pointer event should have pressure as 0.0 if it is not in a active buttons state."); + } else { + is(aEvent.pressure, 0.5, + "The spoofed pointer event should have pressure as 0.5 if it is in a active buttons state."); + } + is(aEvent.tangentialPressure, 0, "The spoofed pointer event should always have tangentialPressure as 0."); + is(aEvent.tiltX, 0, "The spoofed pointer event should always have tiltX as 0."); + is(aEvent.tiltY, 0, "The spoofed pointer event should always have tiltY as 0."); + is(aEvent.twist, 0, "The spoofed pointer event should always have twist as 0."); + is(aEvent.pointerType, "mouse", "The spoofed pointer event should always has mouse pointerType."); + is(aEvent.isPrimary, true, "The spoofed pointer event should only receive primary pointer events."); + } + + // A helper function to create a promise for waiting the event. + function promiseForEvent(aEventType, aCheckFunc) { + return new Promise(resolve => { + target0.addEventListener(aEventType, (event) => { + is(event.type, aEventType, "receive " + event.type + " on target0"); + aCheckFunc(event); + resolve(); + }, { once: true }); + }); + } + + // A test for pointer events from touch interface. + async function doTestForTouchPointerEvent() { + let eventPromises = [ + promiseForEvent("pointerover", checkPointerEvent), + promiseForEvent("pointerenter", checkPointerEvent), + promiseForEvent("pointerdown", checkPointerEvent), + promiseForEvent("pointermove", checkPointerEvent), + promiseForEvent("pointerup", checkPointerEvent), + promiseForEvent("pointerout", checkPointerEvent), + promiseForEvent("pointerleave", checkPointerEvent), + ]; + + synthesizeMouse(target0, 5, 5, { type: "mousedown", inputSource: MouseEvent.MOZ_SOURCE_TOUCH, pressure: 0.75 }); + synthesizeMouse(target0, 5, 5, { type: "mousemove", inputSource: MouseEvent.MOZ_SOURCE_TOUCH, pressure: 0.75 }); + synthesizeMouse(target0, 5, 5, { type: "mouseup", inputSource: MouseEvent.MOZ_SOURCE_TOUCH, pressure: 0.75 }); + + await Promise.all(eventPromises); + } + + // A test for pointercancel event. + async function doTestForTouchPointerCancelEvent() { + let eventPromises = [ + promiseForEvent("pointerover", checkPointerEvent), + promiseForEvent("pointerenter", checkPointerEvent), + promiseForEvent("pointerdown", checkPointerEvent), + promiseForEvent("pointermove", checkPointerEvent), + promiseForEvent("pointercancel", checkPointerEvent), + promiseForEvent("pointerout", checkPointerEvent), + promiseForEvent("pointerleave", checkPointerEvent), + ]; + + synthesizeTouch(target0, 5, 5, { type: "touchstart" }); + synthesizeTouch(target0, 6, 6, { type: "touchmove" }); + synthesizeTouch(target0, 6, 6, { type: "touchcancel" }); + + await Promise.all(eventPromises); + } + + // A test for pointer events from pen interface. + async function doTestForPenPointerEvent() { + let eventPromises = [ + promiseForEvent("pointerover", checkPointerEvent), + promiseForEvent("pointerenter", checkPointerEvent), + promiseForEvent("pointerdown", checkPointerEvent), + promiseForEvent("pointermove", checkPointerEvent), + promiseForEvent("pointerup", checkPointerEvent), + promiseForEvent("pointerout", checkPointerEvent), + promiseForEvent("pointerleave", checkPointerEvent), + ]; + + synthesizeMouse(target0, 5, 5, { type: "mousedown", inputSource: MouseEvent.MOZ_SOURCE_PEN }); + synthesizeMouse(target0, 5, 5, { type: "mousemove", inputSource: MouseEvent.MOZ_SOURCE_PEN }); + synthesizeMouse(target0, 5, 5, { type: "mouseup", inputSource: MouseEvent.MOZ_SOURCE_PEN }); + synthesizeMouse(target1, 5, 5, { type: "mousemove", inputSource: MouseEvent.MOZ_SOURCE_PEN }); + + await Promise.all(eventPromises); + } + + // A test for gotpointercapture and lostpointercapture events. + // We would also test releasePointerCapture for only accepting spoofed pointer + // Id here. + async function doTestForPointerCapture() { + // We test for both mouse and touch to see whether the capture events are + // filed properly. We don't check pen here since it won't file capture + // events. + let inputSources = [ MouseEvent.MOZ_SOURCE_MOUSE, + MouseEvent.MOZ_SOURCE_TOUCH ]; + + for (let inputSource of inputSources) { + function eventHandler(event) { + checkPointerEvent(event); + if (event.type === "pointerdown") { + target0.setPointerCapture(event.pointerId); + } else if (event.type === "pointermove") { + if (inputSource === MouseEvent.MOZ_SOURCE_TOUCH) { + try { + target0.releasePointerCapture(utils.DEFAULT_TOUCH_POINTER_ID); + ok(false, "The releasePointerCapture should fail here, but it is not."); + } catch (e) { + ok(true, "The releasePointerCapture fails properly."); + } + } + target0.releasePointerCapture(event.pointerId); + } + } + + let eventPromises = [ + promiseForEvent("pointerover", eventHandler), + promiseForEvent("pointerenter", eventHandler), + promiseForEvent("pointerdown", eventHandler), + promiseForEvent("gotpointercapture", eventHandler), + promiseForEvent("pointermove", eventHandler), + promiseForEvent("lostpointercapture", eventHandler), + promiseForEvent("pointerup", eventHandler), + promiseForEvent("pointerout", eventHandler), + promiseForEvent("pointerleave", eventHandler), + ]; + + synthesizeMouse(target0, 5, 5, { type: "mousedown", inputSource }); + synthesizeMouse(target0, 5, 5, { type: "mousemove", inputSource }); + synthesizeMouse(target0, 5, 5, { type: "mouseup", inputSource }); + synthesizeMouse(target1, 5, 5, { type: "mousemove", inputSource }); + + await Promise.all(eventPromises); + } + } + + // A test for setPointerCapture() for only accepting spoofed pointer id. + async function doTestForSetPointerCapture() { + function eventHandler(event) { + checkPointerEvent(event); + if (event.type === "pointerdown") { + try { + target0.setPointerCapture(utils.DEFAULT_TOUCH_POINTER_ID); + ok(false, "The setPointerCapture should fail here, but it is not."); + } catch (e) { + ok(true, "The setPointerCapture fails properly."); + } + } + } + + let eventPromises = [ + promiseForEvent("pointerover", eventHandler), + promiseForEvent("pointerenter", eventHandler), + promiseForEvent("pointerdown", eventHandler), + promiseForEvent("pointermove", eventHandler), + promiseForEvent("pointerup", eventHandler), + promiseForEvent("pointerout", eventHandler), + promiseForEvent("pointerleave", eventHandler), + ]; + + synthesizeMouse(target0, 5, 5, { type: "mousedown", inputSource: MouseEvent.MOZ_SOURCE_TOUCH }); + synthesizeMouse(target0, 5, 5, { type: "mousemove", inputSource: MouseEvent.MOZ_SOURCE_TOUCH }); + synthesizeMouse(target0, 5, 5, { type: "mouseup", inputSource: MouseEvent.MOZ_SOURCE_TOUCH }); + + await Promise.all(eventPromises); + } + + // A test for assuring that script generated events won't be spoofed. + function doTestNoSpoofingForScriptGeneratedEvent() { + return new Promise(resolve => { + // Generate a custom pointer event by script. + let pointerEventCustom = new PointerEvent("pointerover", { + pointerId: utils.DEFAULT_TOUCH_POINTER_ID, + pointerType: "touch", + width: 5, + height: 5, + pressure: 0.75, + tangentialPressure: 0.5, + isPrimary: false, + }); + + target0.addEventListener("pointerover", (event) => { + // Check that script generated event is not spoofed. + is(event.pointerType, "touch", "The pointerEvent.pointerType is not spoofed."); + is(event.width, 5, "The pointerEvent.width is not spoofed."); + is(event.height, 5, "The pointerEvent.height is not spoofed."); + is(event.pressure, 0.75, "The pointerEvent.pressure is not spoofed."); + is(event.tangentialPressure, 0.5, "The pointerEvent.tangentialPressure is not spoofed."); + is(event.isPrimary, false, "The pointerEvent.isPrimary is not spoofed."); + resolve(); + }, { once: true }); + + target0.dispatchEvent(pointerEventCustom); + }); + } + + async function doTests() { + await doTestForTouchPointerEvent(); + await doTestForTouchPointerCancelEvent(); + await doTestForPenPointerEvent(); + await doTestForPointerCapture(); + await doTestForSetPointerCapture(); + await doTestNoSpoofingForScriptGeneratedEvent(); + + SimpleTest.finish(); + } + + SimpleTest.waitForFocus(() => { + SpecialPowers.pushPrefEnv({"set": [["privacy.resistFingerprinting", true]]}, + doTests); + }); + +</script> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/mochitest/test_speech_synthesis.html b/browser/components/resistfingerprinting/test/mochitest/test_speech_synthesis.html new file mode 100644 index 0000000000..e8df16c665 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_speech_synthesis.html @@ -0,0 +1,105 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1333641 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1333641</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript"> + + /** Test for Bug 1333641 **/ + SimpleTest.waitForExplicitFinish(); + window.onload = setupSpeechSynthesis; + + // This function setup the speechSynthesis and flip 'privacy.resistFingerprinting' + // after it has been setup correctly. + function setupSpeechSynthesis() { + window.speechSynthesis.addEventListener("voiceschanged", () => { + isnot(window.speechSynthesis.getVoices().length, 0, "Voices added"); + SimpleTest.waitForFocus(() => { + SpecialPowers.pushPrefEnv({"set": + [["privacy.resistFingerprinting", true]], + }, doGetVoicesTest); + }, window); + }, {once: true}); + + is(window.speechSynthesis.getVoices().length, 0, "No voices added initially"); + } + + function doGetVoicesTest() { + is(window.speechSynthesis.getVoices().length, 0, + "There should be no voices after fingerprinting resistance is enabled."); + doVoiceschangedEventTest(); + } + + function doVoiceschangedEventTest() { + window.speechSynthesis.addEventListener("voiceschanged", () => { + ok(false, "The voiceschanged event should not be fired."); + doSpeakTestAsync(); + }, {once: true}); + + window.addEventListener("TestEvent", () => { + // If we receive this event without receiving a 'voiceschanged' event, this means + // the voiceschanged event has been blocked correctly. + ok(true, "Got the 'TestEvent' event."); + doSpeakTestAsync(); + }, {once: true}); + + // Notify 'synth-voices-changed' for triggering the voiceschanged event. + SpecialPowers.Services.obs.notifyObservers(null, "synth-voices-changed"); + window.dispatchEvent(new CustomEvent("TestEvent")); + } + + // This tests Speak() and its asynchronousness. + function doSpeakTestAsync() { + // For non-e10s, this test will always fail since the event will be triggered immediately + // after speak() is called. So, new added events after speak() won't be called. We skip + // this test if it is non-e10s. + if (SpecialPowers.Services.appinfo.browserTabsRemoteAutostart) { + let utterance = new window.SpeechSynthesisUtterance("Hello, world!"); + window.speechSynthesis.speak(utterance); + + utterance.addEventListener("start", () => { + ok(false, "speechSynthesis should not start speaking if fingerprinting resistance is enabled."); + doSpeakTestSync(); + }, {once: true}); + + utterance.addEventListener("error", () => { + ok(true, "speechSynthesis.speak should fail if fingerprinting resistance is enabled."); + doSpeakTestSync(); + }, {once: true}); + } else { + doSpeakTestSync(); + } + } + + // This tests Speak() and its synchronousness. + function doSpeakTestSync() { + let utterance = new window.SpeechSynthesisUtterance("Hello, world!"); + utterance.addEventListener("start", () => { + ok(false, "speechSynthesis should not start speaking if fingerprinting resistance is enabled."); + SimpleTest.finish(); + }, {once: true}); + + utterance.addEventListener("error", () => { + ok(true, "speechSynthesis.speak should fail if fingerprinting resistance is enabled."); + SimpleTest.finish(); + }, {once: true}); + + window.speechSynthesis.speak(utterance); + } + + </script> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"></pre> +</body> +</html> diff --git a/browser/components/resistfingerprinting/test/mochitest/worker_child.js b/browser/components/resistfingerprinting/test/mochitest/worker_child.js new file mode 100644 index 0000000000..fa340fc652 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/worker_child.js @@ -0,0 +1,28 @@ +let timeStampCodes; +let worker = new Worker("worker_grandchild.js"); + +function listenToParent(event) { + self.removeEventListener("message", listenToParent); + timeStampCodes = event.data; + + let timeStamps = []; + for (let timeStampCode of timeStampCodes) { + timeStamps.push(eval(timeStampCode)); + } + // Send the timeStamps to the parent. + postMessage(timeStamps); + + // Tell the grandchild to start. + worker.postMessage(timeStampCodes); +} + +// The worker grandchild will send results back. +function listenToChild(event) { + worker.removeEventListener("message", listenToChild); + // Pass the results to the parent. + postMessage(event.data); + worker.terminate(); +} + +worker.addEventListener("message", listenToChild); +self.addEventListener("message", listenToParent); diff --git a/browser/components/resistfingerprinting/test/mochitest/worker_grandchild.js b/browser/components/resistfingerprinting/test/mochitest/worker_grandchild.js new file mode 100644 index 0000000000..cd21508b2b --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/worker_grandchild.js @@ -0,0 +1,10 @@ +self.addEventListener("message", function(event) { + let timeStampCodes = event.data; + + let timeStamps = []; + for (let timeStampCode of timeStampCodes) { + timeStamps.push(eval(timeStampCode)); + } + // Send the timeStamps to the parent. + postMessage(timeStamps); +}); |