Auto merge of #25651 - medimatrix:xhr-progress-timeout, r=jdm

Do not include request progress/total values on XHR timeout

<!-- Please describe your changes on the following line: -->

Do not include request progress/total values on XHR timeout as [the specification]( https://xhr.spec.whatwg.org/#request-error-steps) states that upload events when errors occur should always pass 0 for both values.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24286

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-02-01 04:59:58 -05:00 committed by GitHub
commit e71dc9977c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 43 deletions

View file

@ -618,7 +618,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
}
// Substep 2
if !self.upload_complete.get() {
self.dispatch_upload_progress_event(atom!("loadstart"), Some(0));
self.dispatch_upload_progress_event(atom!("loadstart"), Ok(Some(0)));
if self.generation_id.get() != gen_id {
return Ok(());
}
@ -1062,11 +1062,11 @@ impl XMLHttpRequest {
self.upload_complete.set(true);
// Substeps 2-4
if !self.sync.get() {
self.dispatch_upload_progress_event(atom!("progress"), None);
self.dispatch_upload_progress_event(atom!("progress"), Ok(None));
return_if_fetch_was_terminated!();
self.dispatch_upload_progress_event(atom!("load"), None);
self.dispatch_upload_progress_event(atom!("load"), Ok(None));
return_if_fetch_was_terminated!();
self.dispatch_upload_progress_event(atom!("loadend"), None);
self.dispatch_upload_progress_event(atom!("loadend"), Ok(None));
return_if_fetch_was_terminated!();
}
// Part of step 13, send() (processing response)
@ -1164,9 +1164,9 @@ impl XMLHttpRequest {
let upload_complete = &self.upload_complete;
if !upload_complete.get() {
upload_complete.set(true);
self.dispatch_upload_progress_event(Atom::from(errormsg), None);
self.dispatch_upload_progress_event(Atom::from(errormsg), Err(()));
return_if_fetch_was_terminated!();
self.dispatch_upload_progress_event(atom!("loadend"), None);
self.dispatch_upload_progress_event(atom!("loadend"), Err(()));
return_if_fetch_was_terminated!();
}
self.dispatch_response_progress_event(Atom::from(errormsg));
@ -1210,11 +1210,19 @@ impl XMLHttpRequest {
progressevent.upcast::<Event>().fire(target);
}
fn dispatch_upload_progress_event(&self, type_: Atom, partial_load: Option<u64>) {
// If partial_load is None, loading has completed and we can just use the value from the request body
fn dispatch_upload_progress_event(&self, type_: Atom, partial_load: Result<Option<u64>, ()>) {
// If partial_load is Ok(None), loading has completed and we can just use the value from the request body
// If an error occured, we pass 0 for both loaded and total
let total = self.request_body_len.get() as u64;
self.dispatch_progress_event(true, type_, partial_load.unwrap_or(total), Some(total));
let request_body_len = self.request_body_len.get() as u64;
let (loaded, total) = match partial_load {
Ok(l) => match l {
Some(loaded) => (loaded, Some(request_body_len)),
None => (request_body_len, Some(request_body_len)),
},
Err(()) => (0, None),
};
self.dispatch_progress_event(true, type_, loaded, total);
}
fn dispatch_response_progress_event(&self, type_: Atom) {