| <HTML> |
| <head> |
| <title>Test case for bug 40952</title> |
| </head> |
| <body> |
| <p> Test case for <a href="https://bugs.webkit.org/show_bug.cgi?id=40952"> bug 40952</a>: Onloadend event is not supported in XMLHttpRequest</p> |
| <p> Verify that a loadend ProgressEvent is dispatched after a load, error, or abort ProgressEvent when a synchronous request completes normally, fails, or is aborted respectively.</p> |
| <p>PASS PASS PASS should appear below:</p> |
| <p id=console></p> |
| <script type="text/javascript"> |
| if (window.testRunner) { |
| testRunner.dumpAsText(); |
| testRunner.waitUntilDone(); |
| } |
| |
| function log(message) |
| { |
| var consoleElt = document.getElementById("console"); |
| consoleElt.appendChild(document.createTextNode(message + " ")); |
| } |
| |
| var xhr = new XMLHttpRequest(); |
| var results; |
| |
| function logProgressEvent(e) { |
| results += " " + e.type; |
| } |
| |
| function logUnexpectedProgressEvent(e) { |
| results += " [unexpected ProgressEvent: " + e.type + "]"; |
| completeTest(); |
| } |
| |
| function completeTest(expected) |
| { |
| log(results == expected ? "PASS" : "FAILED results : '" + results + "', expected : '" + expected + "'"); |
| if (window.testRunner) |
| testRunner.notifyDone(); |
| } |
| |
| function testNormal() |
| { |
| results = ""; |
| |
| xhr.onloadstart = logUnexpectedProgressEvent; |
| xhr.onabort = logUnexpectedProgressEvent; |
| xhr.onerror = logUnexpectedProgressEvent; |
| xhr.onload = logProgressEvent; |
| xhr.onloadend = logProgressEvent; |
| |
| xhr.open("GET", "resources/get.txt", false); |
| xhr.send(); |
| |
| completeTest(" load loadend"); |
| } |
| |
| function testError() |
| { |
| results = ""; |
| |
| xhr.onloadstart = logUnexpectedProgressEvent; |
| xhr.onabort = logUnexpectedProgressEvent; |
| xhr.onerror = logProgressEvent; |
| xhr.onload = logUnexpectedProgressEvent; |
| xhr.onloadend = logProgressEvent; |
| |
| xhr.open("GET", "resources/infinite-loop.py", false); |
| try { |
| xhr.send(); |
| } |
| catch (e) { |
| if (e.code != e.NETWORK_ERR) |
| results += " " + e; |
| } |
| |
| completeTest(" error loadend"); |
| } |
| |
| function testAbort() |
| { |
| results = ""; |
| |
| xhr.onloadstart = logUnexpectedProgressEvent; |
| xhr.onabort = logUnexpectedProgressEvent; |
| xhr.onerror = logUnexpectedProgressEvent; |
| xhr.onload = logProgressEvent; |
| xhr.onloadend = logProgressEvent; |
| xhr.onreadystatechange = function(e) { |
| // abort in DONE state should do nothing. |
| if (xhr.readyState == xhr.DONE) |
| xhr.abort(); |
| } |
| |
| xhr.open("GET", "resources/get.txt", false); |
| try { |
| xhr.send(); |
| } |
| catch (e) { |
| if (e.code != e.NETWORK_ERR) |
| results += " " + e; |
| } |
| completeTest(" load loadend"); |
| } |
| |
| testNormal(); |
| testError(); |
| testAbort(); |
| |
| </script> |
| </body> |