xmlhttprequest-eventtarget.htm (1610B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>XMLHttpRequest: implements EventTarget</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/#xmlhttprequesteventtarget" data-tested-assertations=".." /> 8 <!-- Obviously, most of the stuff actually being tested here is covered in the DOM events spec, not in the XHR spec --> 9 </head> 10 <body> 11 <div id="log"></div> 12 <script> 13 var test = async_test(), 14 x = null, 15 expected = ["a1", "b1", "c1", "a2", "b2", "c2", "a3", "c3", "a4", "c4"], 16 result = [] 17 function callback(e) { 18 result.push("b" + x.readyState) 19 test.step(function() { 20 if(x.readyState == 3) 21 assert_unreached() 22 }) 23 } 24 test.step(function() { 25 x = new XMLHttpRequest() 26 x.onreadystatechange = function() { 27 test.step(function() { 28 result.push("a" + x.readyState) 29 }) 30 } 31 x.addEventListener("readystatechange", callback, false) 32 x.addEventListener("readystatechange", function() { 33 test.step(function() { 34 result.push("c" + x.readyState) 35 if(x.readyState == 2) 36 x.removeEventListener("readystatechange", callback, false) 37 if(x.readyState == 4) { 38 assert_array_equals(result, expected) 39 test.done() 40 } 41 }) 42 }, false) 43 x.open("GET", "folder.txt") 44 x.send(null) 45 }) 46 </script> 47 </body> 48 </html>