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
This commit is contained in:
Olli Pettay 2014-01-09 21:23:08 +02:00
parent 334958a29b
commit c1ef502d06
2 changed files with 13 additions and 4 deletions

View File

@ -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,

View File

@ -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,