XMLHttpRequest should support attribute responseURL as per latest XHR spec.
[WebKit-https.git] / LayoutTests / http / tests / xmlhttprequest / redirect-credentials-responseURL.html
1 <html>
2 <head></head>
3 <body>
4 <script src="/js-test-resources/js-test.js"></script>
5 <script>
6
7 description('Test XMLHttpRequest responseURL.');
8
9 window.jsTestIsAsync = true;
10
11 function runTest(url, type, async, user, pwd) {
12     return new Promise(function(resolve, reject) {
13         var req = new XMLHttpRequest();
14         window.responseURL = req.responseURL;
15         debug('req.readyState = ' + req.readyState + ': responseURL = ' + req.responseURL);
16         shouldBeEqualToString('responseURL', '');
17
18         req.open('GET', url, async, user, pwd);
19         req.responseType = type;
20         debug('req.readyState = ' + req.readyState + ': responseURL = ' + req.responseURL);
21         window.responseURL = req.responseURL;
22         shouldBeEqualToString('responseURL', '');
23
24         req.onreadystatechange = function() {
25             debug('req.readyState = ' + req.readyState + ': responseURL = ' + req.responseURL);
26             if (req.readyState == req.DONE)
27                 resolve(req);
28         }       
29
30         req.send();
31         debug('req.readyState = ' + req.readyState + ': responseURL = ' + req.responseURL);
32         window.responseURL = req.responseURL;
33         shouldBeEqualToString('responseURL', '');
34     });
35 }
36
37 runTest('resources/basic-auth-default/dir1/basic-auth.php', true, "test", "test", 'text').then(function(req) {
38     window.responseURL = req.responseURL;
39     shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/basic-auth-default/dir1/basic-auth.php');
40
41     return runTest('resources/basic-auth-default/dir2/basic-auth.php', true, 'text');
42 }).then(function(req) {
43     window.responseURL = req.responseURL;
44     shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/basic-auth-default/dir2/basic-auth.php');
45
46     req.open('GET', 'http://127.0.0.1:8000/xmlhttprequest/resources/not-found.txt');
47 }).catch(function(reason) {
48     testFailed(String(reason));
49 }).then(finishJSTest, finishJSTest);
50
51 </script>
52 </body>
53 </html>