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

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: update html paths 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 testSuccess= false;
mmenke 2015/08/27 17:21:29 Currently doesn't need to be a global.
5 var backwardsProgress = false;
6 var ranProgressHandler= false;
mmenke 2015/08/27 17:21:29 nit: space before =
7 var completedUpload = false;
8
9 var asyncXHR;
10 var lastSeenProgress = 0;
11 // build a long string, fast.
mmenke 2015/08/27 17:21:29 nit: capitalize Build
12 // data.length = 2 * 3^15 = 28697814
13
14 var data = "yo";
15 var iterations = 15;
16 for (var i = 0; i < iterations; i++) {
17 data = data + data + data;
18 }
19
20 function progressListener(e) {
21 var progress = e.loaded;
22 // The |progress| event should not be called after the |load| event.
23 // e.loaded should never hold the same value twice.
24 if (completedUpload ||
25 progress <= lastSeenProgress ||
26 e.total != data.length ||
27 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
28 window.domAutomationController.send(false);
mmenke 2015/08/27 17:21:29 nit: Use braces when the if condition or body tak
29 lastSeenProgress = progress;
30 ranProgressHandler = true;
31 }
32
33 function completedUpload(e) {
34 completedUpload = true;
35 }
36
37 function onFinished(e) {
38 testSuccess = ranProgressHandler &&
39 lastSeenProgress == data.length &&
40 this.responseText == "hello";
41 window.domAutomationController.send(testSuccess);
42 }
43
44 function onError(e) {
45 window.domAutomationController.send(false);
46 }
47
48 function WaitForAsyncXHR(url) {
49 asyncXHR = new XMLHttpRequest();
50 asyncXHR.addEventListener('load', onFinished);
51 asyncXHR.addEventListener('error', onError);
52
53 asyncXHR.upload.addEventListener('progress', progressListener);
54 asyncXHR.upload.addEventListener('load', completedUpload);
55
56 asyncXHR.open('POST', url, true);
57
58 asyncXHR.setRequestHeader('Content-Type', 'text/plain');
59 asyncXHR.send(data);
60 }
61 </script>
62 </head>
63 <body>
64 This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url).
65 </body>
66 </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