|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test that the cd() jsterm helper function works as expected. See bug 609872. |
|
5 |
|
6 function test() { |
|
7 let hud; |
|
8 |
|
9 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-609872-cd-iframe-parent.html"; |
|
10 |
|
11 const parentMessages = [{ |
|
12 name: "document.title in parent iframe", |
|
13 text: "bug 609872 - iframe parent", |
|
14 category: CATEGORY_OUTPUT, |
|
15 }, { |
|
16 name: "paragraph content", |
|
17 text: "p: test for bug 609872 - iframe parent", |
|
18 category: CATEGORY_OUTPUT, |
|
19 }, { |
|
20 name: "object content", |
|
21 text: "obj: parent!", |
|
22 category: CATEGORY_OUTPUT, |
|
23 }]; |
|
24 |
|
25 const childMessages = [{ |
|
26 name: "document.title in child iframe", |
|
27 text: "bug 609872 - iframe child", |
|
28 category: CATEGORY_OUTPUT, |
|
29 }, { |
|
30 name: "paragraph content", |
|
31 text: "p: test for bug 609872 - iframe child", |
|
32 category: CATEGORY_OUTPUT, |
|
33 }, { |
|
34 name: "object content", |
|
35 text: "obj: child!", |
|
36 category: CATEGORY_OUTPUT, |
|
37 }]; |
|
38 |
|
39 Task.spawn(runner).then(finishTest); |
|
40 |
|
41 function* runner() { |
|
42 const {tab} = yield loadTab(TEST_URI); |
|
43 hud = yield openConsole(tab); |
|
44 |
|
45 executeWindowTest(); |
|
46 |
|
47 yield waitForMessages({ webconsole: hud, messages: parentMessages }); |
|
48 |
|
49 info("cd() into the iframe using a selector"); |
|
50 hud.jsterm.clearOutput(); |
|
51 hud.jsterm.execute("cd('iframe')"); |
|
52 executeWindowTest(); |
|
53 |
|
54 yield waitForMessages({ webconsole: hud, messages: childMessages }); |
|
55 |
|
56 info("cd() out of the iframe, reset to default window"); |
|
57 hud.jsterm.clearOutput(); |
|
58 hud.jsterm.execute("cd()"); |
|
59 executeWindowTest(); |
|
60 |
|
61 yield waitForMessages({ webconsole: hud, messages: parentMessages }); |
|
62 |
|
63 info("call cd() with unexpected arguments"); |
|
64 hud.jsterm.clearOutput(); |
|
65 hud.jsterm.execute("cd(document)"); |
|
66 |
|
67 yield waitForMessages({ |
|
68 webconsole: hud, |
|
69 messages: [{ |
|
70 text: "Cannot cd()", |
|
71 category: CATEGORY_OUTPUT, |
|
72 severity: SEVERITY_ERROR, |
|
73 }], |
|
74 }); |
|
75 |
|
76 hud.jsterm.clearOutput(); |
|
77 hud.jsterm.execute("cd('p')"); |
|
78 |
|
79 yield waitForMessages({ |
|
80 webconsole: hud, |
|
81 messages: [{ |
|
82 text: "Cannot cd()", |
|
83 category: CATEGORY_OUTPUT, |
|
84 severity: SEVERITY_ERROR, |
|
85 }], |
|
86 }); |
|
87 |
|
88 info("cd() into the iframe using an iframe DOM element"); |
|
89 hud.jsterm.clearOutput(); |
|
90 hud.jsterm.execute("cd($('iframe'))"); |
|
91 executeWindowTest(); |
|
92 |
|
93 yield waitForMessages({ webconsole: hud, messages: childMessages }); |
|
94 |
|
95 info("cd(window.parent)"); |
|
96 hud.jsterm.clearOutput(); |
|
97 hud.jsterm.execute("cd(window.parent)"); |
|
98 executeWindowTest(); |
|
99 |
|
100 yield waitForMessages({ webconsole: hud, messages: parentMessages }); |
|
101 |
|
102 yield closeConsole(tab); |
|
103 } |
|
104 |
|
105 function executeWindowTest() { |
|
106 hud.jsterm.execute("document.title"); |
|
107 hud.jsterm.execute("'p: ' + document.querySelector('p').textContent"); |
|
108 hud.jsterm.execute("'obj: ' + window.foobarBug609872"); |
|
109 } |
|
110 } |