Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // Tests if the JSTerm sandbox is updated when the user navigates from one |
michael@0 | 7 | // domain to another, in order to avoid permission denied errors with a sandbox |
michael@0 | 8 | // created for a different origin. |
michael@0 | 9 | |
michael@0 | 10 | function test() |
michael@0 | 11 | { |
michael@0 | 12 | const TEST_URI1 = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; |
michael@0 | 13 | const TEST_URI2 = "http://example.org/browser/browser/devtools/webconsole/test/test-console.html"; |
michael@0 | 14 | |
michael@0 | 15 | let hud; |
michael@0 | 16 | let msgForLocation1; |
michael@0 | 17 | |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | gBrowser.selectedTab = gBrowser.addTab(TEST_URI1); |
michael@0 | 21 | gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 22 | gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 23 | openConsole(gBrowser.selectedTab, pageLoad1); |
michael@0 | 24 | }, true); |
michael@0 | 25 | |
michael@0 | 26 | function pageLoad1(aHud) |
michael@0 | 27 | { |
michael@0 | 28 | hud = aHud; |
michael@0 | 29 | |
michael@0 | 30 | hud.jsterm.clearOutput(); |
michael@0 | 31 | hud.jsterm.execute("window.location.href"); |
michael@0 | 32 | |
michael@0 | 33 | info("wait for window.location.href"); |
michael@0 | 34 | |
michael@0 | 35 | msgForLocation1 = { |
michael@0 | 36 | webconsole: hud, |
michael@0 | 37 | messages: [ |
michael@0 | 38 | { |
michael@0 | 39 | name: "window.location.href jsterm input", |
michael@0 | 40 | text: "window.location.href", |
michael@0 | 41 | category: CATEGORY_INPUT, |
michael@0 | 42 | }, |
michael@0 | 43 | { |
michael@0 | 44 | name: "window.location.href result is displayed", |
michael@0 | 45 | text: TEST_URI1, |
michael@0 | 46 | category: CATEGORY_OUTPUT, |
michael@0 | 47 | }, |
michael@0 | 48 | ] |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | waitForMessages(msgForLocation1).then(() => { |
michael@0 | 52 | gBrowser.selectedBrowser.addEventListener("load", onPageLoad2, true); |
michael@0 | 53 | content.location = TEST_URI2; |
michael@0 | 54 | }); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function onPageLoad2() { |
michael@0 | 58 | gBrowser.selectedBrowser.removeEventListener("load", onPageLoad2, true); |
michael@0 | 59 | |
michael@0 | 60 | is(hud.outputNode.textContent.indexOf("Permission denied"), -1, |
michael@0 | 61 | "no permission denied errors"); |
michael@0 | 62 | |
michael@0 | 63 | hud.jsterm.clearOutput(); |
michael@0 | 64 | hud.jsterm.execute("window.location.href"); |
michael@0 | 65 | |
michael@0 | 66 | info("wait for window.location.href after page navigation"); |
michael@0 | 67 | |
michael@0 | 68 | waitForMessages({ |
michael@0 | 69 | webconsole: hud, |
michael@0 | 70 | messages: [ |
michael@0 | 71 | { |
michael@0 | 72 | name: "window.location.href jsterm input", |
michael@0 | 73 | text: "window.location.href", |
michael@0 | 74 | category: CATEGORY_INPUT, |
michael@0 | 75 | }, |
michael@0 | 76 | { |
michael@0 | 77 | name: "window.location.href result is displayed", |
michael@0 | 78 | text: TEST_URI2, |
michael@0 | 79 | category: CATEGORY_OUTPUT, |
michael@0 | 80 | }, |
michael@0 | 81 | ] |
michael@0 | 82 | }).then(() => { |
michael@0 | 83 | is(hud.outputNode.textContent.indexOf("Permission denied"), -1, |
michael@0 | 84 | "no permission denied errors"); |
michael@0 | 85 | |
michael@0 | 86 | gBrowser.goBack(); |
michael@0 | 87 | waitForSuccess(waitForBack); |
michael@0 | 88 | }); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | let waitForBack = { |
michael@0 | 92 | name: "go back", |
michael@0 | 93 | validatorFn: function() |
michael@0 | 94 | { |
michael@0 | 95 | return content.location.href == TEST_URI1; |
michael@0 | 96 | }, |
michael@0 | 97 | successFn: function() |
michael@0 | 98 | { |
michael@0 | 99 | hud.jsterm.clearOutput(); |
michael@0 | 100 | executeSoon(() => { |
michael@0 | 101 | hud.jsterm.execute("window.location.href"); |
michael@0 | 102 | }); |
michael@0 | 103 | |
michael@0 | 104 | info("wait for window.location.href after goBack()"); |
michael@0 | 105 | waitForMessages(msgForLocation1).then(() => executeSoon(() => { |
michael@0 | 106 | is(hud.outputNode.textContent.indexOf("Permission denied"), -1, |
michael@0 | 107 | "no permission denied errors"); |
michael@0 | 108 | finishTest(); |
michael@0 | 109 | })); |
michael@0 | 110 | }, |
michael@0 | 111 | failureFn: finishTest, |
michael@0 | 112 | }; |
michael@0 | 113 | } |