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

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: single quotes, nits, and return success on success 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
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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';
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.length ? failures.join('\n') : "success";
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(
57 'Receieved responseText: \'' + this.responseText +'\'. Expected: \'hello \'.');
58 }
59 sendResults(failureList);
60 }
61
62 function onError(e) {
63 sendResults(['Received an XHR error event.']);
64 }
65
66 function WaitForAsyncXHR(url) {
67 asyncXHR = new XMLHttpRequest();
68 asyncXHR.addEventListener('load', onFinished);
69 asyncXHR.addEventListener('error', onError);
70
71 asyncXHR.upload.addEventListener('progress', progressListener);
72 asyncXHR.upload.addEventListener('load', completedUpload);
73
74 asyncXHR.open('POST', url, true);
75
76 asyncXHR.setRequestHeader('Content-Type', 'text/plain');
77 asyncXHR.send(data);
78 }
79 </script>
80 </head>
81 <body>
82 This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url).
83 </body>
84 </html>
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698