Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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";
20 SimpleTest.waitForExplicitFinish();
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";
29 info("Informing server about the current host");
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");
38 var worker = new Worker(path + workerFilename);
39 worker.postMessage("http://" + otherHost + path + serverFilename);
41 worker.onmessage = function(event) {
42 ok(event.data.response === "", "Worker responded, saw no response");
44 var loopCount = 0;
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 };
66 info("Checking server status (" + loopCount + ")");
67 xhr2.send();
68 }
70 checkServer();
71 };
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();
82 </script>
83 </pre>
84 </body>
85 </html>