content/base/test/test_CrossSiteXHR_cache.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
michael@0 5 <title>Test for Cross Site XMLHttpRequest</title>
michael@0 6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8 </head>
michael@0 9 <body onload="gen.next()">
michael@0 10 <p id="display">
michael@0 11 <iframe id=loader></iframe>
michael@0 12 </p>
michael@0 13 <div id="content" style="display: none">
michael@0 14
michael@0 15 </div>
michael@0 16 <pre id="test">
michael@0 17 <script class="testbody" type="application/javascript;version=1.7">
michael@0 18
michael@0 19 SimpleTest.waitForExplicitFinish();
michael@0 20
michael@0 21 window.addEventListener("message", function(e) {
michael@0 22 gen.send(e.data);
michael@0 23 }, false);
michael@0 24
michael@0 25 gen = runTest();
michael@0 26
michael@0 27 function runTest() {
michael@0 28 var loader = document.getElementById('loader');
michael@0 29 var loaderWindow = loader.contentWindow;
michael@0 30 loader.onload = function () { gen.next() };
michael@0 31
michael@0 32 loader.src = "http://example.org/tests/content/base/test/file_CrossSiteXHR_inner.html";
michael@0 33 origin = "http://example.org";
michael@0 34 yield undefined;
michael@0 35
michael@0 36 tests = [{ pass: 0,
michael@0 37 method: "GET",
michael@0 38 headers: { "x-my-header": "myValue" },
michael@0 39 },
michael@0 40 { pass: 1,
michael@0 41 method: "GET",
michael@0 42 headers: { "x-my-header": "myValue" },
michael@0 43 allowHeaders: "x-my-header",
michael@0 44 cacheTime: 3600
michael@0 45 },
michael@0 46 { pass: 1,
michael@0 47 method: "GET",
michael@0 48 headers: { "x-my-header": "myValue" },
michael@0 49 },
michael@0 50 { pass: 1,
michael@0 51 method: "GET",
michael@0 52 headers: { "x-my-header": "myValue" },
michael@0 53 },
michael@0 54 { pass: 0,
michael@0 55 method: "GET",
michael@0 56 headers: { "x-my-header": "myValue",
michael@0 57 "y-my-header": "second" },
michael@0 58 },
michael@0 59 { pass: 1,
michael@0 60 method: "GET",
michael@0 61 headers: { "y-my-header": "hello" },
michael@0 62 allowHeaders: "y-my-header",
michael@0 63 },
michael@0 64 { pass: 0,
michael@0 65 method: "GET",
michael@0 66 headers: { "y-my-header": "hello" },
michael@0 67 },
michael@0 68 { pass: 1,
michael@0 69 method: "GET",
michael@0 70 headers: { "y-my-header": "hello" },
michael@0 71 allowHeaders: "y-my-header,x-my-header",
michael@0 72 cacheTime: 3600,
michael@0 73 },
michael@0 74 { pass: 1,
michael@0 75 method: "GET",
michael@0 76 headers: { "x-my-header": "myValue",
michael@0 77 "y-my-header": "second" },
michael@0 78 },
michael@0 79 { newTest: "*******" },
michael@0 80 { pass: 0,
michael@0 81 method: "GET",
michael@0 82 headers: { "x-my-header": "myValue" },
michael@0 83 },
michael@0 84 { pass: 1,
michael@0 85 method: "GET",
michael@0 86 headers: { "x-my-header": "myValue" },
michael@0 87 allowHeaders: "x-my-header",
michael@0 88 cacheTime: 2
michael@0 89 },
michael@0 90 { pause: 2.1 },
michael@0 91 { pass: 0,
michael@0 92 method: "GET",
michael@0 93 headers: { "x-my-header": "myValue" },
michael@0 94 },
michael@0 95 { newTest: "*******" },
michael@0 96 { pass: 1,
michael@0 97 method: "GET",
michael@0 98 headers: { "x-my-header": "myValue" },
michael@0 99 allowHeaders: "x-my-header, y-my-header",
michael@0 100 cacheTime: 3600
michael@0 101 },
michael@0 102 { pass: 1,
michael@0 103 method: "GET",
michael@0 104 headers: { "x-my-header": "myValue" },
michael@0 105 },
michael@0 106 { pass: 1,
michael@0 107 method: "GET",
michael@0 108 headers: { "y-my-header": "myValue" },
michael@0 109 },
michael@0 110 { pass: 0,
michael@0 111 method: "GET",
michael@0 112 headers: { "z-my-header": "myValue" },
michael@0 113 },
michael@0 114 { newTest: "*******" },
michael@0 115 { pass: 1,
michael@0 116 method: "GET",
michael@0 117 headers: { "x-my-header": "myValue" },
michael@0 118 allowHeaders: "x-my-header",
michael@0 119 cacheTime: "\t 3600 \t ",
michael@0 120 },
michael@0 121 { pass: 1,
michael@0 122 method: "GET",
michael@0 123 headers: { "x-my-header": "myValue" },
michael@0 124 },
michael@0 125 { newTest: "*******" },
michael@0 126 { pass: 1,
michael@0 127 method: "GET",
michael@0 128 headers: { "x-my-header": "myValue" },
michael@0 129 allowHeaders: "x-my-header",
michael@0 130 cacheTime: "3600 3",
michael@0 131 },
michael@0 132 { pass: 0,
michael@0 133 method: "GET",
michael@0 134 headers: { "x-my-header": "myValue" },
michael@0 135 },
michael@0 136 { newTest: "*******" },
michael@0 137 { pass: 1,
michael@0 138 method: "GET",
michael@0 139 headers: { "x-my-header": "myValue" },
michael@0 140 allowHeaders: "x-my-header",
michael@0 141 cacheTime: "asdf",
michael@0 142 },
michael@0 143 { pass: 0,
michael@0 144 method: "GET",
michael@0 145 headers: { "x-my-header": "myValue" },
michael@0 146 },
michael@0 147 { newTest: "*******" },
michael@0 148 { pass: 1,
michael@0 149 method: "GET",
michael@0 150 headers: { "first-header": "myValue" },
michael@0 151 allowHeaders: "first-header",
michael@0 152 cacheTime: 2,
michael@0 153 },
michael@0 154 { pass: 1,
michael@0 155 method: "GET",
michael@0 156 headers: { "second-header": "myValue" },
michael@0 157 allowHeaders: "second-header",
michael@0 158 cacheTime: 3600,
michael@0 159 },
michael@0 160 { pass: 1,
michael@0 161 method: "GET",
michael@0 162 headers: { "third-header": "myValue" },
michael@0 163 allowHeaders: "third-header",
michael@0 164 cacheTime: 2,
michael@0 165 },
michael@0 166 { pause: 2.1 },
michael@0 167 { pass: 1,
michael@0 168 method: "GET",
michael@0 169 headers: { "second-header": "myValue" },
michael@0 170 },
michael@0 171 { pass: 0,
michael@0 172 method: "GET",
michael@0 173 headers: { "first-header": "myValue" },
michael@0 174 },
michael@0 175 { newTest: "*******" },
michael@0 176 { pass: 1,
michael@0 177 method: "GET",
michael@0 178 headers: { "first-header": "myValue" },
michael@0 179 allowHeaders: "first-header",
michael@0 180 cacheTime: 2,
michael@0 181 },
michael@0 182 { pass: 1,
michael@0 183 method: "GET",
michael@0 184 headers: { "second-header": "myValue" },
michael@0 185 allowHeaders: "second-header",
michael@0 186 cacheTime: 3600,
michael@0 187 },
michael@0 188 { pass: 1,
michael@0 189 method: "GET",
michael@0 190 headers: { "third-header": "myValue" },
michael@0 191 allowHeaders: "third-header",
michael@0 192 cacheTime: 2,
michael@0 193 },
michael@0 194 { pause: 2.1 },
michael@0 195 { pass: 1,
michael@0 196 method: "GET",
michael@0 197 headers: { "second-header": "myValue" },
michael@0 198 },
michael@0 199 { pass: 0,
michael@0 200 method: "GET",
michael@0 201 headers: { "third-header": "myValue" },
michael@0 202 },
michael@0 203 { newTest: "*******" },
michael@0 204 { pass: 0,
michael@0 205 method: "DELETE",
michael@0 206 },
michael@0 207 { pass: 1,
michael@0 208 method: "DELETE",
michael@0 209 allowMethods: "DELETE",
michael@0 210 cacheTime: 3600
michael@0 211 },
michael@0 212 { pass: 1,
michael@0 213 method: "DELETE",
michael@0 214 },
michael@0 215 { pass: 1,
michael@0 216 method: "DELETE",
michael@0 217 },
michael@0 218 { pass: 0,
michael@0 219 method: "PATCH",
michael@0 220 },
michael@0 221 { pass: 1,
michael@0 222 method: "PATCH",
michael@0 223 allowMethods: "PATCH",
michael@0 224 },
michael@0 225 { pass: 0,
michael@0 226 method: "PATCH",
michael@0 227 },
michael@0 228 { pass: 1,
michael@0 229 method: "PATCH",
michael@0 230 allowMethods: "PATCH",
michael@0 231 cacheTime: 3600,
michael@0 232 },
michael@0 233 { pass: 1,
michael@0 234 method: "PATCH",
michael@0 235 },
michael@0 236 { pass: 0,
michael@0 237 method: "DELETE",
michael@0 238 },
michael@0 239 { pass: 0,
michael@0 240 method: "PUT",
michael@0 241 },
michael@0 242 { newTest: "*******" },
michael@0 243 { pass: 0,
michael@0 244 method: "DELETE",
michael@0 245 },
michael@0 246 { pass: 1,
michael@0 247 method: "DELETE",
michael@0 248 allowMethods: "DELETE",
michael@0 249 cacheTime: 2
michael@0 250 },
michael@0 251 { pause: 2.1 },
michael@0 252 { pass: 0,
michael@0 253 method: "DELETE",
michael@0 254 },
michael@0 255 { newTest: "*******" },
michael@0 256 { pass: 1,
michael@0 257 method: "DELETE",
michael@0 258 allowMethods: "DELETE, PUT",
michael@0 259 cacheTime: 3600
michael@0 260 },
michael@0 261 { pass: 1,
michael@0 262 method: "DELETE",
michael@0 263 },
michael@0 264 { pass: 1,
michael@0 265 method: "PUT",
michael@0 266 },
michael@0 267 { pass: 0,
michael@0 268 method: "PATCH",
michael@0 269 },
michael@0 270 { newTest: "*******" },
michael@0 271 { pass: 1,
michael@0 272 method: "FIRST",
michael@0 273 allowMethods: "FIRST",
michael@0 274 cacheTime: 2,
michael@0 275 },
michael@0 276 { pass: 1,
michael@0 277 method: "SECOND",
michael@0 278 allowMethods: "SECOND",
michael@0 279 cacheTime: 3600,
michael@0 280 },
michael@0 281 { pass: 1,
michael@0 282 method: "THIRD",
michael@0 283 allowMethods: "THIRD",
michael@0 284 cacheTime: 2,
michael@0 285 },
michael@0 286 { pause: 2.1 },
michael@0 287 { pass: 1,
michael@0 288 method: "SECOND",
michael@0 289 },
michael@0 290 { pass: 0,
michael@0 291 method: "FIRST",
michael@0 292 },
michael@0 293 { newTest: "*******" },
michael@0 294 { pass: 1,
michael@0 295 method: "FIRST",
michael@0 296 allowMethods: "FIRST",
michael@0 297 cacheTime: 2,
michael@0 298 },
michael@0 299 { pass: 1,
michael@0 300 method: "SECOND",
michael@0 301 allowMethods: "SECOND",
michael@0 302 cacheTime: 3600,
michael@0 303 },
michael@0 304 { pass: 1,
michael@0 305 method: "THIRD",
michael@0 306 allowMethods: "THIRD",
michael@0 307 cacheTime: 2,
michael@0 308 },
michael@0 309 { pause: 2.1 },
michael@0 310 { pass: 1,
michael@0 311 method: "SECOND",
michael@0 312 },
michael@0 313 { pass: 0,
michael@0 314 method: "THIRD",
michael@0 315 },
michael@0 316 { newTest: "*******" },
michael@0 317 { pass: 1,
michael@0 318 method: "GET",
michael@0 319 headers: { "x-my-header": "x-value" },
michael@0 320 allowHeaders: "x-my-header",
michael@0 321 cacheTime: 3600,
michael@0 322 },
michael@0 323 { pass: 1,
michael@0 324 method: "GET",
michael@0 325 headers: { "x-my-header": "x-value" }
michael@0 326 },
michael@0 327 { pass: 0,
michael@0 328 method: "GET",
michael@0 329 headers: { "y-my-header": "y-value" }
michael@0 330 },
michael@0 331 { pass: 0,
michael@0 332 method: "GET",
michael@0 333 headers: { "x-my-header": "x-value" }
michael@0 334 },
michael@0 335 { newTest: "*******" },
michael@0 336 { pass: 1,
michael@0 337 method: "GET",
michael@0 338 headers: { "x-my-header": "x-value" },
michael@0 339 allowHeaders: "x-my-header",
michael@0 340 cacheTime: 3600,
michael@0 341 },
michael@0 342 { pass: 1,
michael@0 343 method: "GET",
michael@0 344 headers: { "x-my-header": "x-value" },
michael@0 345 },
michael@0 346 { pass: 0,
michael@0 347 method: "PUT",
michael@0 348 },
michael@0 349 { pass: 0,
michael@0 350 method: "GET",
michael@0 351 headers: { "x-my-header": "x-value" },
michael@0 352 },
michael@0 353 { newTest: "*******" },
michael@0 354 { pass: 1,
michael@0 355 method: "GET",
michael@0 356 headers: { "x-my-header": "x-value" },
michael@0 357 allowHeaders: "x-my-header",
michael@0 358 cacheTime: 3600,
michael@0 359 },
michael@0 360 { pass: 1,
michael@0 361 method: "GET",
michael@0 362 headers: { "x-my-header": "x-value" },
michael@0 363 },
michael@0 364 { pass: 0,
michael@0 365 method: "GET",
michael@0 366 noOrigin: 1,
michael@0 367 },
michael@0 368 { pass: 0,
michael@0 369 method: "GET",
michael@0 370 headers: { "x-my-header": "x-value" },
michael@0 371 },
michael@0 372 { newTest: "*******" },
michael@0 373 { pass: 1,
michael@0 374 method: "DELETE",
michael@0 375 allowMethods: "DELETE",
michael@0 376 cacheTime: 3600,
michael@0 377 },
michael@0 378 { pass: 1,
michael@0 379 method: "DELETE"
michael@0 380 },
michael@0 381 { pass: 0,
michael@0 382 method: "PUT"
michael@0 383 },
michael@0 384 { pass: 0,
michael@0 385 method: "DELETE"
michael@0 386 },
michael@0 387 { newTest: "*******" },
michael@0 388 { pass: 1,
michael@0 389 method: "DELETE",
michael@0 390 allowMethods: "DELETE",
michael@0 391 cacheTime: 3600,
michael@0 392 },
michael@0 393 { pass: 1,
michael@0 394 method: "DELETE"
michael@0 395 },
michael@0 396 { pass: 0,
michael@0 397 method: "DELETE",
michael@0 398 headers: { "my-header": "value" },
michael@0 399 },
michael@0 400 { pass: 0,
michael@0 401 method: "DELETE"
michael@0 402 },
michael@0 403 { newTest: "*******" },
michael@0 404 { pass: 1,
michael@0 405 method: "DELETE",
michael@0 406 allowMethods: "DELETE",
michael@0 407 cacheTime: 3600,
michael@0 408 },
michael@0 409 { pass: 1,
michael@0 410 method: "DELETE"
michael@0 411 },
michael@0 412 { pass: 0,
michael@0 413 method: "GET",
michael@0 414 noOrigin: 1,
michael@0 415 },
michael@0 416 { pass: 0,
michael@0 417 method: "DELETE"
michael@0 418 },
michael@0 419 ];
michael@0 420
michael@0 421 for (let i = 0; i < 110; i++) {
michael@0 422 tests.push({ newTest: "*******" },
michael@0 423 { pass: 1,
michael@0 424 method: "DELETE",
michael@0 425 allowMethods: "DELETE",
michael@0 426 cacheTime: 3600,
michael@0 427 });
michael@0 428 }
michael@0 429
michael@0 430 baseURL = "http://mochi.test:8888/tests/content/base/test/" +
michael@0 431 "file_CrossSiteXHR_cache_server.sjs?";
michael@0 432 setStateURL = baseURL + "setState=";
michael@0 433
michael@0 434 var unique = Date.now();
michael@0 435 for (test of tests) {
michael@0 436 if (test.newTest) {
michael@0 437 unique++;
michael@0 438 continue;
michael@0 439 }
michael@0 440 if (test.pause) {
michael@0 441 setTimeout(function() { gen.next() }, test.pause * 1000);
michael@0 442 yield undefined;
michael@0 443 continue;
michael@0 444 }
michael@0 445
michael@0 446 req = {
michael@0 447 url: baseURL + "c=" + unique,
michael@0 448 method: test.method,
michael@0 449 headers: test.headers,
michael@0 450 };
michael@0 451
michael@0 452 sec = { allowOrigin: test.noOrigin ? "" : origin,
michael@0 453 allowHeaders: test.allowHeaders,
michael@0 454 allowMethods: test.allowMethods,
michael@0 455 cacheTime: test.cacheTime };
michael@0 456 xhr = new XMLHttpRequest();
michael@0 457 xhr.open("POST", setStateURL + escape(sec.toSource()), true);
michael@0 458 xhr.onloadend = function() { gen.next(); }
michael@0 459 xhr.send();
michael@0 460 yield undefined;
michael@0 461
michael@0 462 loaderWindow.postMessage(req.toSource(), origin);
michael@0 463
michael@0 464 res = eval(yield);
michael@0 465
michael@0 466 testName = test.toSource() + " (index " + tests.indexOf(test) + ")";
michael@0 467
michael@0 468 if (test.pass) {
michael@0 469 is(res.didFail, false,
michael@0 470 "shouldn't have failed in test for " + testName);
michael@0 471 is(res.status, 200, "wrong status in test for " + testName);
michael@0 472 is(res.responseXML, "<res>hello pass</res>",
michael@0 473 "wrong responseXML in test for " + testName);
michael@0 474 is(res.responseText, "<res>hello pass</res>\n",
michael@0 475 "wrong responseText in test for " + testName);
michael@0 476 is(res.events.join(","),
michael@0 477 "opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend",
michael@0 478 "wrong events in test for " + testName);
michael@0 479 }
michael@0 480 else {
michael@0 481 is(res.didFail, true,
michael@0 482 "should have failed in test for " + testName);
michael@0 483 is(res.status, 0, "wrong status in test for " + testName);
michael@0 484 is(res.responseXML, null,
michael@0 485 "wrong responseXML in test for " + testName);
michael@0 486 is(res.responseText, "",
michael@0 487 "wrong responseText in test for " + testName);
michael@0 488 is(res.events.join(","),
michael@0 489 "opening,rs1,sending,loadstart,rs2,rs4,error,loadend",
michael@0 490 "wrong events in test for " + testName);
michael@0 491 is(res.progressEvents, 0,
michael@0 492 "wrong events in test for " + testName);
michael@0 493 }
michael@0 494 }
michael@0 495
michael@0 496 SimpleTest.finish();
michael@0 497
michael@0 498 yield undefined;
michael@0 499 }
michael@0 500
michael@0 501 </script>
michael@0 502 </pre>
michael@0 503 </body>
michael@0 504 </html>

mercurial