test_bug1070763.html (1435B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1405571 5 --> 6 <head> 7 <title>XMLHttpRequest send data and headers</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" 13 href="https://bugzilla.mozilla.org/show_bug.cgi?id=1405571">Mozilla Bug 1405571</a> 14 <p id="display"> 15 </p> 16 <div id="content" style="display: none"> 17 18 </div> 19 <pre id="test"> 20 <script class="testbody" type="application/javascript"> 21 SimpleTest.waitForExplicitFinish(); 22 23 const url = "http://example.com/tests/dom/xhr/tests/file_XHRResponseURL.text"; 24 25 function runTest(testName, testFn) { 26 return new Promise(resolve => { 27 const xhr = new XMLHttpRequest(); 28 xhr.onloadend = () => { 29 xhr.onloadend = null; 30 xhr.onreadystatechange = () => { 31 if (xhr.readyState === 1) { 32 testFn(xhr); 33 } else if (xhr.readyState === 4) { 34 ok(true, testName); 35 resolve(); 36 } 37 }; 38 xhr.open("GET", url); 39 xhr.send(null); 40 }; 41 xhr.open("GET", url); 42 xhr.send(null); 43 }); 44 } 45 46 async function runTests() { 47 await runTest("Abort #1", xhr => { xhr.abort() }); 48 await runTest("Abort #2", xhr => { setTimeout(() => xhr.abort(), 0) }); 49 await runTest("Timeout", xhr => { xhr.timeout = 1 }); 50 SimpleTest.finish(); 51 } 52 53 runTests(); 54 55 </script> 56 </pre> 57 </body> 58 </html>