dom/tests/mochitest/whatwg/test_postMessage_origin.xhtml

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:5837e7ad49df
1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=417075
5 -->
6 <head>
7 <title>postMessage from about:blank, data URLs</title>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="text/javascript" src="browserFu.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=417075">Mozilla Bug 417075</a>
14 <p id="display"></p>
15 <div id="content" style="display: none"></div>
16
17 <iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
18 id="sameDomain"></iframe>
19 <iframe src="http://example.com/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
20 id="otherDomain"></iframe>
21 <iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
22 id="otherDomainPort"></iframe>
23 <iframe src="ftp://mochi.test:27534/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
24 id="localNoExist"></iframe>
25
26 <iframe src="http://sub1.παράδειγμα.δοκιμή/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
27 id="idnKidWhitelist"></iframe>
28
29 <iframe src="http://sub1.exaмple.test/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
30 id="idnKidNoWhitelist"></iframe>
31
32
33 <pre id="test">
34 <script class="testbody" type="application/javascript"><![CDATA[
35 /** Test for Bug 417075 **/
36
37 SimpleTest.waitForExplicitFinish();
38
39 function errorCheck(i, called, error, actual)
40 {
41 ok(!called, "receiver should not have been called for test #" + i);
42 is(actual, error, "wrong error thrown in test #" + i);
43 }
44
45 var tests =
46 [
47 // 0
48 {
49 args: ["NOT-RECEIVED", ""],
50 source: "sameDomain",
51 name: "SyntaxError",
52 code: DOMException.SYNTAX_ERR
53 },
54 {
55 args: ["NOT-RECEIVED", "null"],
56 source: "sameDomain",
57 name: "SyntaxError",
58 code: DOMException.SYNTAX_ERR
59 },
60 {
61 args: ["NOT-RECEIVED", "a"],
62 source: "sameDomain",
63 name: "SyntaxError",
64 code: DOMException.SYNTAX_ERR
65 },
66 {
67 args: ["NOT-RECEIVED", "http :"],
68 source: "sameDomain",
69 name: "SyntaxError",
70 code: DOMException.SYNTAX_ERR
71 },
72 {
73 args: ["NOT-RECEIVED", "http: //"],
74 source: "sameDomain",
75 name: "SyntaxError",
76 code: DOMException.SYNTAX_ERR,
77
78 hasThrowsNoExceptionBug: true
79 },
80 // 5
81 {
82 args: ["NOT-RECEIVED", "http ://"],
83 source: "sameDomain",
84 name: "SyntaxError",
85 code: DOMException.SYNTAX_ERR
86 },
87 {
88 args: ["TODO", " http://localhost:8888"],
89 source: "sameDomain",
90 name: "SyntaxError",
91 code: DOMException.SYNTAX_ERR,
92
93 returnOrigin: "http://mochi.test:8888",
94 hasThrowsNoExceptionBug: true
95 },
96 {
97 args: ["NOT-RECEIVED", "hä"],
98 source: "sameDomain",
99 name: "SyntaxError",
100 code: DOMException.SYNTAX_ERR
101 },
102 {
103 args: ["NOT-RECEIVED", "http://lo\0k.com"],
104 source: "sameDomain",
105 name: "SyntaxError",
106 code: DOMException.SYNTAX_ERR
107 },
108 {
109 args: ["NOT-RECEIVED", "http: //localhost:8888"],
110 source: "sameDomain",
111 name: "SyntaxError",
112 code: DOMException.SYNTAX_ERR,
113
114 hasThrowsNoExceptionBug: true
115 },
116 // 10
117 {
118 args: ["NOT-RECEIVED", "http://localhost :8888"],
119 source: "sameDomain",
120 name: "SyntaxError",
121 code: DOMException.SYNTAX_ERR
122 },
123 {
124 args: ["NOT-RECEIVED", "http:// localhost:8888"],
125 source: "sameDomain",
126 name: "SyntaxError",
127 code: DOMException.SYNTAX_ERR,
128
129 hasThrowsNoExceptionBug: true
130 },
131 {
132 args: ["TODO", "http://\nlocalhost:8888"],
133 source: "sameDomain",
134 name: "SyntaxError",
135 code: DOMException.SYNTAX_ERR,
136
137 returnOrigin: "http://mochi.test:8888",
138 hasThrowsNoExceptionBug: true
139 },
140 {
141 args: ["TODO", "http://localhost:8888\0"],
142 source: "sameDomain",
143 name: "SyntaxError",
144 code: DOMException.SYNTAX_ERR,
145
146 returnOrigin: "http://mochi.test:8888",
147 hasThrowsNoExceptionBug: true
148 },
149 {
150 args: ["TODO", "http://localhost:8888\n"],
151 source: "sameDomain",
152 name: "SyntaxError",
153 code: DOMException.SYNTAX_ERR,
154
155 returnOrigin: "http://mochi.test:8888",
156 hasThrowsNoExceptionBug: true
157 },
158 // 15
159 {
160 args: ["PASS", "*"],
161 source: "sameDomain",
162 returnOrigin: "http://mochi.test:8888"
163 },
164 {
165 args: ["PASS", "http://mochi.test:8888"],
166 source: "sameDomain",
167 returnOrigin: "http://mochi.test:8888"
168 },
169 {
170 args: ["PASS", "http://example.com"],
171 source: "otherDomain",
172 returnOrigin: "http://example.com"
173 },
174 {
175 args: ["PASS", "http://example.com/"],
176 source: "otherDomain",
177 returnOrigin: "http://example.com"
178 },
179 {
180 args: ["PASS", "http://example.com:80"],
181 source: "otherDomain",
182 returnOrigin: "http://example.com"
183 },
184 // 20
185 {
186 args: ["PASS", "http://example.com:80/"],
187 source: "otherDomain",
188 returnOrigin: "http://example.com"
189 },
190 {
191 args: ["PASS", "http://example.com:80/foobar"],
192 source: "otherDomain",
193 returnOrigin: "http://example.com"
194 },
195 {
196 args: ["PASS", "http://example.com/foobar"],
197 source: "otherDomain",
198 returnOrigin: "http://example.com"
199 },
200 {
201 args: ["PASS", "http://example.com:8000"],
202 source: "otherDomain",
203 expectNoCallback: true
204 },
205 {
206 args: ["PASS", "http://example.com:8000/"],
207 source: "otherDomain",
208 expectNoCallback: true
209 },
210 // 25
211 {
212 args: ["PASS", "http://example.org:8000"],
213 source: "otherDomainPort",
214 returnOrigin: "http://example.org:8000"
215 },
216 {
217 args: ["PASS", "http://example.org:8000/"],
218 source: "otherDomainPort",
219 returnOrigin: "http://example.org:8000"
220 },
221 {
222 args: ["PASS", "http://example.org:8000/tests/dom/test/mochitest/whatwg/postMessage_origin_helper.xhtml"],
223 source: "otherDomainPort",
224 returnOrigin: "http://example.org:8000"
225 },
226 {
227 args: ["PASS", "http://example.org:8000/tests/dom/test/mochitest/whatwg/this_file_does_not_exist.xhtml"],
228 source: "otherDomainPort",
229 returnOrigin: "http://example.org:8000"
230 },
231 {
232 args: ["PASS", "http://example.org"],
233 source: "otherDomainPort",
234 expectNoCallback: true
235 },
236 // 30
237 {
238 args: ["PASS", "http://example.org:80"],
239 source: "otherDomainPort",
240 expectNoCallback: true
241 },
242 {
243 args: ["PASS", "http://example.org/"],
244 source: "otherDomainPort",
245 expectNoCallback: true
246 },
247 {
248 args: ["PASS", "http://example.org"],
249 source: "otherDomain",
250 expectNoCallback: true
251 },
252 {
253 args: ["PASS", "ftp://mochi.test:8888"],
254 source: "sameDomain",
255 expectNoCallback: true
256 },
257 {
258 args: ["PASS", "http://mochi.test:8888"],
259 source: "sameDomain",
260 returnOrigin: "http://mochi.test:8888"
261 },
262 // 35
263 {
264 args: ["PASS", "http://mochi.test:27534"],
265 source: "sameDomain",
266 expectNoCallback: true
267 },
268 {
269 args: ["PASS", "http://sub1.παράδειγμα.δοκιμή"],
270 source: "idnKidWhitelist",
271 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
272 },
273 {
274 args: ["PASS", "http://sub1.παράδειγμα.δοκιμή:80"],
275 source: "idnKidWhitelist",
276 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
277 },
278 {
279 args: ["PASS", "http://sub1.παράδειγμα.δοκιμή:80/"],
280 source: "idnKidWhitelist",
281 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
282 },
283 {
284 args: ["PASS", "http://sub1.παράδειγμα.δοκιμή:80/foobar"],
285 source: "idnKidWhitelist",
286 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
287 },
288 // 40
289 {
290 args: ["PASS", "http://sub1.παράδειγμα.δοκιμή/foobar"],
291 source: "idnKidWhitelist",
292 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
293 },
294 {
295 args: ["PASS", "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp"],
296 source: "idnKidWhitelist",
297 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
298 },
299 {
300 args: ["PASS", "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp:80"],
301 source: "idnKidWhitelist",
302 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
303 },
304 {
305 args: ["PASS", "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp:80/"],
306 source: "idnKidWhitelist",
307 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
308 },
309 {
310 args: ["PASS", "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp:80/foo"],
311 source: "idnKidWhitelist",
312 returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
313 },
314 // 45
315 {
316 args: ["PASS", "http://sub1.exaмple.test"],
317 source: "idnKidNoWhitelist",
318 returnOrigin: "http://sub1.exaмple.test",
319
320 hasWrongReturnOriginBug: true
321 },
322 {
323 args: ["PASS", "http://sub1.exaмple.test:80"],
324 source: "idnKidNoWhitelist",
325 returnOrigin: "http://sub1.exaмple.test",
326
327 hasWrongReturnOriginBug: true
328 },
329 {
330 args: ["PASS", "http://sub1.exaмple.test:80/"],
331 source: "idnKidNoWhitelist",
332 returnOrigin: "http://sub1.exaмple.test",
333
334 hasWrongReturnOriginBug: true
335 },
336 {
337 args: ["PASS", "http://sub1.exaмple.test/"],
338 source: "idnKidNoWhitelist",
339 returnOrigin: "http://sub1.exaмple.test",
340
341 hasWrongReturnOriginBug: true
342 },
343 {
344 args: ["PASS", "http://sub1.exaмple.test/foobar"],
345 source: "idnKidNoWhitelist",
346 returnOrigin: "http://sub1.exaмple.test",
347
348 hasWrongReturnOriginBug: true
349 },
350 // 50
351 {
352 args: ["PASS", "http://sub1.xn--exaple-kqf.test"],
353 source: "idnKidNoWhitelist",
354 returnOrigin: "http://sub1.exaмple.test",
355
356 hasWrongReturnOriginBug: true
357 },
358 {
359 args: ["PASS", "http://sub1.xn--exaple-kqf.test:80"],
360 source: "idnKidNoWhitelist",
361 returnOrigin: "http://sub1.exaмple.test",
362
363 hasWrongReturnOriginBug: true
364 },
365 {
366 args: ["PASS", "http://sub1.xn--exaple-kqf.test:80/"],
367 source: "idnKidNoWhitelist",
368 returnOrigin: "http://sub1.exaмple.test",
369
370 hasWrongReturnOriginBug: true
371 },
372 {
373 args: ["PASS", "http://sub1.xn--exaple-kqf.test/"],
374 source: "idnKidNoWhitelist",
375 returnOrigin: "http://sub1.exaмple.test",
376
377 hasWrongReturnOriginBug: true
378 },
379 {
380 args: ["PASS", "http://sub1.xn--exaple-kqf.test/foobar"],
381 source: "idnKidNoWhitelist",
382 returnOrigin: "http://sub1.exaмple.test",
383
384 hasWrongReturnOriginBug: true
385 },
386 // 55
387 {
388 args: ["NOT-RECEIVED", undefined],
389 source: "sameDomain",
390 name: "SyntaxError",
391 code: DOMException.SYNTAX_ERR
392 },
393 ];
394
395 function allTests(callback)
396 {
397 var test, target, called;
398
399 function eventCheck(evt)
400 {
401 ok(test === tests[i],
402 "i and test are out of sync! async is hard, let's go shopping");
403
404 var originCheck = test.hasWrongReturnOriginBug ? todo_is : is;
405 originCheck(evt.origin, test.returnOrigin, "wrong origin for #" + i);
406 if (test.args[0] == "TODO")
407 todo_is(evt.data, "PASS", "wrong data");
408 else
409 is(evt.data, "PASS", "wrong data");
410 is(evt.lastEventId, "",
411 "postMessage creates events with empty lastEventId");
412 ok(evt.source === target, "wrong source");
413 called = true;
414 }
415
416 function nextTest()
417 {
418 i++;
419
420 if (i === end)
421 {
422 removeListener(listener);
423
424 setTimeout(callback, 0);
425 return;
426 }
427
428 test = tests[i];
429
430 target = $(test.source).contentWindow;
431 try
432 {
433 called = false;
434 target.postMessage.apply(target, test.args);
435 }
436 catch (e)
437 {
438 // Since an exception was thrown, we know at this point that we're not
439 // waiting on anything else in the queue of script to run, and we can just
440 // call nextTest directly.
441 errorCheck(i, called, e.name, test.name);
442 errorCheck(i, called, e.code, test.code);
443 nextTest();
444 return;
445 }
446
447 // We've set up the event generated by postMessage to be dispatched, and
448 // it's sitting in a queue somewhere. However, it hasn't arrived yet, and
449 // the target document hasn't received the event -- so we need to continue
450 // our tests later.
451 setTimeout(function()
452 {
453 // The event was dispatched, and the target frame's code processed it and
454 // responded -- so now *that* response is sitting in the queue of script to
455 // execute. Process pending script one more time so we know we've gotten
456 // the response.
457 setTimeout(function()
458 {
459 // Finally, we've posted our message and received our response, and
460 // there's nothing further coming down the pipe.
461 if (test.hasThrowsNoExceptionBug)
462 todo(false, "should throw on test #" + i);
463 else
464 ok(test.expectNoCallback ^ called, "should have been called #" + i);
465
466 nextTest();
467 }, 0);
468 }, 0);
469 }
470
471 var listener = registerMessageListener(eventCheck);
472
473 var i = -1, end = tests.length;
474 nextTest();
475 }
476
477 function registerMessageListener(func, callback)
478 {
479 function receive(evt)
480 {
481 func(evt);
482 if (callback)
483 callback();
484 }
485
486 window.addEventListener("message", receive, false);
487
488 return receive;
489 }
490
491 function removeListener(listener)
492 {
493 window.removeEventListener("message", listener, false);
494 }
495
496 function oddballTests(callback)
497 {
498 var called = false;
499
500 function eventChecks(evt)
501 {
502 is(evt.origin, "http://mochi.test:8888", "wrong sender");
503 is(evt.data, "PASS", "wrong data");
504 is(evt.lastEventId, "",
505 "postMessage creates events with empty lastEventId");
506 ok(evt.source === window, "wrong source");
507 called = true;
508 }
509
510 var listener = registerMessageListener(eventChecks, function()
511 {
512 is(called, true, "should have been called");
513 removeListener(listener);
514
515 called = false;
516 listener = registerMessageListener(eventChecks, function()
517 {
518 is(called, true, "should have been called");
519
520 removeListener(listener);
521 callback();
522 });
523
524 window.postMessage("PASS", "http://mochi.test:8888");
525 });
526
527 window.postMessage("PASS", "http://mochi.test:8888");
528 }
529
530 function run()
531 {
532 oddballTests(function()
533 {
534 allTests(function()
535 {
536 SimpleTest.finish();
537 });
538 });
539 }
540
541 window.addEventListener("load", run, false);
542 ]]></script>
543 </pre>
544 </body>
545 </html>

mercurial