dom/workers/test/test_xhr_headers.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/test/test_xhr_headers.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +<!--
     1.5 +  Any copyright is dedicated to the Public Domain.
     1.6 +  http://creativecommons.org/publicdomain/zero/1.0/
     1.7 +-->
     1.8 +<!DOCTYPE HTML>
     1.9 +<html>
    1.10 +  <head>
    1.11 +    <title>Test for XHR Headers</title>
    1.12 +    <script src="/tests/SimpleTest/SimpleTest.js">
    1.13 +    </script>
    1.14 +    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
    1.15 +  </head>
    1.16 +  <body>
    1.17 +    <p id="display"></p>
    1.18 +    <div id="content" style="display: none"></div>
    1.19 +    <pre id="test">
    1.20 +      <script class="testbody">
    1.21 +"use strict";
    1.22 +
    1.23 +SimpleTest.waitForExplicitFinish();
    1.24 +
    1.25 +var path =
    1.26 +  location.pathname.substring(0, location.pathname.lastIndexOf("/") + 1);
    1.27 +var filenamePrefix = "xhr_headers_";
    1.28 +var serverFilename = filenamePrefix + "server.sjs";
    1.29 +var workerFilename = filenamePrefix + "worker.js";
    1.30 +var otherHost = "example.com";
    1.31 +
    1.32 +info("Informing server about the current host");
    1.33 +
    1.34 +var xhr = new XMLHttpRequest();
    1.35 +xhr.open("POST", path + serverFilename);
    1.36 +xhr.setRequestHeader("options-host", otherHost);
    1.37 +xhr.onreadystatechange = function() {
    1.38 +  if (xhr.readyState == 4) {
    1.39 +    info("Launching worker");
    1.40 +
    1.41 +    var worker = new Worker(path + workerFilename);
    1.42 +    worker.postMessage("http://" + otherHost + path + serverFilename);
    1.43 +
    1.44 +    worker.onmessage = function(event) {
    1.45 +      ok(event.data.response === "", "Worker responded, saw no response");
    1.46 +
    1.47 +      var loopCount = 0;
    1.48 +
    1.49 +      function checkServer() {
    1.50 +        var xhr2 = new XMLHttpRequest();
    1.51 +        xhr2.open("GET", path + serverFilename);
    1.52 +        xhr2.onreadystatechange = function() {
    1.53 +          if (xhr2.readyState == 4) {
    1.54 +            if (xhr2.responseText) {
    1.55 +              is(xhr2.responseText,
    1.56 +                 "Success: expected OPTIONS request with '" +
    1.57 +                 event.data.header + "' header",
    1.58 +                 "Server saw expected requests");
    1.59 +              SimpleTest.finish();
    1.60 +            } else if (++loopCount < 30) {
    1.61 +              setTimeout(checkServer, 1000);
    1.62 +            } else {
    1.63 +              ok(false, "Server never saw any requests");
    1.64 +              SimpleTest.finish();
    1.65 +            }
    1.66 +          }
    1.67 +        };
    1.68 +
    1.69 +        info("Checking server status (" + loopCount + ")");
    1.70 +        xhr2.send();
    1.71 +      }
    1.72 +
    1.73 +      checkServer();
    1.74 +    };
    1.75 +
    1.76 +    worker.onerror = function(event) {
    1.77 +      ok(false, "Worker had an error: '" + event.message + "'");
    1.78 +      event.preventDefault();
    1.79 +      SimpleTest.finish();
    1.80 +    };
    1.81 +  }
    1.82 +};
    1.83 +xhr.send();
    1.84 +
    1.85 +      </script>
    1.86 +    </pre>
    1.87 +  </body>
    1.88 +</html>

mercurial