2 <script src=
"/js-test-resources/js-test.js"></script>
5 description("Request a file as the document type with asynchronous XMLHttpRequest in a document context.");
6 window
.jsTestIsAsync
= true;
10 function rejectIfThrown(func
, reject
) {
20 new Promise(function(resolve
, reject
) {
21 global
.req
= new XMLHttpRequest
;
22 req
.responseType
= 'document';
23 req
.open('GET', 'resources/test.html', true);
24 req
.onreadystatechange
= rejectIfThrown(function() {
25 if (req
.readyState
!= req
.DONE
) {
29 shouldBe('req.status', '200');
30 shouldBeNonNull('req.response');
31 global
.result
= req
.response
.querySelector('p').innerText
;
32 shouldBeEqualToString('result', 'PASS');
37 }).catch(function(r
) {
38 testFailed('Set responseType to document before open(): Failed: ' + r
);
40 return new Promise(function(resolve
, reject
)
42 global
.req
= new XMLHttpRequest
;
43 req
.responseType
= 'blob';
44 req
.open('GET', 'resources/test.html', true);
45 req
.onreadystatechange
= rejectIfThrown(function() {
46 if (req
.readyState
!= req
.DONE
) {
50 shouldBe('req.status', '200');
51 shouldBeNonNull('req.response');
52 global
.result
= req
.response
.querySelector('p').innerText
;
53 shouldBeEqualToString('result', 'PASS');
57 req
.responseType
= 'document';
60 }).catch(function(r
) {
61 testFailed('Change responseType from blob to document between open() and send(): Failed: ' + r
);
63 return new Promise(function(resolve
, reject
)
65 global
.req
= new XMLHttpRequest
;
66 req
.responseType
= 'blob';
67 req
.open('GET', 'resources/test.html', true);
68 req
.onreadystatechange
= rejectIfThrown(function() {
69 if (req
.readyState
== req
.HEADERS_RECEIVED
) {
70 req
.responseType
= 'document';
72 } else if (req
.readyState
!= req
.DONE
) {
76 shouldBe('req.status', '200');
77 shouldBeNonNull('req.response');
78 global
.result
= req
.response
.querySelector('p').innerText
;
79 shouldBeEqualToString('result', 'PASS');
85 }).catch(function(r
) {
86 testFailed('Change responseType from blob to document in HEADERS_RECEIVED: Failed: ' + r
);
87 }).then(finishJSTest
, finishJSTest
);