Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / response-document.html
blobd3f0e3426ec32398dcaa98f2b819c5ae677e15d0
1 <!DOCTYPE html>
2 <script src="/js-test-resources/js-test.js"></script>
3 <script>
5 description("Request a file as the document type with asynchronous XMLHttpRequest in a document context.");
6 window.jsTestIsAsync = true;
8 var global = window;
10 function rejectIfThrown(func, reject) {
11 return function() {
12 try {
13 func();
14 } catch (e) {
15 reject(e);
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) {
26 return;
29 shouldBe('req.status', '200');
30 shouldBeNonNull('req.response');
31 global.result = req.response.querySelector('p').innerText;
32 shouldBeEqualToString('result', 'PASS');
34 resolve();
35 }, reject);
36 req.send(null);
37 }).catch(function(r) {
38 testFailed('Set responseType to document before open(): Failed: ' + r);
39 }).then(function() {
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) {
47 return;
50 shouldBe('req.status', '200');
51 shouldBeNonNull('req.response');
52 global.result = req.response.querySelector('p').innerText;
53 shouldBeEqualToString('result', 'PASS');
55 resolve();
56 }, reject);
57 req.responseType = 'document';
58 req.send(null);
59 });
60 }).catch(function(r) {
61 testFailed('Change responseType from blob to document between open() and send(): Failed: ' + r);
62 }).then(function() {
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';
71 return;
72 } else if (req.readyState != req.DONE) {
73 return;
76 shouldBe('req.status', '200');
77 shouldBeNonNull('req.response');
78 global.result = req.response.querySelector('p').innerText;
79 shouldBeEqualToString('result', 'PASS');
81 resolve();
82 }, reject);
83 req.send(null);
84 });
85 }).catch(function(r) {
86 testFailed('Change responseType from blob to document in HEADERS_RECEIVED: Failed: ' + r);
87 }).then(finishJSTest, finishJSTest);
89 </script>