Skip to content

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.cpp
index 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 the
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 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-inte
Text/input/wpt-import/navigation-api/navigation-methods/return-value/reload-intercept.html
Text/input/wpt-import/navigation-api/navigation-methods/return-value/reload-preventDefault.html
Text/input/wpt-import/navigation-api/navigation-methods/navigate-same-document.html
+Text/input/wpt-import/navigation-api/navigate-event/navigate-meta-refresh.html
Text/input/wpt-import/navigation-api/navigate-event/navigate-multiple-history-pushState.html
Text/input/wpt-import/navigation-api/navigate-event/navigate-destination-getState-back-forward.html
Text/input/wpt-import/navigation-api/navigate-event/defaultPrevented-navigation-preempted.html
diff --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.txt
new file mode 100644
index 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 file
diff --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.html
new file mode 100644
index 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.html
new file mode 100644
index 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>