Fix problems with cross-origin redirects
[WebKit-https.git] / LayoutTests / http / tests / xmlhttprequest / access-control-and-redirects.html
1 <p>Tests that redirects between origins are never allowed, even when access control is involved.</p>
2 <p>Per the spec, these test cases should be allowed, but cross-origin redirects are currently unsupported in WebCore.</p>
3
4 <pre id="console"></pre>
5 <script>
6 if (window.testRunner) {
7     testRunner.dumpAsText();
8     testRunner.waitUntilDone();
9 }
10
11 function log(message)
12 {
13     document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
14 }
15
16 function runTest(url, expectSyncSuccess, expectAsyncSuccess)
17 {
18     log("Testing " + url + " (sync)");
19     log("Expecting success: " + expectSyncSuccess);
20
21     var req = new XMLHttpRequest();
22     req.open("GET", url, false);
23
24     try {
25         req.send(null);
26         log((expectSyncSuccess ? "PASS" : "FAIL") + ": " + req.responseText);
27     } catch (ex) {
28         log((expectSyncSuccess ? "FAIL" : "PASS") + ": " + ex);
29     }
30     
31     log("Testing " + url + "(async)");
32     log("Expecting success: " + expectAsyncSuccess);
33
34     req = new XMLHttpRequest();
35     req.open("GET", url, true);
36     req.onload = function() {
37         log((expectAsyncSuccess ? "PASS" : "FAIL") + ": " + req.responseText);
38         nextTest();
39     }
40     req.onerror = function() {
41         log((expectAsyncSuccess ? "FAIL" : "PASS") + ": " + req.status);
42         nextTest();
43     }
44     req.send(null);
45 }
46
47 var tests = [
48     ["/resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow.cgi", false, true],
49     ["http://localhost:8000/resources/redirect.php?url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow.cgi", false, false],
50     ["http://localhost:8000/resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow.cgi", false, false]
51 ]
52
53 var currentTest = 0;
54
55 function nextTest() {
56     if (currentTest < tests.length)
57         runTest.apply(null, tests[currentTest++]);
58     else if (window.testRunner)
59         testRunner.notifyDone();
60 }
61
62 nextTest();
63 </script>