timeout-cors-async.htm (2041B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>XMLHttpRequest: timeout event and cross-origin request</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <link rel="help" href="https://xhr.spec.whatwg.org/#the-timeout-attribute" data-tested-assertations="following::ol[1]/li[2]" /> 8 <link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-ontimeout" data-tested-assertations="../.."/> 9 <link rel="help" href="https://xhr.spec.whatwg.org/#timeout-error" data-tested-assertations=".."/> 10 <link rel="help" href="https://xhr.spec.whatwg.org/#request-error" data-tested-assertations="following::ol[1]/li[4] following::ol[1]/li[9]"/> 11 <link rel="help" href="https://xhr.spec.whatwg.org/#cross-origin-request-event-rules" data-tested-assertations="following::dl//code[contains(@title,'dom-XMLHttpRequest-timeout')]/.. following::dl//code[contains(@title,'dom-XMLHttpRequest-timeout')]/../following-sibling::dd following::dt[1] following::dd[1]" /> 12 </head> 13 <body> 14 <div id="log"></div> 15 <script> 16 var test = async_test() 17 var client = new XMLHttpRequest() 18 var gotTimeout = false 19 client.open("GET", "http://www2." + location.hostname + (location.port ? ":" + location.port : "") +(location.pathname.replace(/[^\/]+$/, '')+'resources/corsenabled.py')+"?delay=2&code=200") 20 client.timeout = 100 21 client.addEventListener('timeout', function (e) { 22 test.step(function() { 23 assert_equals(e.type, 'timeout') 24 assert_equals(client.status, 0) 25 gotTimeout = true 26 }) 27 }) 28 client.addEventListener('load', function (e) { 29 test.step(function() { 30 assert_unreached('load event should not fire') 31 }) 32 }) 33 client.addEventListener('loadend', function (e) { 34 test.step(function() { 35 assert_true(gotTimeout, "timeout event should fire") 36 test.done() 37 }) 38 }) 39 40 client.send(null) 41 </script> 42 </body> 43 </html>