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

Unified Diff: content/test/data/loader/async_resource_handler.html

Issue 1301103002: moved upload progress logic from ResourceLoader to AsyncResourceHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update html paths Created 5 years, 4 months 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: content/test/data/loader/async_resource_handler.html
diff --git a/content/test/data/loader/async_resource_handler.html b/content/test/data/loader/async_resource_handler.html
new file mode 100644
index 0000000000000000000000000000000000000000..20bccbcdabe56f4bec6a74f1a573e1433d2a46e7
--- /dev/null
+++ b/content/test/data/loader/async_resource_handler.html
@@ -0,0 +1,66 @@
+<html>
+<head>
+<script>
+var testSuccess= false;
mmenke 2015/08/27 17:21:29 Currently doesn't need to be a global.
+var backwardsProgress = false;
+var ranProgressHandler= false;
mmenke 2015/08/27 17:21:29 nit: space before =
+var completedUpload = false;
+
+var asyncXHR;
+var lastSeenProgress = 0;
+// build a long string, fast.
mmenke 2015/08/27 17:21:29 nit: capitalize Build
+// data.length = 2 * 3^15 = 28697814
+
+var data = "yo";
+var iterations = 15;
+for (var i = 0; i < iterations; i++) {
+ data = data + data + data;
+}
+
+function progressListener(e) {
+ var progress = e.loaded;
+ // The |progress| event should not be called after the |load| event.
+ // e.loaded should never hold the same value twice.
+ if (completedUpload ||
+ progress <= lastSeenProgress ||
+ e.total != data.length ||
+ progress > e.total)
mmenke 2015/08/27 17:21:29 We're testing for a ton of failure cases here. I
Charlie Harrison 2015/08/27 18:43:53 Great idea, otherwise this test would be very diff
+ window.domAutomationController.send(false);
mmenke 2015/08/27 17:21:29 nit: Use braces when the if condition or body tak
+ lastSeenProgress = progress;
+ ranProgressHandler = true;
+}
+
+function completedUpload(e) {
+ completedUpload = true;
+}
+
+function onFinished(e) {
+ testSuccess = ranProgressHandler &&
+ lastSeenProgress == data.length &&
+ this.responseText == "hello";
+ window.domAutomationController.send(testSuccess);
+}
+
+function onError(e) {
+ window.domAutomationController.send(false);
+}
+
+function WaitForAsyncXHR(url) {
+ asyncXHR = new XMLHttpRequest();
+ asyncXHR.addEventListener('load', onFinished);
+ asyncXHR.addEventListener('error', onError);
+
+ asyncXHR.upload.addEventListener('progress', progressListener);
+ asyncXHR.upload.addEventListener('load', completedUpload);
+
+ asyncXHR.open('POST', url, true);
+
+ asyncXHR.setRequestHeader('Content-Type', 'text/plain');
+ asyncXHR.send(data);
+}
+</script>
+</head>
+<body>
+This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url).
+</body>
+</html>
« content/browser/loader/async_resource_handler_browsertest.cc ('K') | « content/content_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698