5 <script src=
"/js-test-resources/js-test.js"></script>
7 description('Test XMLHttpRequest.responseURL');
8 window
.jsTestIsAsync
= true;
10 function get(url
, type
) {
11 return new Promise(function(resolve
, reject
) {
12 var xhr
= new XMLHttpRequest();
13 window
.responseURL
= xhr
.responseURL
;
14 shouldBeEqualToString('responseURL', '');
17 xhr
.responseType
= type
;
18 window
.responseURL
= xhr
.responseURL
;
19 shouldBeEqualToString('responseURL', '');
21 xhr
.onreadystatechange = function() {
22 debug('xhr.readyState = ' + xhr
.readyState
+ ': responseURL = ' + xhr
.responseURL
);
23 if (xhr
.readyState
=== 4) {
31 get('resources/reply2.txt', 'text').then(function(xhr
) {
32 window
.status
= xhr
.status
;
33 shouldBeEqualToString('status', '200');
34 window
.responseURL
= xhr
.responseURL
;
35 shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/reply2.txt');
37 return get('resources/redirect.php?url=reply2.xml', 'document');
38 }).then(function(xhr
) {
39 window
.status
= xhr
.status
;
40 shouldBeEqualToString('status', '200');
41 window
.responseURL
= xhr
.responseURL
;
42 shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/reply2.xml');
44 return get('resources/navigation-target.html#foobar', 'text');
45 }).then(function(xhr
) {
46 window
.status
= xhr
.status
;
47 shouldBeEqualToString('status', '200');
48 window
.responseURL
= xhr
.responseURL
;
49 shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/navigation-target.html');
51 return get('resources/redirect.php?url=not-found.txt', 'text');
52 }).then(function(xhr
) {
53 window
.status
= xhr
.status
;
54 shouldBeEqualToString('status', '404');
55 window
.responseURL
= xhr
.responseURL
;
56 shouldBeEqualToString('responseURL', 'http://127.0.0.1:8000/xmlhttprequest/resources/not-found.txt');
58 xhr
.open('GET', xhr
.responseURL
);
59 }).catch(function(reason
) {
60 testFailed(String(reason
));
61 }).then(finishJSTest
, finishJSTest
);