XMLHttpRequestUpload's loadstart event not correct initialized
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Mar 2019 18:10:51 +0000 (18:10 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Mar 2019 18:10:51 +0000 (18:10 +0000)
commit98bbed8dbfcef6a3a06f7daa237b252f5bd7ee81
treeb0abebc99e4e9e061786a415968fba81a4990378
parent3afb353af94e4efdf96fa747a8748baf5f7eef7f
XMLHttpRequestUpload's loadstart event not correct initialized
https://bugs.webkit.org/show_bug.cgi?id=196174
<rdar://problem/49191412>

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/xhr/event-error-order.sub.html:
Update test after https://github.com/web-platform-tests/wpt/pull/13365

* web-platform-tests/xhr/abort-during-upload-expected.txt:
* web-platform-tests/xhr/event-error-order.sub-expected.txt:
* web-platform-tests/xhr/event-loadstart-upload-expected.txt:
* web-platform-tests/xhr/event-timeout-order-expected.txt:
* web-platform-tests/xhr/send-response-event-order-expected.txt:
Rebaseline several WPT tests that are now passing.

Source/WebCore:

Align progress event firing with the XHR specification.

No new tests, rebaselined existing tests.

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::createRequest):
As per [1], the loadstart event fired on the XMLHttpRequestUpload object should use
loaded=0 and total=`req’s body’s total bytes`.
[1] https://xhr.spec.whatwg.org/#the-send()-method (step 11.2.)

(WebCore::XMLHttpRequest::didSendData):
As per [2], the progress / load / loadend should use loaded=transmitted and total=length.
[2] https://xhr.spec.whatwg.org/#ref-for-process-request-end-of-body (steps 5, 6 and 7)

(WebCore::XMLHttpRequest::didReceiveData):
As per [3], we should fire the readystatechange event *before* the progress event.
This is covered by web-platform-tests/xhr/send-response-event-order.htm which was failing
differently after the other changes in this patch.
[3] https://xhr.spec.whatwg.org/#ref-for-process-response (steps 9.4 and 9.5)

(WebCore::XMLHttpRequest::dispatchErrorEvents):
As per [4], in case of an error, we should fire the provided 'event' and 'loadend' with
loaded=0 and total=0.
[4] https://xhr.spec.whatwg.org/#request-error-steps (steps 7 and 8)

* xml/XMLHttpRequestUpload.cpp:
(WebCore::XMLHttpRequestUpload::dispatchProgressEvent):
* xml/XMLHttpRequestUpload.h:
Simplify XMLHttpRequestUpload. It no longer needs to store loaded / total as data
members now that they are always passed by the call site. lengthComputable is set
to !!total as [5] says to set it to true if length/total is not 0.
[5] https://xhr.spec.whatwg.org/#concept-event-fire-progress

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243551 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
LayoutTests/http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/xhr/abort-during-upload-expected.txt
LayoutTests/imported/w3c/web-platform-tests/xhr/event-error-order.sub-expected.txt
LayoutTests/imported/w3c/web-platform-tests/xhr/event-error-order.sub.html
LayoutTests/imported/w3c/web-platform-tests/xhr/event-loadstart-upload-expected.txt
LayoutTests/imported/w3c/web-platform-tests/xhr/event-timeout-order-expected.txt
LayoutTests/imported/w3c/web-platform-tests/xhr/send-response-event-order-expected.txt
LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/xhr/event-error-order.sub-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebCore/xml/XMLHttpRequest.h
Source/WebCore/xml/XMLHttpRequestUpload.cpp
Source/WebCore/xml/XMLHttpRequestUpload.h