Truly independent web browser
LibWeb: Navigate for a declarative refresh from a task
Andreas Kling2d1ce2d53a02
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex e1858a604a9..66c1a65f8ca 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -7761,14 +7761,19 @@ void Document::shared_declarative_refresh_steps(Utf16View input, GC::Ptr<HTML::H// flag set, then navigate document's node navigable to urlRecord using document, with historyHandling set to// "replace".m_active_refresh_timer = Core::Timer::create_single_shot(AK::Duration::from_seconds(time), [this, has_meta_element = !!meta_element, url_record = move(url_record)]() {- if (has_meta_element && has_flag(active_sandboxing_flag_set(), HTML::SandboxingFlagSet::SandboxedAutomaticFeatures))- return;+ // AD-HOC: Navigate from a task, so that the refresh comes after the tasks that "completely finish loading"+ // queued, such as the one that fires the load event at the container, as the refresh is due only+ // after the document has completely loaded.+ HTML::queue_global_task(HTML::Task::Source::DOMManipulation, relevant_global_object(*this), GC::create_function(heap(), [document = GC::Ref { *this }, has_meta_element, url_record] {+ if (has_meta_element && has_flag(document->active_sandboxing_flag_set(), HTML::SandboxingFlagSet::SandboxedAutomaticFeatures))+ return;- auto navigable = this->navigable();- if (!navigable || navigable->has_been_destroyed())- return;+ auto navigable = document->navigable();+ if (!navigable || navigable->has_been_destroyed())+ return;- MUST(navigable->navigate({ .url = url_record, .source_document = *this, .history_handling = HTML::NavigationHistoryBehavior::Replace }));+ MUST(navigable->navigate({ .url = url_record, .source_document = document, .history_handling = HTML::NavigationHistoryBehavior::Replace }));+ }));});// For the purposes of the previous paragraph, a refresh is said to have come due as soon as the later of thediff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 161af90467d..83c6d4baeaf 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -378,6 +378,7 @@ Text/input/wpt-import/navigation-api/navigation-methods/return-value/reload-inteText/input/wpt-import/navigation-api/navigation-methods/return-value/reload-intercept.htmlText/input/wpt-import/navigation-api/navigation-methods/return-value/reload-preventDefault.htmlText/input/wpt-import/navigation-api/navigation-methods/navigate-same-document.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-meta-refresh.htmlText/input/wpt-import/navigation-api/navigate-event/navigate-multiple-history-pushState.htmlText/input/wpt-import/navigation-api/navigate-event/navigate-destination-getState-back-forward.htmlText/input/wpt-import/navigation-api/navigate-event/defaultPrevented-navigation-preempted.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-meta-refresh.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-meta-refresh.txtnew file mode 100644index 00000000000..7a000482488--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-meta-refresh.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail <meta> refresh fires navigate event\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-meta-refresh.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-meta-refresh.htmlnew file mode 100644index 00000000000..a7d7a8a9432--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-meta-refresh.html@@ -0,0 +1,28 @@+<!doctype html>+<head>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<iframe id="i" src="resources/meta-refresh.html"></iframe>+</head>+<script>+async_test(t => {+ i.onload = t.step_func(() => {+ i.contentWindow.navigation.onnavigate = t.step_func_done(e => {+ assert_equals(e.navigationType, "reload");+ assert_true(e.cancelable);+ assert_true(e.canIntercept);+ assert_false(e.userInitiated);+ assert_false(e.hashChange);+ assert_equals(e.downloadRequest, null);+ assert_equals(e.destination.url, i.contentWindow.location.href);+ assert_false(e.destination.sameDocument);+ assert_equals(e.destination.key, "");+ assert_equals(e.destination.id, "");+ assert_equals(e.destination.index, -1);+ assert_equals(e.formData, null);+ assert_equals(e.sourceElement, null);+ e.preventDefault();+ });+ });+}, "<meta> refresh fires navigate event");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/resources/meta-refresh.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/resources/meta-refresh.htmlnew file mode 100644index 00000000000..04df0353459--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/resources/meta-refresh.html@@ -0,0 +1,4 @@+<head>+<meta http-equiv="refresh" content="0">+</head>+<body></body>