Chromium Code Reviews| Index: content/test/data/async_resource_handler.html |
| diff --git a/content/test/data/async_resource_handler.html b/content/test/data/async_resource_handler.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5d00a6dc4ca3efe42ba7f40ed7d328978dc904b9 |
| --- /dev/null |
| +++ b/content/test/data/async_resource_handler.html |
| @@ -0,0 +1,65 @@ |
| +<html> |
|
mmenke
2015/08/26 19:13:13
Suggest putting this in a new directory content/te
|
| +<head> |
| +<script> |
| +var test_success = false; |
| +var backwards_progress = false; |
| +var ran_progress_handler = false; |
| +var completed_upload = false; |
|
mmenke
2015/08/26 19:13:13
Javascript value should use javascriptNamingStyle.
|
| + |
| +var uReq; |
|
mmenke
2015/08/26 19:13:13
Suspect you copied this from another test, but ple
|
| + |
| +// build a long string, fast |
|
mmenke
2015/08/26 19:13:13
nit: "Build a long string, fast."
|
| +// data.length = 2 * 3^15 = 28697814 |
| + |
| +var data = "yo"; |
| +var iterations = 15; |
| +for (var i = 0; i < iterations; i++) { |
| + data += data + data; // length *= 3 |
|
mmenke
2015/08/26 19:13:13
Suggest just data += data, for simplicity. Or dat
|
| +} |
| + |
| +var progress = 0; |
| +function progressListener(e) { |
|
mmenke
2015/08/26 19:13:13
If this is called after completedUpload, it should
|
| + if (e.lengthComputable) { |
|
mmenke
2015/08/26 19:13:13
Can this ever be false?
|
| + ran_progress_handler = true; |
| + var percent = e.loaded / e.total; |
|
mmenke
2015/08/26 19:13:13
Can check e.total here, too.
|
| + if (percent < progress) |
| + 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?
|
| + progress = percent; |
|
mmenke
2015/08/26 19:13:13
suggest last_seen_progress / current_progress - it
|
| + } |
| +} |
| + |
| +function completedUpload(e) { |
| + completed_upload = true; |
| +} |
| + |
| +function onFinished(e) { |
| + test_success = ran_progress_handler && |
| + !backwards_progress && |
| + completed_upload && |
| + this.responseText == "hello"; |
|
mmenke
2015/08/26 19:13:13
Are we guaranteed to have progress == 1 at this po
|
| + window.domAutomationController.send(test_success); |
| +} |
| + |
| +function onError(e) { |
| + window.domAutomationController.send(false); |
| +} |
| + |
| +function WaitForAsyncXHR(url) { |
| + uReq = new XMLHttpRequest(); |
| + uReq.addEventListener('load', onFinished); |
| + uReq.addEventListener('error', onError); |
| + |
| + uReq.upload.addEventListener('progress', progressListener); |
| + uReq.upload.addEventListener('load', completedUpload); |
| + |
| + uReq.open('POST', url, true); |
| + |
| + uReq.setRequestHeader('Content-Type', 'text/plain'); |
| + uReq.send(data); |
| +} |
| +</script> |
| +</head> |
| +<body> |
| +This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url). |
| +</body> |
| +</html> |