|
1 <!-- |
|
2 Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 --> |
|
5 <!DOCTYPE HTML> |
|
6 <html> |
|
7 <head> |
|
8 <title>Test for XHR Headers</title> |
|
9 <script src="/tests/SimpleTest/SimpleTest.js"> |
|
10 </script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> |
|
12 </head> |
|
13 <body> |
|
14 <p id="display"></p> |
|
15 <div id="content" style="display: none"></div> |
|
16 <pre id="test"> |
|
17 <script class="testbody"> |
|
18 "use strict"; |
|
19 |
|
20 SimpleTest.waitForExplicitFinish(); |
|
21 |
|
22 var path = |
|
23 location.pathname.substring(0, location.pathname.lastIndexOf("/") + 1); |
|
24 var filenamePrefix = "xhr_headers_"; |
|
25 var serverFilename = filenamePrefix + "server.sjs"; |
|
26 var workerFilename = filenamePrefix + "worker.js"; |
|
27 var otherHost = "example.com"; |
|
28 |
|
29 info("Informing server about the current host"); |
|
30 |
|
31 var xhr = new XMLHttpRequest(); |
|
32 xhr.open("POST", path + serverFilename); |
|
33 xhr.setRequestHeader("options-host", otherHost); |
|
34 xhr.onreadystatechange = function() { |
|
35 if (xhr.readyState == 4) { |
|
36 info("Launching worker"); |
|
37 |
|
38 var worker = new Worker(path + workerFilename); |
|
39 worker.postMessage("http://" + otherHost + path + serverFilename); |
|
40 |
|
41 worker.onmessage = function(event) { |
|
42 ok(event.data.response === "", "Worker responded, saw no response"); |
|
43 |
|
44 var loopCount = 0; |
|
45 |
|
46 function checkServer() { |
|
47 var xhr2 = new XMLHttpRequest(); |
|
48 xhr2.open("GET", path + serverFilename); |
|
49 xhr2.onreadystatechange = function() { |
|
50 if (xhr2.readyState == 4) { |
|
51 if (xhr2.responseText) { |
|
52 is(xhr2.responseText, |
|
53 "Success: expected OPTIONS request with '" + |
|
54 event.data.header + "' header", |
|
55 "Server saw expected requests"); |
|
56 SimpleTest.finish(); |
|
57 } else if (++loopCount < 30) { |
|
58 setTimeout(checkServer, 1000); |
|
59 } else { |
|
60 ok(false, "Server never saw any requests"); |
|
61 SimpleTest.finish(); |
|
62 } |
|
63 } |
|
64 }; |
|
65 |
|
66 info("Checking server status (" + loopCount + ")"); |
|
67 xhr2.send(); |
|
68 } |
|
69 |
|
70 checkServer(); |
|
71 }; |
|
72 |
|
73 worker.onerror = function(event) { |
|
74 ok(false, "Worker had an error: '" + event.message + "'"); |
|
75 event.preventDefault(); |
|
76 SimpleTest.finish(); |
|
77 }; |
|
78 } |
|
79 }; |
|
80 xhr.send(); |
|
81 |
|
82 </script> |
|
83 </pre> |
|
84 </body> |
|
85 </html> |