| OLD | NEW |
| (Empty) |
| 1 <button onclick="presetAuthorization()">Start</button> | |
| 2 <pre id="console"></pre> | |
| 3 <script> | |
| 4 if (window.testRunner) { | |
| 5 testRunner.dumpAsText(); | |
| 6 testRunner.waitUntilDone(); | |
| 7 testRunner.setCanOpenWindows(); | |
| 8 } | |
| 9 | |
| 10 function log(message) | |
| 11 { | |
| 12 document.getElementById('console').appendChild(document.createTextNode(messa
ge + '\n')); | |
| 13 } | |
| 14 | |
| 15 function presetAuthorization() | |
| 16 { | |
| 17 window.addEventListener("message", test, false); | |
| 18 window.open("http://localhost:8000/xmlhttprequest/resources/cross-origin-pre
set-authorization-frame.html"); | |
| 19 } | |
| 20 | |
| 21 function test() | |
| 22 { | |
| 23 log("Trying different ways to access a password protected resource from anot
her origin. The UA already has login and password for this protection space.\n") | |
| 24 log("You should see several PASS messages followed by a DONE\n"); | |
| 25 log("SCRIPT SRC='...' Should succeed, since authorization is sent for cross-
origin subresource loads."); | |
| 26 var scriptElement = document.createElement("script"); | |
| 27 scriptElement.setAttribute("src", "http://localhost:8000/xmlhttprequest/reso
urces/cross-origin-authorization.php"); | |
| 28 scriptElement.setAttribute("onload", "test_sync_auth_stored()"); | |
| 29 scriptElement.setAttribute("onerror", "test_sync_auth_stored()"); | |
| 30 document.body.appendChild(scriptElement); | |
| 31 } | |
| 32 | |
| 33 function test_sync_auth_stored() | |
| 34 { | |
| 35 log("Cross-origin XMLHttpRequest (sync), testing stored authorization."); | |
| 36 | |
| 37 var req = new XMLHttpRequest; | |
| 38 req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin
-authorization.php", false); | |
| 39 req.withCredentials = true; | |
| 40 try { | |
| 41 req.send(); | |
| 42 log((req.status == 401) ? "FAIL: 401 Authorization required" : "PASS"); | |
| 43 } catch (ex) { | |
| 44 log("FAIL: Got an exception. " + ex); | |
| 45 } | |
| 46 test_sync_cookies(); | |
| 47 } | |
| 48 | |
| 49 function test_sync_cookies() | |
| 50 { | |
| 51 log("Cross-origin XMLHttpRequest (sync), testing cookies."); | |
| 52 | |
| 53 var req = new XMLHttpRequest; | |
| 54 req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin
-check-cookies.php", false); | |
| 55 req.withCredentials = true; | |
| 56 req.send(); | |
| 57 if (req.status == 200) | |
| 58 log(req.responseText.match(/WK\-cross\-origin/) ? "PASS" : "FAIL"); | |
| 59 else | |
| 60 log("FAIL: Wrong status code " + req.status); | |
| 61 test_async_auth_stored(); | |
| 62 } | |
| 63 | |
| 64 function test_async_auth_stored() | |
| 65 { | |
| 66 log("Cross-origin XMLHttpRequest (async), testing stored authorization."); | |
| 67 | |
| 68 var req = new XMLHttpRequest; | |
| 69 req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin
-authorization.php", true); | |
| 70 req.withCredentials = true; | |
| 71 req.send(); | |
| 72 req.onload = function() { | |
| 73 log((req.status == 401) ? "FAIL: 401 Authorization required" : "PASS"); | |
| 74 test_async_cookies(); | |
| 75 } | |
| 76 req.onerror = function() { | |
| 77 log("FAIL: Received error event."); | |
| 78 test_async_cookies(); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 function test_async_cookies() | |
| 83 { | |
| 84 log("Cross-origin XMLHttpRequest (async), testing cookies."); | |
| 85 | |
| 86 var req = new XMLHttpRequest; | |
| 87 req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin
-check-cookies.php", true); | |
| 88 req.withCredentials = true; | |
| 89 req.send(); | |
| 90 req.onload = function() { | |
| 91 log(req.responseText.match(/WK\-cross\-origin/) ? "PASS" : "FAIL"); | |
| 92 test_sync_auth_explicit(); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 function test_sync_auth_explicit() | |
| 97 { | |
| 98 log("Cross-origin XMLHttpRequest (sync), testing authorization with explicit
ly provided credentials that should be ignored."); | |
| 99 | |
| 100 var req = new XMLHttpRequest; | |
| 101 req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin
-authorization.php", false, "test2", "test2"); | |
| 102 req.withCredentials = true; | |
| 103 try { | |
| 104 req.send(); | |
| 105 if (req.status == 200) | |
| 106 log(req.responseText.match(/test2/) ? "FAIL: Explicit credentials we
re not ignored" : "PASS"); | |
| 107 else | |
| 108 log("FAIL: Wrong status code " + req.status); | |
| 109 } catch (ex) { | |
| 110 log("FAIL: Got an exception. " + ex); | |
| 111 } | |
| 112 test_async_auth_explicit(); | |
| 113 } | |
| 114 | |
| 115 | |
| 116 function test_async_auth_explicit() | |
| 117 { | |
| 118 log("Cross-origin XMLHttpRequest (async), testing authorization with explici
tly provided credentials that should be ignored."); | |
| 119 | |
| 120 var req = new XMLHttpRequest; | |
| 121 req.open("GET", "http://localhost:8000/xmlhttprequest/resources/cross-origin
-authorization.php", true, "test2", "test2"); | |
| 122 req.withCredentials = true; | |
| 123 req.send(); | |
| 124 req.onload = function() { | |
| 125 if (req.status == 200) | |
| 126 log(req.responseText.match(/test2/) ? "FAIL: Explicit credentials we
re not ignored" : "PASS"); | |
| 127 else | |
| 128 log("FAIL: Wrong status code " + req.status); | |
| 129 log("DONE"); | |
| 130 if (window.testRunner) | |
| 131 testRunner.notifyDone(); | |
| 132 } | |
| 133 req.onerror = function() { | |
| 134 log("FAIL: Received error event."); | |
| 135 log("DONE"); | |
| 136 if (window.testRunner) | |
| 137 testRunner.notifyDone(); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 if (window.testRunner) | |
| 142 presetAuthorization(); | |
| 143 </script> | |
| OLD | NEW |