| <p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=13075">bug 13075</a>: |
| XMLHttpRequest with failed authentication should set status to 401.</p> |
| <ol> |
| <li>Sync, no credentials: |
| <li>Sync, incorrect credentials: |
| <li>Async, no credentials: |
| <li>Async, incorrect credentials: |
| </ol> |
| <script> |
| function checkResult(n, code) { |
| document.getElementsByTagName("li")[n - 1].firstChild.nodeValue += |
| ((code == 401) ? " OK" : (" " + code + " != 401")); |
| } |
| |
| function log(n, message) { |
| document.getElementsByTagName("li")[n - 1].firstChild.nodeValue += |
| " " + message; |
| } |
| |
| |
| if (window.testRunner) { |
| testRunner.dumpAsText(); |
| testRunner.waitUntilDone(); |
| } else { |
| alert("Please cancel all authentication dialogs that will appear"); |
| } |
| |
| try { |
| var r = new XMLHttpRequest(); |
| r.open("GET", "resources/basic-auth/basic-auth.php?uid=login1", false); |
| r.send(); |
| checkResult(1, r.status); |
| } catch (ex) { |
| log(1, ex); |
| } |
| |
| try { |
| var r = new XMLHttpRequest(); |
| r.open("GET", "resources/basic-auth/basic-auth.php?uid=login2", false, "badname", "passpw"); |
| r.send(); |
| checkResult(2, r.status); |
| } catch (ex) { |
| log(2, ex); |
| } |
| |
| try { |
| var r = new XMLHttpRequest(); |
| r.open("GET", "resources/basic-auth/basic-auth.php?uid=login3", true); |
| r.onreadystatechange = function() { |
| if (r.readyState == 4) { |
| checkResult(3, r.status); |
| test4(); |
| } |
| }; |
| r.send(); |
| } catch (ex) { |
| log(3, ex); |
| test4(); |
| } |
| |
| function test4() { |
| try { |
| var r = new XMLHttpRequest(); |
| r.open("GET", "resources/basic-auth/basic-auth.php?uid=login4", true, "badname", "passpw"); |
| r.onreadystatechange = function() { |
| if (r.readyState == 4) { |
| checkResult(4, r.status); |
| testRunner.notifyDone(); |
| } |
| }; |
| r.send(); |
| } catch (ex) { |
| log(4, ex); |
| testRunner.notifyDone(); |
| } |
| } |
| </script> |