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