mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1303121 - Do not fire one last progress event on XHR errors, to match a spec change. r=annevk
--HG-- extra : rebase_source : 9a59934cfe8fc7f2ee8ef7788813f97e2355ce2a
This commit is contained in:
parent
87f3ac8197
commit
c190891418
@ -217,7 +217,7 @@ var tests =
|
|||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "GET", withUpload: none, testAbort: true, testRedirectError: false, testNetworkError: false,
|
{ method: "GET", withUpload: none, testAbort: true, testRedirectError: false, testNetworkError: false,
|
||||||
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
||||||
{target: XHR, type: "progress", optional: false},
|
{target: XHR, type: "progress", optional: true},
|
||||||
{target: XHR, type: "abort", optional: false},
|
{target: XHR, type: "abort", optional: false},
|
||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "GET", withUpload: none, testAbort: false, testRedirectError: true, testNetworkError: false,
|
{ method: "GET", withUpload: none, testAbort: false, testRedirectError: true, testNetworkError: false,
|
||||||
@ -236,7 +236,7 @@ var tests =
|
|||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "GET", withUpload: small, testAbort: true, testRedirectError: false, testNetworkError: false,
|
{ method: "GET", withUpload: small, testAbort: true, testRedirectError: false, testNetworkError: false,
|
||||||
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
||||||
{target: XHR, type: "progress", optional: false},
|
{target: XHR, type: "progress", optional: true},
|
||||||
{target: XHR, type: "abort", optional: false},
|
{target: XHR, type: "abort", optional: false},
|
||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "GET", withUpload: small, testAbort: false, testRedirectError: true, testNetworkError: false,
|
{ method: "GET", withUpload: small, testAbort: false, testRedirectError: true, testNetworkError: false,
|
||||||
@ -255,7 +255,7 @@ var tests =
|
|||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "GET", withUpload: mid, testAbort: true, testRedirectError: false, testNetworkError: false,
|
{ method: "GET", withUpload: mid, testAbort: true, testRedirectError: false, testNetworkError: false,
|
||||||
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
||||||
{target: XHR, type: "progress", optional: false},
|
{target: XHR, type: "progress", optional: true},
|
||||||
{target: XHR, type: "abort", optional: false},
|
{target: XHR, type: "abort", optional: false},
|
||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "GET", withUpload: mid, testAbort: false, testRedirectError: true, testNetworkError: false,
|
{ method: "GET", withUpload: mid, testAbort: false, testRedirectError: true, testNetworkError: false,
|
||||||
@ -274,7 +274,7 @@ var tests =
|
|||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "GET", withUpload: large, testAbort: true, testRedirectError: false, testNetworkError: false,
|
{ method: "GET", withUpload: large, testAbort: true, testRedirectError: false, testNetworkError: false,
|
||||||
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
||||||
{target: XHR, type: "progress", optional: false},
|
{target: XHR, type: "progress", optional: true},
|
||||||
{target: XHR, type: "abort", optional: false},
|
{target: XHR, type: "abort", optional: false},
|
||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "GET", withUpload: large, testAbort: false, testRedirectError: true, testNetworkError: false,
|
{ method: "GET", withUpload: large, testAbort: false, testRedirectError: true, testNetworkError: false,
|
||||||
@ -293,7 +293,7 @@ var tests =
|
|||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "POST", withUpload: none, testAbort: true, testRedirectError: false, testNetworkError: false,
|
{ method: "POST", withUpload: none, testAbort: true, testRedirectError: false, testNetworkError: false,
|
||||||
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
||||||
{target: XHR, type: "progress", optional: false},
|
{target: XHR, type: "progress", optional: true},
|
||||||
{target: XHR, type: "abort", optional: false},
|
{target: XHR, type: "abort", optional: false},
|
||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "POST", withUpload: none, testAbort: false, testRedirectError: true, testNetworkError: false,
|
{ method: "POST", withUpload: none, testAbort: false, testRedirectError: true, testNetworkError: false,
|
||||||
@ -317,10 +317,10 @@ var tests =
|
|||||||
{ method: "POST", withUpload: small, testAbort: true, testRedirectError: false, testNetworkError: false,
|
{ method: "POST", withUpload: small, testAbort: true, testRedirectError: false, testNetworkError: false,
|
||||||
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
||||||
{target: UPLOAD, type: "loadstart", optional: false},
|
{target: UPLOAD, type: "loadstart", optional: false},
|
||||||
{target: UPLOAD, type: "progress", optional: false},
|
{target: UPLOAD, type: "progress", optional: true},
|
||||||
{target: UPLOAD, type: "abort", optional: false},
|
{target: UPLOAD, type: "abort", optional: false},
|
||||||
{target: UPLOAD, type: "loadend", optional: false},
|
{target: UPLOAD, type: "loadend", optional: false},
|
||||||
{target: XHR, type: "progress", optional: false},
|
{target: XHR, type: "progress", optional: true},
|
||||||
{target: XHR, type: "abort", optional: false},
|
{target: XHR, type: "abort", optional: false},
|
||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "POST", withUpload: small, testAbort: false, testRedirectError: true, testNetworkError: false,
|
{ method: "POST", withUpload: small, testAbort: false, testRedirectError: true, testNetworkError: false,
|
||||||
@ -351,10 +351,10 @@ var tests =
|
|||||||
{ method: "POST", withUpload: mid, testAbort: true, testRedirectError: false, testNetworkError: false,
|
{ method: "POST", withUpload: mid, testAbort: true, testRedirectError: false, testNetworkError: false,
|
||||||
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
||||||
{target: UPLOAD, type: "loadstart", optional: false},
|
{target: UPLOAD, type: "loadstart", optional: false},
|
||||||
{target: UPLOAD, type: "progress", optional: false},
|
{target: UPLOAD, type: "progress", optional: true},
|
||||||
{target: UPLOAD, type: "abort", optional: false},
|
{target: UPLOAD, type: "abort", optional: false},
|
||||||
{target: UPLOAD, type: "loadend", optional: false},
|
{target: UPLOAD, type: "loadend", optional: false},
|
||||||
{target: XHR, type: "progress", optional: false},
|
{target: XHR, type: "progress", optional: true},
|
||||||
{target: XHR, type: "abort", optional: false},
|
{target: XHR, type: "abort", optional: false},
|
||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "POST", withUpload: mid, testAbort: false, testRedirectError: true, testNetworkError: false,
|
{ method: "POST", withUpload: mid, testAbort: false, testRedirectError: true, testNetworkError: false,
|
||||||
@ -385,10 +385,10 @@ var tests =
|
|||||||
{ method: "POST", withUpload: large, testAbort: true, testRedirectError: false, testNetworkError: false,
|
{ method: "POST", withUpload: large, testAbort: true, testRedirectError: false, testNetworkError: false,
|
||||||
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
|
||||||
{target: UPLOAD, type: "loadstart", optional: false},
|
{target: UPLOAD, type: "loadstart", optional: false},
|
||||||
{target: UPLOAD, type: "progress", optional: false},
|
{target: UPLOAD, type: "progress", optional: true},
|
||||||
{target: UPLOAD, type: "abort", optional: false},
|
{target: UPLOAD, type: "abort", optional: false},
|
||||||
{target: UPLOAD, type: "loadend", optional: false},
|
{target: UPLOAD, type: "loadend", optional: false},
|
||||||
{target: XHR, type: "progress", optional: false},
|
{target: XHR, type: "progress", optional: true},
|
||||||
{target: XHR, type: "abort", optional: false},
|
{target: XHR, type: "abort", optional: false},
|
||||||
{target: XHR, type: "loadend", optional: false}]},
|
{target: XHR, type: "loadend", optional: false}]},
|
||||||
{ method: "POST", withUpload: large, testAbort: false, testRedirectError: true, testNetworkError: false,
|
{ method: "POST", withUpload: large, testAbort: false, testRedirectError: true, testNetworkError: false,
|
||||||
|
@ -759,10 +759,8 @@ function runTest() {
|
|||||||
"wrong responseXML in test for " + test.toSource());
|
"wrong responseXML in test for " + test.toSource());
|
||||||
is(res.responseText, "",
|
is(res.responseText, "",
|
||||||
"wrong responseText in test for " + test.toSource());
|
"wrong responseText in test for " + test.toSource());
|
||||||
var expectedProgressCount = 0;
|
|
||||||
if (!res.sendThrew) {
|
if (!res.sendThrew) {
|
||||||
if (test.username) {
|
if (test.username) {
|
||||||
expectedProgressCount = 1;
|
|
||||||
is(res.events.join(","),
|
is(res.events.join(","),
|
||||||
"opening,rs1,sending,loadstart,rs4,error,loadend",
|
"opening,rs1,sending,loadstart,rs4,error,loadend",
|
||||||
"wrong events in test for " + test.toSource());
|
"wrong events in test for " + test.toSource());
|
||||||
@ -772,7 +770,7 @@ function runTest() {
|
|||||||
"wrong events in test for " + test.toSource());
|
"wrong events in test for " + test.toSource());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is(res.progressEvents, expectedProgressCount,
|
is(res.progressEvents, 0,
|
||||||
"wrong events in test for " + test.toSource());
|
"wrong events in test for " + test.toSource());
|
||||||
if (test.responseHeaders) {
|
if (test.responseHeaders) {
|
||||||
for (header in test.responseHeaders) {
|
for (header in test.responseHeaders) {
|
||||||
|
@ -1036,10 +1036,8 @@ XMLHttpRequestMainThread::CloseRequestWithError(const ProgressEventType aType)
|
|||||||
if (!mFlagSyncLooping) {
|
if (!mFlagSyncLooping) {
|
||||||
if (mUpload && !mUploadComplete) {
|
if (mUpload && !mUploadComplete) {
|
||||||
mUploadComplete = true;
|
mUploadComplete = true;
|
||||||
DispatchProgressEvent(mUpload, ProgressEventType::progress, 0, 0);
|
|
||||||
DispatchProgressEvent(mUpload, aType, 0, 0);
|
DispatchProgressEvent(mUpload, aType, 0, 0);
|
||||||
}
|
}
|
||||||
DispatchProgressEvent(this, ProgressEventType::progress, 0, 0);
|
|
||||||
DispatchProgressEvent(this, aType, 0, 0);
|
DispatchProgressEvent(this, aType, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2182,10 +2180,9 @@ XMLHttpRequestMainThread::ChangeStateToDone()
|
|||||||
// Per spec, fire readystatechange=4/done before final error events.
|
// Per spec, fire readystatechange=4/done before final error events.
|
||||||
ChangeState(State::done, true);
|
ChangeState(State::done, true);
|
||||||
|
|
||||||
// Per spec, if we failed in the upload phase, fire a final progress, error,
|
// Per spec, if we failed in the upload phase, fire a final error
|
||||||
// and loadend event for the upload after readystatechange=4/done.
|
// and loadend events for the upload after readystatechange=4/done.
|
||||||
if (!mFlagSynchronous && mUpload && !mUploadComplete) {
|
if (!mFlagSynchronous && mUpload && !mUploadComplete) {
|
||||||
DispatchProgressEvent(mUpload, ProgressEventType::progress, 0, 0);
|
|
||||||
DispatchProgressEvent(mUpload, ProgressEventType::error, 0, 0);
|
DispatchProgressEvent(mUpload, ProgressEventType::error, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
[progress-events-response-data-gzip.htm]
|
|
||||||
type: testharness
|
|
||||||
[XMLHttpRequest: progress events and GZIP encoding]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
|||||||
<title>XMLHttpRequest: abort() after send()</title>
|
<title>XMLHttpRequest: abort() after send()</title>
|
||||||
<script src="/resources/testharness.js"></script>
|
<script src="/resources/testharness.js"></script>
|
||||||
<script src="/resources/testharnessreport.js"></script>
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<script src="resources/xmlhttprequest-event-order.js"></script>
|
||||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[1] following-sibling::ol/li[3] following-sibling::ol/li[4] following-sibling::ol/li[4]/ol/li[1] following-sibling::ol/li[4]/ol/li[3] following-sibling::ol/li[4]/ol/li[4] following-sibling::ol/li[4]/ol/li[5] following-sibling::ol/li[4]/ol/li[6] following-sibling::ol/li[5]" />
|
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[1] following-sibling::ol/li[3] following-sibling::ol/li[4] following-sibling::ol/li[4]/ol/li[1] following-sibling::ol/li[4]/ol/li[3] following-sibling::ol/li[4]/ol/li[4] following-sibling::ol/li[4]/ol/li[5] following-sibling::ol/li[4]/ol/li[6] following-sibling::ol/li[5]" />
|
||||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol/li[3]" />
|
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol/li[3]" />
|
||||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsexml-attribute" data-tested-assertations="following::ol/li[3]" />
|
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsexml-attribute" data-tested-assertations="following::ol/li[3]" />
|
||||||
@ -19,36 +20,26 @@
|
|||||||
var test = async_test()
|
var test = async_test()
|
||||||
test.step(function() {
|
test.step(function() {
|
||||||
var client = new XMLHttpRequest(),
|
var client = new XMLHttpRequest(),
|
||||||
control_flag = false,
|
control_flag = false;
|
||||||
result = [],
|
prepare_xhr_for_event_order_test(client);
|
||||||
expected = [1, 4, 'progress', 'abort', 'loadend'] // open() -> 1, abort() -> 4
|
client.addEventListener("readystatechange", test.step_func(function() {
|
||||||
client.onreadystatechange = function() {
|
if(client.readyState == 4) {
|
||||||
test.step(function() {
|
control_flag = true
|
||||||
result.push(client.readyState)
|
assert_equals(client.responseXML, null)
|
||||||
if(client.readyState == 4) {
|
assert_equals(client.responseText, "")
|
||||||
control_flag = true
|
assert_equals(client.status, 0)
|
||||||
assert_equals(client.responseXML, null)
|
assert_equals(client.statusText, "")
|
||||||
assert_equals(client.responseText, "")
|
assert_equals(client.getAllResponseHeaders(), "")
|
||||||
assert_equals(client.status, 0)
|
assert_equals(client.getResponseHeader('Content-Type'), null)
|
||||||
assert_equals(client.statusText, "")
|
}
|
||||||
assert_equals(client.getAllResponseHeaders(), "")
|
}))
|
||||||
assert_equals(client.getResponseHeader('Content-Type'), null)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
client.open("GET", "resources/well-formed.xml", true)
|
client.open("GET", "resources/well-formed.xml", true)
|
||||||
client.send(null)
|
client.send(null)
|
||||||
client.addEventListener('progress', logEvt)
|
|
||||||
client.addEventListener('abort', logEvt)
|
|
||||||
client.addEventListener('loadend', logEvt)
|
|
||||||
client.abort()
|
client.abort()
|
||||||
assert_true(control_flag)
|
assert_true(control_flag)
|
||||||
assert_equals(client.readyState, 0)
|
assert_equals(client.readyState, 0)
|
||||||
assert_array_equals(result, expected)
|
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", 4, "abort(0,0,false)", "loadend(0,0,false)"])
|
||||||
test.done()
|
test.done()
|
||||||
function logEvt (e) {
|
|
||||||
result.push(e.type)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
client.open("POST", "resources/delay.py?ms=1000")
|
client.open("POST", "resources/delay.py?ms=1000")
|
||||||
client.addEventListener("loadend", function(e) {
|
client.addEventListener("loadend", function(e) {
|
||||||
test.step(function() {
|
test.step(function() {
|
||||||
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", "upload.loadstart(0,9999,true)", 4, "upload.progress(0,0,false)", "upload.abort(0,0,false)", "upload.loadend(0,0,false)", "progress(0,0,false)", "abort(0,0,false)", "loadend(0,0,false)"]);
|
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", "upload.loadstart(0,9999,true)", 4, "upload.abort(0,0,false)", "upload.loadend(0,0,false)", "abort(0,0,false)", "loadend(0,0,false)"]);
|
||||||
test.done()
|
test.done()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
{
|
{
|
||||||
test.step(function()
|
test.step(function()
|
||||||
{
|
{
|
||||||
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", 4, "upload.progress(0,0,false)", "upload.abort(0,0,false)", "upload.loadend(0,0,false)", "progress(0,0,false)", "abort(0,0,false)", "loadend(0,0,false)"]);
|
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", 4, "upload.abort(0,0,false)", "upload.loadend(0,0,false)", "abort(0,0,false)", "loadend(0,0,false)"]);
|
||||||
|
|
||||||
assert_equals(xhr.readyState, 0, 'state should be UNSENT');
|
assert_equals(xhr.readyState, 0, 'state should be UNSENT');
|
||||||
test.done();
|
test.done();
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
prepare_xhr_for_event_order_test(xhr);
|
prepare_xhr_for_event_order_test(xhr);
|
||||||
xhr.addEventListener("loadend", function() {
|
xhr.addEventListener("loadend", function() {
|
||||||
test.step(function() {
|
test.step(function() {
|
||||||
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", "upload.loadstart(0,12,true)", 4, "upload.progress(0,0,false)", "upload.timeout(0,0,false)", "upload.loadend(0,0,false)", "progress(0,0,false)", "timeout(0,0,false)", "loadend(0,0,false)"]);
|
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", "upload.loadstart(0,12,true)", 4, "upload.timeout(0,0,false)", "upload.loadend(0,0,false)", "timeout(0,0,false)", "loadend(0,0,false)"]);
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -36,17 +36,20 @@
|
|||||||
|
|
||||||
* If lengthComputable is true:
|
* If lengthComputable is true:
|
||||||
* Event.total must match Content-length header
|
* Event.total must match Content-length header
|
||||||
* event.loaded should be a smaller number while resource is loading
|
* event.loaded must only ever increase in progress events
|
||||||
and match Content-length when loading is finished
|
(and may never repeat its value).
|
||||||
* Setting event.loaded to equal event.total for each progress event if the
|
* event.loaded must never exceed the Content-length.
|
||||||
resource is not fully downloaded would be cheating
|
|
||||||
|
|
||||||
* If lengthComputable is false:
|
* If lengthComputable is false:
|
||||||
* event.total should be 0
|
* event.total should be 0
|
||||||
|
* event.loaded must only ever increase in progress events
|
||||||
|
(and may never repeat its value).
|
||||||
* event.loaded should be the length of the decompressed content, i.e.
|
* event.loaded should be the length of the decompressed content, i.e.
|
||||||
bigger than Content-length header value when finished loading
|
bigger than Content-length header value when finished loading
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
var lastTotal;
|
||||||
|
var lastLoaded = -1;
|
||||||
client.addEventListener('loadend', test.step_func(function(e){
|
client.addEventListener('loadend', test.step_func(function(e){
|
||||||
var len = parseInt(client.getResponseHeader('content-length'), 10)
|
var len = parseInt(client.getResponseHeader('content-length'), 10)
|
||||||
if(e.lengthComputable){
|
if(e.lengthComputable){
|
||||||
@ -59,14 +62,17 @@
|
|||||||
test.done();
|
test.done();
|
||||||
}), false)
|
}), false)
|
||||||
client.addEventListener('progress', test.step_func(function(e){
|
client.addEventListener('progress', test.step_func(function(e){
|
||||||
if(e.lengthComputable && e.total && e.loaded && e.target.readyState < 4){
|
if(lastTotal === undefined){
|
||||||
assert_not_equals(e.total, e.loaded, 'total should not equal loaded while download/decode is incomplete')
|
lastTotal = e.total;
|
||||||
// We should only do this assertation once
|
|
||||||
// it's theoretically possible that all the data would get in
|
|
||||||
// and a progress event fire before the readyState switches from 3 to 4 -
|
|
||||||
// in this case we might report bogus and random failures. Better to remove the event listener again..
|
|
||||||
client.removeEventListener('progress', arguments.callee, false);
|
|
||||||
}
|
}
|
||||||
|
if(e.lengthComputable && e.total && e.loaded){
|
||||||
|
assert_equals(e.total, lastTotal, 'event.total should remain invariant')
|
||||||
|
assert_less_than_equal(e.loaded, lastTotal, 'event.loaded should not exceed content-length')
|
||||||
|
}else{
|
||||||
|
assert_equals(e.total, 0, 'event.total should be 0')
|
||||||
|
}
|
||||||
|
assert_greater_than(e.loaded, lastLoaded, 'event.loaded should only ever increase')
|
||||||
|
lastLoaded = e.loaded;
|
||||||
}), false)
|
}), false)
|
||||||
// image.gif is 165375 bytes compressed. Sending 45000 bytes at a time with 1 second delay will load it in 4 seconds
|
// image.gif is 165375 bytes compressed. Sending 45000 bytes at a time with 1 second delay will load it in 4 seconds
|
||||||
client.open("GET", "resources/image.gif?pipe=gzip|trickle(45000:d1:r2)", true)
|
client.open("GET", "resources/image.gif?pipe=gzip|trickle(45000:d1:r2)", true)
|
||||||
|
@ -21,13 +21,60 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNextEvent(arr) {
|
||||||
|
var eventStr = arr.shift();
|
||||||
|
|
||||||
|
// we can only handle strings, numbers (readystates) and undefined
|
||||||
|
if (eventStr === undefined) {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
if (typeof eventStr !== "string") {
|
||||||
|
if (Number.isInteger(eventStr)) {
|
||||||
|
eventStr = "readystatechange(" + eventStr + ")";
|
||||||
|
} else {
|
||||||
|
throw "Test error: unexpected event type " + eventStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse out the general type, loaded and total values
|
||||||
|
var type = eventStr.type = eventStr.split("(")[0].split(".").pop();
|
||||||
|
eventStr.mayFollowOptionalProgressEvents = type == "progress" ||
|
||||||
|
type == "load" || type == "abort" || type == "error";
|
||||||
|
var loadedAndTotal = eventStr.match(/\((\d)+,(\d)+/);
|
||||||
|
if (loadedAndTotal) {
|
||||||
|
eventStr.loaded = parseInt(loadedAndTotal[0]);
|
||||||
|
eventStr.total = parseInt(loadedAndTotal[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return eventStr;
|
||||||
|
}
|
||||||
|
|
||||||
global.assert_xhr_event_order_matches = function(expected) {
|
global.assert_xhr_event_order_matches = function(expected) {
|
||||||
try {
|
var recorded = recorded_xhr_events;
|
||||||
assert_array_equals(recorded_xhr_events, expected);
|
var lastRecordedLoaded = -1;
|
||||||
} catch(e) {
|
|
||||||
e.message += "\nRecorded events were:" + recorded_xhr_events.join(", ");
|
while(expected.length && recorded.length) {
|
||||||
e.message += "\nExpected events were:" + expected.join(", ");
|
var currentExpected = getNextEvent(expected),
|
||||||
throw e;
|
currentRecorded = getNextEvent(recorded);
|
||||||
|
|
||||||
|
// skip to the last progress event if we've hit one
|
||||||
|
while (recorded.length && currentRecorded.type == "progress") {
|
||||||
|
assert_greater(currentRecorded.loaded, lastRecordedLoaded,
|
||||||
|
"progress event 'loaded' values must only increase");
|
||||||
|
lastRecordedLoaded = currentRecorded.loaded;
|
||||||
|
currentRecorded = getNextEvent(recorded);
|
||||||
|
}
|
||||||
|
if (currentRecorded.type == "loadstart") {
|
||||||
|
lastRecordedLoaded = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equals(currentRecorded, currentExpected);
|
||||||
|
}
|
||||||
|
if (recorded.length) {
|
||||||
|
throw "\nUnexpected extra events: " + recorded.join(", ");
|
||||||
|
}
|
||||||
|
if (expected.length) {
|
||||||
|
throw "\nExpected more events: " + expected.join(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(this));
|
}(this));
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
<link rel="help" href="https://xhr.spec.whatwg.org/#switch-done" data-tested-assertations="following::ol[1]/li[3] following::ol[1]/li[4] following::ol[1]/li[5] following::ol[1]/li[6] following::ol[1]/li[7]" />
|
<link rel="help" href="https://xhr.spec.whatwg.org/#switch-done" data-tested-assertations="following::ol[1]/li[3] following::ol[1]/li[4] following::ol[1]/li[5] following::ol[1]/li[6] following::ol[1]/li[7]" />
|
||||||
<script src="/resources/testharness.js"></script>
|
<script src="/resources/testharness.js"></script>
|
||||||
<script src="/resources/testharnessreport.js"></script>
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<script src="resources/xmlhttprequest-event-order.js"></script>
|
||||||
<title>XMLHttpRequest: The send() method: event order when synchronous flag is unset</title>
|
<title>XMLHttpRequest: The send() method: event order when synchronous flag is unset</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -24,38 +25,12 @@
|
|||||||
test.step(function()
|
test.step(function()
|
||||||
{
|
{
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
var expect = ["loadstart", "upload.loadstart", "upload.progress", "upload.load", "upload.loadend", "progress", 4, "load", "loadend"];
|
prepare_xhr_for_event_order_test(xhr);
|
||||||
var actual = [];
|
|
||||||
|
|
||||||
xhr.onreadystatechange = function()
|
xhr.addEventListener("loadend", test.step_func(function() {
|
||||||
{
|
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", "upload.loadstart(0,12,true)", "upload.progress(12,12,true)", "upload.load(12,12,true)", "upload.loadend(12,12,true)", 2, 3, "progress(12,12,true)", 4, "load(12,12,true)", "loadend(12,12,true)"]);
|
||||||
test.step(function()
|
test.done();
|
||||||
{
|
}));
|
||||||
if (xhr.readyState == 4)
|
|
||||||
{
|
|
||||||
actual.push(xhr.readyState);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.onloadstart = function(e){ actual.push(e.type); };
|
|
||||||
xhr.onload = function(e){ actual.push(e.type); };
|
|
||||||
xhr.onloadend = function(e){ actual.push(e.type); VerifyResult()};
|
|
||||||
xhr.onprogress = function(e){ actual.push(e.type);};
|
|
||||||
|
|
||||||
xhr.upload.onloadstart = function(e){ actual.push("upload." + e.type); };
|
|
||||||
xhr.upload.onload = function(e){ actual.push("upload." + e.type); };
|
|
||||||
xhr.upload.onloadend = function(e){ actual.push("upload." + e.type);};
|
|
||||||
xhr.upload.onprogress = function(e){ actual.push("upload." + e.type);};
|
|
||||||
|
|
||||||
function VerifyResult()
|
|
||||||
{
|
|
||||||
test.step(function()
|
|
||||||
{
|
|
||||||
assert_array_equals(actual, expect);
|
|
||||||
test.done();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.open("POST", "./resources/content.py", true);
|
xhr.open("POST", "./resources/content.py", true);
|
||||||
xhr.send("Test Message");
|
xhr.send("Test Message");
|
||||||
|
Loading…
Reference in New Issue
Block a user