Skip to content
  • dominik.rottsches@intel.com's avatar
    Add timeout support to XMLHttpRequest · 29d9065a
    dominik.rottsches@intel.com authored
    https://bugs.webkit.org/show_bug.cgi?id=74802
    
    Reviewed by Nate Chapin.
    
    Source/WebCore:
    
    An implementation of XHR2 timeouts by using ResourceRequest's setTimeoutInterval.
    This made several changes necessary in CachedResource and SubresourceLoader in order
    to distinguish and forward the timeout case from there.
    
    The case of late updates to the timeout property, changing the timeout value after send()
    is not supported yet and handled separately in bug 98156.
    
    XHR2 timeout tests were initially written by Mozilla's Alex Vincent's. He granted
    permission to reuse them under PD/BSD license
    in https://bugzilla.mozilla.org/show_bug.cgi?id=525816#c86 - big thanks!
    I adapted them for W3C testharness.js and split them into groups with shorter test running time
    so that they can be used as WebKit layout tests.
    
    Tests: http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html
           http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html
    
    * loader/DocumentThreadableLoader.cpp:
    (WebCore::DocumentThreadableLoader::notifyFinished): Forward information about timeout case.
    * loader/SubresourceLoader.cpp:
    (WebCore::SubresourceLoader::didFail): Distinguish timeout case when informing client.
    * loader/cache/CachedResource.h: Distinguishing timeout case for errors.
    (WebCore::CachedResource::errorOccurred):
    (WebCore::CachedResource::loadFailedOrCanceled):
    (WebCore::CachedResource::timedOut):
    * xml/XMLHttpRequest.cpp:
    (WebCore::XMLHttpRequest::XMLHttpRequest): Initializing m_timeout value to zero.
    (WebCore::XMLHttpRequest::setTimeout): Setter function, possibly raising JS exception.
    (WebCore):
    (WebCore::XMLHttpRequest::open): Open call may raise exception for synchronous requests when timeout value is set.
    (WebCore::XMLHttpRequest::createRequest): Assigning timeout value to ResourceRequest.
    (WebCore::XMLHttpRequest::didFail): Handling timeout case separately.
    (WebCore::XMLHttpRequest::didTimeout): Timeout case state transisition and event firing as spec'ed.
    * xml/XMLHttpRequest.h: New event listener, member and callback for handling timeout.
    (WebCore::XMLHttpRequest::timeout):
    (XMLHttpRequest):
    * xml/XMLHttpRequest.idl: New event listener and property added.
    * xml/XMLHttpRequestException.cpp:
    * xml/XMLHttpRequestException.h: Added an exception value for the timeout case.
    
    LayoutTests:
    
    XHR2 timeout tests were initially written by Mozilla's Alex Vincent's. He granted
    permission to reuse them under PD/BSD license
    in https://bugzilla.mozilla.org/show_bug.cgi?id=525816#c86 - big thanks!
    I adapted them for W3C testharness.js and split them into groups with shorter test running time
    so that they can be used as WebKit layout tests. Each individual test should
    complete in less than 20 seconds.
    
    The case of late updates to the timeout property, changing the timeout value after send()
    is not supported yet and handled separately in bug 98156. Tests that are testing this feature
    are commented out until this bug is tackled.
    
    The suffix of the html test filename matches the groups in xmlhttprequest-timeout.js which contains
    all tests that are run. The result of assertions is reported back to testharness.js.
    
    For example, the "overrides" group is currently not run yet since all tests in that group are cases
    of late updates, see above. Once late updates are supported we can add a file
    xmlhttprequest-timeout-overrides.html to run them.
    
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-runner.js: Added. Distinguishes which group of tests to run based on filename suffix.
    (testResultCallbackHandler.return):
    (groupFromLocation):
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice-expected.txt: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html: Added.
    * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout.js: Added. Contains test cases for all individual test html files.
    (message): Wrapper for postMessage in worker and document context case.
    (is),
    (ok): Assertion functions.
    (RequestTracker): Class for variations of the regular timeout case.
    (RequestTracker.prototype.startXHR.handleEvent):
    (RequestTracker.prototype.startXHR):
    (RequestTracker.prototype.getMessage):
    (RequestTracker.prototype.handleEvent):
    (AbortedRequest): Class for testing timeout event vs. abort events.
    (AbortedRequest.prototype.startXHR.handleEvent):
    (AbortedRequest.prototype.startXHR.abortReq):
    (AbortedRequest.prototype.startXHR.else):
    (AbortedRequest.prototype.startXHR):
    (AbortedRequest.prototype.noEventsFired):
    (AbortedRequest.prototype.getMessage):
    (AbortedRequest.prototype.handleEvent):
    (SyncRequestSettingTimeoutAfterOpen.startXHR),
    (SyncRequestSettingTimeoutBeforeOpen.startXHR): Test classes for synchronous XHR cases.
    (TestCounter.testComplete),
    (TestCounter.next): Used for cycling through tests.
    * platform/chromium/TestExpectations: Skipping XHR timeout cases since setTimeoutInterval is not supported in Chromium's HTTP stack.
    * platform/gtk/TestExpectations: Marking XHR timeout cases as slow in order to run them with a longer test timeout threshold.
    * platform/qt/TestExpectations: Skipping XHR timeout cases since setTimeoutInterval is not supported in Chromium's HTTP stack.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@132252 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    29d9065a