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

Side by Side 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: nits I missed Created 5 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script>
4 var ranProgressHandler = false;
5 var completedUpload = false;
6
7 var asyncXHR;
8 var lastSeenProgress = 0;
9 // Build a long string, fast.
10 // data.length = 2 * 3^15 = 28697814
11
12 var data = "yo";
mmenke 2015/08/27 22:46:57 nit: Single quotes are actually preferred in Java
13 var iterations = 15;
14 for (var i = 0; i < iterations; i++) {
15 data = data + data + data;
16 }
17
18 function sendResults(failures) {
19 var resultString = failures.join("\n");
20 window.domAutomationController.send(resultString);
21 }
22
23 function progressListener(e) {
24 var progress = e.loaded;
25 var failureList = [];
26
27 // The |progress| event should not be called after the |load| event.
28 // e.loaded should never hold the same value twice.
29 if (completedUpload)
30 failureList.push("Progress event occurred after load event.");
31 if (progress <= lastSeenProgress)
32 failureList.push("No forward upload progress between events.");
33 if (e.total != data.length)
34 failureList.push("Upload total does not match payload size.");
35 if (progress > e.total)
36 failureList.push("Upload progress exceeds payload size.");
37
38 if (failureList.length)
39 sendResults(failureList);
40
41 lastSeenProgress = progress;
42 ranProgressHandler = true;
43 }
44
45 function completedUpload(e) {
46 completedUpload = true;
47 }
48
49 function onFinished(e) {
50 var failureList = [];
51 if (!ranProgressHandler)
52 failureList.push("Finished upload without firing a progress event.");
53 if (lastSeenProgress != data.length)
54 failureList.push("Final progress event before data transfer completed.");
55 if (this.responseText != "hello")
56 failureList.push("Receieved responseText: '" + this.responseText +"'. Expect ed 'hello'");
mmenke 2015/08/27 22:46:57 nit: lines should be at most 80 characters (And y
57
58 sendResults(failureList);
59 }
60
61 function onError(e) {
62 sendResults(["Received an XHR error event."]);
63 }
64
65 function WaitForAsyncXHR(url) {
66 asyncXHR = new XMLHttpRequest();
67 asyncXHR.addEventListener('load', onFinished);
68 asyncXHR.addEventListener('error', onError);
69
70 asyncXHR.upload.addEventListener('progress', progressListener);
71 asyncXHR.upload.addEventListener('load', completedUpload);
72
73 asyncXHR.open('POST', url, true);
74
75 asyncXHR.setRequestHeader('Content-Type', 'text/plain');
76 asyncXHR.send(data);
77 }
78 </script>
79 </head>
80 <body>
81 This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url).
82 </body>
83 </html>
OLDNEW
« 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