1 SimpleTest.waitForExplicitFinish();
3 // The main testing function.
4 var test = async function(isContent) {
5 await SpecialPowers.contentTransformsReceived(window);
7 // Each definition is [eventType, prefSetting]
8 // Where we are setting the "privacy.resistFingerprinting" pref.
18 // Declare ahead of time.
21 // This function is called when the event handler fires.
22 let handleEvent = function(event, prefVal) {
23 let resisting = prefVal && isContent;
28 "event.screenX and event.clientX should be the same"
33 "event.screenY and event.clientY should be the same"
36 // We can't be sure about X coordinates not being equal, but we can test Y.
37 isnot(event.screenY, event.clientY, "event.screenY !== event.clientY");
40 if (testCounter < eventDefs.length) {
47 // In this function, we set up the nth div and event handler,
48 // and then synthesize a mouse event in the div, to test
49 // whether the resulting events resist fingerprinting by
50 // suppressing absolute screen coordinates.
51 nextTest = function() {
52 let [eventType, prefVal] = eventDefs[testCounter];
53 SpecialPowers.pushPrefEnv(
54 { set: [["privacy.resistFingerprinting", prefVal]] },
56 // The following code creates a new div for each event in eventDefs,
57 // attaches a listener to listen for the event, and then generates
58 // a fake event at the center of the div.
59 let div = document.createElementNS(
60 "http://www.w3.org/1999/xhtml",
63 div.style.width = "10px";
64 div.style.height = "10px";
65 div.style.backgroundColor = "red";
66 // Name the div after the event we're listening for.
68 document.getElementById("body").appendChild(div);
69 // Seems we can't add an event listener in chrome unless we run
70 // it in a later task.
71 window.setTimeout(function() {
72 div.addEventListener(eventType, event => handleEvent(event, prefVal));
73 // For some reason, the following synthesizeMouseAtCenter call only seems to run if we
74 // wrap it in a window.setTimeout(..., 0).
75 window.setTimeout(function() {
76 synthesizeMouseAtCenter(div, { type: eventType });
83 // Now run by starting with the 0th event.