Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <html> | |
|
mmenke
2015/08/26 19:13:13
Suggest putting this in a new directory content/te
| |
| 2 <head> | |
| 3 <script> | |
| 4 var test_success = false; | |
| 5 var backwards_progress = false; | |
| 6 var ran_progress_handler = false; | |
| 7 var completed_upload = false; | |
|
mmenke
2015/08/26 19:13:13
Javascript value should use javascriptNamingStyle.
| |
| 8 | |
| 9 var uReq; | |
|
mmenke
2015/08/26 19:13:13
Suspect you copied this from another test, but ple
| |
| 10 | |
| 11 // build a long string, fast | |
|
mmenke
2015/08/26 19:13:13
nit: "Build a long string, fast."
| |
| 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; // length *= 3 | |
|
mmenke
2015/08/26 19:13:13
Suggest just data += data, for simplicity. Or dat
| |
| 18 } | |
| 19 | |
| 20 var progress = 0; | |
| 21 function progressListener(e) { | |
|
mmenke
2015/08/26 19:13:13
If this is called after completedUpload, it should
| |
| 22 if (e.lengthComputable) { | |
|
mmenke
2015/08/26 19:13:13
Can this ever be false?
| |
| 23 ran_progress_handler = true; | |
| 24 var percent = e.loaded / e.total; | |
|
mmenke
2015/08/26 19:13:13
Can check e.total here, too.
| |
| 25 if (percent < progress) | |
| 26 backwards_progress = true; | |
|
mmenke
2015/08/26 19:13:13
Should we ever get the same value multiple times?
mmenke
2015/08/26 19:13:13
percent should be <= 1, right?
| |
| 27 progress = percent; | |
|
mmenke
2015/08/26 19:13:13
suggest last_seen_progress / current_progress - it
| |
| 28 } | |
| 29 } | |
| 30 | |
| 31 function completedUpload(e) { | |
| 32 completed_upload = true; | |
| 33 } | |
| 34 | |
| 35 function onFinished(e) { | |
| 36 test_success = ran_progress_handler && | |
| 37 !backwards_progress && | |
| 38 completed_upload && | |
| 39 this.responseText == "hello"; | |
|
mmenke
2015/08/26 19:13:13
Are we guaranteed to have progress == 1 at this po
| |
| 40 window.domAutomationController.send(test_success); | |
| 41 } | |
| 42 | |
| 43 function onError(e) { | |
| 44 window.domAutomationController.send(false); | |
| 45 } | |
| 46 | |
| 47 function WaitForAsyncXHR(url) { | |
| 48 uReq = new XMLHttpRequest(); | |
| 49 uReq.addEventListener('load', onFinished); | |
| 50 uReq.addEventListener('error', onError); | |
| 51 | |
| 52 uReq.upload.addEventListener('progress', progressListener); | |
| 53 uReq.upload.addEventListener('load', completedUpload); | |
| 54 | |
| 55 uReq.open('POST', url, true); | |
| 56 | |
| 57 uReq.setRequestHeader('Content-Type', 'text/plain'); | |
| 58 uReq.send(data); | |
| 59 } | |
| 60 </script> | |
| 61 </head> | |
| 62 <body> | |
| 63 This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url). | |
| 64 </body> | |
| 65 </html> | |
| OLD | NEW |