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