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