Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / xmlhttprequest-responseText-exception.html
blob1bb1bb41c73e0e86db5b17229c0ba0d37ba4c8f6
1 <!doctype html>
2 <script src="/js-test-resources/js-test.js"></script>
3 <script type="text/javascript">
4 window.jsTestIsAsync = true;
5 description('XMLHttpRequest.responseText should not throw even when not (loading or done).');
6 function test(readyState) {
7 var xhr;
8 return new Promise(function(resolve, reject) {
9 xhr = new XMLHttpRequest();
10 xhr.onreadystatechange = function() {
11 try {
12 if (this.readyState === readyState) {
13 // We evaluate responseText because we want to make sure
14 // doing that doesn't throw.
15 var response = xhr.responseText;
16 resolve(response);
18 } catch(e) {
19 reject(e);
22 xhr.onerror = reject;
23 xhr.open('GET', 'resources/1251.html');
24 if (readyState !== 1) {
25 xhr.send();
27 }).then(function() {
28 testPassed('readyState = ' + readyState);
29 xhr.abort();
30 }, function(e) {
31 testFailed('readyState = ' + readyState, + ', ' + e);
32 });
35 var promise = Promise.resolve();
36 for (var readyState = 1; readyState <= 4; ++readyState) {
37 promise = promise.then(test.bind(undefined, readyState));
39 promise.then(finishJSTest, function(e) {
40 testFailed(e);
41 finishJSTest();
42 });
43 </script>