send-sync-blocks-async.htm (1809B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <title>XMLHttpRequest: sync requests should block events on pending async requests</title> 7 </head> 8 9 <body> 10 <div id="log"></div> 11 12 <script type="text/javascript"> 13 var test = async_test(); 14 15 var expect = ['sync 4', 'async 2', 'async 3', 'async 4'] 16 var actual = [] 17 18 test.step(function() 19 { 20 var xhr_async = new XMLHttpRequest() 21 xhr_async.open('GET', 'resources/delay.py?ms=1000', true) // first launch an async request, completes in 1 second 22 xhr_async.onreadystatechange = test.step_func(() => { 23 actual.push('async ' + xhr_async.readyState) 24 if(xhr_async.readyState === 4 && actual.indexOf('sync 4')>-1){ 25 VerifyResult() 26 } 27 }); 28 xhr_async.send() 29 30 test.step_timeout(() => { 31 var xhr_sync = new XMLHttpRequest(); 32 xhr_sync.open('GET', 'resources/delay.py?ms=2000', false) // here's a sync request that will take 2 seconds to finish 33 xhr_sync.onreadystatechange = test.step_func(() => { 34 actual.push('sync ' + xhr_sync.readyState) 35 if(xhr_sync.readyState === 4 && actual.indexOf('async 4')>-1){ 36 VerifyResult() 37 } 38 }); 39 xhr_sync.send() 40 }, 10); 41 42 function VerifyResult() 43 { 44 test.step(function() 45 { 46 assert_array_equals(actual, expect); 47 test.done(); 48 }); 49 }; 50 }); 51 </script> 52 </body> 53 </html>