OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <body> |
| 3 <script src="/js-test-resources/js-test.js"></script> |
| 4 <script> |
| 5 (function() { |
| 6 description('Make two XHRs for the resource which is already cached.'); |
| 7 window.jsTestIsAsync = true; |
| 8 var url = 'resources/get.txt'; |
| 9 function get(xhr, async) { |
| 10 return new Promise(function(resolve, reject) { |
| 11 xhr.onreadystatechange = function() { |
| 12 if (xhr.readyState === xhr.DONE) { |
| 13 if (xhr.status === 200) { |
| 14 resolve(xhr.responseText); |
| 15 } else { |
| 16 reject(xhr.status); |
| 17 } |
| 18 } |
| 19 }; |
| 20 xhr.open('GET', url, async); |
| 21 xhr.send(); |
| 22 }); |
| 23 } |
| 24 var xhr1 = new XMLHttpRequest(); |
| 25 var xhr2 = new XMLHttpRequest(); |
| 26 |
| 27 Promise.resolve().then(function() { |
| 28 var async = get(xhr1, true); |
| 29 var sync = get(xhr2, false); |
| 30 return Promise.all([sync, async]); |
| 31 }).then(function(results) { |
| 32 window.result1 = results[0]; |
| 33 window.result2 = results[1]; |
| 34 shouldBeEqualToString('result1', 'PASS'); |
| 35 shouldBeEqualToString('result2', 'PASS'); |
| 36 if (localStorage.reload) { |
| 37 testPassed('DONE'); |
| 38 finishJSTest(); |
| 39 } else { |
| 40 localStorage.reload = true; |
| 41 location.reload(true); |
| 42 } |
| 43 }, function(e) { |
| 44 testFailed(e); |
| 45 finishJSTest(); |
| 46 }); |
| 47 }()); |
| 48 |
| 49 </script> |
| 50 </body> |
| 51 </html> |
OLD | NEW |