Truly independent web browser
LibWebView: Create a traversable's session history with its first entry
Shannon Booth9ed0f240d633
diff --git a/Libraries/LibWebView/ApplyHistoryStep.cpp b/Libraries/LibWebView/ApplyHistoryStep.cppindex 7f4f97e3429..ee9c9319be8 100644--- a/Libraries/LibWebView/ApplyHistoryStep.cpp+++ b/Libraries/LibWebView/ApplyHistoryStep.cpp@@ -482,14 +482,11 @@ void ApplyHistoryStep::set_current_session_history_step()// See https://github.com/whatwg/html/issues/12576.if (m_generation > m_traversable_state.committed_generation) {// 20. Set traversable's current session history step to targetStep.- auto used_target_step = m_session_history.get_the_used_step(m_target_step);- if (used_target_step.has_value()) {- auto current_step = m_session_history.current_step();- if (!current_step.has_value() || *current_step != *used_target_step)- m_traversable_state.committed_generation = m_generation;- m_session_history.set_current_session_history_step(*used_target_step);- m_committed_step = *used_target_step;- }+ auto used_target_step = m_session_history.get_the_used_step(m_target_step).value();+ if (m_session_history.current_step() != used_target_step)+ m_traversable_state.committed_generation = m_generation;+ m_session_history.set_current_session_history_step(used_target_step);+ m_committed_step = used_target_step;}// 21. Return "applied".diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex 9d32a7c025e..23a951c388e 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -732,10 +732,8 @@ ErrorOr<NonnullRefPtr<WebContentPage>> CanonicalNavigable::obtain_page_to_host_i// A page beginning to host the navigable starts from a document standing in for the current entry's.auto current_entry_descriptor = [&] {- auto current_step = traversable.session_history().current_step();- VERIFY(current_step.has_value());// NB: Until the update for its creation, the navigable's entry is the one initializing it created.- if (auto const* current_entry = traversable.session_history().get_the_target_history_entry(*this, *current_step))+ if (auto const* current_entry = traversable.session_history().get_the_target_history_entry(*this, traversable.session_history().current_step()))return current_entry->descriptor();return active_session_history_entry()->descriptor();};diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex 3d2deeb9948..2b887d03576 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -29,8 +29,9 @@ static Vector<NonnullOwnPtr<CanonicalTraversable>>& user_agent_top_level_traversreturn *set;}-CanonicalTraversable::CanonicalTraversable(Web::HTML::CrossProcessId id)+CanonicalTraversable::CanonicalTraversable(Web::HTML::CrossProcessId id, NonnullRefPtr<CanonicalSessionHistoryEntry> initial_history_entry): CanonicalNavigable(id)+ , m_session_history(move(initial_history_entry)), m_session_storage(StorageJar::create()){}@@ -443,9 +444,7 @@ ErrorOr<NonnullRefPtr<WebContentPage>> CanonicalTraversable::obtain_page_to_hostif (host && display_page && display_page->is_open() && host == &display_page->client())return display_page.release_nonnull();- auto current_step = m_session_history.current_step();- VERIFY(current_step.has_value());- auto const* current_entry = m_session_history.get_the_target_history_entry(*this, *current_step);+ auto const* current_entry = m_session_history.get_the_target_history_entry(*this, m_session_history.current_step());VERIFY(current_entry);auto current_entry_descriptor = current_entry->descriptor();@@ -575,11 +574,8 @@ void CanonicalTraversable::stand_in_for_lost_document(CanonicalNavigable& naviganavigable.did_lose_active_document();if (auto state = navigable.replicated_state(); state.has_value())reporting_page->async_update_remote_navigable(navigable.id(), *state);- auto current_step = m_session_history.current_step();- if (!current_step.has_value())- return;// NB: The canonical session history can still lack the nested history of a newly created navigable.- auto const* current_entry = m_session_history.get_the_target_history_entry(navigable, *current_step);+ auto const* current_entry = m_session_history.get_the_target_history_entry(navigable, m_session_history.current_step());if (!current_entry)return;reporting_page->async_begin_hosting_navigable(navigable.id(), current_entry->descriptor(), system_visibility_state());@@ -754,7 +750,9 @@ CanonicalTraversable& CanonicalTraversable::create_a_new_top_level_traversable(Whistory_entry->document_state->origin = document->origin();// 5. Let traversable be a new traversable navigable.- auto traversable = make<CanonicalTraversable>(id);+ // NB: Its session history entries start out as steps 7-9 leave them.+ history_entry->step = 0;+ auto traversable = make<CanonicalTraversable>(id, history_entry);// 6. Initialize the navigable traversable given documentState.traversable->set_current_session_history_entry(history_entry);@@ -772,10 +770,8 @@ CanonicalTraversable& CanonicalTraversable::create_a_new_top_level_traversable(W// 7. Let initialHistoryEntry be traversable's active session history entry.// 8. Set initialHistoryEntry's step to 0.- history_entry->step = 0;-// 9. Append initialHistoryEntry to traversable's session history entries.- traversable->m_session_history.initialize_with_initial_history_entry(move(history_entry));+ // NB: Done as traversable was created.// 10. If opener is non-null, then legacy-clone a traversable storage shed given opener's top-level traversable and traversable. [STORAGE]if (opener.has_value())@@ -936,12 +932,11 @@ void CanonicalTraversable::reset_session_history_for_testing(Web::HTML::SessionHistoryEntryDescriptor active_entry){abandon_history_operations();- m_session_history.clear();auto entry = MUST(CanonicalSessionHistoryEntry::create_from_descriptor(active_entry));entry->document_state->document = active_document();set_current_session_history_entry(entry);set_active_session_history_entry(entry);- m_session_history.initialize_with_initial_history_entry(move(entry));+ m_session_history = TraversableSessionHistory(move(entry));session_history_changed();}@@ -1116,10 +1111,7 @@ void CanonicalTraversable::traverse_the_history_by_delta(int delta, CheckForCanc// 4. If allSteps[targetStepIndex] does not exist, then abort these steps.// 5. Apply the traverse history step allSteps[targetStepIndex] to traversable, given sourceSnapshotParams,// initiatorToCheck, and userInvolvement.- auto current_step = m_session_history.current_step();- if (!current_step.has_value())- return {};- return used_step_at_delta(m_session_history, *current_step, delta);+ return used_step_at_delta(m_session_history, m_session_history.current_step(), delta);},check_for_cancelation, move(on_ready), move(promise));});@@ -1226,7 +1218,7 @@ void CanonicalTraversable::recover_from_web_content_process_crash(OnHistoryStepAclear_active_document_load();// The step a traversal the crash interrupted was applying is applied again, otherwise the current step is.- auto target_step = m_session_history.current_step().value();+ auto target_step = m_session_history.current_step();if (auto* traversal = ongoing_browser_history_traversal())target_step = traversal->browser_traversal().target_step;abandon_history_operations();@@ -2186,9 +2178,8 @@ void CanonicalTraversable::enqueue_history_operation(Web::HTML::CrossProcessId o// navigation's start arrives after this request, and is canceled before it fetches anything.if (auto const* parameters = request.get_pointer<Web::NavigableCreationHistoryOperationParameters>()) {auto navigable = find(parameters->navigable_id);- auto current_step = m_session_history.current_step();- if (navigable.has_value() && current_step.has_value() && !navigable->ongoing_navigation_id().has_value()- && m_session_history.get_the_target_history_entry(*navigable, *current_step)) {+ if (navigable.has_value() && !navigable->ongoing_navigation_id().has_value()+ && m_session_history.get_the_target_history_entry(*navigable, m_session_history.current_step())) {navigable->set_ongoing_navigation_to_traversal(operation_id);}}@@ -2278,7 +2269,7 @@ void CanonicalTraversable::apply_the_push_or_replace_history_step(HistoryOperativoid CanonicalTraversable::apply_the_reload_history_step(HistoryOperation& operation, Web::HTML::UserNavigationInvolvement user_involvement){// 1. Let step be traversable's current session history step.- auto step = m_session_history.current_step().value();+ auto step = m_session_history.current_step();// 2. Return the result of applying the history step step to traversable given true, null, null, userInvolvement, and "reload".apply_history_step(operation, step, true, {}, user_involvement, Web::Bindings::NavigationType::Reload);@@ -2302,7 +2293,7 @@ void CanonicalTraversable::resume_applying_the_traverse_history_step(HistoryOpervoid CanonicalTraversable::update_for_navigable_creation_or_destruction(HistoryOperation& operation){// 1. Let step be traversable's current session history step.- auto step = m_session_history.current_step().value();+ auto step = m_session_history.current_step();// 2. Return the result of applying the history step step to traversable given false, null, null, "none", and null.apply_history_step(operation, step, false, {}, Web::HTML::UserNavigationInvolvement::None, {});@@ -2318,7 +2309,7 @@ void CanonicalTraversable::traverse_the_history_by_a_delta_at_queue_position(Hisauto all_steps = m_session_history.used_steps();// 2. Let currentStepIndex be the index of traversable's current session history step within allSteps.- auto current_step_index = all_steps.find_first_index(m_session_history.current_step().value());+ auto current_step_index = all_steps.find_first_index(m_session_history.current_step());VERIFY(current_step_index.has_value());// 3. Let targetStepIndex be currentStepIndex plus delta.@@ -2431,7 +2422,7 @@ void CanonicalTraversable::finalize_a_same_document_navigation(HistoryOperation&return;}- auto current_step = m_session_history.current_step().value();+ auto current_step = m_session_history.current_step();// 5. If entryToReplace is null:if (!request.entry_to_replace.has_value()) {@@ -2476,7 +2467,7 @@ void CanonicalTraversable::run_history_operation(HistoryOperation& operation)[&](Web::ReloadHistoryOperationParameters const& parameters) {// NB: A navigable that is gone has no entry to reload. Applying the reload history step then changes nothing.if (auto navigable = find(parameters.navigable_id); navigable.has_value()) {- if (auto* target_entry = m_session_history.get_the_target_history_entry(*navigable, m_session_history.current_step().value())) {+ if (auto* target_entry = m_session_history.get_the_target_history_entry(*navigable, m_session_history.current_step())) {target_entry->document_state->reload_pending = true;session_history_changed();}@@ -2509,7 +2500,7 @@ void CanonicalTraversable::run_history_operation(HistoryOperation& operation)// A navigable created by a document repopulated for its entry already has the nested history that entry// kept. Updating for its creation populates the entry the history holds for it at the current step.- if (m_session_history.get_the_target_history_entry(*child_navigable, m_session_history.current_step().value())) {+ if (m_session_history.get_the_target_history_entry(*child_navigable, m_session_history.current_step())) {update_for_navigable_creation_or_destruction(operation);return;}@@ -2684,7 +2675,7 @@ void CanonicalTraversable::finalize_a_cross_document_navigation(HistoryOperation}// 4. Set targetStep to traversable's current session history step.- target_step = m_session_history.current_step().value();+ target_step = m_session_history.current_step();}// 10. Apply the push/replace history step targetStep to traversable given historyHandling and userInvolvement.diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.hindex cdb241c96a4..a2992887292 100644--- a/Libraries/LibWebView/CanonicalTraversable.h+++ b/Libraries/LibWebView/CanonicalTraversable.h@@ -46,7 +46,7 @@ enum class WebContentProcessLost : bool {class WEBVIEW_API CanonicalTraversable final: public CanonicalNavigable {public:- explicit CanonicalTraversable(Web::HTML::CrossProcessId id = {});+ CanonicalTraversable(Web::HTML::CrossProcessId id, NonnullRefPtr<CanonicalSessionHistoryEntry> initial_history_entry);virtual ~CanonicalTraversable() override;virtual bool is_top_level_traversable() const override { return true; }diff --git a/Libraries/LibWebView/SessionHistory.cpp b/Libraries/LibWebView/SessionHistory.cppindex 610a8489152..e1d83dfee12 100644--- a/Libraries/LibWebView/SessionHistory.cpp+++ b/Libraries/LibWebView/SessionHistory.cpp@@ -202,12 +202,6 @@ static void clear_forward_session_history_entries(Vector<NonnullRefPtr<Canonical}}-void TraversableSessionHistory::clear()-{- m_entries.clear();- m_current_session_history_step.clear();-}-bool TraversableSessionHistory::initialize_for_testing(Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index){if (entries.is_empty() || current_used_step_index >= used_steps.size())@@ -221,10 +215,9 @@ bool TraversableSessionHistory::initialize_for_testing(Vector<Web::HTML::Sessionreturn true;}-void TraversableSessionHistory::initialize_with_initial_history_entry(NonnullRefPtr<CanonicalSessionHistoryEntry> initial_history_entry)+TraversableSessionHistory::TraversableSessionHistory(NonnullRefPtr<CanonicalSessionHistoryEntry> initial_history_entry){m_entries.append(move(initial_history_entry));- m_current_session_history_step = 0;}static void assign_fresh_ids_to_restored_entries(Vector<Web::HTML::SessionHistoryEntryDescriptor>& entries, Function<Web::HTML::CrossProcessId()> const& allocate_cross_process_id, HashMap<Web::HTML::CrossProcessId, Web::HTML::CrossProcessId>& assigned_ids)@@ -251,9 +244,6 @@ ErrorOr<void> TraversableSessionHistory::restore_from_ui_snapshot(Vector<Web::HTOptional<i32> TraversableSessionHistory::append_nested_history(CanonicalNavigable const& parent_navigable, CanonicalDocumentState& parent_document_state, Web::HTML::CrossProcessId child_navigable_id, NonnullRefPtr<CanonicalSessionHistoryEntry> history_entry){- if (!m_current_session_history_step.has_value())- return {};-// https://html.spec.whatwg.org/multipage/document-sequences.html#create-a-new-child-navigable// Steps 2 to 6 of the session history traversal steps appended by "create a new child navigable".@@ -287,9 +277,6 @@ Optional<i32> TraversableSessionHistory::append_nested_history(CanonicalNavigablbool TraversableSessionHistory::remove_nested_history(CanonicalNavigable const& parent_navigable, Web::HTML::CrossProcessId parent_document_state_id, Web::HTML::CrossProcessId child_navigable_id){- if (!m_current_session_history_step.has_value())- return false;-// https://html.spec.whatwg.org/multipage/document-sequences.html#destroy-a-child-navigable// Let parentDocState be container's node navigable's active session history entry's document state. The live// parent entry was read before these traversal steps were appended, so use the reported stable document-state@@ -311,30 +298,25 @@ bool TraversableSessionHistory::remove_nested_history(CanonicalNavigable const&void TraversableSessionHistory::clear_the_forward_session_history(){- VERIFY(m_current_session_history_step.has_value());- clear_forward_session_history_entries(m_entries, *m_current_session_history_step);+ clear_forward_session_history_entries(m_entries, m_current_session_history_step);}// https://html.spec.whatwg.org/multipage/browsing-the-web.html#finalize-a-cross-document-navigation, step 9// https://html.spec.whatwg.org/multipage/browsing-the-web.html#finalize-a-same-document-navigation, step 5Optional<i32> TraversableSessionHistory::push_session_history_entry(CanonicalNavigable const& navigable, NonnullRefPtr<CanonicalSessionHistoryEntry> entry){- auto current_step = this->current_step();- if (!current_step.has_value())- return {};-// NB: The entries of a navigable whose document is active are among those clearing the forward session history// keeps, as the entry of the document containing it is at or before the current step.// FIXME: Assert that instead, once navigable creation and destruction are ordered with the session history.- if (!session_history_entries_at_or_before(navigable, *current_step).has_value())+ if (!session_history_entries_at_or_before(navigable, m_current_session_history_step).has_value())return {};// 1. Clear the forward session history of traversable.clear_the_forward_session_history();// 2. Set targetStep to traversable's current session history step + 1.- VERIFY(*current_step < NumericLimits<i32>::max());- auto target_step = *current_step + 1;+ VERIFY(m_current_session_history_step < NumericLimits<i32>::max());+ auto target_step = m_current_session_history_step + 1;// 3. Set historyEntry's step to targetStep.entry->step = target_step;@@ -371,16 +353,12 @@ bool TraversableSessionHistory::replace_session_history_entry(CanonicalNavigableOptional<size_t> TraversableSessionHistory::current_top_level_entry_index() const{- if (!m_current_session_history_step.has_value())- return {};- return top_level_entry_index_for_step(m_entries, *m_current_session_history_step);+ return top_level_entry_index_for_step(m_entries, m_current_session_history_step);}Optional<size_t> TraversableSessionHistory::current_used_step_index() const{- if (!m_current_session_history_step.has_value())- return {};- auto used_step = get_the_used_step(*m_current_session_history_step);+ auto used_step = get_the_used_step(m_current_session_history_step);if (!used_step.has_value())return {};return used_steps().find_first_index(*used_step);@@ -561,9 +539,7 @@ Optional<i32> TraversableSessionHistory::step_at(size_t index) constCanonicalSessionHistoryEntry* TraversableSessionHistory::current_entry() const{- if (!m_current_session_history_step.has_value())- return nullptr;- return top_level_entry_for_step(*m_current_session_history_step);+ return top_level_entry_for_step(m_current_session_history_step);}CanonicalSessionHistoryEntry* TraversableSessionHistory::entry_at(size_t index) constdiff --git a/Libraries/LibWebView/SessionHistory.h b/Libraries/LibWebView/SessionHistory.hindex 86adf7e7974..45eb5f587c4 100644--- a/Libraries/LibWebView/SessionHistory.h+++ b/Libraries/LibWebView/SessionHistory.h@@ -38,21 +38,19 @@ public:bool changes_top_level_entry { false };};- TraversableSessionHistory() = default;+ explicit TraversableSessionHistory(NonnullRefPtr<CanonicalSessionHistoryEntry> initial_history_entry);TraversableSessionHistory(TraversableSessionHistory&&) = default;TraversableSessionHistory& operator=(TraversableSessionHistory&&) = default;bool is_empty() const { return m_entries.is_empty(); }size_t size() const { return m_entries.size(); }size_t used_step_count() const { return used_steps().size(); }- Optional<i32> current_step() const { return m_current_session_history_step; }+ i32 current_step() const { return m_current_session_history_step; }// The index in the used steps of the used step the current step resolves to.Optional<size_t> current_used_step_index() const;Optional<size_t> current_top_level_entry_index() const;- void clear();bool initialize_for_testing(Vector<Web::HTML::SessionHistoryEntryDescriptor>, Vector<i32> used_steps, size_t current_used_step_index);- void initialize_with_initial_history_entry(NonnullRefPtr<CanonicalSessionHistoryEntry> initial_history_entry);[[nodiscard]] ErrorOr<void> restore_from_ui_snapshot(Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index, Function<Web::HTML::CrossProcessId()> allocate_cross_process_id);Optional<i32> append_nested_history(CanonicalNavigable const& parent_navigable, CanonicalDocumentState& parent_document_state, Web::HTML::CrossProcessId child_navigable_id, NonnullRefPtr<CanonicalSessionHistoryEntry> history_entry);bool remove_nested_history(CanonicalNavigable const& parent_navigable, Web::HTML::CrossProcessId parent_document_state_id, Web::HTML::CrossProcessId child_navigable_id);@@ -104,7 +102,7 @@ private:// https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step// NB: A step that removing a navigable or replacing an entry made unused stays until applying the history step// resolves it to the used step at or before it, as getting the used step does.- Optional<i32> m_current_session_history_step;+ i32 m_current_session_history_step { 0 };};struct SessionHistorySnapshot {diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex a4ef6086da9..39f39fd6b16 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -3061,11 +3061,9 @@ void ViewImplementation::reconstruct_current_session_history_entry_with_history_if (!current_entry)return;- auto current_step = traversable().session_history().current_step();- VERIFY(current_step.has_value());set_url(current_entry->url);begin_webdriver_navigation(WebDriverNavigationCompletionSource::HistoryTraversal);- traversable().reconstruct_the_history_to_step(*current_step);+ traversable().reconstruct_the_history_to_step(traversable().session_history().current_step());dump_session_history(reason);}diff --git a/Tests/LibWebView/TestApplyHistoryStep.cpp b/Tests/LibWebView/TestApplyHistoryStep.cppindex 74182fe6e57..1e42f37745d 100644--- a/Tests/LibWebView/TestApplyHistoryStep.cpp+++ b/Tests/LibWebView/TestApplyHistoryStep.cpp@@ -15,6 +15,11 @@#include <LibWebView/CanonicalTraversable.h>#include <LibWebView/WebContentClient.h>+static NonnullRefPtr<WebView::CanonicalSessionHistoryEntry> initial_history_entry()+{+ return MUST(WebView::CanonicalSessionHistoryEntry::create_from_descriptor(Web::HTML::create_initial_session_history_entry_descriptor({}, {}, {})));+}+static Web::HTML::CrossProcessId root_id() { return { 1, 1 }; }static Web::HTML::CrossProcessId child_id() { return { 1, 2 }; }static Web::HTML::CrossProcessId first_operation_id() { return { 2, 1 }; }@@ -261,8 +266,8 @@ struct TestTraversable {});}- WebView::TraversableSessionHistory history;- WebView::CanonicalTraversable traversable;+ WebView::TraversableSessionHistory history { initial_history_entry() };+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };WebView::SessionHistoryTraversalQueue queue;WebView::TraversableApplyHistoryStepState state;FakeJobRunner runner;diff --git a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cppindex 1e0e16ca38f..308113f6e4b 100644--- a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp+++ b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp@@ -16,6 +16,11 @@#include <LibWebView/CanonicalTraversable.h>#include <LibWebView/CanonicalWindow.h>+static NonnullRefPtr<WebView::CanonicalSessionHistoryEntry> initial_history_entry()+{+ return MUST(WebView::CanonicalSessionHistoryEntry::create_from_descriptor(Web::HTML::create_initial_session_history_entry_descriptor({}, {}, {})));+}+// A navigation whose steps are checking if unloading is canceled, in no page.static WebView::CanonicalNavigation::Start navigation_for_testing(Utf16String navigation_id, u64 sequence_number = 0, RefPtr<WebView::CanonicalSessionHistoryEntry> history_entry = {}){@@ -64,7 +69,7 @@ TEST_CASE(top_level_browsing_context_is_alone_in_a_new_group)TEST_CASE(auxiliary_browsing_context_joins_the_openers_group){- WebView::CanonicalTraversable opener;+ WebView::CanonicalTraversable opener { {}, initial_history_entry() };opener.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document)));auto popup_browsing_context = WebView::CanonicalBrowsingContext::create_a_new_auxiliary_browsing_context_and_document(opener, {}).browsing_context;@@ -94,7 +99,7 @@ TEST_CASE(child_browsing_context_is_not_in_the_group)TEST_CASE(replacing_a_traversables_browsing_context_leaves_its_group){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document)));auto* initial_browsing_context = &traversable.active_browsing_context();VERIFY(initial_browsing_context->group());@@ -121,7 +126,7 @@ TEST_CASE(removing_a_browsing_context_clears_its_group)TEST_CASE(target_snapshot_params_take_the_popup_or_container_sandboxing_flags){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };auto top_level = WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({});traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, top_level.document)));auto popup_flags = Web::HTML::SandboxingFlagSet::SandboxedNavigation | Web::HTML::SandboxingFlagSet::SandboxPropagatesToAuxiliaryBrowsingContexts;@@ -154,7 +159,7 @@ TEST_CASE(target_snapshot_params_take_the_popup_or_container_sandboxing_flags)TEST_CASE(response_browsing_context_is_activated_only_at_commit){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document)));auto* initial_context = &traversable.active_browsing_context();auto initial_group = initial_context->group();@@ -208,7 +213,7 @@ TEST_CASE(response_browsing_context_is_activated_only_at_commit)TEST_CASE(child_navigation_under_a_document_that_switched_groups_uses_its_group){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document)));auto displayed_group = traversable.active_browsing_context().group();@@ -273,7 +278,7 @@ TEST_CASE(child_navigation_under_a_document_that_switched_groups_uses_its_group)TEST_CASE(clearing_a_navigation_abandons_only_the_document_populated_for_it){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };auto make_document = [] { return WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document; };traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, make_document())));@@ -299,7 +304,7 @@ TEST_CASE(clearing_a_navigation_abandons_only_the_document_populated_for_it)TEST_CASE(document_claimed_by_a_history_job_outlives_a_newer_navigation){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };auto make_document = [] { return WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document; };traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, make_document())));@@ -333,7 +338,7 @@ TEST_CASE(document_claimed_by_a_history_job_outlives_a_newer_navigation)TEST_CASE(populated_document_replaces_tracked_load_when_document_state_is_reused){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };auto entry = WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create(Web::HTML::CrossProcessId { 1, 1 }, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document));entry->navigation_api_id = Utf16String::from_utf8("entry"sv);traversable.set_active_session_history_entry(entry);@@ -357,7 +362,7 @@ TEST_CASE(populated_document_replaces_tracked_load_when_document_state_is_reusedTEST_CASE(same_document_traversal_commits_only_navigations_admitted_before_it){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };auto entry = WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create(Web::HTML::CrossProcessId { 1, 1 }, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document));traversable.set_active_session_history_entry(entry);auto committed_state = [] {@@ -448,7 +453,7 @@ static NonnullRefPtr<WebView::CanonicalDocument> navigate_to_a_new_group(WebViewTEST_CASE(same_origin_plus_coep_response_isolates_its_new_group){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document)));auto document = navigate_to_a_new_group(traversable, Web::HTML::OpenerPolicyValue::SameOriginPlusCOEP);auto group = document->browsing_context().group();@@ -461,7 +466,7 @@ TEST_CASE(same_origin_plus_coep_response_isolates_its_new_group)TEST_CASE(same_origin_response_leaves_its_new_group_unisolated){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document)));auto document = navigate_to_a_new_group(traversable, Web::HTML::OpenerPolicyValue::SameOrigin);auto group = document->browsing_context().group();diff --git a/Tests/LibWebView/TestSessionHistory.cpp b/Tests/LibWebView/TestSessionHistory.cppindex 5b9254b319d..87c23ca11be 100644--- a/Tests/LibWebView/TestSessionHistory.cpp+++ b/Tests/LibWebView/TestSessionHistory.cpp@@ -15,6 +15,11 @@#include <LibWebView/SessionHistory.h>#include <LibWebView/WebContentClient.h>+static NonnullRefPtr<WebView::CanonicalSessionHistoryEntry> initial_history_entry()+{+ return MUST(WebView::CanonicalSessionHistoryEntry::create_from_descriptor(Web::HTML::create_initial_session_history_entry_descriptor({}, {}, {})));+}+static void give_active_document(WebView::CanonicalNavigable& navigable){navigable.set_active_session_history_entry(WebView::CanonicalSessionHistoryEntry::create(WebView::CanonicalDocumentState::create({}, WebView::CanonicalBrowsingContext::create_a_new_top_level_browsing_context_and_document({}).document)));@@ -347,7 +352,7 @@ static void expect_nested_entry(WebView::CanonicalNestedHistory const& nested_hiTEST_CASE(entry_updates_address_the_navigables_session_history_entries){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame-1"sv)));@@ -387,7 +392,7 @@ TEST_CASE(entry_updates_address_the_navigables_session_history_entries)TEST_CASE(entry_updates_require_entry_and_document_state_identity){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);@@ -417,7 +422,7 @@ TEST_CASE(entry_updates_require_entry_and_document_state_identity)TEST_CASE(queued_same_document_entries_are_addressed_by_identity){Core::EventLoop event_loop;- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);@@ -498,13 +503,13 @@ TEST_CASE(entry_among_its_own_nested_histories_is_rejected)TEST_CASE(failed_push_keeps_entries_and_document_states){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame"sv)));// The child's session history entries are in the forward history, which pushing an entry clears.- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };EXPECT(history.initialize_for_testing({ entry(0, "https://parent.example/"sv), entry(1, "https://parent.example/next"sv, 10, "main"sv, { nested_history("frame"sv, { entry(1, "https://child.example/"sv) }) }) }, { 0, 1 }, 0));auto const* forward_entry = history.entry_at(1);VERIFY(forward_entry);@@ -524,11 +529,11 @@ TEST_CASE(failed_push_keeps_entries_and_document_states)TEST_CASE(child_history_mutations_use_the_reported_parent_document_state){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto earlier_parent_entry = entry(0, "https://parent.example/earlier"sv, 10, "main"sv);auto current_parent_entry = entry(1, "https://parent.example/current"sv, 11, "main"sv);current_parent_entry.document_state.nested_histories.append(nested_history("frame"sv, {@@ -564,7 +569,7 @@ TEST_CASE(child_history_mutations_use_the_reported_parent_document_state)TEST_CASE(used_steps_include_nested_history_steps){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({entry(0, "https://a.example/"sv, {@@ -614,7 +619,7 @@ TEST_CASE(used_steps_include_nested_history_steps)TEST_CASE(traversal_target_for_top_level_step){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({entry(0, "https://a.example/"sv),entry(1, "https://b.example/"sv),@@ -636,7 +641,7 @@ TEST_CASE(traversal_target_for_top_level_step)TEST_CASE(traversal_target_for_nested_step_in_current_top_level_entry){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({entry(0, "https://a.example/"sv, {@@ -664,7 +669,7 @@ TEST_CASE(traversal_target_for_nested_step_in_current_top_level_entry)TEST_CASE(traversal_target_for_nested_step_in_earlier_top_level_entry){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({entry(0, "https://a.example/"sv, 7, "main"sv, {@@ -707,7 +712,7 @@ TEST_CASE(traversal_target_for_nested_step_in_earlier_top_level_entry)TEST_CASE(traversal_target_for_delta_outside_used_steps){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({ entry(0, "https://a.example/"sv) }, { 0 }, 0);EXPECT_EQ(update_result, true);@@ -719,7 +724,7 @@ TEST_CASE(traversal_target_for_delta_outside_used_steps)TEST_CASE(clear_forward_session_history_rebuilds_traversal_state){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };Vector<Web::HTML::SessionHistoryEntryDescriptor> child_entries {entry(0, "https://frame.example/a"sv),entry(1, "https://frame.example/b"sv),@@ -752,10 +757,10 @@ TEST_CASE(clear_forward_session_history_rebuilds_traversal_state)TEST_CASE(cross_document_push_clears_forward_history_at_finalization){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({entry(0, "https://a.example/"sv, {@@ -796,7 +801,7 @@ TEST_CASE(cross_document_push_clears_forward_history_at_finalization)TEST_CASE(history_log_entries_marks_current_entries_steps_and_reload_pending){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto post_entry = entry_with_post_resource(1, "https://b.example/"sv);post_entry.document_state.id = test_document_state_id(1001);@@ -832,7 +837,7 @@ TEST_CASE(history_log_entries_marks_current_entries_steps_and_reload_pending)TEST_CASE(history_log_entries_marks_nested_histories){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({entry(0, "https://a.example/"sv),@@ -853,10 +858,10 @@ TEST_CASE(history_log_entries_marks_nested_histories)TEST_CASE(cross_document_push_preserves_document_resource){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({ entry(0, "https://a.example/"sv) }, { 0 }, 0);@@ -875,10 +880,10 @@ TEST_CASE(cross_document_push_preserves_document_resource)TEST_CASE(cross_document_replacement_preserves_forward_history){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto entry_to_replace = entry(0, "https://a.example/"sv, 7, "main"sv, {nested_history("frame-1"sv, {@@ -919,10 +924,10 @@ TEST_CASE(cross_document_replacement_preserves_forward_history)TEST_CASE(cross_document_replacement_in_a_parent_keeps_a_current_step_in_a_child_history){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };// The frame of the parent's document navigated, so the current step is in the frame's session history entries.auto parent_entry = entry(0, "https://a.example/"sv, 7, "main"sv, {@@ -953,11 +958,11 @@ TEST_CASE(cross_document_replacement_in_a_parent_keeps_a_current_step_in_a_childTEST_CASE(nested_cross_document_push_updates_copied_session_histories){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame"sv)));- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto child_entry = entry(0, "https://frame.example/first"sv, 20, ""sv);child_entry.navigation_api_key = Utf16String::from_utf8("child-current"sv);@@ -989,11 +994,11 @@ TEST_CASE(nested_cross_document_push_updates_copied_session_histories)TEST_CASE(nested_cross_document_replacement_updates_copied_session_histories){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame"sv)));- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto child_entry = entry(0, "https://frame.example/first"sv, 20, ""sv);child_entry.navigation_api_key = Utf16String::from_utf8("child-current"sv);@@ -1027,7 +1032,7 @@ TEST_CASE(nested_cross_document_replacement_updates_copied_session_histories)TEST_CASE(same_document_push_clears_forward_history_at_queue_position){Core::EventLoop event_loop;- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);@@ -1065,7 +1070,7 @@ TEST_CASE(same_document_push_clears_forward_history_at_queue_position)TEST_CASE(failed_nested_same_document_push_preserves_forward_history){Core::EventLoop event_loop;- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame"sv)));@@ -1105,11 +1110,11 @@ TEST_CASE(failed_nested_same_document_push_preserves_forward_history)TEST_CASE(failed_nested_cross_document_push_preserves_forward_history){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame"sv)));- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto update_result = history.initialize_for_testing({@@ -1135,7 +1140,7 @@ TEST_CASE(failed_nested_cross_document_push_preserves_forward_history)TEST_CASE(same_document_replacement_replaces_the_active_entry){Core::EventLoop event_loop;- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);@@ -1174,11 +1179,11 @@ TEST_CASE(same_document_replacement_replaces_the_active_entry)TEST_CASE(nested_finalization_rejects_a_changed_initial_entry_identity){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame"sv)));- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto initial_entry = entry(0, "about:blank"sv);initial_entry.navigation_api_key = Utf16String::from_utf8("canonical-initial"sv);auto live_initial_entry = initial_entry;@@ -1206,11 +1211,11 @@ TEST_CASE(nested_finalization_rejects_a_changed_initial_entry_identity)TEST_CASE(nested_finalization_rejects_wrong_active_entry_for_populated_history){- WebView::CanonicalTraversable traversable;+ WebView::CanonicalTraversable traversable { {}, initial_history_entry() };traversable.set_id({ 9, 1 });give_active_document(traversable);auto& child = traversable.append_child(make<WebView::CanonicalNavigable>(navigable_id("frame"sv)));- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto populated_entry = entry(0, "https://frame.example/first"sv, 2, ""sv);populated_entry.navigation_api_key = Utf16String::from_utf8("canonical"sv);auto update_result = history.initialize_for_testing({ entry(0, "https://top.example/"sv, {@@ -1236,7 +1241,7 @@ static constexpr auto restore_error_no_document_state = "Session history snapshoTEST_CASE(restore_from_ui_snapshot_installs_a_valid_snapshot){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto result = history.restore_from_ui_snapshot({entry(0, "https://a.example/"sv, 1, "main"sv),@@ -1258,7 +1263,7 @@ TEST_CASE(restore_from_ui_snapshot_installs_a_valid_snapshot)TEST_CASE(restore_from_ui_snapshot_installs_a_valid_nested_snapshot){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };// Nested step 1 lives under the step-0 entry, which is the correct top-level entry for step 1.Vector<Web::HTML::SessionHistoryEntryDescriptor> entries;@@ -1278,7 +1283,7 @@ TEST_CASE(restore_from_ui_snapshot_installs_a_valid_nested_snapshot)TEST_CASE(restore_from_ui_snapshot_preserves_shared_document_state_identity){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto original_id = test_document_state_id(1);auto result = history.restore_from_ui_snapshot({@@ -1298,11 +1303,11 @@ TEST_CASE(restore_from_ui_snapshot_preserves_shared_document_state_identity)TEST_CASE(restore_from_ui_snapshot_rejects_structurally_invalid_snapshots){auto restore = [](Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index) {- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto result = history.restore_from_ui_snapshot(move(entries), move(used_steps), current_used_step_index, allocate_test_ui_process_document_state_id);EXPECT(result.is_error());EXPECT_EQ(result.error().string_literal(), restore_error_structurally_invalid);- EXPECT_EQ(history.size(), 0uz);+ EXPECT_EQ(history.size(), 1uz);};restore({}, { 0 }, 0);@@ -1322,16 +1327,16 @@ TEST_CASE(restore_from_ui_snapshot_rejects_excessive_nesting_before_restoration)nested_entry = entry_with_reload_pending(0, "https://nested.example/"sv, depth + 2, "frame"sv, { move(nested_history) });}- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto result = history.restore_from_ui_snapshot({ move(nested_entry) }, { 0 }, 0, allocate_test_ui_process_document_state_id);EXPECT(result.is_error());EXPECT_EQ(result.error().string_literal(), restore_error_structurally_invalid);- EXPECT_EQ(history.size(), 0uz);+ EXPECT_EQ(history.size(), 1uz);}TEST_CASE(restore_from_ui_snapshot_rejects_current_entry_without_document_state){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };auto result = history.restore_from_ui_snapshot({entry(0, "https://a.example/"sv, 1, "main"sv),@@ -1341,12 +1346,12 @@ TEST_CASE(restore_from_ui_snapshot_rejects_current_entry_without_document_state)EXPECT(result.is_error());EXPECT_EQ(result.error().string_literal(), restore_error_no_document_state);- EXPECT_EQ(history.size(), 0uz);+ EXPECT_EQ(history.size(), 1uz);}TEST_CASE(restore_from_ui_snapshot_rejects_used_step_without_top_level_entry){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };// The only top-level entry is at step 5, but used step 1 (a nested step) has no top-level entry,// so a later back traversal to step 1 would crash. The step set is internally consistent.@@ -1358,12 +1363,12 @@ TEST_CASE(restore_from_ui_snapshot_rejects_used_step_without_top_level_entry)EXPECT(result.is_error());EXPECT_EQ(result.error().string_literal(), restore_error_step_not_reachable);- EXPECT_EQ(history.size(), 0uz);+ EXPECT_EQ(history.size(), 1uz);}TEST_CASE(restore_from_ui_snapshot_rejects_used_step_under_shadowed_top_level_entry){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };// Nested step 4 lives under the step-0 entry, but the step-2 top-level entry shadows it, so// top_level_entry_for_step(4) resolves to page 2, which does not contain step 4.@@ -1376,12 +1381,12 @@ TEST_CASE(restore_from_ui_snapshot_rejects_used_step_under_shadowed_top_level_enEXPECT(result.is_error());EXPECT_EQ(result.error().string_literal(), restore_error_step_not_reachable);- EXPECT_EQ(history.size(), 0uz);+ EXPECT_EQ(history.size(), 1uz);}TEST_CASE(restore_from_ui_snapshot_rejects_step_under_inactive_nested_sibling){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };// The child history's active entry for step 4 is the sibling at step 2, but the step-4 grandchild// lives under the inactive child at step 0, so step 4 is unreachable on the active path.@@ -1397,12 +1402,12 @@ TEST_CASE(restore_from_ui_snapshot_rejects_step_under_inactive_nested_sibling)EXPECT(result.is_error());EXPECT_EQ(result.error().string_literal(), restore_error_step_not_reachable);- EXPECT_EQ(history.size(), 0uz);+ EXPECT_EQ(history.size(), 1uz);}TEST_CASE(restore_from_ui_snapshot_leaves_history_untouched_on_failure){- WebView::TraversableSessionHistory history;+ WebView::TraversableSessionHistory history { initial_history_entry() };MUST(history.restore_from_ui_snapshot({ entry(0, "https://a.example/"sv, 1, "main"sv) }, { 0 }, 0, allocate_test_ui_process_document_state_id));EXPECT_EQ(history.size(), 1uz);diff --git a/Tests/LibWebView/TestStorageJar.cpp b/Tests/LibWebView/TestStorageJar.cppindex 1ebf8bc058f..07810d3ca20 100644--- a/Tests/LibWebView/TestStorageJar.cpp+++ b/Tests/LibWebView/TestStorageJar.cpp@@ -10,6 +10,11 @@#include <LibWebView/CanonicalTraversable.h>#include <LibWebView/StorageJar.h>+static NonnullRefPtr<WebView::CanonicalSessionHistoryEntry> initial_history_entry()+{+ return MUST(WebView::CanonicalSessionHistoryEntry::create_from_descriptor(Web::HTML::create_initial_session_history_entry_descriptor({}, {}, {})));+}+TEST_CASE(storage_round_trips_on_fresh_database){auto database = TRY_OR_FAIL(Database::Database::create_memory_backed());@@ -87,8 +92,8 @@ TEST_CASE(storage_usage_counts_utf8_bytes_not_code_units)TEST_CASE(legacy_cloning_a_canonical_traversable_creates_an_independent_copy){- WebView::CanonicalTraversable source;- WebView::CanonicalTraversable clone;+ WebView::CanonicalTraversable source { {}, initial_history_entry() };+ WebView::CanonicalTraversable clone { {}, initial_history_entry() };source.session_storage().set_item(WebView::StorageEndpointType::SessionStorage, "https://a.example"_string, "key"_utf16, "source"_utf16);source.session_storage().set_item(WebView::StorageEndpointType::SessionStorage, "https://b.example"_string, "other"_utf16, "preserved"_utf16);