content/base/test/test_CrossSiteXHR_cache.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_CrossSiteXHR_cache.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,504 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
     1.8 +  <title>Test for Cross Site XMLHttpRequest</title>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body onload="gen.next()">
    1.13 +<p id="display">
    1.14 +<iframe id=loader></iframe>
    1.15 +</p>
    1.16 +<div id="content" style="display: none">
    1.17 +  
    1.18 +</div>
    1.19 +<pre id="test">
    1.20 +<script class="testbody" type="application/javascript;version=1.7">
    1.21 +
    1.22 +SimpleTest.waitForExplicitFinish();
    1.23 +
    1.24 +window.addEventListener("message", function(e) {
    1.25 +  gen.send(e.data);
    1.26 +}, false);
    1.27 +
    1.28 +gen = runTest();
    1.29 +
    1.30 +function runTest() {
    1.31 +  var loader = document.getElementById('loader');
    1.32 +  var loaderWindow = loader.contentWindow;
    1.33 +  loader.onload = function () { gen.next() };
    1.34 +
    1.35 +  loader.src = "http://example.org/tests/content/base/test/file_CrossSiteXHR_inner.html";
    1.36 +  origin = "http://example.org";
    1.37 +  yield undefined;
    1.38 +
    1.39 +  tests = [{ pass: 0,
    1.40 +             method: "GET",
    1.41 +             headers: { "x-my-header": "myValue" },
    1.42 +           },
    1.43 +           { pass: 1,
    1.44 +             method: "GET",
    1.45 +             headers: { "x-my-header": "myValue" },
    1.46 +             allowHeaders: "x-my-header",
    1.47 +             cacheTime: 3600
    1.48 +           },
    1.49 +           { pass: 1,
    1.50 +             method: "GET",
    1.51 +             headers: { "x-my-header": "myValue" },
    1.52 +           },
    1.53 +           { pass: 1,
    1.54 +             method: "GET",
    1.55 +             headers: { "x-my-header": "myValue" },
    1.56 +           },
    1.57 +           { pass: 0,
    1.58 +             method: "GET",
    1.59 +             headers: { "x-my-header": "myValue",
    1.60 +                        "y-my-header": "second" },
    1.61 +           },
    1.62 +           { pass: 1,
    1.63 +             method: "GET",
    1.64 +             headers: { "y-my-header": "hello" },
    1.65 +             allowHeaders: "y-my-header",
    1.66 +           },
    1.67 +           { pass: 0,
    1.68 +             method: "GET",
    1.69 +             headers: { "y-my-header": "hello" },
    1.70 +           },
    1.71 +           { pass: 1,
    1.72 +             method: "GET",
    1.73 +             headers: { "y-my-header": "hello" },
    1.74 +             allowHeaders: "y-my-header,x-my-header",
    1.75 +             cacheTime: 3600,
    1.76 +           },
    1.77 +           { pass: 1,
    1.78 +             method: "GET",
    1.79 +             headers: { "x-my-header": "myValue",
    1.80 +                        "y-my-header": "second" },
    1.81 +           },
    1.82 +           { newTest: "*******" },
    1.83 +           { pass: 0,
    1.84 +             method: "GET",
    1.85 +             headers: { "x-my-header": "myValue" },
    1.86 +           },
    1.87 +           { pass: 1,
    1.88 +             method: "GET",
    1.89 +             headers: { "x-my-header": "myValue" },
    1.90 +             allowHeaders: "x-my-header",
    1.91 +             cacheTime: 2
    1.92 +           },
    1.93 +           { pause: 2.1 },
    1.94 +           { pass: 0,
    1.95 +             method: "GET",
    1.96 +             headers: { "x-my-header": "myValue" },
    1.97 +           },
    1.98 +           { newTest: "*******" },
    1.99 +           { pass: 1,
   1.100 +             method: "GET",
   1.101 +             headers: { "x-my-header": "myValue" },
   1.102 +             allowHeaders: "x-my-header, y-my-header",
   1.103 +             cacheTime: 3600
   1.104 +           },
   1.105 +           { pass: 1,
   1.106 +             method: "GET",
   1.107 +             headers: { "x-my-header": "myValue" },
   1.108 +           },
   1.109 +           { pass: 1,
   1.110 +             method: "GET",
   1.111 +             headers: { "y-my-header": "myValue" },
   1.112 +           },
   1.113 +           { pass: 0,
   1.114 +             method: "GET",
   1.115 +             headers: { "z-my-header": "myValue" },
   1.116 +           },
   1.117 +           { newTest: "*******" },
   1.118 +           { pass: 1,
   1.119 +             method: "GET",
   1.120 +             headers: { "x-my-header": "myValue" },
   1.121 +             allowHeaders: "x-my-header",
   1.122 +             cacheTime: "\t  3600 \t ",
   1.123 +           },
   1.124 +           { pass: 1,
   1.125 +             method: "GET",
   1.126 +             headers: { "x-my-header": "myValue" },
   1.127 +           },
   1.128 +           { newTest: "*******" },
   1.129 +           { pass: 1,
   1.130 +             method: "GET",
   1.131 +             headers: { "x-my-header": "myValue" },
   1.132 +             allowHeaders: "x-my-header",
   1.133 +             cacheTime: "3600 3",
   1.134 +           },
   1.135 +           { pass: 0,
   1.136 +             method: "GET",
   1.137 +             headers: { "x-my-header": "myValue" },
   1.138 +           },
   1.139 +           { newTest: "*******" },
   1.140 +           { pass: 1,
   1.141 +             method: "GET",
   1.142 +             headers: { "x-my-header": "myValue" },
   1.143 +             allowHeaders: "x-my-header",
   1.144 +             cacheTime: "asdf",
   1.145 +           },
   1.146 +           { pass: 0,
   1.147 +             method: "GET",
   1.148 +             headers: { "x-my-header": "myValue" },
   1.149 +           },
   1.150 +           { newTest: "*******" },
   1.151 +           { pass: 1,
   1.152 +             method: "GET",
   1.153 +             headers: { "first-header": "myValue" },
   1.154 +             allowHeaders: "first-header",
   1.155 +             cacheTime: 2,
   1.156 +           },
   1.157 +           { pass: 1,
   1.158 +             method: "GET",
   1.159 +             headers: { "second-header": "myValue" },
   1.160 +             allowHeaders: "second-header",
   1.161 +             cacheTime: 3600,
   1.162 +           },
   1.163 +           { pass: 1,
   1.164 +             method: "GET",
   1.165 +             headers: { "third-header": "myValue" },
   1.166 +             allowHeaders: "third-header",
   1.167 +             cacheTime: 2,
   1.168 +           },
   1.169 +           { pause: 2.1 },
   1.170 +           { pass: 1,
   1.171 +             method: "GET",
   1.172 +             headers: { "second-header": "myValue" },
   1.173 +           },
   1.174 +           { pass: 0,
   1.175 +             method: "GET",
   1.176 +             headers: { "first-header": "myValue" },
   1.177 +           },
   1.178 +           { newTest: "*******" },
   1.179 +           { pass: 1,
   1.180 +             method: "GET",
   1.181 +             headers: { "first-header": "myValue" },
   1.182 +             allowHeaders: "first-header",
   1.183 +             cacheTime: 2,
   1.184 +           },
   1.185 +           { pass: 1,
   1.186 +             method: "GET",
   1.187 +             headers: { "second-header": "myValue" },
   1.188 +             allowHeaders: "second-header",
   1.189 +             cacheTime: 3600,
   1.190 +           },
   1.191 +           { pass: 1,
   1.192 +             method: "GET",
   1.193 +             headers: { "third-header": "myValue" },
   1.194 +             allowHeaders: "third-header",
   1.195 +             cacheTime: 2,
   1.196 +           },
   1.197 +           { pause: 2.1 },
   1.198 +           { pass: 1,
   1.199 +             method: "GET",
   1.200 +             headers: { "second-header": "myValue" },
   1.201 +           },
   1.202 +           { pass: 0,
   1.203 +             method: "GET",
   1.204 +             headers: { "third-header": "myValue" },
   1.205 +           },
   1.206 +           { newTest: "*******" },
   1.207 +           { pass: 0,
   1.208 +             method: "DELETE",
   1.209 +           },
   1.210 +           { pass: 1,
   1.211 +             method: "DELETE",
   1.212 +             allowMethods: "DELETE",
   1.213 +             cacheTime: 3600
   1.214 +           },
   1.215 +           { pass: 1,
   1.216 +             method: "DELETE",
   1.217 +           },
   1.218 +           { pass: 1,
   1.219 +             method: "DELETE",
   1.220 +           },
   1.221 +           { pass: 0,
   1.222 +             method: "PATCH",
   1.223 +           },
   1.224 +           { pass: 1,
   1.225 +             method: "PATCH",
   1.226 +             allowMethods: "PATCH",
   1.227 +           },
   1.228 +           { pass: 0,
   1.229 +             method: "PATCH",
   1.230 +           },
   1.231 +           { pass: 1,
   1.232 +             method: "PATCH",
   1.233 +             allowMethods: "PATCH",
   1.234 +             cacheTime: 3600,
   1.235 +           },
   1.236 +           { pass: 1,
   1.237 +             method: "PATCH",
   1.238 +           },
   1.239 +           { pass: 0,
   1.240 +             method: "DELETE",
   1.241 +           },
   1.242 +           { pass: 0,
   1.243 +             method: "PUT",
   1.244 +           },
   1.245 +           { newTest: "*******" },
   1.246 +           { pass: 0,
   1.247 +             method: "DELETE",
   1.248 +           },
   1.249 +           { pass: 1,
   1.250 +             method: "DELETE",
   1.251 +             allowMethods: "DELETE",
   1.252 +             cacheTime: 2
   1.253 +           },
   1.254 +           { pause: 2.1 },
   1.255 +           { pass: 0,
   1.256 +             method: "DELETE",
   1.257 +           },
   1.258 +           { newTest: "*******" },
   1.259 +           { pass: 1,
   1.260 +             method: "DELETE",
   1.261 +             allowMethods: "DELETE, PUT",
   1.262 +             cacheTime: 3600
   1.263 +           },
   1.264 +           { pass: 1,
   1.265 +             method: "DELETE",
   1.266 +           },
   1.267 +           { pass: 1,
   1.268 +             method: "PUT",
   1.269 +           },
   1.270 +           { pass: 0,
   1.271 +             method: "PATCH",
   1.272 +           },
   1.273 +           { newTest: "*******" },
   1.274 +           { pass: 1,
   1.275 +             method: "FIRST",
   1.276 +             allowMethods: "FIRST",
   1.277 +             cacheTime: 2,
   1.278 +           },
   1.279 +           { pass: 1,
   1.280 +             method: "SECOND",
   1.281 +             allowMethods: "SECOND",
   1.282 +             cacheTime: 3600,
   1.283 +           },
   1.284 +           { pass: 1,
   1.285 +             method: "THIRD",
   1.286 +             allowMethods: "THIRD",
   1.287 +             cacheTime: 2,
   1.288 +           },
   1.289 +           { pause: 2.1 },
   1.290 +           { pass: 1,
   1.291 +             method: "SECOND",
   1.292 +           },
   1.293 +           { pass: 0,
   1.294 +             method: "FIRST",
   1.295 +           },
   1.296 +           { newTest: "*******" },
   1.297 +           { pass: 1,
   1.298 +             method: "FIRST",
   1.299 +             allowMethods: "FIRST",
   1.300 +             cacheTime: 2,
   1.301 +           },
   1.302 +           { pass: 1,
   1.303 +             method: "SECOND",
   1.304 +             allowMethods: "SECOND",
   1.305 +             cacheTime: 3600,
   1.306 +           },
   1.307 +           { pass: 1,
   1.308 +             method: "THIRD",
   1.309 +             allowMethods: "THIRD",
   1.310 +             cacheTime: 2,
   1.311 +           },
   1.312 +           { pause: 2.1 },
   1.313 +           { pass: 1,
   1.314 +             method: "SECOND",
   1.315 +           },
   1.316 +           { pass: 0,
   1.317 +             method: "THIRD",
   1.318 +           },
   1.319 +           { newTest: "*******" },
   1.320 +           { pass: 1,
   1.321 +             method: "GET",
   1.322 +             headers: { "x-my-header": "x-value" },
   1.323 +             allowHeaders: "x-my-header",
   1.324 +             cacheTime: 3600,
   1.325 +           },
   1.326 +           { pass: 1,
   1.327 +             method: "GET",
   1.328 +             headers: { "x-my-header": "x-value" }
   1.329 +           },
   1.330 +           { pass: 0,
   1.331 +             method: "GET",
   1.332 +             headers: { "y-my-header": "y-value" }
   1.333 +           },
   1.334 +           { pass: 0,
   1.335 +             method: "GET",
   1.336 +             headers: { "x-my-header": "x-value" }
   1.337 +           },
   1.338 +           { newTest: "*******" },
   1.339 +           { pass: 1,
   1.340 +             method: "GET",
   1.341 +             headers: { "x-my-header": "x-value" },
   1.342 +             allowHeaders: "x-my-header",
   1.343 +             cacheTime: 3600,
   1.344 +           },
   1.345 +           { pass: 1,
   1.346 +             method: "GET",
   1.347 +             headers: { "x-my-header": "x-value" },
   1.348 +           },
   1.349 +           { pass: 0,
   1.350 +             method: "PUT",
   1.351 +           },
   1.352 +           { pass: 0,
   1.353 +             method: "GET",
   1.354 +             headers: { "x-my-header": "x-value" },
   1.355 +           },
   1.356 +           { newTest: "*******" },
   1.357 +           { pass: 1,
   1.358 +             method: "GET",
   1.359 +             headers: { "x-my-header": "x-value" },
   1.360 +             allowHeaders: "x-my-header",
   1.361 +             cacheTime: 3600,
   1.362 +           },
   1.363 +           { pass: 1,
   1.364 +             method: "GET",
   1.365 +             headers: { "x-my-header": "x-value" },
   1.366 +           },
   1.367 +           { pass: 0,
   1.368 +             method: "GET",
   1.369 +             noOrigin: 1,
   1.370 +           },
   1.371 +           { pass: 0,
   1.372 +             method: "GET",
   1.373 +             headers: { "x-my-header": "x-value" },
   1.374 +           },
   1.375 +           { newTest: "*******" },
   1.376 +           { pass: 1,
   1.377 +             method: "DELETE",
   1.378 +             allowMethods: "DELETE",
   1.379 +             cacheTime: 3600,
   1.380 +           },
   1.381 +           { pass: 1,
   1.382 +             method: "DELETE"
   1.383 +           },
   1.384 +           { pass: 0,
   1.385 +             method: "PUT"
   1.386 +           },
   1.387 +           { pass: 0,
   1.388 +             method: "DELETE"
   1.389 +           },
   1.390 +           { newTest: "*******" },
   1.391 +           { pass: 1,
   1.392 +             method: "DELETE",
   1.393 +             allowMethods: "DELETE",
   1.394 +             cacheTime: 3600,
   1.395 +           },
   1.396 +           { pass: 1,
   1.397 +             method: "DELETE"
   1.398 +           },
   1.399 +           { pass: 0,
   1.400 +             method: "DELETE",
   1.401 +             headers: { "my-header": "value" },
   1.402 +           },
   1.403 +           { pass: 0,
   1.404 +             method: "DELETE"
   1.405 +           },
   1.406 +           { newTest: "*******" },
   1.407 +           { pass: 1,
   1.408 +             method: "DELETE",
   1.409 +             allowMethods: "DELETE",
   1.410 +             cacheTime: 3600,
   1.411 +           },
   1.412 +           { pass: 1,
   1.413 +             method: "DELETE"
   1.414 +           },
   1.415 +           { pass: 0,
   1.416 +             method: "GET",
   1.417 +             noOrigin: 1,
   1.418 +           },
   1.419 +           { pass: 0,
   1.420 +             method: "DELETE"
   1.421 +           },
   1.422 +           ];
   1.423 +
   1.424 +  for (let i = 0; i < 110; i++) {
   1.425 +    tests.push({ newTest: "*******" },
   1.426 +               { pass: 1,
   1.427 +                 method: "DELETE",
   1.428 +                 allowMethods: "DELETE",
   1.429 +                 cacheTime: 3600,
   1.430 +               });
   1.431 +  }
   1.432 +
   1.433 +  baseURL = "http://mochi.test:8888/tests/content/base/test/" +
   1.434 +             "file_CrossSiteXHR_cache_server.sjs?";
   1.435 +  setStateURL = baseURL + "setState=";
   1.436 +
   1.437 +  var unique = Date.now();
   1.438 +  for (test of tests) {
   1.439 +    if (test.newTest) {
   1.440 +      unique++;
   1.441 +      continue;
   1.442 +    }
   1.443 +    if (test.pause) {
   1.444 +      setTimeout(function() { gen.next() }, test.pause * 1000);
   1.445 +      yield undefined;
   1.446 +      continue;
   1.447 +    }
   1.448 +
   1.449 +    req = {
   1.450 +      url: baseURL + "c=" + unique,
   1.451 +      method: test.method,
   1.452 +      headers: test.headers,
   1.453 +    };
   1.454 +
   1.455 +    sec = { allowOrigin: test.noOrigin ? "" : origin,
   1.456 +            allowHeaders: test.allowHeaders,
   1.457 +            allowMethods: test.allowMethods,
   1.458 +            cacheTime: test.cacheTime };
   1.459 +    xhr = new XMLHttpRequest();
   1.460 +    xhr.open("POST", setStateURL + escape(sec.toSource()), true);
   1.461 +    xhr.onloadend = function() { gen.next(); }
   1.462 +    xhr.send();
   1.463 +    yield undefined;
   1.464 +
   1.465 +    loaderWindow.postMessage(req.toSource(), origin);
   1.466 +
   1.467 +    res = eval(yield);
   1.468 +
   1.469 +    testName = test.toSource() + " (index " + tests.indexOf(test) + ")";
   1.470 +
   1.471 +    if (test.pass) {
   1.472 +      is(res.didFail, false,
   1.473 +        "shouldn't have failed in test for " + testName);
   1.474 +      is(res.status, 200, "wrong status in test for " + testName);
   1.475 +      is(res.responseXML, "<res>hello pass</res>",
   1.476 +         "wrong responseXML in test for " + testName);
   1.477 +      is(res.responseText, "<res>hello pass</res>\n",
   1.478 +         "wrong responseText in test for " + testName);
   1.479 +      is(res.events.join(","),
   1.480 +         "opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend",
   1.481 +         "wrong events in test for " + testName);
   1.482 +    }
   1.483 +    else {
   1.484 +      is(res.didFail, true,
   1.485 +        "should have failed in test for " + testName);
   1.486 +      is(res.status, 0, "wrong status in test for " + testName);
   1.487 +      is(res.responseXML, null,
   1.488 +         "wrong responseXML in test for " + testName);
   1.489 +      is(res.responseText, "",
   1.490 +         "wrong responseText in test for " + testName);
   1.491 +      is(res.events.join(","),
   1.492 +         "opening,rs1,sending,loadstart,rs2,rs4,error,loadend",
   1.493 +         "wrong events in test for " + testName);
   1.494 +      is(res.progressEvents, 0,
   1.495 +         "wrong events in test for " + testName);
   1.496 +    }
   1.497 +  }
   1.498 +
   1.499 +  SimpleTest.finish();
   1.500 +
   1.501 +  yield undefined;
   1.502 +}
   1.503 +
   1.504 +</script>
   1.505 +</pre>
   1.506 +</body>
   1.507 +</html>

mercurial