test_navigator_buildID.html (2653B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=583181 5 --> 6 <head> 7 <title>Test for Bug 583181</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/ChromeTask.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 11 </head> 12 <body onload="onLoad()"> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=583181">Mozilla Bug 583181</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 17 </div> 18 <pre id="test"> 19 <script class="testbody" type="text/javascript"> 20 "use strict"; 21 22 SimpleTest.waitForExplicitFinish(); 23 24 const LEGACY_BUILD_ID = 20181001000000; 25 26 // 27 // Access navigator.buildID from unprivileged web content. 28 // 29 var isOK = false; 30 try { 31 var contentBuildID = navigator.buildID; 32 isOK = true; 33 } catch (ex) { 34 } 35 ok(isOK, "navigator.buildID should never throw"); 36 is(typeof(contentBuildID), "string", "navigator.buildID should be a string"); 37 is(+contentBuildID, LEGACY_BUILD_ID, 38 "navigator.buildID should be spoofed in content"); 39 40 async function onLoad() { 41 // 42 // Access navigator.buildID from chrome. 43 // 44 let chromeBuildID = await ChromeTask.spawn(null, () => { 45 const browser = Services.wm.getMostRecentBrowserWindow(); 46 return browser.navigator.buildID; 47 }); 48 49 ok(+chromeBuildID > LEGACY_BUILD_ID, 50 `navigator.buildID should be exposed in chrome - got "${chromeBuildID}"`); 51 52 // 53 // Access navigator.buildID from mozilla.org. 54 // 55 let mozillaBuildID = await getMozillaBuildID(); 56 57 ok(+mozillaBuildID > LEGACY_BUILD_ID, 58 `navigator.buildID should be exposed on mozilla.org ` + 59 `- got "${mozillaBuildID}"`); 60 is(chromeBuildID, mozillaBuildID, 61 "navigator.buildID should be the same in chrome and on mozilla.org"); 62 63 // 64 // Access navigator.buildID from mozilla.org when resisting fingerprinting. 65 // 66 await SpecialPowers.pushPrefEnv( 67 {"set": [["privacy.resistFingerprinting", true]]}); 68 69 let resistBuildID = await getMozillaBuildID(); 70 71 is(+resistBuildID, LEGACY_BUILD_ID, 72 "navigator.buildID should be spoofed on mozilla.org when " + 73 "resisting fingerprinting"); 74 75 SimpleTest.finish(); 76 } 77 78 async function getMozillaBuildID() { 79 let iframe = document.getElementById("mozillaIFrame"); 80 81 await new Promise(resolve => { 82 iframe.addEventListener("load", resolve, { once: true }); 83 SpecialPowers.spawn(iframe, [], () => this.content.location.reload()); 84 }); 85 86 return SpecialPowers.spawn( 87 iframe, [], () => this.content.wrappedJSObject.navigator.buildID); 88 } 89 </script> 90 </pre> 91 <iframe id="mozillaIFrame" src="https://www.mozilla.org/" /> 92 </body> 93 </html>