Bug 1369303 - Part 4: Add a test case for workers to check whether performance API has been correctly spoofed when 'privacy.resistFingerprinting' is true. r?baku,arthuredelstein
This patch adds a test case in the same file of part 3 that to check that does
fingerprinting resistance work correctly for workers when 'privacy.resistFingerprinting'
is true.
MozReview-Commit-ID: FoceQTGg127
--- a/browser/components/resistfingerprinting/test/browser/browser.ini
+++ b/browser/components/resistfingerprinting/test/browser/browser.ini
@@ -1,12 +1,13 @@
[DEFAULT]
tags = resistfingerprinting
support-files =
file_dummy.html
+ file_workerPerformance.js
head.js
[browser_performanceAPI.js]
[browser_roundedWindow_dialogWindow.js]
[browser_roundedWindow_newWindow.js]
[browser_roundedWindow_open_max.js]
[browser_roundedWindow_open_mid.js]
[browser_roundedWindow_open_min.js]
--- a/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js
@@ -24,21 +24,23 @@ const PERFORMANCE_TIMINGS = [
"domInteractive",
"domContentLoadedEventStart",
"domContentLoadedEventEnd",
"domComplete",
"loadEventStart",
"loadEventEnd",
];
-add_task(async function runTests() {
+add_task(async function setup() {
await SpecialPowers.pushPrefEnv({"set":
[["privacy.resistFingerprinting", true]]
});
+});
+add_task(async function runTests() {
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser, TEST_PATH + "file_dummy.html");
await ContentTask.spawn(tab.linkedBrowser, PERFORMANCE_TIMINGS, async function(list) {
// Check that whether the performance timing API is correctly spoofed.
for (let time of list) {
is(content.performance.timing[time], 0, `The timing(${time}) is correctly spoofed.`);
}
@@ -52,8 +54,32 @@ add_task(async function runTests() {
is(content.performance.getEntries().length, 0, "No entries for performance.getEntries()");
is(content.performance.getEntriesByType("resource").length, 0, "No entries for performance.getEntriesByType()");
is(content.performance.getEntriesByName("Test", "mark").length, 0, "No entries for performance.getEntriesByName()");
});
await BrowserTestUtils.removeTab(tab);
});
+
+add_task(async function runTestsForWorker() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(
+ gBrowser, TEST_PATH + "file_dummy.html");
+
+ await ContentTask.spawn(tab.linkedBrowser, null, async function() {
+ 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") {
+ resolve();
+ } else {
+ ok(false, "Unknown message type");
+ resolve();
+ }
+ }
+ worker.postMessage({type: "runTests"});
+ });
+ });
+
+ await BrowserTestUtils.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/file_workerPerformance.js
@@ -0,0 +1,33 @@
+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() {
+ // 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, "No entries for performance.getEntries() for workers");
+ is(performance.getEntriesByType("resource").length, 0, "No entries for performance.getEntriesByType() for workers");
+ is(performance.getEntriesByName("Test", "mark").length, 0, "No entries for performance.getEntriesByName() for workers");
+
+ finish();
+}
+
+self.onmessage = function(e) {
+ if (e.data.type === "runTests") {
+ runTests();
+ } else {
+ ok(false, "Unknown message type");
+ }
+}