Truly independent web browser
LibWeb: Fire `loadeddata` when media loads without the load algorithm
Tim Ledbetter199c4c68a4db
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cppindex 3d7367f3167..f9d23ced127 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp@@ -797,7 +797,7 @@ GC::Ref<TextTrack> HTMLMediaElement::add_text_track(Bindings::TextTrackKind kind// https://html.spec.whatwg.org/multipage/media.html#media-element-load-algorithmWebIDL::ExceptionOr<void> HTMLMediaElement::load_element(){- m_first_data_load_event_since_load_start = true;+ m_has_fired_loadeddata = false;// FIXME: 1. Set this element's is currently stalled to false.@@ -2500,8 +2500,8 @@ void HTMLMediaElement::set_ready_state(ReadyState ready_state)if (old_ready_state == ReadyState::HaveMetadata && ready_state >= ReadyState::HaveCurrentData) {// If this is the first time this occurs for this media element since the load() algorithm was last invoked, the user agent must queue a media// element task given the media element to fire an event named loadeddata at the element.- if (m_first_data_load_event_since_load_start) {- m_first_data_load_event_since_load_start = false;+ if (!m_has_fired_loadeddata) {+ m_has_fired_loadeddata = true;queue_a_media_element_task([](HTMLMediaElement& self) {self.dispatch_event(DOM::Event::create(HTML::relevant_global_object(self), HTML::EventNames::loadeddata));diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.hindex c5363e51c6b..38ef8ec4d35 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.h+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h@@ -361,7 +361,7 @@ private:// https://html.spec.whatwg.org/multipage/media.html#dom-media-readystateReadyState m_ready_state { ReadyState::HaveNothing };- bool m_first_data_load_event_since_load_start { false };+ bool m_has_fired_loadeddata { false };// https://html.spec.whatwg.org/multipage/media.html#dom-media-seekingbool m_seeking { false };diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex d998aa10618..d6bf124ffe6 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -543,6 +543,9 @@ Text/input/wpt-import/content-security-policy/unsafe-eval/eval-scripts-setTimeou; Adds a policy to a same-origin iframe's document.Text/input/wpt-import/content-security-policy/unsafe-eval/eval-scripts-setTimeout-setInterval-policy-added-later.html+; Its meta policy allows script-src *, which a file:// testharness does not match.+Text/input/wpt-import/content-security-policy/media-src/media-src-7_2.html+; scroll-to-text-fragment tests all rely on loading/fetching other pages.Text/input/scroll-to-text-fragment/history.htmlText/input/scroll-to-text-fragment/searchable-text-visibility.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/media-src/media-src-7_2.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/media-src/media-src-7_2.txtnew file mode 100644index 00000000000..0ba5f5bb4d1--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/media-src/media-src-7_2.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 3 tests++3 Pass+Pass In-policy audio src+Pass In-policy audio source element+Pass Should not fire policy violation events\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/media-src/media-src-7_2.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/media-src/media-src-7_2.htmlnew file mode 100644index 00000000000..e4338e21d22--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/media-src/media-src-7_2.html@@ -0,0 +1,48 @@+<!DOCTYPE HTML>+<html>+<head>+ <title>Audio element src attribute must match src list - positive test</title>+ <meta http-equiv="Content-Security-Policy" content="script-src * 'unsafe-inline'; media-src 'self';">+ <script src='../../resources/testharness.js'></script>+ <script src='../../resources/testharnessreport.js'></script>+</head>+<body>+ <h1>Audio element src attribute must match src list - positive test</h1>+ <div id='log'></div>++ <script>+ var src_test = async_test("In-policy audio src");+ var source_test = async_test("In-policy audio source element");+ var t_spv = async_test("Should not fire policy violation events");+ var test_count = 2;+ window.addEventListener("securitypolicyviolation", t_spv.unreached_func("Should not have fired any event"));++ function media_loaded(t) {+ t.done();+ if (--test_count <= 0) {+ t_spv.done();+ }+ }++ function media_error_handler(t) {+ t.step( function () {+ assert_unreached("Media error handler should be triggered for non-allowed domain.");+ });+ t.done();+ }+ </script>++ <audio id="audioObject" width="320" height="240" controls+ onloadeddata="media_loaded(source_test)">+ <source id="audioSourceObject"+ type="audio/ogg"+ onerror="media_error_handler(source_test)"+ src="../../media/sound_5.oga">+ </audio>+ <audio id="audioObject2" width="320" height="240" controls+ onerror="media_error_handler(src_test)"+ onloadeddata="media_loaded(src_test)"+ src="../../media/sound_5.oga">++</body>+</html>