dom/tests/mochitest/whatwg/test_postMessage_origin.xhtml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial