| <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>Upload case: 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 = 1; |
| var loaded = 1; |
| var uploadedData = "d"; |
| |
| function onProgressEvent(e) |
| { |
| if (!e.lengthComputable) |
| fail("Event " + e.type + " lengthComputable is false"); |
| if (e.total != total || e.loaded != 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 req = new XMLHttpRequest(); |
| req.upload.onerror = onUnexpectedProgressEvent; |
| req.upload.onload = onUnexpectedProgressEvent; |
| req.upload.onabort = onProgressEvent; |
| req.upload.onprogress = function(e) { |
| onProgressEvent(e); |
| req.abort(); |
| } |
| req.upload.onloadend = function(e) { |
| onProgressEvent(e); |
| completeTest(); |
| } |
| |
| req.open("POST", "resources/post-echo.cgi", true); |
| req.send(uploadedData); |
| } |
| |
| |
| function log(message) |
| { |
| var consoleElt = document.getElementById("console"); |
| consoleElt.innerHTML += message + "<br/>"; |
| } |
| |
| test(); |
| |
| </script> |
| </body> |
| </html> |