Source/WebCore: Correctly set XHR loadend attributes (loaded and total).
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Jan 2014 21:22:18 +0000 (21:22 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Jan 2014 21:22:18 +0000 (21:22 +0000)
commit07061f0919840ab915543910431c5e480e6af4d2
treeee2fd734433fda50ece23e4f87d66e09bbd538aa
parent65158ec3ce4d8b26cb8dcd24caf83664b34e204c
Source/WebCore: Correctly set XHR loadend attributes (loaded and total).
https://bugs.webkit.org/show_bug.cgi?id=120828

Patch by Youenn Fablet <youennf@gmail.com> on 2014-01-10
Reviewed by Alexey Proskuryakov.

Added correct initialization of lengthComputable, loaded and total attributes
to XHR ProgressEvent events (load, loadstart, loadend, abort, error and timeout).

XMLHttpRequestProgressEventThrottle and XMLHttpRequestUpload now keep persistent knowledge
of m_loaded and m_total values with this patch.

Code refactoring to handle event dispatching in case of error in a single manner.
XMLHttpRequestProgressEventThrottle::dispatchProgressEvent is renamed as dispatchThrottledProgressEvent
XMLHttpRequestProgressEventThrottle::dispatchEventAndLoadend is replaced by dispatchProgressEvent(const AtomicString&)

Fixed assertion issues over bug 120828 patch

Tests: http/tests/xmlhttprequest/loadstart-event-init.html
       http/tests/xmlhttprequest/onabort-progressevent-attributes.html
       http/tests/xmlhttprequest/onload-progressevent-attributes.html
       http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html
       http/tests/xmlhttprequest/upload-onload-progressevent-attributes.html

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::callReadyStateChangeListener): changed readystatechange event from ProgressEvent to Event (not cancellable, not bubblable) to better match the spec
(WebCore::XMLHttpRequest::createRequest):
(WebCore::XMLHttpRequest::abort): code refactoring to handle error event dispatching in a single way
(WebCore::XMLHttpRequest::networkError): code refactoring to handle error event dispatching in a single way
(WebCore::XMLHttpRequest::abortError): code refactoring to handle error event dispatching in a single way
(WebCore::XMLHttpRequest::didSendData):
(WebCore::XMLHttpRequest::didReceiveData):
(WebCore::XMLHttpRequest::dispatchErrorEvents): dispatch progress events in case of error
(WebCore::XMLHttpRequest::didTimeout): code refactoring to handle error event dispatching in a single way
* xml/XMLHttpRequest.h:
* xml/XMLHttpRequestProgressEventThrottle.cpp: before the patch, the fact that a progress event is being throttled is stored indirectly (m_loaded or m_total not equal to zero). With the patch, this information is stored in m_hasThrottledProgressEvent. The m_loaded and m_total values are no longer set back to zero after a progress event is dispatched. This allows using these values to correctly initialize other ProgressEvent events (in particular loadend, abort, timeout...)
(WebCore::XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle):
(WebCore::XMLHttpRequestProgressEventThrottle::dispatchThrottledProgressEvent): always update the new m_loaded and m_total values. If progress event is not sent as part of the function call, store the fact that a progress event is being throttled through m_hasThrottledProgressEvent.
(WebCore::XMLHttpRequestProgressEventThrottle::dispatchProgressEvent): used to send any ProgressEvent event that is not be throttled
(WebCore::XMLHttpRequestProgressEventThrottle::flushProgressEvent): after the call, no progress event is throttled anymore
(WebCore::XMLHttpRequestProgressEventThrottle::fired): after the call, no progress event is throttled anymore
(WebCore::XMLHttpRequestProgressEventThrottle::hasEventToDispatch):
(WebCore::XMLHttpRequestProgressEventThrottle::suspend):
* xml/XMLHttpRequestProgressEventThrottle.h: introduced m_hasThrottledProgressEvent which stores whether a progress event is being throttled and m_computableLength which is used to initialize ProgressEvent computableLength
* xml/XMLHttpRequestUpload.cpp:
(WebCore::XMLHttpRequestUpload::XMLHttpRequestUpload):
(WebCore::XMLHttpRequestUpload::dispatchProgressEvent):
* xml/XMLHttpRequestUpload.h: introduced m_loaded, m_total and m_lengthComputable, similarly to XMLHttpRequestProgressEventThrottle

LayoutTests: Correctly set XHR loadend event attributes (loaded and total).
https://bugs.webkit.org/show_bug.cgi?id=120828

Patch by Youenn Fablet <youennf@gmail.com> on 2014-01-10
Reviewed by Alexey Proskuryakov.

Tests for abort, load, loadstart and loadend ProgressEvent events for XMLHttpRequest and XMLHttpRequestUpload

* fast/xmlhttprequest/xmlhttprequest-get-expected.txt: Changed to correct event values
* http/tests/xmlhttprequest/loadstart-event-init-expected.txt: Added.
* http/tests/xmlhttprequest/loadstart-event-init.html: Added.
* http/tests/xmlhttprequest/onabort-progressevent-attributes-expected.txt: Added.
* http/tests/xmlhttprequest/onabort-progressevent-attributes.html: Added.
* http/tests/xmlhttprequest/onload-progressevent-attributes-expected.txt: Added.
* http/tests/xmlhttprequest/onload-progressevent-attributes.html: Added.
* http/tests/xmlhttprequest/upload-onabort-progressevent-attributes-expected.txt: Added.
* http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html: Added.
* http/tests/xmlhttprequest/upload-onload-progressevent-attributes-expected.txt: Added.
* http/tests/xmlhttprequest/upload-onload-progressevent-attributes.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt
LayoutTests/http/tests/xmlhttprequest/loadstart-event-init-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/loadstart-event-init.html [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/onabort-progressevent-attributes-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/onabort-progressevent-attributes.html [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/onload-progressevent-attributes-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/onload-progressevent-attributes.html [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/upload-onabort-progressevent-attributes-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/upload-onload-progressevent-attributes-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/upload-onload-progressevent-attributes.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebCore/xml/XMLHttpRequest.h
Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.cpp
Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.h
Source/WebCore/xml/XMLHttpRequestUpload.cpp
Source/WebCore/xml/XMLHttpRequestUpload.h