browser_webconsole_sandbox_update_after_navigation.js (1805B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Tests if the JSTerm sandbox is updated when the user navigates from one 5 // domain to another, in order to avoid permission denied errors with a sandbox 6 // created for a different origin. See Bug 664688. 7 8 "use strict"; 9 10 const BASE_URI = 11 "browser/devtools/client/webconsole/test/browser/test-console.html"; 12 const TEST_URI1 = "https://example.com/" + BASE_URI; 13 const TEST_URI2 = "https://example.org/" + BASE_URI; 14 15 add_task(async function () { 16 await pushPref("devtools.webconsole.persistlog", false); 17 18 const hud = await openNewTabAndConsole(TEST_URI1); 19 20 await executeAndWaitForResultMessage(hud, "window.location.href", TEST_URI1); 21 22 // load second url 23 await navigateTo(TEST_URI2); 24 25 ok( 26 !findErrorMessage(hud, "Permission denied"), 27 "no permission denied errors" 28 ); 29 30 info("wait for window.location.href after page navigation"); 31 await clearOutput(hud); 32 await executeAndWaitForResultMessage(hud, "window.location.href", TEST_URI2); 33 34 ok( 35 !findErrorMessage(hud, "Permission denied"), 36 "no permission denied errors" 37 ); 38 39 // Navigation clears messages. Wait for that clear to happen before 40 // continuing the test or it might destroy messages we wait later on (Bug 41 // 1270234). 42 const promises = [ 43 hud.ui.once("messages-cleared"), 44 hud.commands.targetCommand.once("switched-target"), 45 ]; 46 47 gBrowser.goBack(); 48 49 info("Waiting for messages-cleared event due to navigation"); 50 await Promise.all(promises); 51 52 info("Messages cleared after navigation; checking location"); 53 await executeAndWaitForResultMessage(hud, "window.location.href", TEST_URI1); 54 55 ok( 56 !findErrorMessage(hud, "Permission denied"), 57 "no permission denied errors" 58 ); 59 });