mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 10:09:14 +00:00
LibWeb: Fire error event if HTMLTrackElement src is empty on load
Previously, we would hang while waiting for the track to load.
This commit is contained in:
parent
4d1329e0ea
commit
6aeb3e8839
Notes:
github-actions[bot]
2025-03-01 13:26:09 +00:00
Author: https://github.com/tcl3
Commit: 6aeb3e8839
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3742
Reviewed-by: https://github.com/trflynn89 ✅
3 changed files with 39 additions and 5 deletions
|
@ -180,6 +180,13 @@ void HTMLTrackElement::start_the_track_processing_model_parallel_steps(JS::Realm
|
||||||
|
|
||||||
// 9. End the synchronous section, continuing the remaining steps in parallel.
|
// 9. End the synchronous section, continuing the remaining steps in parallel.
|
||||||
|
|
||||||
|
auto fire_error_event = [&]() {
|
||||||
|
queue_an_element_task(Task::Source::DOMManipulation, [this, &realm]() {
|
||||||
|
m_track->set_readiness_state(TextTrack::ReadinessState::FailedToLoad);
|
||||||
|
dispatch_event(DOM::Event::create(realm, HTML::EventNames::error));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// 10. If URL is not the empty string, then:
|
// 10. If URL is not the empty string, then:
|
||||||
if (!url.is_empty()) {
|
if (!url.is_empty()) {
|
||||||
// 1. Let request be the result of creating a potential-CORS request given URL, "track", and corsAttributeState,
|
// 1. Let request be the result of creating a potential-CORS request given URL, "track", and corsAttributeState,
|
||||||
|
@ -193,17 +200,14 @@ void HTMLTrackElement::start_the_track_processing_model_parallel_steps(JS::Realm
|
||||||
request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Track);
|
request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Track);
|
||||||
|
|
||||||
Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};
|
Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};
|
||||||
fetch_algorithms_input.process_response_consume_body = [this, &realm](auto response, auto body_bytes) {
|
fetch_algorithms_input.process_response_consume_body = [this, &realm, &fire_error_event](auto response, auto body_bytes) {
|
||||||
m_loading = false;
|
m_loading = false;
|
||||||
|
|
||||||
// If fetching fails for any reason (network error, the server returns an error code, CORS fails, etc.),
|
// If fetching fails for any reason (network error, the server returns an error code, CORS fails, etc.),
|
||||||
// or if URL is the empty string, then queue an element task on the DOM manipulation task source given the media element
|
// or if URL is the empty string, then queue an element task on the DOM manipulation task source given the media element
|
||||||
// to first change the text track readiness state to failed to load and then fire an event named error at the track element.
|
// to first change the text track readiness state to failed to load and then fire an event named error at the track element.
|
||||||
if (!response->url().has_value() || body_bytes.template has<Empty>() || body_bytes.template has<Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag>() || !Fetch::Infrastructure::is_ok_status(response->status()) || response->is_network_error()) {
|
if (!response->url().has_value() || body_bytes.template has<Empty>() || body_bytes.template has<Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag>() || !Fetch::Infrastructure::is_ok_status(response->status()) || response->is_network_error()) {
|
||||||
queue_an_element_task(Task::Source::DOMManipulation, [this, &realm]() {
|
fire_error_event();
|
||||||
m_track->set_readiness_state(TextTrack::ReadinessState::FailedToLoad);
|
|
||||||
dispatch_event(DOM::Event::create(realm, HTML::EventNames::error));
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,6 +236,9 @@ void HTMLTrackElement::start_the_track_processing_model_parallel_steps(JS::Realm
|
||||||
m_fetch_algorithms = Fetch::Infrastructure::FetchAlgorithms::create(vm(), move(fetch_algorithms_input));
|
m_fetch_algorithms = Fetch::Infrastructure::FetchAlgorithms::create(vm(), move(fetch_algorithms_input));
|
||||||
m_fetch_controller = MUST(Fetch::Fetching::fetch(realm, request, *m_fetch_algorithms));
|
m_fetch_controller = MUST(Fetch::Fetching::fetch(realm, request, *m_fetch_algorithms));
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
fire_error_event();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 11. Wait until the text track readiness state is no longer set to loading.
|
// 11. Wait until the text track readiness state is no longer set to loading.
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 1 tests
|
||||||
|
|
||||||
|
1 Pass
|
||||||
|
Pass Setting HTMLTrackElement.src to the empty string fires 'error' and sets readyState to ERROR
|
|
@ -0,0 +1,21 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<title>Setting HTMLTrackElement.src to the empty string fires 'error' and sets readyState to ERROR</title>
|
||||||
|
<link rel="help" href="https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks">
|
||||||
|
<script src="../../../../../../resources/testharness.js"></script>
|
||||||
|
<script src="../../../../../../resources/testharnessreport.js"></script>
|
||||||
|
<video></video>
|
||||||
|
<script>
|
||||||
|
async_test(t => {
|
||||||
|
let track = document.createElement("track");
|
||||||
|
track.src = '';
|
||||||
|
track.default = true;
|
||||||
|
track.onerror = t.step_func_done(() => {
|
||||||
|
assert_equals(track.readyState, HTMLTrackElement.ERROR);
|
||||||
|
});
|
||||||
|
track.onload = t.unreached_func('fired load');
|
||||||
|
|
||||||
|
assert_equals(track.readyState, HTMLTrackElement.NONE);
|
||||||
|
|
||||||
|
document.querySelector('video').appendChild(track);
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue