XMLHttpRequest should support attribute responseURL as per latest XHR spec.
[WebKit-https.git] / LayoutTests / http / tests / xmlhttprequest / cross-origin-redirect-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) {
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);
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/redirect.php?url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow.cgi', 'text').then(function(req) {
38     window.responseURL = req.responseURL;
39     shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/redirect.php?url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow.cgi');
40
41     return runTest('resources/redirect.php?url=http://localhost:7/', 'document');
42 }).then(function(req) {
43     window.responseURL = req.responseURL;
44     shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/redirect.php?url=http://localhost:7/');
45
46     return runTest('resources/redirect.php?url=http://localhost:22/', 'text');
47 }).then(function(req) {
48     window.responseURL = req.responseURL;
49     shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/redirect.php?url=http://localhost:22/');
50
51     return runTest('resources/redirect-cors.php', 'text');
52 }).then(function(req) {
53     window.responseURL = req.responseURL;
54     shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/redirect-cors.php');
55
56     req.open('GET', 'http://127.0.0.1:8000/xmlhttprequest/resources/not-found.txt');
57 }).catch(function(reason) {
58     testFailed(String(reason));
59 }).then(finishJSTest, finishJSTest);
60
61 </script>
62 </body>
63 </html>