Remove media element state changes triggered by network responses (#32643)

* Do not change media element ready state when network response is complete.

* Do not fire multiple error events for the same media content.

* Inform media backend when media response is complete.

* Continue delaying the load event when a complete media response is received.

* Only mark a media response as complete when the response is the active one.

* Update expectations for imagebitmap tests using video element.

* Update fetch ORB video test expectations.

* Update media CSS selector test expectation for non-implemented feature.

* Update expectations for media element tests that now work.

* Updat expected result for failing reftest.

* Update expected failure for test that loads an audio file in a video element.

* Update media test expectation for unimplemented track feature.

* Do not process media element ready state changes that are unchanged.

* Reset media element ready state to Current when playback finishes.

* Set media element ready state to Enough when appropriate player event is received.

* Update test expectations.
This commit is contained in:
Josh Matthews 2024-07-09 02:48:44 -04:00 committed by GitHub
parent f29dd64a7b
commit 72e6a1f007
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 80 additions and 203 deletions

View file

@ -615,6 +615,10 @@ impl HTMLMediaElement {
return;
}
if old_ready_state == ready_state {
return;
}
let window = window_from_node(self);
let task_source = window.task_manager().media_element_task_source();
@ -1064,6 +1068,10 @@ impl HTMLMediaElement {
task_source.queue_simple_event(self.upcast(), atom!("ratechange"), &window);
}
fn in_error_state(&self) -> bool {
self.error.get().is_some()
}
// https://html.spec.whatwg.org/multipage/#potentially-playing
fn is_potentially_playing(&self) -> bool {
!self.paused.get() &&
@ -1538,6 +1546,9 @@ impl HTMLMediaElement {
}),
window.upcast(),
);
// https://html.spec.whatwg.org/multipage/#dom-media-have_current_data
self.change_ready_state(ReadyState::HaveCurrentData);
}
},
@ -1556,6 +1567,14 @@ impl HTMLMediaElement {
},
PlayerEvent::Error(ref error) => {
error!("Player error: {:?}", error);
// If we have already flagged an error condition while processing
// the network response, we should silently skip any observable
// errors originating while decoding the erroneous response.
if self.in_error_state() {
return;
}
// https://html.spec.whatwg.org/multipage/#loading-the-media-resource:media-data-13
// 1. The user agent should cancel the fetching process.
if let Some(ref mut current_fetch_context) =
@ -1803,6 +1822,8 @@ impl HTMLMediaElement {
}
},
PlayerEvent::EnoughData => {
self.change_ready_state(ReadyState::HaveEnoughData);
// The player has enough data and it is asking us to stop pushing
// bytes, so we cancel the ongoing fetch request iff we are able
// to restart it from where we left. Otherwise, we continue the
@ -2795,56 +2816,53 @@ impl FetchResponseListener for HTMLMediaElementFetchListener {
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
fn process_response_eof(&mut self, status: Result<ResourceFetchTiming, NetworkError>) {
trace!("process response eof");
if let Some(seek_lock) = self.seek_lock.take() {
seek_lock.unlock(/* successful seek */ false);
}
let elem = self.elem.root();
if elem.player.borrow().is_none() {
if elem.generation_id.get() != self.generation_id || elem.player.borrow().is_none() {
return;
}
// If an error was previously received and no new fetch request was triggered,
// we skip processing the payload and notify the media backend that we are done
// pushing data.
if elem.generation_id.get() == self.generation_id {
if let Some(ref current_fetch_context) = *elem.current_fetch_context.borrow() {
if let Some(CancelReason::Error) = current_fetch_context.cancel_reason() {
if let Err(e) = elem
.player
.borrow()
.as_ref()
.unwrap()
.lock()
.unwrap()
.end_of_stream()
{
warn!("Could not signal EOS to player {:?}", e);
}
return;
}
// There are no more chunks of the response body forthcoming, so we can
// go ahead and notify the media backend not to expect any further data.
if let Err(e) = elem
.player
.borrow()
.as_ref()
.unwrap()
.lock()
.unwrap()
.end_of_stream()
{
warn!("Could not signal EOS to player {:?}", e);
}
// If an error was previously received we skip processing the payload.
if let Some(ref current_fetch_context) = *elem.current_fetch_context.borrow() {
if let Some(CancelReason::Error) = current_fetch_context.cancel_reason() {
return;
}
}
if status.is_ok() && self.latest_fetched_content != 0 {
if elem.ready_state.get() == ReadyState::HaveNothing {
// Make sure that we don't skip the HaveMetadata and HaveCurrentData
// states for short streams.
elem.change_ready_state(ReadyState::HaveMetadata);
}
elem.change_ready_state(ReadyState::HaveEnoughData);
elem.upcast::<EventTarget>().fire_event(atom!("progress"));
elem.network_state.set(NetworkState::Idle);
elem.upcast::<EventTarget>().fire_event(atom!("suspend"));
elem.delay_load_event(false);
}
// => "If the connection is interrupted after some media data has been received..."
else if elem.ready_state.get() != ReadyState::HaveNothing {
// If the media backend has already flagged an error, skip any observable
// network-related errors.
if elem.in_error_state() {
return;
}
// Step 1
if let Some(ref mut current_fetch_context) = *elem.current_fetch_context.borrow_mut() {
current_fetch_context.cancel(CancelReason::Error);

View file

@ -1,2 +0,0 @@
[mix-blend-mode-video.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[overflow-video.html]
expected: FAIL

View file

@ -1,4 +1,5 @@
[media-playback-state.html]
expected: TIMEOUT
[Test :pseudo-class syntax is supported without throwing a SyntaxError]
expected: FAIL
@ -6,7 +7,7 @@
expected: FAIL
[Test :paused pseudo-classes]
expected: FAIL
expected: TIMEOUT
[Test :seeking pseudo-class]
expected: FAIL
expected: NOTRUN

View file

@ -27,101 +27,26 @@
[ORB should block opaque text/plain: fetch(..., {mode: "no-cors"})]
expected: FAIL
[ORB should block opaque text/plain: <audio src=...>]
expected: TIMEOUT
[ORB should block opaque text/plain: <video src=...>]
expected: NOTRUN
[ORB should block opaque text/plain: <script src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque application/json (non-empty): fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB should block opaque application/json (non-empty): <img src=...>]
expected: NOTRUN
[ORB should block opaque application/json (non-empty): <audio src=...>]
expected: NOTRUN
[ORB should block opaque application/json (non-empty): <video src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque application/json (non-empty): <script src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque application/json (empty): fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB should block opaque application/json (empty): <img src=...>]
expected: NOTRUN
[ORB should block opaque application/json (empty): <audio src=...>]
expected: NOTRUN
[ORB should block opaque application/json (empty): <video src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque application/json (empty): <script src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque application/json which contains non ascii characters: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB should block opaque application/json which contains non ascii characters: <img src=...>]
expected: NOTRUN
[ORB should block opaque application/json which contains non ascii characters: <audio src=...>]
expected: NOTRUN
[ORB should block opaque application/json which contains non ascii characters: <video src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque application/json which contains non ascii characters: <script src=...>]
expected: NOTRUN
[ORB shouldn't block opaque image/png: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB shouldn't block opaque image/png: <img src=...>]
expected: NOTRUN
[ORB shouldn't block opaque text/javascript: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB shouldn't block opaque text/javascript: <script src=...>]
expected: NOTRUN
[ORB shouldn't block opaque text/javascript (utf16 encoded with BOM): fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB shouldn't block opaque text/javascript (utf16 encoded with BOM): <script src=...>]
expected: NOTRUN
[ORB shouldn't block opaque text/javascript (utf16 encoded without BOM but charset is provided in content-type): fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB shouldn't block opaque text/javascript (utf16 encoded without BOM but charset is provided in content-type): <script src=...>]
expected: NOTRUN
[ORB shouldn't block opaque text/javascript (iso-8559-1 encoded): fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB shouldn't block opaque text/javascript (iso-8559-1 encoded): <script src=...>]
expected: NOTRUN
[ORB shouldn't block text/javascript with valid asm.js: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB shouldn't block text/javascript with valid asm.js: <script src=...>]
expected: NOTRUN
[ORB shouldn't block text/javascript with invalid asm.js: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB shouldn't block text/javascript with invalid asm.js: <script src=...>]
expected: NOTRUN
expected: FAIL
[known-mime-type.sub.any.worker.html]

View file

@ -1,73 +1,25 @@
[nosniff.sub.any.html]
expected: TIMEOUT
[ORB should block opaque text/plain with nosniff]
expected: FAIL
[ORB should block opaque-response-blocklisted MIME type with nosniff]
expected: FAIL
[ORB should block opaque response with empty Content-Type and nosniff]
expected: FAIL
expected: ERROR
[ORB should block opaque text/plain with nosniff: fetch(..., {mode: "no-cors"})]
expected: FAIL
[ORB should block opaque text/plain with nosniff: <audio src=...>]
expected: TIMEOUT
[ORB should block opaque text/plain with nosniff: <video src=...>]
expected: NOTRUN
[ORB should block opaque text/plain with nosniff: <script src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque-response-blocklisted MIME type with nosniff: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB should block opaque-response-blocklisted MIME type with nosniff: <img src=...>]
expected: NOTRUN
[ORB should block opaque-response-blocklisted MIME type with nosniff: <audio src=...>]
expected: NOTRUN
[ORB should block opaque-response-blocklisted MIME type with nosniff: <video src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque-response-blocklisted MIME type with nosniff: <script src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque response with empty Content-Type and nosniff: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB should block opaque response with empty Content-Type and nosniff: <img src=...>]
expected: NOTRUN
[ORB should block opaque response with empty Content-Type and nosniff: <audio src=...>]
expected: NOTRUN
[ORB should block opaque response with empty Content-Type and nosniff: <video src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque response with empty Content-Type and nosniff: <script src=...>]
expected: NOTRUN
[ORB shouldn't block opaque image with empty Content-Type and nosniff: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB shouldn't block opaque image with empty Content-Type and nosniff: <img src=...>]
expected: NOTRUN
expected: FAIL
[nosniff.sub.any.worker.html]
[ORB should block opaque text/plain with nosniff]
expected: FAIL
[ORB should block opaque-response-blocklisted MIME type with nosniff]
expected: FAIL
[ORB should block opaque response with empty Content-Type and nosniff]
expected: FAIL
[ORB should block opaque text/plain with nosniff: fetch(..., {mode: "no-cors"})]
expected: FAIL

View file

@ -1,5 +1,5 @@
[status.sub.any.html]
expected: TIMEOUT
expected: ERROR
[ORB should block opaque-response-blocklisted MIME type with status 206]
expected: FAIL
@ -9,29 +9,11 @@
[ORB should block opaque-response-blocklisted MIME type with status 206: fetch(..., {mode: "no-cors"})]
expected: FAIL
[ORB should block opaque-response-blocklisted MIME type with status 206: <audio src=...>]
expected: TIMEOUT
[ORB should block opaque-response-blocklisted MIME type with status 206: <video src=...>]
expected: NOTRUN
[ORB should block opaque-response-blocklisted MIME type with status 206: <script src=...>]
expected: NOTRUN
expected: FAIL
[ORB should block opaque response with non-ok status: fetch(..., {mode: "no-cors"})]
expected: NOTRUN
[ORB should block opaque response with non-ok status: <img src=...>]
expected: NOTRUN
[ORB should block opaque response with non-ok status: <audio src=...>]
expected: NOTRUN
[ORB should block opaque response with non-ok status: <video src=...>]
expected: NOTRUN
[ORB should block opaque response with non-ok status: <script src=...>]
expected: NOTRUN
expected: FAIL
[status.sub.any.worker.html]

View file

@ -0,0 +1,3 @@
[non-matching-range-response.html]
[Range response out of range of request should succeed]
expected: FAIL

View file

@ -1,4 +1,5 @@
[createImageBitmap-colorSpaceConversion.html]
expected: ERROR
[createImageBitmap from a bitmap HTMLImageElement, and drawImage on the created ImageBitmap with colorSpaceConversion: none]
expected: FAIL

View file

@ -1,5 +1,5 @@
[createImageBitmap-drawImage.html]
expected: TIMEOUT
expected: ERROR
[createImageBitmap from an OffscreenCanvas resized, and drawImage on the created ImageBitmap]
expected: NOTRUN

View file

@ -1,5 +1,5 @@
[createImageBitmap-invalid-args.html]
expected: TIMEOUT
expected: ERROR
[createImageBitmap with a vector HTMLImageElement source and sw set to 0]
expected: FAIL

View file

@ -1,5 +0,0 @@
[audio_loop_base.html]
expected: TIMEOUT
[Check if audio.loop is set to true that expecting the seeking event is fired more than once]
expected: NOTRUN

View file

@ -1,3 +0,0 @@
[audio_loop_seek_to_eos.html]
[seeking to the end of looping audio]
expected: FAIL

View file

@ -1,7 +1,8 @@
[loop-from-ended.tentative.html]
expected: TIMEOUT
[Test looping edge case to verify http://crbug.com/364442.]
expected: FAIL
[play() with loop set to true after playback ended]
expected: FAIL
expected: TIMEOUT

View file

@ -1,4 +1,5 @@
[track-cue-mutable-fragment.html]
expected: TIMEOUT
[Cue fragment is mutable]
expected: FAIL
expected: TIMEOUT

View file

@ -1,4 +1,5 @@
[track-mode-not-changed-by-new-track.html]
expected: TIMEOUT
[A track appended after the initial track configuration does not change other tracks]
expected: FAIL
expected: TIMEOUT