michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Tests if the JSTerm sandbox is updated when the user navigates from one michael@0: // domain to another, in order to avoid permission denied errors with a sandbox michael@0: // created for a different origin. michael@0: michael@0: function test() michael@0: { michael@0: const TEST_URI1 = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; michael@0: const TEST_URI2 = "http://example.org/browser/browser/devtools/webconsole/test/test-console.html"; michael@0: michael@0: let hud; michael@0: let msgForLocation1; michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(TEST_URI1); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: openConsole(gBrowser.selectedTab, pageLoad1); michael@0: }, true); michael@0: michael@0: function pageLoad1(aHud) michael@0: { michael@0: hud = aHud; michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute("window.location.href"); michael@0: michael@0: info("wait for window.location.href"); michael@0: michael@0: msgForLocation1 = { michael@0: webconsole: hud, michael@0: messages: [ michael@0: { michael@0: name: "window.location.href jsterm input", michael@0: text: "window.location.href", michael@0: category: CATEGORY_INPUT, michael@0: }, michael@0: { michael@0: name: "window.location.href result is displayed", michael@0: text: TEST_URI1, michael@0: category: CATEGORY_OUTPUT, michael@0: }, michael@0: ] michael@0: }; michael@0: michael@0: waitForMessages(msgForLocation1).then(() => { michael@0: gBrowser.selectedBrowser.addEventListener("load", onPageLoad2, true); michael@0: content.location = TEST_URI2; michael@0: }); michael@0: } michael@0: michael@0: function onPageLoad2() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onPageLoad2, true); michael@0: michael@0: is(hud.outputNode.textContent.indexOf("Permission denied"), -1, michael@0: "no permission denied errors"); michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute("window.location.href"); michael@0: michael@0: info("wait for window.location.href after page navigation"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [ michael@0: { michael@0: name: "window.location.href jsterm input", michael@0: text: "window.location.href", michael@0: category: CATEGORY_INPUT, michael@0: }, michael@0: { michael@0: name: "window.location.href result is displayed", michael@0: text: TEST_URI2, michael@0: category: CATEGORY_OUTPUT, michael@0: }, michael@0: ] michael@0: }).then(() => { michael@0: is(hud.outputNode.textContent.indexOf("Permission denied"), -1, michael@0: "no permission denied errors"); michael@0: michael@0: gBrowser.goBack(); michael@0: waitForSuccess(waitForBack); michael@0: }); michael@0: } michael@0: michael@0: let waitForBack = { michael@0: name: "go back", michael@0: validatorFn: function() michael@0: { michael@0: return content.location.href == TEST_URI1; michael@0: }, michael@0: successFn: function() michael@0: { michael@0: hud.jsterm.clearOutput(); michael@0: executeSoon(() => { michael@0: hud.jsterm.execute("window.location.href"); michael@0: }); michael@0: michael@0: info("wait for window.location.href after goBack()"); michael@0: waitForMessages(msgForLocation1).then(() => executeSoon(() => { michael@0: is(hud.outputNode.textContent.indexOf("Permission denied"), -1, michael@0: "no permission denied errors"); michael@0: finishTest(); michael@0: })); michael@0: }, michael@0: failureFn: finishTest, michael@0: }; michael@0: }