bug418986-3.js (2792B)
1 SimpleTest.waitForExplicitFinish(); 2 3 // The main testing function. 4 var test = async function (isContent) { 5 await SpecialPowers.contentTransformsReceived(window); 6 7 // Each definition is [eventType, prefSetting] 8 // Where we are setting the "privacy.resistFingerprinting" pref. 9 let eventDefs = [ 10 ["mousedown", true], 11 ["mouseup", true], 12 ["mousedown", false], 13 ["mouseup", false], 14 ]; 15 16 let testCounter = 0; 17 18 // Declare ahead of time. 19 let setup; 20 21 // This function is called when the event handler fires. 22 let handleEvent = function (event, prefVal) { 23 let resisting = prefVal && isContent; 24 if (resisting) { 25 is( 26 event.screenX, 27 event.clientX, 28 "event.screenX and event.clientX should be the same" 29 ); 30 is( 31 event.screenY, 32 event.clientY, 33 "event.screenY and event.clientY should be the same" 34 ); 35 } else { 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"); 38 } 39 ++testCounter; 40 if (testCounter < eventDefs.length) { 41 nextTest(); 42 } else { 43 SimpleTest.finish(); 44 } 45 }; 46 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]] }, 55 function () { 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", 61 "div" 62 ); 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. 67 div.id = eventType; 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 }); 77 }, 0); 78 }, 0); 79 } 80 ); 81 }; 82 83 // Now run by starting with the 0th event. 84 nextTest(); 85 };