Reviewed by Darin.
[WebKit-https.git] / LayoutTests / http / tests / xmlhttprequest / basic-auth.html
1 <html>
2 <body>
3 <p>Tests for <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=7877">bug 7877</a>: 
4 XMLHttpRequest ignores username/password passed to open()
5 <script>
6     if (window.layoutTestController) {
7         layoutTestController.dumpAsText();
8         layoutTestController.waitUntilDone();
9     }
10     
11     var console_messages = document.createElement("ol");
12     document.body.appendChild(console_messages);
13     
14     function log(message)
15     {
16         var item = document.createElement("li");
17         item.appendChild(document.createTextNode(message));
18         console_messages.appendChild(item);
19     }
20
21     // sync
22     req = new XMLHttpRequest;
23     req.open("GET", "resources/basic-auth.php?uid=sync", false, "sync", "123");
24     req.send("");
25     log('sync: ' + req.responseText);
26
27     req.open("GET", document.URL.replace("basic-auth.html", "resources/basic-auth.php?uid=sync2"), false, "sync2", "123");
28     req.send("");
29     log('sync2: ' + req.responseText);
30
31     req.open("GET", document.URL.replace("basic-auth.html", "resources/basic-auth.php?uid=sync3").replace("http://", "http://sync3:123@"), false);
32     req.send("");
33     log('sync3: ' + req.responseText);
34
35     req.open("GET", document.URL.replace("basic-auth.html", "resources/basic-auth.php?uid=sync4").replace("http://", "http://incorrect:incorrect@"), false, "sync4", "123");
36     req.send("");
37     log('sync4: ' + req.responseText);
38
39     // async
40     var asyncStep = 1;
41
42     req.onreadystatechange = processStateChange;
43     req.open("GET", "resources/basic-auth.php?uid=async", true, "async", "123");
44     req.send("");
45
46     function processStateChange() {
47     
48       if (req.readyState == 4){
49         if (req.status == 200){
50           if (asyncStep == 1) {
51             asyncStep = 2;
52             log('async: ' + req.responseText);
53             req.onreadystatechange = processStateChange;
54             req.open("GET", document.URL.replace("basic-auth.html", "resources/basic-auth.php?uid=async2"), true, "async2", "123");
55             req.send("");
56           } else if (asyncStep == 2) {
57             asyncStep = 3;
58             log('async2: ' + req.responseText);
59             req.onreadystatechange = processStateChange;
60             req.open("GET", document.URL.replace("basic-auth.html", "resources/basic-auth.php?uid=async3").replace("http://", "http://async3:123@"), true, "async3", "123");
61             req.send("");
62           } else if (asyncStep == 3) {
63             asyncStep = 4;
64             log('async3: ' + req.responseText);
65             req.onreadystatechange = processStateChange;
66             req.open("GET", document.URL.replace("basic-auth.html", "resources/basic-auth.php?uid=async4").replace("http://", "http://incorrect:incorrect@"), true, "async4", "123");
67             req.send("");
68           } else if (asyncStep == 4) {
69             log('async4: ' + req.responseText);
70             if (window.layoutTestController)
71               layoutTestController.notifyDone();
72           }
73         }
74       }
75     }
76
77 </script>
78 </body>
79 </html>