| Index: LayoutTests/http/tests/xmlhttprequest/upload-onloadend-event-after-load.html
|
| diff --git a/LayoutTests/http/tests/xmlhttprequest/upload-onloadend-event-after-load.html b/LayoutTests/http/tests/xmlhttprequest/upload-onloadend-event-after-load.html
|
| index c05b5b30fadf0741c40ac402f9fe4ae571f7f306..5fc988ab067f424b38a57307af3bf7a2ec965624 100644
|
| --- a/LayoutTests/http/tests/xmlhttprequest/upload-onloadend-event-after-load.html
|
| +++ b/LayoutTests/http/tests/xmlhttprequest/upload-onloadend-event-after-load.html
|
| @@ -1,61 +1,68 @@
|
| +<!doctype html>
|
| <html>
|
| <head>
|
| <title>Test case for bug 40952</title>
|
| +<script src="../resources/testharness.js"></script>
|
| +<script src="../resources/testharnessreport.js"></script>
|
| </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 the load ProgressEvent when an async upload request completes normally.</p>
|
| -<p>PASS should appear below:</p>
|
| -<p id=console></p>
|
| +<div id="log"></div>
|
| <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 xhr;
|
| +var payload = "data";
|
| +var expectedLength = payload.length;
|
| var results = "";
|
| var expected = " loadstart load loadend";
|
|
|
| +function verifyProgressEvent(context, e, expected)
|
| +{
|
| + assert_true(e.lengthComputable);
|
| + assert_equals(e.loaded, expected, "Expected 'loaded' value for '" + context + " ' event.");
|
| + assert_equals(e.total, expected, "Expected 'total' value for '" + context + "' event.");
|
| +}
|
| +
|
| function logProgressEvent(e) {
|
| results += " " + e.type;
|
| }
|
|
|
| +function log(message)
|
| +{
|
| + var consoleElt = document.getElementById("console");
|
| + consoleElt.appendChild(document.createTextNode(message));
|
| +}
|
| function logUnexpectedProgressEvent(e) {
|
| results += " [unexpected ProgressEvent: " + e.type + "]";
|
| completeTest();
|
| }
|
|
|
| -function completeTest()
|
| +function loadendHandler(e)
|
| {
|
| - log(results == expected ? "PASS" : "FAILED results : '" + results + "', expected : '" + expected + "'");
|
| - if (window.testRunner)
|
| - testRunner.notifyDone();
|
| + logProgressEvent(e);
|
| + assert_true(e instanceof ProgressEvent);
|
| + verifyProgressEvent("onload", e, expectedLength);
|
| + completeTest();
|
| }
|
|
|
| -function test()
|
| +function completeTest()
|
| {
|
| - xhr.onreadystatechange = function(e) {
|
| - if (xhr.readyState == xhr.DONE)
|
| - completeTest();
|
| - }
|
| - xhr.upload.onloadstart = logProgressEvent;
|
| - xhr.upload.onabort = logUnexpectedProgressEvent;
|
| - xhr.upload.onerror = logUnexpectedProgressEvent;
|
| - xhr.upload.onload = logProgressEvent;
|
| - xhr.upload.onloadend = logProgressEvent;
|
| -
|
| - xhr.open("POST", "resources/post-echo.cgi", true);
|
| - xhr.send("data");
|
| + assert_equals(results, expected, "Expected load event sequence");
|
| + testUploadOnloadEndEvent.done();
|
| }
|
|
|
| -test();
|
| -
|
| +var testUploadOnloadEndEvent = async_test("Check that upload 'loadend' events are delivered and have expected values.");
|
| +testUploadOnloadEndEvent.step(function () {
|
| + xhr = new XMLHttpRequest();
|
| + xhr.upload.onloadstart = testUploadOnloadEndEvent.step_func(logProgressEvent);
|
| + xhr.upload.onabort = testUploadOnloadEndEvent.step_func(logUnexpectedProgressEvent);
|
| + xhr.upload.onerror = testUploadOnloadEndEvent.step_func(logUnexpectedProgressEvent);
|
| + xhr.upload.onload = testUploadOnloadEndEvent.step_func(logProgressEvent);
|
| + xhr.upload.onloadend = testUploadOnloadEndEvent.step_func(loadendHandler);
|
| + xhr.open("POST", "resources/post-echo.php", true);
|
| + xhr.send(payload);
|
| +});
|
| </script>
|
| </body>
|
| +</html>
|
|
|