browser_test_web_manifest_mixed_content.js (1555B)
1 /* 2 * Description of the test: 3 * Check that mixed content blocker works prevents fetches of 4 * mixed content manifests. 5 */ 6 /*globals Cu, ok*/ 7 "use strict"; 8 const { ManifestObtainer } = ChromeUtils.importESModule( 9 "resource://gre/modules/ManifestObtainer.sys.mjs" 10 ); 11 const path = "/tests/dom/security/test/csp/"; 12 const mixedContent = `${path}file_web_manifest_mixed_content.html`; 13 const server = `${path}file_testserver.sjs`; 14 const secureURL = new URL(`https://example.com${server}`); 15 const tests = [ 16 // Trying to load mixed content in file_web_manifest_mixed_content.html 17 // needs to result in an error. 18 { 19 expected: "Mixed Content Blocker prevents fetching manifest.", 20 get tabURL() { 21 const url = new URL(secureURL); 22 url.searchParams.append("file", mixedContent); 23 return url.href; 24 }, 25 run(error) { 26 // Check reason for error. 27 const check = /NetworkError when attempting to fetch resource/.test( 28 error.message 29 ); 30 ok(check, this.expected); 31 }, 32 }, 33 ]; 34 35 //jscs:disable 36 add_task(async function () { 37 //jscs:enable 38 const testPromises = tests.map(test => { 39 const tabOptions = { 40 gBrowser, 41 url: test.tabURL, 42 skipAnimation: true, 43 }; 44 return BrowserTestUtils.withNewTab(tabOptions, browser => 45 testObtainingManifest(browser, test) 46 ); 47 }); 48 await Promise.all(testPromises); 49 }); 50 51 async function testObtainingManifest(aBrowser, aTest) { 52 try { 53 await ManifestObtainer.browserObtainManifest(aBrowser); 54 } catch (e) { 55 aTest.run(e); 56 } 57 }