Truly independent web browser
LibWeb: Report failed stylesheet imports through link errors
Andreas Klingeb5fd4451656
diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cppindex a5aebd478b2..4d1899d8d7e 100644--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp@@ -181,7 +181,7 @@ RefPtr<CSS::StyleSheetState> HTMLLinkElement::sheet() constreturn m_loaded_style_sheet;}-void HTMLLinkElement::finished_loading_critical_style_subresources(AnyFailed)+void HTMLLinkElement::finished_loading_critical_style_subresources(AnyFailed any_failed){// NB: The style sheet of an older fetch stays associated until a newer fetch's response is processed. That newer// fetch owns the document load event delayer, so the old sheet's imports must not release it.@@ -194,12 +194,14 @@ void HTMLLinkElement::finished_loading_critical_style_subresources(AnyFailed)if (!fetch_generation.has_value())return;- queue_an_element_task(Task::Source::Networking, [link = GC::Ref { *this }, fetch_generation = *fetch_generation] {+ queue_an_element_task(Task::Source::Networking, [link = GC::Ref { *this }, fetch_generation = *fetch_generation, any_failed] {if (fetch_generation != link->m_current_fetch_generation || !link->m_stylesheet_processing_pending)return;// 2. Fire an event named load at el.- link->dispatch_event(create_event_for_element(*link, HTML::EventNames::load));+ // INTEROP: Other browsers fire error instead when an import failed.+ auto event_name = any_failed == AnyFailed::Yes ? HTML::EventNames::error : HTML::EventNames::load;+ link->dispatch_event(create_event_for_element(*link, event_name));link->finish_processing_stylesheet_resource(fetch_generation);});}@@ -1524,7 +1526,10 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru}// 2. Fire an event named load at el.- link->dispatch_event(create_event_for_element(*link, HTML::EventNames::load));+ // INTEROP: Other browsers fire error instead when an import failed, including before the+ // sheet was associated with the link.+ auto event_name = sheet->loading_state() == CSS::StyleSheetState::LoadingState::Error ? HTML::EventNames::error : HTML::EventNames::load;+ link->dispatch_event(create_event_for_element(*link, event_name));link->finish_processing_stylesheet_resource(fetch_generation);});});diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.txtindex 99d65cf32fa..d21c2c2bb0e 100644--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.txt@@ -2,8 +2,8 @@ Harness status: OKFound 26 tests-18 Pass-8 Fail+24 Pass+2 FailPass Should get an error event for a 404 error.Pass Should get an error event for an unsupported URL.Pass Stylesheet loading using <link> with no Content-Type, same-origin, and no nosniff@@ -19,14 +19,14 @@ Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, andPass Stylesheet loading using <link> with broken Content-Type, cross-origin, and no nosniffPass Stylesheet loading using <link> with broken Content-Type, cross-origin, and nosniffPass Stylesheet loading using @import with no Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with no Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, same-origin, and nosniffFail Stylesheet loading using @import with wrong Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniffPass Stylesheet loading using @import with broken Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, same-origin, and nosniffPass Stylesheet loading using @import with no Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with no Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, cross-origin, and nosniffFail Stylesheet loading using @import with wrong Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniffPass Stylesheet loading using @import with broken Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of file+Pass Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.txtindex c2628512d40..0e42e031c18 100644--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.txt@@ -2,8 +2,8 @@ Harness status: OKFound 24 tests-16 Pass-8 Fail+22 Pass+2 FailPass Stylesheet loading using <link> with no Content-Type, same-origin, and no nosniffPass Stylesheet loading using <link> with no Content-Type, same-origin, and nosniffPass Stylesheet loading using <link> with wrong Content-Type, same-origin, and no nosniff@@ -17,14 +17,14 @@ Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, andPass Stylesheet loading using <link> with broken Content-Type, cross-origin, and no nosniffPass Stylesheet loading using <link> with broken Content-Type, cross-origin, and nosniffPass Stylesheet loading using @import with no Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with no Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, same-origin, and nosniffFail Stylesheet loading using @import with wrong Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniffPass Stylesheet loading using @import with broken Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, same-origin, and nosniffPass Stylesheet loading using @import with no Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with no Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, cross-origin, and nosniffFail Stylesheet loading using @import with wrong Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniffPass Stylesheet loading using @import with broken Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of file+Pass Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txtindex 44d657a96e4..ff42c136c5f 100644--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txt@@ -2,8 +2,8 @@ Harness status: OKFound 24 tests-16 Pass-8 Fail+22 Pass+2 FailPass Stylesheet loading using <link> with no Content-Type, same-origin, and no nosniffPass Stylesheet loading using <link> with no Content-Type, same-origin, and nosniffFail Stylesheet loading using <link> with wrong Content-Type, same-origin, and no nosniff@@ -17,14 +17,14 @@ Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, andPass Stylesheet loading using <link> with broken Content-Type, cross-origin, and no nosniffPass Stylesheet loading using <link> with broken Content-Type, cross-origin, and nosniffPass Stylesheet loading using @import with no Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with no Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, same-origin, and nosniffPass Stylesheet loading using @import with wrong Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniffPass Stylesheet loading using @import with broken Content-Type, same-origin, and no nosniff-Fail Stylesheet loading using @import with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, same-origin, and nosniffPass Stylesheet loading using @import with no Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with no Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, cross-origin, and nosniffFail Stylesheet loading using @import with wrong Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniffPass Stylesheet loading using @import with broken Content-Type, cross-origin, and no nosniff-Fail Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of file+Pass Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of file