XHR: compliant event sequencing on request errors and aborts.

Implement the event sequencing that the XHR spec now mandates for
request errors and abort()s. For request errors over async requests,
the following steps and sequence of events should now be dispatched:

  - readyState transitions to state DONE, dispatching a
    readystatechange event.

  - The ordered event triple (progress, <event type>, loadend) is
    dispatched to the upload event listeners, if any.

  - The ordered event triple (progress, <event type>, loadend) is
    dispatched to the regular/download event listeners.

  - readyState transitions to UNSENT.

where <event type> is one of {'error', 'timeout', 'abort'}.

Same steps for abort(), for both sync and async requests.

The required dispatching of 'progress' here is a relatively new
addition to the specification, late 2012.

A behavioral implementation change is the fourth step of transitioning
to UNSENT. This was previously done as step two (after dispatching
readystatechange), an out-of-spec and incorrect quirk.

For the above sequence, to allow for the delivery of
'readystatechange' on transitioning to DONE, but delay the delivery of
the final 'progress', we carefully only flush any deferred 'progress'
event before that 'readystatechange' event, but do not issue new. That
dispatch happens after the upload progress events have been dealt
with.

To make the correspondence clearer to the underlying spec text, the
request error steps have been factored out into a separate method.

R=tyoshino,abarth
BUG=315488

Review URL: https://codereview.chromium.org/66323004

git-svn-id: svn://svn.chromium.org/blink/trunk@162340 bbb929c8-8fbe-4397-9dbb-9b2b20218538
11 files changed
tree: bf57ed040df906f1aeba1f35de86fc1a117fc2d9
  1. third_party/