Truly independent web browser
LibWeb: Honor force-load-at-top
Sam Atkins10b528286dd7
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 97f40f19d4b..5413021a700 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -7312,10 +7312,15 @@ void Document::update_for_history_step_application(NonnullRefPtr<HTML::SessionHi// 4. Set document's history object's length to scriptHistoryLength.history()->m_length = script_history_length;- // 5. Let navigation be history's relevant global object's navigation API.+ // https://wicg.github.io/scroll-to-text-fragment/#restricting-scroll-on-load+ // 5. Let scrollingBlockedInNewDocument be the result of getting the policy value for+ // force-load-at-top for document.+ auto const scrolling_blocked_in_new_document = policy_container()->force_load_at_top;++ // 6. Let navigation be history's relevant global object's navigation API.auto navigation = HTML::relevant_window(*this).navigation();- // 6. If documentsEntryChanged is true, then:+ // 7. If documentsEntryChanged is true, then:// NOTE: documentsEntryChanged can be false for one of two reasons: either we are restoring from bfcache,// or we are asynchronously finishing up a synchronous navigation which already synchronously set document's latest entry.// The doNotReactivate argument distinguishes between these two cases.@@ -7374,7 +7379,7 @@ void Document::update_for_history_step_application(NonnullRefPtr<HTML::SessionHi// 4. Restore persisted state given entry.if (auto navigable = this->navigable())- navigable->restore_persisted_state_from_session_history_entry(*entry);+ navigable->restore_persisted_state_from_session_history_entry(*entry, false);// 5. If oldURL's fragment is not equal to entry's URL's fragment, then queue a global task on the DOM manipulation task source// given document's relevant global object to fire an event named hashchange at document's relevant global object,@@ -7399,8 +7404,9 @@ void Document::update_for_history_step_application(NonnullRefPtr<HTML::SessionHi// 2. Restore persisted state given entry.if (auto navigable = this->navigable()) {- navigable->restore_persisted_state_from_session_history_entry(*entry);- navigable->schedule_persisted_state_restoration_retry(*entry);+ navigable->restore_persisted_state_from_session_history_entry(*entry, scrolling_blocked_in_new_document);+ if (!scrolling_blocked_in_new_document)+ navigable->schedule_persisted_state_restoration_retry(*entry);}// 3. Initialize the navigation API entries for a new document given navigation, entriesForNavigationAPI, and entry.@@ -7408,7 +7414,7 @@ void Document::update_for_history_step_application(NonnullRefPtr<HTML::SessionHi}}- // 7. If all the following are true:+ // 8. If all the following are true:// - previousEntryForActivation is given;// - navigationType is non-null; and// - navigationType is "reload" or previousEntryForActivation's document is not document,@@ -7452,20 +7458,21 @@ void Document::update_for_history_step_application(NonnullRefPtr<HTML::SessionHi}}- // 8. If documentIsNew is true, then:+ // 9. If documentIsNew is true, then:if (document_is_new) {// FIXME: 1. Assert: document's during-loading navigation ID for WebDriver BiDi is not null.// FIXME: 2. Invoke WebDriver BiDi navigation committed with navigable and a new WebDriver BiDi navigation// status whose id is document's during-loading navigation ID for WebDriver BiDi, status is "committed", and url is document's URL- // 3. Try to scroll to the fragment for document.- try_to_scroll_to_the_fragment(allow_text_directive_scroll);+ // 3. If scrollingBlockedInNewDocument is false, try to scroll to the fragment for document.+ if (!scrolling_blocked_in_new_document)+ try_to_scroll_to_the_fragment(allow_text_directive_scroll);// 4. At this point scripts may run for the newly-created document document.set_ready_to_run_scripts();}- // 9. Otherwise, if documentsEntryChanged is false and doNotReactivate is false, then:+ // 10. Otherwise, if documentsEntryChanged is false and doNotReactivate is false, then:// NOTE: This is for bfcache restorationif (!documents_entry_changed && !do_not_reactivate) {// FIXME: 1. Assert: entriesForNavigationAPI is given.diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex f28c69a7284..0c9da4717b1 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -1303,14 +1303,15 @@ void LocalNavigable::save_persisted_state_to_active_session_history_entry()}// https://html.spec.whatwg.org/multipage/browsing-the-web.html#restore-persisted-user-state-void LocalNavigable::restore_persisted_state_from_session_history_entry(SessionHistoryEntry const& entry)+// https://wicg.github.io/scroll-to-text-fragment/#restricting-scroll-on-load+void LocalNavigable::restore_persisted_state_from_session_history_entry(SessionHistoryEntry const& entry, bool suppress_scrolling){m_pending_persisted_state_restoration.clear();- // 1. If entry's scroll restoration mode is "auto", and entry's document's relevant global object's navigation- // API's suppress normal scroll restoration during ongoing navigation is false, then restore scroll position- // data given entry.- if (entry.scroll_restoration_mode() == ScrollRestorationMode::Auto) {+ // 1. If entry's scroll restoration mode is "auto", suppressScrolling is false, and entry's+ // document's relevant global object's navigation API's suppress normal scroll restoration+ // during ongoing navigation is false, then restore scroll position data given entry.+ if (entry.scroll_restoration_mode() == ScrollRestorationMode::Auto && !suppress_scrolling) {if (auto window = active_window()) {if (!window->navigation()->suppress_normal_scroll_restoration_during_ongoing_navigation()) {restore_scroll_position_data(entry);@@ -1353,7 +1354,7 @@ void LocalNavigable::restore_pending_persisted_state_for_completed_document(GC::auto document_state = entry->document_state();if (!document_state || document_state->cross_process_id() != restoration.document_state_id)return;- restore_persisted_state_from_session_history_entry(*entry);+ restore_persisted_state_from_session_history_entry(*entry, false);}// https://html.spec.whatwg.org/multipage/browsing-the-web.html#restore-scroll-position-datadiff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.hindex 336e54a15ce..23f10ca28e2 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.h+++ b/Libraries/LibWeb/HTML/LocalNavigable.h@@ -156,7 +156,7 @@ public:HostedNavigableState hosted_state() const;void save_persisted_state_to_active_session_history_entry();- void restore_persisted_state_from_session_history_entry(SessionHistoryEntry const&);+ void restore_persisted_state_from_session_history_entry(SessionHistoryEntry const&, bool suppress_scrolling);void schedule_persisted_state_restoration_retry(SessionHistoryEntry const&);void restore_pending_persisted_state_for_completed_document(GC::Ref<DOM::Document>);void restore_scroll_position_data(SessionHistoryEntry const&);diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cppindex 1adf2b94c33..99160a0a835 100644--- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp+++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp@@ -51,6 +51,7 @@#include <LibWeb/HTML/Parser/HTMLToken.h>#include <LibWeb/HTML/Parser/ParserScriptingMode.h>#include <LibWeb/HTML/Parser/SpeculativeHTMLParser.h>+#include <LibWeb/HTML/PolicyContainers.h>#include <LibWeb/HTML/Scripting/Environments.h>#include <LibWeb/HTML/Scripting/ExceptionReporter.h>#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>@@ -819,7 +820,10 @@ void HTMLParserEndState::advance_to_dom_content_loaded_phase()// so only do this if there is an actual fragment to avoid resetting the scroll position unexpectedly.// Spec bug: https://github.com/whatwg/html/issues/10914auto indicated_part = m_document->determine_the_indicated_part();- if (indicated_part.has<DOM::Element*>() && indicated_part.get<DOM::Element*>() != nullptr) {+ // https://wicg.github.io/scroll-to-text-fragment/#restricting-scroll-on-load+ // If scrollingBlockedInNewDocument is false, try to scroll to the fragment for document.+ if (!m_document->policy_container()->force_load_at_top+ && indicated_part.has<DOM::Element*>() && indicated_part.get<DOM::Element*>() != nullptr) {m_document->scroll_to_the_fragment();}diff --git a/Libraries/LibWeb/HTML/PolicyContainers.cpp b/Libraries/LibWeb/HTML/PolicyContainers.cppindex d53f693af19..87c0d65ba87 100644--- a/Libraries/LibWeb/HTML/PolicyContainers.cpp+++ b/Libraries/LibWeb/HTML/PolicyContainers.cpp@@ -5,6 +5,7 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <AK/GenericLexer.h>#include <LibGC/Heap.h>#include <LibURL/URL.h>#include <LibWeb/ContentSecurityPolicy/Policy.h>@@ -59,6 +60,72 @@ GC::Ref<PolicyContainer> create_a_policy_container_from_a_fetch_response(GC::Refif (parsed_referrer_policy != ReferrerPolicy::ReferrerPolicy::EmptyString)result->referrer_policy = parsed_referrer_policy;+ // https://wicg.github.io/scroll-to-text-fragment/#document-policy-integration+ // This specification defines a configuration point in Document Policy with name+ // "force-load-at-top". Its type is boolean with default value false.+ if (auto document_policy = response->header_list()->get("Document-Policy"sv); document_policy.has_value()) {+ // https://www.rfc-editor.org/rfc/rfc8941.html#name-parsing-a-dictionary+ // Parse this as a Structured Fields dictionary so commas inside strings or inner lists do+ // not accidentally create a force-load-at-top member. LibHTTP does not yet have a general+ // Structured Fields parser, so keep the member splitting local to this policy lookup.+ GenericLexer lexer { document_policy->view() };+ while (!lexer.is_eof()) {+ lexer.consume_while([](char code_unit) { return code_unit == ' ' || code_unit == '\t'; });+ auto const member_start = lexer.tell();+ auto member_end = member_start;+ bool inside_string = false;+ bool escaped = false;+ size_t inner_list_depth = 0;+ while (!lexer.is_eof()) {+ auto const code_unit = lexer.consume();+ if (inside_string) {+ if (escaped) {+ escaped = false;+ } else if (code_unit == '\\') {+ escaped = true;+ } else if (code_unit == '"') {+ inside_string = false;+ }+ } else if (code_unit == '"') {+ inside_string = true;+ } else if (code_unit == '(') {+ ++inner_list_depth;+ } else if (code_unit == ')' && inner_list_depth > 0) {+ --inner_list_depth;+ } else if (code_unit == ',' && inner_list_depth == 0) {+ member_end = lexer.tell() - 1;+ break;+ }+ member_end = lexer.tell();+ }++ auto member = document_policy->view().substring_view(member_start, member_end - member_start).trim_whitespace();+ GenericLexer member_lexer { member };+ auto const key = member_lexer.consume_while([](char code_unit) {+ return is_ascii_lower_alpha(code_unit) || is_ascii_digit(code_unit) || first_is_one_of(code_unit, '_', '-', '.', '*');+ });+ if (key != "force-load-at-top"sv)+ continue;++ // https://www.rfc-editor.org/rfc/rfc8941.html#name-dictionaries+ // A dictionary member with no value has the value Boolean true.+ if (member_lexer.is_eof() || member_lexer.next_is(';')) {+ result->force_load_at_top = true;+ continue;+ }++ if (!member_lexer.consume_specific("=?"sv) || member_lexer.is_eof())+ continue;+ auto const value = member_lexer.consume();+ if (!member_lexer.is_eof() && !member_lexer.next_is(';'))+ continue;+ if (value == '1')+ result->force_load_at_top = true;+ else if (value == '0')+ result->force_load_at_top = false;+ }+ }+// FIXME: 6. Parse Integrity-Policy headers with response and result.// 7. Return result.@@ -73,6 +140,7 @@ GC::Ref<PolicyContainer> create_a_policy_container_from_serialized_policy_contairesult->csp_list = ContentSecurityPolicy::PolicyList::create(heap, serialized_policy_container.csp_list);result->embedder_policy = serialized_policy_container.embedder_policy;result->referrer_policy = serialized_policy_container.referrer_policy;+ result->force_load_at_top = serialized_policy_container.force_load_at_top;return result;}@@ -95,6 +163,11 @@ GC::Ref<PolicyContainer> PolicyContainer::clone(GC::Heap& heap) const// 5. Set clone's integrity policy to a copy of policyContainer's integrity policy.clone->integrity_policy = integrity_policy;+ // https://wicg.github.io/scroll-to-text-fragment/#document-policy-integration+ // This specification defines a configuration point in Document Policy with name+ // "force-load-at-top".+ clone->force_load_at_top = force_load_at_top;+// 6. Return clone.return clone;}@@ -105,6 +178,7 @@ SerializedPolicyContainer PolicyContainer::serialize() const.csp_list = csp_list->serialize(),.embedder_policy = embedder_policy,.referrer_policy = referrer_policy,+ .force_load_at_top = force_load_at_top,};}diff --git a/Libraries/LibWeb/HTML/PolicyContainers.h b/Libraries/LibWeb/HTML/PolicyContainers.hindex 2fea7f30767..6a4bca83b2b 100644--- a/Libraries/LibWeb/HTML/PolicyContainers.h+++ b/Libraries/LibWeb/HTML/PolicyContainers.h@@ -56,6 +56,11 @@ public:// A report only integrity policy, which is an integrity policy, initially a new integrity policy.IntegrityPolicy report_only_integrity_policy {};+ // https://wicg.github.io/scroll-to-text-fragment/#document-policy-integration+ // This specification defines a configuration point in Document Policy with name+ // "force-load-at-top". Its type is boolean with default value false.+ bool force_load_at_top { false };+[[nodiscard]] GC::Ref<PolicyContainer> clone(GC::Heap&) const;[[nodiscard]] SerializedPolicyContainer serialize() const;diff --git a/Libraries/LibWebCommon/HTML/SerializedPolicyContainer.cpp b/Libraries/LibWebCommon/HTML/SerializedPolicyContainer.cppindex 31d3abe91c7..41f58987f4b 100644--- a/Libraries/LibWebCommon/HTML/SerializedPolicyContainer.cpp+++ b/Libraries/LibWebCommon/HTML/SerializedPolicyContainer.cpp@@ -16,6 +16,7 @@ ErrorOr<void> encode(Encoder& encoder, Web::HTML::SerializedPolicyContainer consTRY(encoder.encode(serialized_policy_container.csp_list));TRY(encoder.encode(serialized_policy_container.embedder_policy));TRY(encoder.encode(serialized_policy_container.referrer_policy));+ TRY(encoder.encode(serialized_policy_container.force_load_at_top));return {};}@@ -28,6 +29,7 @@ ErrorOr<Web::HTML::SerializedPolicyContainer> decode(Decoder& decoder)serialized_policy_container.csp_list = TRY(decoder.decode<Vector<Web::ContentSecurityPolicy::SerializedPolicy>>());serialized_policy_container.embedder_policy = TRY(decoder.decode<Web::HTML::EmbedderPolicy>());serialized_policy_container.referrer_policy = TRY(decoder.decode<Web::ReferrerPolicy::ReferrerPolicy>());+ serialized_policy_container.force_load_at_top = TRY(decoder.decode<bool>());return serialized_policy_container;}diff --git a/Libraries/LibWebCommon/HTML/SerializedPolicyContainer.h b/Libraries/LibWebCommon/HTML/SerializedPolicyContainer.hindex bbd02897745..cb11037c140 100644--- a/Libraries/LibWebCommon/HTML/SerializedPolicyContainer.h+++ b/Libraries/LibWebCommon/HTML/SerializedPolicyContainer.h@@ -17,6 +17,7 @@ struct SerializedPolicyContainer {Vector<ContentSecurityPolicy::SerializedPolicy> csp_list;EmbedderPolicy embedder_policy;ReferrerPolicy::ReferrerPolicy referrer_policy;+ bool force_load_at_top { false };};}diff --git a/Libraries/LibWebView/SessionHistorySnapshotStorage.cpp b/Libraries/LibWebView/SessionHistorySnapshotStorage.cppindex e3868826999..d9fb6d0e3b0 100644--- a/Libraries/LibWebView/SessionHistorySnapshotStorage.cpp+++ b/Libraries/LibWebView/SessionHistorySnapshotStorage.cpp@@ -574,11 +574,11 @@ ErrorOr<SessionHistorySnapshotStatements> prepare_session_history_snapshot_stateINSERT INTO SessionPolicyContainers (history_id, entry_ordinal, referrer_policy, embedder_policy_value,embedder_policy_report_only_value, embedder_policy_reporting_endpoint,- embedder_policy_report_only_reporting_endpoint)+ embedder_policy_report_only_reporting_endpoint, force_load_at_top)VALUES (:history_id, :entry_ordinal, :referrer_policy, :embedder_policy_value,:embedder_policy_report_only_value, :embedder_policy_reporting_endpoint,- :embedder_policy_report_only_reporting_endpoint)+ :embedder_policy_report_only_reporting_endpoint, :force_load_at_top)RETURNING id;)#"sv)),.insert_csp_policy = TRY(database.prepare_statement(R"#(@@ -626,7 +626,8 @@ ErrorOr<SessionHistorySnapshotStatements> prepare_session_history_snapshot_state.select_policy_containers = TRY(database.prepare_statement(R"#(SELECT SessionPolicyContainers.id AS id, history_id, entry_ordinal, referrer_policy,embedder_policy_value, embedder_policy_report_only_value,- embedder_policy_reporting_endpoint, embedder_policy_report_only_reporting_endpoint+ embedder_policy_reporting_endpoint, embedder_policy_report_only_reporting_endpoint,+ force_load_at_topFROM SessionPolicyContainersINNER JOIN SessionHistories ON SessionPolicyContainers.history_id = SessionHistories.idWHERE SessionHistories.tab_id = :tab_id;@@ -692,6 +693,7 @@ static ErrorOr<void> store_policy_container(Database::Database& database, SessioTRY(bind("embedder_policy_report_only_value"sv, encode_embedder_policy_value(container.embedder_policy.report_only_value)));TRY(bind("embedder_policy_reporting_endpoint"sv, container.embedder_policy.reporting_endpoint));TRY(bind("embedder_policy_report_only_reporting_endpoint"sv, container.embedder_policy.report_only_reporting_endpoint));+ TRY(bind("force_load_at_top"sv, container.force_load_at_top));return {};}));@@ -933,6 +935,7 @@ struct PolicyContainerRow {i64 embedder_policy_report_only_value { 0 };Utf16String embedder_policy_reporting_endpoint;Utf16String embedder_policy_report_only_reporting_endpoint;+ bool force_load_at_top { false };};struct CspPolicyRow {@@ -1057,6 +1060,7 @@ static ErrorOr<Web::HTML::SerializedPolicyContainer> build_policy_container(Poli.report_only_reporting_endpoint = row.embedder_policy_report_only_reporting_endpoint,},.referrer_policy = TRY(decode_referrer_policy(row.referrer_policy)),+ .force_load_at_top = row.force_load_at_top,};}@@ -1076,6 +1080,7 @@ static ErrorOr<HashMap<i64, HashMap<i64, Web::HTML::SerializedPolicyContainer>>>row.embedder_policy_report_only_value = TRY(result_row.read_integer<i64>("embedder_policy_report_only_value"sv));row.embedder_policy_reporting_endpoint = TRY(read_snapshot_utf16_text(result_row, "embedder_policy_reporting_endpoint"sv, totals));row.embedder_policy_report_only_reporting_endpoint = TRY(read_snapshot_utf16_text(result_row, "embedder_policy_report_only_reporting_endpoint"sv, totals));+ row.force_load_at_top = TRY(result_row.read_bool("force_load_at_top"sv));return row;}));diff --git a/Libraries/LibWebView/SessionStore.cpp b/Libraries/LibWebView/SessionStore.cppindex 577d7b20abc..ba4f8293525 100644--- a/Libraries/LibWebView/SessionStore.cpp+++ b/Libraries/LibWebView/SessionStore.cpp@@ -19,6 +19,8 @@ namespace WebView {static constexpr u32 SESSIONS_SCHEMA_BASELINE_VERSION = 1u;static constexpr u32 SESSIONS_SCHEMA_USER_AGENT_INITIATED_VERSION = 2u;+static constexpr u32 SESSIONS_SCHEMA_DIRECTIVE_STATE_VERSION = 2u;+static constexpr u32 SESSIONS_SCHEMA_DOCUMENT_POLICY_VERSION = 4u;static constexpr u32 MAX_CLOSED_TABS = 25;static constexpr u32 MAX_CLOSED_WINDOWS = 5;static constexpr size_t MAX_ACTIVE_URL_BYTES = 8uz * 1024 * 1024;@@ -198,6 +200,20 @@ ErrorOr<Database::MigrationOutcome> SessionStore::PersistedStorage::migrate_scheALTER TABLE SessionEntries ADD COLUMN user_agent_initiated INTEGER NOT NULL DEFAULT 0;)#"sv,},+ {+ .version = SESSIONS_SCHEMA_DIRECTIVE_STATE_VERSION,+ .sql = R"#(+ ALTER TABLE SessionEntries ADD COLUMN directive_state_namespace_id INTEGER NOT NULL DEFAULT 0;+ ALTER TABLE SessionEntries ADD COLUMN directive_state_local_id INTEGER NOT NULL DEFAULT 0;+ ALTER TABLE SessionEntries ADD COLUMN directive_state_value TEXT;+ )#"sv,+ },+ {+ .version = SESSIONS_SCHEMA_DOCUMENT_POLICY_VERSION,+ .sql = R"#(+ ALTER TABLE SessionPolicyContainers ADD COLUMN force_load_at_top INTEGER NOT NULL DEFAULT 0;+ )#"sv,+ },});return database.migrate("Sessions"sv, migrations, mode);@@ -1033,7 +1049,8 @@ static bool serialized_policy_containers_match(Web::HTML::SerializedPolicyContai{return serialized_policies_match(a.csp_list, b.csp_list)&& embedder_policies_match(a.embedder_policy, b.embedder_policy)- && a.referrer_policy == b.referrer_policy;+ && a.referrer_policy == b.referrer_policy+ && a.force_load_at_top == b.force_load_at_top;}static bool history_policy_containers_match(Variant<Web::HTML::SerializedPolicyContainer, Web::HTML::DocumentStateClient> const& a, Variant<Web::HTML::SerializedPolicyContainer, Web::HTML::DocumentStateClient> const& b)diff --git a/Tests/LibWeb/Text/expected/scroll-to-text-fragment-force-load-at-top-structured-true.txt b/Tests/LibWeb/Text/expected/scroll-to-text-fragment-force-load-at-top-structured-true.txtnew file mode 100644index 00000000000..4cc7e9f1bfb--- /dev/null+++ b/Tests/LibWeb/Text/expected/scroll-to-text-fragment-force-load-at-top-structured-true.txt@@ -0,0 +1 @@+Scrolled with force-load-at-top=?1: falsediff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-to-text-fragment/force-load-at-top.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-to-text-fragment/force-load-at-top.txtindex 776d13995a3..80d33e957af 100644--- a/Tests/LibWeb/Text/expected/wpt-import/scroll-to-text-fragment/force-load-at-top.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-to-text-fragment/force-load-at-top.txt@@ -2,12 +2,12 @@ Harness status: OKFound 8 tests-4 Pass-4 Fail+7 Pass+1 FailPass force-load-at-top must block scroll on load from text fragment.-Fail force-load-at-top must block scroll on load from text fragment with element fallback.-Fail force-load-at-top must block scroll on load from element fragment.-Fail force-load-at-top must block scroll on load from history scroll restoration.+Pass force-load-at-top must block scroll on load from text fragment with element fallback.+Pass force-load-at-top must block scroll on load from element fragment.+Pass force-load-at-top must block scroll on load from history scroll restoration.Fail no-force-load-at-top must not block scroll on load from text fragment.Pass no-force-load-at-top must not block scroll on load from text fragment with element fallback.Pass no-force-load-at-top must not block scroll on load from element fragment.diff --git a/Tests/LibWeb/Text/input/scroll-to-text-fragment-force-load-at-top-structured-true.html b/Tests/LibWeb/Text/input/scroll-to-text-fragment-force-load-at-top-structured-true.htmlnew file mode 100644index 00000000000..0fe99f8749f--- /dev/null+++ b/Tests/LibWeb/Text/input/scroll-to-text-fragment-force-load-at-top-structured-true.html@@ -0,0 +1,25 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script>+ asyncTest(async () => {+ const server = new HTTPTestServer(httpTestServer().baseURL);+ const targetURL = await server.createEcho("GET", "/scroll-to-text-fragment-force-load-at-top-structured-true", {+ status: 200,+ headers: {+ "Content-Type": "text/html",+ "Document-Policy": "force-load-at-top=?1",+ },+ body: `<!DOCTYPE html>+ <div style="height: 2000px"></div>+ <div id="target">target</div>+ <script>+ addEventListener("load", () => {+ requestAnimationFrame(() => requestAnimationFrame(() => {+ internals.signalTestIsDone(\`Scrolled with force-load-at-top=?1: \${scrollY !== 0}\\n\`);+ }));+ });+ <\/script>`,+ });+ location.href = `${targetURL}#target`;+ });+</script>diff --git a/Tests/LibWebView/TestSessionHistorySnapshotStorage.cpp b/Tests/LibWebView/TestSessionHistorySnapshotStorage.cppindex 5cd1e212f44..ff288cbc447 100644--- a/Tests/LibWebView/TestSessionHistorySnapshotStorage.cpp+++ b/Tests/LibWebView/TestSessionHistorySnapshotStorage.cpp@@ -328,7 +328,8 @@ static void insert_minimal_entry(Database::Database& database, SessionHistorySnadatabase.execute_statement(statements.insert_entry, {},history_id, entry_ordinal, static_cast<i64>(0), MUST(String::from_utf8("https://x.example/"sv)), static_cast<i64>(1), document_state_id,ByteString {}, ByteString {}, String {}, String {},- static_cast<i64>(0), absent_scroll, absent_scroll,+ static_cast<i64>(0), static_cast<i64>(0), static_cast<i64>(0), absent_text,+ absent_scroll, absent_scroll,static_cast<i64>(0), absent_text, absent_text, absent_text, absent_port, absent_text,static_cast<i64>(0), absent_text, absent_text, absent_text, absent_port, absent_text,static_cast<i64>(0), absent_text, static_cast<i64>(0),@@ -416,6 +417,7 @@ static Web::HTML::SerializedPolicyContainer make_policy_container().report_only_reporting_endpoint = "coep-report"_utf16,},.referrer_policy = Web::ReferrerPolicy::ReferrerPolicy::NoReferrer,+ .force_load_at_top = true,};}@@ -440,6 +442,7 @@ static void expect_policy_containers_equal(Web::HTML::SerializedPolicyContainerEXPECT_EQ(restored.embedder_policy.reporting_endpoint, original.embedder_policy.reporting_endpoint);EXPECT_EQ(restored.embedder_policy.report_only_reporting_endpoint, original.embedder_policy.report_only_reporting_endpoint);EXPECT(restored.referrer_policy == original.referrer_policy);+ EXPECT_EQ(restored.force_load_at_top, original.force_load_at_top);}TEST_CASE(snapshot_round_trips_flat_entries)@@ -530,12 +533,16 @@ TEST_CASE(snapshot_entries_saved_before_the_user_agent_initiated_column_load_as_// Take the database back to the baseline schema, keeping the entry's row.TRY_OR_FAIL(database->execute_raw(R"#(+ ALTER TABLE SessionPolicyContainers DROP COLUMN force_load_at_top;+ ALTER TABLE SessionEntries DROP COLUMN directive_state_value;+ ALTER TABLE SessionEntries DROP COLUMN directive_state_local_id;+ ALTER TABLE SessionEntries DROP COLUMN directive_state_namespace_id;ALTER TABLE SessionEntries DROP COLUMN user_agent_initiated;UPDATE SchemaVersions SET version = 1 WHERE store = 'Sessions';)#"sv));auto migrated_statements = prepare_snapshot_tables(*database);- EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 2u });+ EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 4u });auto loaded = TRY_OR_FAIL(load_session_history_snapshot(*database, migrated_statements, 42, 0));EXPECT_EQ(loaded.entries.size(), 1uz);diff --git a/Tests/LibWebView/TestSessionStore.cpp b/Tests/LibWebView/TestSessionStore.cppindex fae3788ac5a..315c7f50fc2 100644--- a/Tests/LibWebView/TestSessionStore.cpp+++ b/Tests/LibWebView/TestSessionStore.cpp@@ -75,7 +75,7 @@ TEST_CASE(fresh_database_migrates_to_the_latest_schema)for (auto table : { "Sessions"sv, "SessionTabs"sv, "SessionUsedSteps"sv, "SessionHistories"sv, "SessionNestedHistories"sv, "SessionEntries"sv })EXPECT(TRY_OR_FAIL(database->table_exists(table)));- EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 2u });+ EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 4u });}TEST_CASE(deleting_a_session_cascades_through_its_tabs)