|
1 <!DOCTYPE HTML> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta charset="utf8"> |
|
5 <title>Test for the cd() function</title> |
|
6 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <script type="text/javascript;version=1.8" src="common.js"></script> |
|
8 <!-- Any copyright is dedicated to the Public Domain. |
|
9 - http://creativecommons.org/publicdomain/zero/1.0/ --> |
|
10 </head> |
|
11 <body> |
|
12 <p>Test for the cd() function</p> |
|
13 |
|
14 <script class="testbody" type="text/javascript;version=1.8"> |
|
15 SimpleTest.waitForExplicitFinish(); |
|
16 |
|
17 let gState; |
|
18 |
|
19 function startTest() |
|
20 { |
|
21 removeEventListener("load", startTest); |
|
22 |
|
23 attachConsole([], onAttach, true); |
|
24 } |
|
25 |
|
26 function onAttach(aState, aResponse) |
|
27 { |
|
28 top.foobarObject = Object.create(null); |
|
29 top.foobarObject.bug609872 = "parent"; |
|
30 |
|
31 window.foobarObject = Object.create(null); |
|
32 window.foobarObject.bug609872 = "child"; |
|
33 |
|
34 gState = aState; |
|
35 |
|
36 let tests = [doCheckParent, doCdIframe, doCheckIframe, doCdParent, |
|
37 doCheckParent2]; |
|
38 runTests(tests, testEnd); |
|
39 } |
|
40 |
|
41 function doCheckParent() |
|
42 { |
|
43 info("check parent window"); |
|
44 gState.client.evaluateJS("window.foobarObject.bug609872", |
|
45 onFooObjectFromParent); |
|
46 } |
|
47 |
|
48 function onFooObjectFromParent(aResponse) |
|
49 { |
|
50 checkObject(aResponse, { |
|
51 from: gState.actor, |
|
52 input: "window.foobarObject.bug609872", |
|
53 result: "parent", |
|
54 }); |
|
55 |
|
56 ok(!aResponse.exception, "no eval exception"); |
|
57 ok(!aResponse.helperResult, "no helper result"); |
|
58 |
|
59 nextTest(); |
|
60 } |
|
61 |
|
62 function doCdIframe() |
|
63 { |
|
64 info("test cd('iframe')"); |
|
65 gState.client.evaluateJS("cd('iframe')", onCdIframe); |
|
66 } |
|
67 |
|
68 function onCdIframe(aResponse) |
|
69 { |
|
70 checkObject(aResponse, { |
|
71 from: gState.actor, |
|
72 input: "cd('iframe')", |
|
73 result: { type: "undefined" }, |
|
74 helperResult: { type: "cd" }, |
|
75 }); |
|
76 |
|
77 ok(!aResponse.exception, "no eval exception"); |
|
78 |
|
79 nextTest(); |
|
80 } |
|
81 |
|
82 function doCheckIframe() |
|
83 { |
|
84 info("check foobarObject from the iframe"); |
|
85 gState.client.evaluateJS("window.foobarObject.bug609872", |
|
86 onFooObjectFromIframe); |
|
87 } |
|
88 |
|
89 function onFooObjectFromIframe(aResponse) |
|
90 { |
|
91 checkObject(aResponse, { |
|
92 from: gState.actor, |
|
93 input: "window.foobarObject.bug609872", |
|
94 result: "child", |
|
95 }); |
|
96 |
|
97 ok(!aResponse.exception, "no js eval exception"); |
|
98 ok(!aResponse.helperResult, "no helper result"); |
|
99 |
|
100 nextTest(); |
|
101 } |
|
102 |
|
103 function doCdParent() |
|
104 { |
|
105 info("test cd() back to parent"); |
|
106 gState.client.evaluateJS("cd()", onCdParent); |
|
107 } |
|
108 |
|
109 function onCdParent(aResponse) |
|
110 { |
|
111 checkObject(aResponse, { |
|
112 from: gState.actor, |
|
113 input: "cd()", |
|
114 result: { type: "undefined" }, |
|
115 helperResult: { type: "cd" }, |
|
116 }); |
|
117 |
|
118 ok(!aResponse.exception, "no eval exception"); |
|
119 |
|
120 nextTest(); |
|
121 } |
|
122 |
|
123 function doCheckParent2() |
|
124 { |
|
125 gState.client.evaluateJS("window.foobarObject.bug609872", |
|
126 onFooObjectFromParent2); |
|
127 } |
|
128 |
|
129 function onFooObjectFromParent2(aResponse) |
|
130 { |
|
131 checkObject(aResponse, { |
|
132 from: gState.actor, |
|
133 input: "window.foobarObject.bug609872", |
|
134 result: "parent", |
|
135 }); |
|
136 |
|
137 ok(!aResponse.exception, "no eval exception"); |
|
138 ok(!aResponse.helperResult, "no helper result"); |
|
139 |
|
140 nextTest(); |
|
141 } |
|
142 |
|
143 function testEnd() |
|
144 { |
|
145 closeDebugger(gState, function() { |
|
146 gState = null; |
|
147 SimpleTest.finish(); |
|
148 }); |
|
149 } |
|
150 |
|
151 addEventListener("load", startTest); |
|
152 </script> |
|
153 </body> |
|
154 </html> |