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

Side by Side Diff: content/test/data/loader/async_resource_handler.html

Issue 1318393003: Updated UploadProgress tests under ThreadSanitizer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
1 <html> 1 <html>
2 <head> 2 <head>
3 <script> 3 <script>
4 var ranProgressHandler = false; 4 var ranProgressHandler = false;
5 var completedUpload = false; 5 var completedUpload = false;
6 6
7 var asyncXHR; 7 var asyncXHR;
8 var lastSeenProgress = 0; 8 var lastSeenProgress = 0;
9 // Build a long string, fast. 9 // Build a long string, fast.
10 // data.length = 2 * 3^15 = 28697814 10 // data.length = 2 * 3^15 = 28697814
11 11 var sent_data;
12 var smaller_data;
12 var data = 'yo'; 13 var data = 'yo';
13 var iterations = 15; 14 var iterations = 15;
14 for (var i = 0; i < iterations; i++) { 15 for (var i = 0; i < iterations; i++) {
15 data = data + data + data; 16 data = data + data + data;
17 if (i === 13)
18 smaller_data = data;
16 } 19 }
17 20
18 function sendResults(failures) { 21 function sendResults(failures) {
19 var resultString = failures.length ? failures.join('\n') : "success"; 22 var resultString = failures.length ? failures.join('\n') : "success";
20 window.domAutomationController.send(resultString); 23 window.domAutomationController.send(resultString);
21 } 24 }
22 25
23 function progressListener(e) { 26 function progressListener(e) {
24 var progress = e.loaded; 27 var progress = e.loaded;
25 var failureList = []; 28 var failureList = [];
26 29
27 // The |progress| event should not be called after the |load| event. 30 // The |progress| event should not be called after the |load| event.
28 // e.loaded should never hold the same value twice. 31 // e.loaded should never hold the same value twice.
29 if (completedUpload) 32 if (completedUpload)
30 failureList.push('Progress event occurred after load event.'); 33 failureList.push('Progress event occurred after load event.');
31 if (progress <= lastSeenProgress) 34 if (progress <= lastSeenProgress)
32 failureList.push('No forward upload progress between events.'); 35 failureList.push('No forward upload progress between events.');
33 if (e.total != data.length) 36 if (e.total != sent_data.length)
34 failureList.push('Upload total does not match payload size.'); 37 failureList.push('Upload total does not match payload size.');
35 if (progress > e.total) 38 if (progress > e.total)
36 failureList.push('Upload progress exceeds payload size.'); 39 failureList.push('Upload progress exceeds payload size.');
37 40
38 if (failureList.length) 41 if (failureList.length)
39 sendResults(failureList); 42 sendResults(failureList);
40 43
41 lastSeenProgress = progress; 44 lastSeenProgress = progress;
42 ranProgressHandler = true; 45 ranProgressHandler = true;
43 } 46 }
44 47
45 function completedUpload(e) { 48 function completedUpload(e) {
46 completedUpload = true; 49 completedUpload = true;
47 } 50 }
48 51
49 function onFinished(e) { 52 function onFinished(e) {
50 var failureList = []; 53 var failureList = [];
51 if (!ranProgressHandler) 54 if (!ranProgressHandler)
52 failureList.push('Finished upload without firing a progress event.'); 55 failureList.push('Finished upload without firing a progress event.');
53 if (lastSeenProgress != data.length) 56 if (lastSeenProgress != sent_data.length)
54 failureList.push('Final progress event before data transfer completed.'); 57 failureList.push('Final progress event before data transfer completed.');
55 if (this.responseText != 'hello') { 58 if (this.responseText != 'hello') {
56 failureList.push( 59 failureList.push(
57 'Receieved responseText: \'' + this.responseText +'\'. Expected: \'hello \'.'); 60 'Receieved responseText: \'' + this.responseText +'\'. Expected: \'hello \'.');
58 } 61 }
59 sendResults(failureList); 62 sendResults(failureList);
60 } 63 }
61 64
62 function onError(e) { 65 function onError(e) {
63 sendResults(['Received an XHR error event.']); 66 sendResults(['Received an XHR error event.']);
64 } 67 }
65 68
66 function WaitForAsyncXHR(url) { 69 function WaitForAsyncXHR(url, data_size) {
67 asyncXHR = new XMLHttpRequest(); 70 asyncXHR = new XMLHttpRequest();
68 asyncXHR.addEventListener('load', onFinished); 71 asyncXHR.addEventListener('load', onFinished);
69 asyncXHR.addEventListener('error', onError); 72 asyncXHR.addEventListener('error', onError);
70 73
71 asyncXHR.upload.addEventListener('progress', progressListener); 74 asyncXHR.upload.addEventListener('progress', progressListener);
72 asyncXHR.upload.addEventListener('load', completedUpload); 75 asyncXHR.upload.addEventListener('load', completedUpload);
73 76
74 asyncXHR.open('POST', url, true); 77 asyncXHR.open('POST', url, true);
75 78
76 asyncXHR.setRequestHeader('Content-Type', 'text/plain'); 79 asyncXHR.setRequestHeader('Content-Type', 'text/plain');
77 asyncXHR.send(data); 80 if (data_size === "small")
81 sent_data = smaller_data;
82 else if (data_size === "large")
83 sent_data = data;
84 asyncXHR.send(sent_data);
78 } 85 }
79 </script> 86 </script>
80 </head> 87 </head>
81 <body> 88 <body>
82 This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url). 89 This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url).
83 </body> 90 </body>
84 </html> 91 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698