From cc7e43847ae8bff30c88230fce28ce6e38ecfe45 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Thu, 9 Jan 2014 21:23:08 +0200 Subject: [PATCH] Bug 948246, don't change xhr.upload's event.total and always fire at least one progress event, r=bz --HG-- extra : rebase_source : 7a265bcb40155a257d885538a5c07825a83b018e --- content/base/src/nsXMLHttpRequest.cpp | 9 +++++---- content/base/test/test_bug435425.html | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 06e4133852dd..bb2add7c710e 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -1899,7 +1899,11 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt) mProgressTimerIsActive = false; mProgressNotifier->Cancel(); } - MaybeDispatchProgressEvents(true); + if (mUploadTransferred < mUploadTotal) { + mUploadTransferred = mUploadTotal; + mProgressSinceLastProgressEvent = true; + MaybeDispatchProgressEvents(true); + } mUploadComplete = true; DispatchProgressEvent(mUpload, NS_LITERAL_STRING(LOAD_STR), true, mUploadTotal, mUploadTotal); @@ -3410,9 +3414,6 @@ nsXMLHttpRequest::MaybeDispatchProgressEvents(bool aFinalProgress) // We're uploading if our state is XML_HTTP_REQUEST_OPENED or // XML_HTTP_REQUEST_SENT if ((XML_HTTP_REQUEST_OPENED | XML_HTTP_REQUEST_SENT) & mState) { - if (aFinalProgress) { - mUploadTotal = mUploadTransferred; - } if (mUpload && !mUploadComplete) { DispatchProgressEvent(mUpload, NS_LITERAL_STRING(PROGRESS_STR), mUploadLengthComputable, mUploadTransferred, diff --git a/content/base/test/test_bug435425.html b/content/base/test/test_bug435425.html index eb778799c434..511e816255ff 100644 --- a/content/base/test/test_bug435425.html +++ b/content/base/test/test_bug435425.html @@ -23,6 +23,7 @@ var xhr = null; var upload = null; var currentEvents = null; var expectedResponseText = null; +var uploadTotal = 0; function logEvent(evt) { var i = 0; @@ -32,6 +33,13 @@ function logEvent(evt) { !(evt.target instanceof currentEvents[i].target))) { ++i; } + if (evt.target instanceof XMLHttpRequestUpload) { + if (evt.type == "loadstart") { + uploadTotal = evt.total + } else { + is(evt.total, uploadTotal, "event(" + evt.type + ").total should not change during upload."); + } + } ok(i != currentEvents.length, "Extra or wrong event?"); is(evt.type, currentEvents[i].type, "Wrong event!") ok(evt.target instanceof currentEvents[i].target,