OLD | NEW |
(Empty) | |
| 1 <p>Tests that asynchronous XMLHttpRequests handle redirects according to the COR
S standard.</p> |
| 2 |
| 3 <pre id="console"></pre> |
| 4 <script> |
| 5 if (window.testRunner) { |
| 6 testRunner.dumpAsText(); |
| 7 testRunner.waitUntilDone(); |
| 8 } |
| 9 |
| 10 function log(message) |
| 11 { |
| 12 document.getElementById('console').appendChild(document.createTextNode(messa
ge + '\n')); |
| 13 } |
| 14 |
| 15 function runTestAsync(url, credentials, addCustomHeader, expectSuccess) { |
| 16 log("Testing " + url + (credentials ? " with " : " without ") + "credentials
"); |
| 17 log("Expecting success: " + expectSuccess); |
| 18 |
| 19 xhr = new XMLHttpRequest(); |
| 20 xhr.withCredentials = credentials; |
| 21 xhr.open("GET", url, true); |
| 22 if (addCustomHeader) |
| 23 xhr.setRequestHeader("x-webkit", "foo"); |
| 24 |
| 25 xhr.onload = function() { |
| 26 log((expectSuccess ? "PASS" : "FAIL") + ": " + xhr.responseText); |
| 27 nextTest(); |
| 28 } |
| 29 xhr.onerror = function() { |
| 30 log((expectSuccess ? "FAIL" : "PASS") + ": " + xhr.status); |
| 31 nextTest(); |
| 32 } |
| 33 xhr.send(null); |
| 34 } |
| 35 |
| 36 var withoutCredentials = false; |
| 37 var withCredentials = true; |
| 38 var noCustomHeader = false; |
| 39 var addCustomHeader = true; |
| 40 var succeeds = true; |
| 41 var fails = false; |
| 42 |
| 43 var tests = [ |
| 44 // Test simple same origin requests that receive cross origin redirects. |
| 45 |
| 46 // Request without credentials is redirected to a cross-origin response with Acc
ess-Control-Allow-Origin=*. |
| 47 // The redirect response passes the access check. |
| 48 ["resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/acce
ss-control-basic-allow-star.cgi", |
| 49 withoutCredentials, noCustomHeader, succeeds], |
| 50 |
| 51 // Request with credentials is redirected to a cross-origin response with Access
-Control-Allow-Origin=*. |
| 52 // The redirect response fails the access check because credentials were sent. |
| 53 ["resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/acce
ss-control-basic-allow-star.cgi", |
| 54 withCredentials, noCustomHeader, fails], |
| 55 |
| 56 // Request without credentials is redirected to a cross-origin response with a s
pecific Access-Control-Allow-Origin. |
| 57 // The redirect response passes the access check. |
| 58 ["resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/acce
ss-control-basic-allow.cgi", |
| 59 withoutCredentials, noCustomHeader, succeeds], |
| 60 |
| 61 // Request with credentials is redirected to a cross-origin response with a spec
ific Access-Control-Allow-Origin. |
| 62 // The redirect response passes the access check. |
| 63 ["resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/acce
ss-control-basic-allow.cgi", |
| 64 withCredentials, noCustomHeader, succeeds], |
| 65 |
| 66 // Request without credentials is redirected to a cross-origin response with a s
pecific Access-Control-Allow-Origin |
| 67 // forbidding credentials. The redirect response passes the access check. |
| 68 ["resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/acce
ss-control-basic-allow-no-credentials.cgi", |
| 69 withoutCredentials, noCustomHeader, succeeds], |
| 70 |
| 71 // Request with credentials is redirected to a cross-origin response with a spec
ific Access-Control-Allow-Origin |
| 72 // forbidding credentials. The redirect response fails the access check. |
| 73 ["resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/acce
ss-control-basic-allow-no-credentials.cgi", |
| 74 withCredentials, noCustomHeader, fails], |
| 75 |
| 76 ] |
| 77 |
| 78 var currentTest = 0; |
| 79 |
| 80 function nextTest() { |
| 81 if (currentTest < tests.length) |
| 82 runTestAsync.apply(null, tests[currentTest++]); |
| 83 else if (window.testRunner) |
| 84 testRunner.notifyDone(); |
| 85 } |
| 86 |
| 87 nextTest(); |
| 88 </script> |
OLD | NEW |