status-error.htm (2677B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>XMLHttpRequest: status error handling</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/#handler-xhr-onerror" data-tested-assertations="../.." /> 8 <link rel="help" href="https://xhr.spec.whatwg.org/#the-status-attribute" data-tested-assertations="/following::ol/li[3]" /> 9 </head> 10 <body> 11 <p>This shouldn't be tested inside a tunnel.</p> 12 <div id="log"></div> 13 <script> 14 function noError(method, code) { 15 var test = async_test(document.title + " " + method + " " + code) 16 17 test.step(function() { 18 var client = new XMLHttpRequest() 19 client.open(method, "resources/status.py?code=" + code, true) 20 21 client.onreadystatechange = test.step_func(function() { 22 assert_equals(client.response, "", "response data") 23 assert_equals(client.status, code, "response status") 24 25 if (client.readyState == client.DONE) 26 /* Give extra time for a bogus error event to pop up */ 27 test.step_timeout(() => { test.done() }, 100) 28 }) 29 client.onerror = test.step_func(function() { 30 assert_unreached("HTTP error should not throw error event") 31 }) 32 client.send() 33 }) 34 } 35 36 function unknownScheme() { 37 test(() => { 38 var client = new XMLHttpRequest(); 39 client.open("GET", "foobar://dummy", false); 40 try { 41 client.send(); 42 } catch(ex) {} 43 assert_equals(client.status, 0, "response data"); 44 }, "Unknown scheme"); 45 } 46 47 48 function postOnBlob() { 49 test(() => { 50 var u = URL.createObjectURL(new Blob([""], {type: 'text/plain'})); 51 var client = new XMLHttpRequest(); 52 client.open("POST", u, false); 53 try { 54 client.send(); 55 } catch(ex) {} 56 assert_equals(client.status, 0, "response data"); 57 }, "POST on blob uri"); 58 } 59 60 noError('GET', 200) 61 noError('GET', 400) 62 noError('GET', 401) 63 noError('GET', 404) 64 noError('GET', 410) 65 noError('GET', 500) 66 noError('GET', 699) 67 68 noError('HEAD', 200) 69 noError('HEAD', 404) 70 noError('HEAD', 500) 71 noError('HEAD', 699) 72 73 noError('POST', 200) 74 noError('POST', 404) 75 noError('POST', 500) 76 noError('POST', 699) 77 78 noError('PUT', 200) 79 noError('PUT', 404) 80 noError('PUT', 500) 81 noError('PUT', 699) 82 83 unknownScheme(); 84 postOnBlob(); 85 </script> 86 </body> 87 </html>