Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Unified Diff: LayoutTests/http/tests/xmlhttprequest/onloadend-event-after-load.html

Issue 79953004: Improve fidelity of XHR progress events. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Make test stable Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/xmlhttprequest/onloadend-event-after-load.html
diff --git a/LayoutTests/http/tests/xmlhttprequest/onloadend-event-after-load.html b/LayoutTests/http/tests/xmlhttprequest/onloadend-event-after-load.html
index 0b2644a07b048ba2c73888eff3272af3941e8fac..bf97ab0d053754583572c7f2e7f8f10a929fd823 100644
--- a/LayoutTests/http/tests/xmlhttprequest/onloadend-event-after-load.html
+++ b/LayoutTests/http/tests/xmlhttprequest/onloadend-event-after-load.html
@@ -1,64 +1,67 @@
-<HTML>
+<!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 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 readyState=DONE 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 logUnexpectedProgressEvent(e) {
results += " [unexpected ProgressEvent: " + e.type + "]";
- completeTest();
+ completeTest();
}
function completeTest()
{
- log(results == expected ? "PASS" : "FAILED results : '" + results + "', expected : '" + expected + "'");
- if (window.testRunner)
- testRunner.notifyDone();
+ assert_equals(results, expected, "Expected load event sequence");
+ testOnloadEndEvent.done();
}
-function test()
+function loadendHandler(e)
{
- xhr.onreadystatechange = function(e) {
- if (xhr.readyState == xhr.DONE)
- results += " readyState=DONE";
- }
- xhr.onloadstart = logProgressEvent;
- xhr.onabort = logUnexpectedProgressEvent;
- xhr.onerror = logUnexpectedProgressEvent;
- xhr.onload = logProgressEvent;
- xhr.onloadend = function(e) {
- logProgressEvent(e);
- completeTest();
- }
-
- xhr.open("GET", "resources/get.txt", true);
- xhr.send();
+ logProgressEvent(e);
+ assert_true(e instanceof ProgressEvent);
+ verifyProgressEvent("onloadend", e, expectedLength);
+ completeTest();
}
-test();
-
+var testOnloadEndEvent = async_test("Check that 'loadend' events are delivered and have expected values.");
+testOnloadEndEvent.step(function () {
+ xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = testOnloadEndEvent.step_func(function(e) {
+ if (xhr.readyState == xhr.DONE)
+ results += " readyState=DONE";
+ });
+ xhr.onloadstart = testOnloadEndEvent.step_func(logProgressEvent);
+ xhr.onabort = testOnloadEndEvent.step_func(logUnexpectedProgressEvent);
+ xhr.onerror = testOnloadEndEvent.step_func(logUnexpectedProgressEvent);
+ xhr.onload = testOnloadEndEvent.step_func(logProgressEvent);
+ xhr.onloadend = testOnloadEndEvent.step_func(loadendHandler);
+ xhr.open("POST", "resources/post-echo.php", true);
+ xhr.send(payload);
+});
</script>
</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698