browser_platform_emulation.js (1719B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const URL = "data:text/html;charset=utf-8,<iframe id='test-iframe'></iframe>"; 7 8 async function contentTaskNoOverride() { 9 let docshell = docShell; 10 is( 11 docshell.browsingContext.customPlatform, 12 "", 13 "There should initially be no customPlatform" 14 ); 15 } 16 17 async function contentTaskOverride() { 18 let docshell = docShell; 19 is( 20 docshell.browsingContext.customPlatform, 21 "foo", 22 "The platform should be changed to foo" 23 ); 24 25 is( 26 content.navigator.platform, 27 "foo", 28 "The platform should be changed to foo" 29 ); 30 31 let frameWin = content.document.querySelector("#test-iframe").contentWindow; 32 is( 33 frameWin.navigator.platform, 34 "foo", 35 "The platform should be passed on to frames." 36 ); 37 38 let newFrame = content.document.createElement("iframe"); 39 content.document.body.appendChild(newFrame); 40 41 let newFrameWin = newFrame.contentWindow; 42 is( 43 newFrameWin.navigator.platform, 44 "foo", 45 "Newly created frames should use the new platform" 46 ); 47 48 newFrameWin.location.reload(); 49 await ContentTaskUtils.waitForEvent(newFrame, "load"); 50 51 is( 52 newFrameWin.navigator.platform, 53 "foo", 54 "New platform should persist across reloads" 55 ); 56 } 57 58 add_task(async function () { 59 await BrowserTestUtils.withNewTab( 60 { gBrowser, url: URL }, 61 async function (browser) { 62 await SpecialPowers.spawn(browser, [], contentTaskNoOverride); 63 64 let browsingContext = BrowserTestUtils.getBrowsingContextFrom(browser); 65 browsingContext.customPlatform = "foo"; 66 67 await SpecialPowers.spawn(browser, [], contentTaskOverride); 68 } 69 ); 70 });