browser_unlinkable_about_page_can_load_module_scripts.js (2329B)
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 6 "use strict"; 7 8 const kTestPage = getRootDirectory(gTestPath) + "file_load_module_script.html"; 9 10 const kDefaultFlags = 11 Ci.nsIAboutModule.ALLOW_SCRIPT | 12 Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD | 13 Ci.nsIAboutModule.URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS | 14 Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT; 15 16 const kAboutPagesRegistered = Promise.all([ 17 BrowserTestUtils.registerAboutPage( 18 registerCleanupFunction, 19 "test-linkable-page", 20 kTestPage, 21 kDefaultFlags | Ci.nsIAboutModule.MAKE_LINKABLE 22 ), 23 BrowserTestUtils.registerAboutPage( 24 registerCleanupFunction, 25 "test-unlinkable-page", 26 kTestPage, 27 kDefaultFlags 28 ), 29 ]); 30 31 add_task(async function () { 32 await kAboutPagesRegistered; 33 34 let consoleListener = { 35 observe() { 36 errorCount++; 37 if (shouldHaveJSError) { 38 ok(true, "JS error is expected and received"); 39 } else { 40 ok(false, "Unexpected JS error was received"); 41 } 42 }, 43 }; 44 Services.console.registerListener(consoleListener); 45 registerCleanupFunction(() => 46 Services.console.unregisterListener(consoleListener) 47 ); 48 49 let shouldHaveJSError = true; 50 let errorCount = 0; 51 await BrowserTestUtils.withNewTab( 52 { gBrowser, url: "about:test-linkable-page" }, 53 async browser => { 54 await SpecialPowers.spawn(browser, [], () => { 55 isnot( 56 content.document.body.textContent, 57 "scriptLoaded", 58 "The page content shouldn't be changed on the linkable page" 59 ); 60 }); 61 } 62 ); 63 Assert.greater( 64 errorCount, 65 0, 66 "Should have an error when loading test-linkable-page, got " + errorCount 67 ); 68 69 shouldHaveJSError = false; 70 errorCount = 0; 71 await BrowserTestUtils.withNewTab( 72 { gBrowser, url: "about:test-unlinkable-page" }, 73 async browser => { 74 await SpecialPowers.spawn(browser, [], () => { 75 is( 76 content.document.body.textContent, 77 "scriptLoaded", 78 "The page content should be changed on the unlinkable page" 79 ); 80 }); 81 } 82 ); 83 is(errorCount, 0, "Should have no errors when loading test-unlinkable-page"); 84 });