mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1830070: Add a test for popup that is an about:blank document r=timhuang
Differential Revision: https://phabricator.services.mozilla.com/D178865
This commit is contained in:
parent
02bba73900
commit
88106c0525
@ -17,6 +17,7 @@ support-files =
|
||||
file_navigator_iframe_worker.sjs
|
||||
file_hwconcurrency_aboutblank_iframer.html
|
||||
file_hwconcurrency_aboutblank_iframee.html
|
||||
file_hwconcurrency_aboutblank_popupmaker.html
|
||||
file_hwconcurrency_aboutsrcdoc_iframer.html
|
||||
file_hwconcurrency_aboutsrcdoc_iframee.html
|
||||
file_hwconcurrency_blob_iframer.html
|
||||
@ -60,6 +61,7 @@ skip-if =
|
||||
[browser_hwconcurrency_iframes_data.js]
|
||||
[browser_hwconcurrency_iframes_sandboxediframe.js]
|
||||
[browser_hwconcurrency_popups.js]
|
||||
[browser_hwconcurrency_popups_aboutblank.js]
|
||||
[browser_hwconcurrency_popups_blob.js]
|
||||
[browser_hwconcurrency_popups_data.js]
|
||||
[browser_math.js]
|
||||
|
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* This test only tests values in an about:blank document that opened in a popup
|
||||
* Because there is no interaction with a third party domain, there's a lot fewer tests
|
||||
*
|
||||
* Covers the following cases:
|
||||
* - RFP is disabled entirely
|
||||
* - RFP is enabled entirely
|
||||
*
|
||||
* - (A) RFP is exempted on the popup maker
|
||||
* - (E) RFP is not exempted on the popup maker
|
||||
*
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const SPOOFED_HW_CONCURRENCY = 2;
|
||||
|
||||
const DEFAULT_HARDWARE_CONCURRENCY = navigator.hardwareConcurrency;
|
||||
|
||||
// =============================================================================================
|
||||
// =============================================================================================
|
||||
|
||||
async function testHWConcurrency(result, expectedResults, extraData) {
|
||||
let testDesc = extraData.testDesc;
|
||||
|
||||
is(
|
||||
result.hardwareConcurrency,
|
||||
expectedResults.hardwareConcurrency,
|
||||
`Checking ${testDesc} navigator.hardwareConcurrency.`
|
||||
);
|
||||
}
|
||||
|
||||
// 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 = structuredClone(allNotSpoofed)` to do a
|
||||
// deep copy and avoiding corrupting the original 'const' object
|
||||
const allNotSpoofed = {
|
||||
hardwareConcurrency: DEFAULT_HARDWARE_CONCURRENCY,
|
||||
};
|
||||
const allSpoofed = {
|
||||
hardwareConcurrency: SPOOFED_HW_CONCURRENCY,
|
||||
};
|
||||
|
||||
const uri = `https://${FRAMER_DOMAIN}/browser/browser/components/resistfingerprinting/test/browser/file_hwconcurrency_aboutblank_popupmaker.html`;
|
||||
|
||||
requestLongerTimeout(2);
|
||||
|
||||
let expectedResults = {};
|
||||
|
||||
expectedResults = structuredClone(allNotSpoofed);
|
||||
add_task(defaultsTest.bind(null, uri, testHWConcurrency, expectedResults));
|
||||
|
||||
expectedResults = structuredClone(allSpoofed);
|
||||
add_task(simpleRFPTest.bind(null, uri, testHWConcurrency, expectedResults));
|
||||
|
||||
// (A) RFP is exempted on the popup maker
|
||||
expectedResults = structuredClone(allNotSpoofed);
|
||||
add_task(testA.bind(null, uri, testHWConcurrency, expectedResults));
|
||||
|
||||
// (E) RFP is not exempted on the popup maker
|
||||
expectedResults = structuredClone(allSpoofed);
|
||||
add_task(testE.bind(null, uri, testHWConcurrency, expectedResults));
|
@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf8">
|
||||
<script src="shared_test_funcs.js"></script>
|
||||
<script>
|
||||
var popup = undefined;
|
||||
function createPopup() {
|
||||
if(popup === undefined) {
|
||||
console.log("TKTK: Creating popup");
|
||||
let s = `
|
||||
window.addEventListener('message', async function listener(event) {
|
||||
if (event.data[0] == 'popup_is_ready') {
|
||||
window.opener.postMessage(["popup_ready"], "*");
|
||||
} else if (event.data[0] == 'popup_request') {
|
||||
let result = {
|
||||
hardwareConcurrency : navigator.hardwareConcurrency
|
||||
};
|
||||
window.opener.postMessage(['popup_response', result], '*');
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
setInterval(function() {
|
||||
if(!window.opener || window.opener.closed) {
|
||||
window.close();
|
||||
}
|
||||
}, 50);`;
|
||||
|
||||
popup = window.open("about:blank", "");
|
||||
popup.eval(s);
|
||||
} else {
|
||||
console.log("TKTK: popup already exists");
|
||||
}
|
||||
}
|
||||
window.addEventListener("load", createPopup);
|
||||
console.log("TKTK: Adding initial load");
|
||||
|
||||
async function runTheTest(iframe_domain, cross_origin_domain, mode) {
|
||||
await new Promise(r => setTimeout(r, 2000));
|
||||
console.log("TKTK: runTheTest() popup =", (popup === undefined ? "undefined" : "something"));
|
||||
if (document.readyState !== 'complete') {
|
||||
console.log("TKTK: !== complete");
|
||||
createPopup();
|
||||
} else if(popup === undefined) {
|
||||
console.log("TKTK: popup is undefined");
|
||||
createPopup();
|
||||
}
|
||||
console.log("TKTK: now popup =", (popup === undefined ? "undefined" : "something"));
|
||||
popup.postMessage(["popup_is_ready", cross_origin_domain], "*");
|
||||
await waitForMessage("popup_ready", `*`);
|
||||
|
||||
const promiseForRFPTest = new Promise(resolve => {
|
||||
window.addEventListener("message", event => {
|
||||
resolve(event.data[1]);
|
||||
}, { once: true });
|
||||
});
|
||||
|
||||
popup.postMessage(["popup_request", cross_origin_domain], "*");
|
||||
var result = await promiseForRFPTest;
|
||||
|
||||
popup.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
</script>
|
||||
<output id="result"></output>
|
Loading…
Reference in New Issue
Block a user