browser_utilityOverlayPrincipal.js (2320B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const gTests = [test_openUILink_checkPrincipal]; 6 7 function test() { 8 waitForExplicitFinish(); 9 executeSoon(runNextTest); 10 } 11 12 function runNextTest() { 13 if (gTests.length) { 14 let testFun = gTests.shift(); 15 info("Running " + testFun.name); 16 testFun(); 17 } else { 18 finish(); 19 } 20 } 21 22 function test_openUILink_checkPrincipal() { 23 let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab( 24 gBrowser, 25 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 26 "http://example.com/" 27 )); // remote tab 28 BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(async function () { 29 is( 30 tab.linkedBrowser.currentURI.spec, 31 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 32 "http://example.com/", 33 "example.com loaded" 34 ); 35 36 await SpecialPowers.spawn(tab.linkedBrowser, [], function () { 37 let channel = content.docShell.currentDocumentChannel; 38 39 const loadingPrincipal = channel.loadInfo.loadingPrincipal; 40 is(loadingPrincipal, null, "sanity: correct loadingPrincipal"); 41 const triggeringPrincipal = channel.loadInfo.triggeringPrincipal; 42 ok( 43 triggeringPrincipal.isSystemPrincipal, 44 "sanity: correct triggeringPrincipal" 45 ); 46 const principalToInherit = channel.loadInfo.principalToInherit; 47 ok( 48 principalToInherit.isNullPrincipal, 49 "sanity: correct principalToInherit" 50 ); 51 ok( 52 content.document.nodePrincipal.isContentPrincipal, 53 "sanity: correct doc.nodePrincipal" 54 ); 55 is( 56 content.document.nodePrincipal.asciiSpec, 57 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 58 "http://example.com/", 59 "sanity: correct doc.nodePrincipal URL" 60 ); 61 }); 62 63 gBrowser.removeCurrentTab(); 64 runNextTest(); 65 }); 66 67 // Ensure we get the correct default of "allowInheritPrincipal: false" from openUILink 68 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 69 openUILink("http://example.com", null, { 70 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal({}), 71 }); // defaults to "current" 72 }