| <html> |
| <head> |
| <title>Test case for bug 120828 (abort case)</title> |
| </head> |
| <body> |
| <p>Test case for <a href="https://bugs.webkit.org/show_bug.cgi?id=120828"> bug 120828</a>: Correctly set XHR loadend attributes (loaded and total).</p> |
| <p>Verify that abort and loadend events have their ProgressEvent attributes (loaded, total and lengthComputable) correctly set.</p> |
| <p id=console></p> |
| <script type="text/javascript"> |
| if (window.testRunner) { |
| testRunner.dumpAsText(); |
| testRunner.waitUntilDone(); |
| } |
| |
| var status = "PASS"; |
| var total = 0; |
| var loaded = 0; |
| |
| function onProgressEvent(e) |
| { |
| if (total != e.total || loaded != e.loaded) |
| fail("Event " + e.type + "total/loaded values not matching: " |
| + "(" + e.loaded + " / " + e.total + "), expected (" + loaded + " / " + total + ")"); |
| } |
| |
| function onUnexpectedProgressEvent(e) |
| { |
| fail("unexpected ProgressEvent: " + e.type); |
| } |
| |
| function fail(msg) |
| { |
| status = "FAILED: " + msg; |
| completeTest(); |
| status = ""; |
| } |
| |
| function completeTest() |
| { |
| log(status); |
| if (window.testRunner) |
| testRunner.notifyDone(); |
| } |
| |
| function test() |
| { |
| var iteration = 2; |
| var delay = "1000"; |
| var hasAborted = false; |
| var req = new XMLHttpRequest(); |
| req.onprogress = function(e){ |
| total = e.total; |
| loaded = e.loaded; |
| if (!hasAborted) { |
| hasAborted = true; |
| req.abort(); |
| } |
| }; |
| req.onerror = onUnexpectedProgressEvent; |
| req.onabort = onProgressEvent; |
| req.onloadend = function(e) { |
| onProgressEvent(e); |
| completeTest(); |
| } |
| req.open("GET", "resources/download-with-delay.py?iteration=" + iteration + "&delay=" + delay, true); |
| req.send(null); |
| |
| } |
| |
| function log(message) |
| { |
| var consoleElt = document.getElementById("console"); |
| consoleElt.innerHTML += message + "<br/>"; |
| } |
| |
| test(); |
| |
| </script> |
| </body> |
| </html> |