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

Unified Diff: LayoutTests/http/tests/xmlhttprequest/onload-event.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/onload-event.html
diff --git a/LayoutTests/http/tests/xmlhttprequest/onload-event.html b/LayoutTests/http/tests/xmlhttprequest/onload-event.html
new file mode 100644
index 0000000000000000000000000000000000000000..bc1c4c948077df801929c0d0e8165d0ffcf569ba
--- /dev/null
+++ b/LayoutTests/http/tests/xmlhttprequest/onload-event.html
@@ -0,0 +1,64 @@
+<!doctype html>
+<html>
+<head>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+</head>
+<body>
+<p> Verify that a load ProgressEvent is dispatched and have the expected values.</p>
+<div id="log"></div>
+<script type="text/javascript">
+
+var xhr;
+var payload = "data";
+var expectedLength = payload.length;
+var results = "";
+var expected = " loadstart readyState=DONE load";
+
+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();
+}
+
+function completeTest()
+{
+ assert_equals(results, expected, "Expected load event sequence");
+ testOnloadEvent.done();
+}
+
+function loadHandler(e)
+{
+ logProgressEvent(e);
+ assert_true(e instanceof ProgressEvent);
+ verifyProgressEvent("onload", e, expectedLength);
+ completeTest();
+}
+
+var testOnloadEvent = async_test("Check that 'load' events are delivered and have expected values.");
+testOnloadEvent.step(function () {
+ xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = testOnloadEvent.step_func(function(e) {
+ if (xhr.readyState == xhr.DONE)
+ results += " readyState=DONE";
+ });
+ xhr.onloadstart = testOnloadEvent.step_func(logProgressEvent);
+ xhr.onabort = testOnloadEvent.step_func(logUnexpectedProgressEvent);
+ xhr.onerror = testOnloadEvent.step_func(logUnexpectedProgressEvent);
+ xhr.onload = testOnloadEvent.step_func(loadHandler);
+ xhr.open("POST", "resources/post-echo.php", true);
+ xhr.send(payload);
+});
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698