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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/xmlhttprequest/upload-progress-events-handlers-must-be-set-before-send.html

Issue 2427553002: Fix XHR's logic to determine whether or not to dispatch upload progress events
Patch Set: a Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/xmlhttprequest/upload-progress-events-handlers-must-be-set-before-send.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/xmlhttprequest/upload-progress-events-handlers-must-be-set-before-send.html b/third_party/WebKit/LayoutTests/http/tests/xmlhttprequest/upload-progress-events-handlers-must-be-set-before-send.html
new file mode 100644
index 0000000000000000000000000000000000000000..8db8fcaaf73a72d392a6e2688974837a54f57d13
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/xmlhttprequest/upload-progress-events-handlers-must-be-set-before-send.html
@@ -0,0 +1,89 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script type="text/javascript">
+async_test(test => {
+ const xhr = new XMLHttpRequest();
+ xhr.open("POST", "resources/post-echo.php", true);
+ xhr.send('hello');
+
+ const upload = xhr.upload;
+ upload.onloadstart = test.step_func(() => {
+ assert_unreached('Unexpected upload.onloadstart call');
+ });
+ upload.onprogress = test.step_func(() => {
+ assert_unreached('Unexpected upload.onprogress call');
+ });
+ upload.onload = test.step_func(() => {
+ assert_unreached('Unexpected upload.onload call');
+ });
+ upload.onloadend = test.step_func(() => {
+ assert_unreached('Unexpected upload.onloadend call');
+ });
+
+ xhr.onload = test.step_func(() => {
+ test.done();
+ });
+}, 'Upload progress events should not be dispatched if the handlers are set after send().');
+
+async_test(test => {
+ const xhr = new XMLHttpRequest();
+ xhr.open("POST", "resources/post-echo.php", true);
+
+ const upload = xhr.upload;
+
+ xhr.send('hello');
+
+ upload.onloadstart = test.step_func(() => {
+ assert_unreached('Unexpected upload.onloadstart call');
+ });
+ upload.onprogress = test.step_func(() => {
+ assert_unreached('Unexpected upload.onprogress call');
+ });
+ upload.onload = test.step_func(() => {
+ assert_unreached('Unexpected upload.onload call');
+ });
+ upload.onloadend = test.step_func(() => {
+ assert_unreached('Unexpected upload.onloadend call');
+ });
+
+ xhr.onload = test.step_func(() => {
+ test.done();
+ });
+}, 'Upload progress events should not be dispatched even if the upload atrribute is touched before send().');
+
+async_test(test => {
+ const xhr = new XMLHttpRequest();
+ xhr.open("POST", "resources/post-echo.php", true);
+
+ const upload = xhr.upload;
+ let onloadstartCalled;
+ upload.onloadstart = test.step_func(() => {
+ onloadstartCalled = true;
+ });
+
+ xhr.send('hello');
+
+ let onprogressCalled;
+ upload.onprogress = test.step_func(() => {
+ onprogressCalled = true;
+ });
+ let onloadCalled;
+ upload.onload = test.step_func(() => {
+ onloadCalled = true;
+ });
+ let onloadendCalled;
+ upload.onloadend = test.step_func(() => {
+ onloadendCalled = true;
+ });
+
+ xhr.onload = test.step_func(() => {
+ assert_true(onloadstartCalled, 'upload.onloadstart is called');
+ assert_true(onprogressCalled, 'upload.onprogress is called');
+ assert_true(onloadCalled, 'upload.onload is called');
+ assert_true(onloadendCalled, 'upload.onloadend is called');
+
+ test.done();
+ });
+}, 'All upload progress events should be dispatched if at least one handler is set to the upload atrribute before send().');
+</script>

Powered by Google App Engine
This is Rietveld 408576698