Truly independent web browser
LibWebView: Make a deep page the default only when it completes
Andreas Kling58fffe945671
diff --git a/Libraries/LibWebView/AutocompleteRanker.cpp b/Libraries/LibWebView/AutocompleteRanker.cppindex cfe0cf36880..8e6dfa02ce6 100644--- a/Libraries/LibWebView/AutocompleteRanker.cpp+++ b/Libraries/LibWebView/AutocompleteRanker.cpp@@ -486,10 +486,13 @@ Vector<AutocompleteSuggestion> rank_engagement_suggestions(StringView query, Vecauto deep_page_has_inline_intent = !is_deep_page_without_path_input|| (exact_association && engagement.explicit_use_count >= 2)|| short_deep_prefix_has_evidence;+ // NB: Return goes where the text shows. A deep page that the text could be completed to only becomes the+ // default when it is completed to, as uses of the default row count toward it but say little.+ if (syntactic_url_prefix && !deep_page_has_inline_intent)+ can_be_automatically_selected = false;can_be_inline_completed = can_be_automatically_selected&& syntactic_url_prefix- && match_class == AutocompleteMatchClass::URLPrefix- && deep_page_has_inline_intent;+ && match_class == AutocompleteMatchClass::URLPrefix;} else {source = AutocompleteSuggestionSource::Search;}diff --git a/Tests/LibWebView/TestAutocompleteRanker.cpp b/Tests/LibWebView/TestAutocompleteRanker.cppindex 4590467e53a..d882aecc74c 100644--- a/Tests/LibWebView/TestAutocompleteRanker.cpp+++ b/Tests/LibWebView/TestAutocompleteRanker.cpp@@ -434,6 +434,26 @@ TEST_CASE(exact_search_like_adaptive_url_requires_one_explicit_use)EXPECT(!suggestions[0].can_be_inline_completed);}+TEST_CASE(deep_adaptive_page_is_the_default_only_when_it_completes)+{+ auto rank = [](i64 explicit_use_count, i64 default_use_count) {+ return WebView::rank_engagement_suggestions("ama"sv, {+ engagement("ama"sv, WebView::OmniboxDestinationKind::URL, "https://www.amazon.example/book/dp/123/"sv, explicit_use_count, default_use_count),+ },+ 8, UnixDateTime::from_seconds_since_epoch(now_seconds));+ };++ auto picked_once = rank(1, 2);+ EXPECT_EQ(picked_once.size(), 1u);+ EXPECT(!picked_once[0].can_be_automatically_selected);+ EXPECT(!picked_once[0].can_be_inline_completed);++ auto picked_twice = rank(2, 0);+ EXPECT_EQ(picked_twice.size(), 1u);+ EXPECT(picked_twice[0].can_be_automatically_selected);+ EXPECT(picked_twice[0].can_be_inline_completed);+}+TEST_CASE(previous_searches_never_become_automatic_completions){auto suggestions = WebView::rank_engagement_suggestions("lady"sv, {diff --git a/Tests/LibWebView/TestOmnibox.cpp b/Tests/LibWebView/TestOmnibox.cppindex fcc0c1e8831..436f72d8f08 100644--- a/Tests/LibWebView/TestOmnibox.cpp+++ b/Tests/LibWebView/TestOmnibox.cpp@@ -1866,6 +1866,33 @@ TEST_CASE(scenario_a_page_matching_only_by_title_does_not_take_return)EXPECT_EQ(scenario.rows_for("example.com/fragrance"sv), 1u);}+// The user picked a deep page of a site once after typing the start of its address, and pressed Return on it twice+// since. Typing that start again completes to the site, as Return goes where the text shows. A second pick of the page+// makes it the completion.+TEST_CASE(scenario_a_deep_page_picked_once_does_not_take_the_start_of_its_address)+{+ auto profile_with_picks = [](i64 explicit_use_count) {+ ScenarioProfile profile;+ profile.visit("https://www.amazon.example/book/dp/123/"sv, "A Book"sv, 7);+ profile.visit("https://www.amazon.example/"sv, "Amazon"sv, 2);+ profile.learn("ama"sv, "https://www.amazon.example/book/dp/123/"sv, explicit_use_count, 2);+ return profile;+ };++ Scenario picked_once(profile_with_picks(1));+ picked_once.type("ama"sv);+ EXPECT_EQ(picked_once.harness.display_text, "amazon.example"sv);+ EXPECT_EQ(picked_once.harness.selection_start, 3u);+ EXPECT(walk_page_address(picked_once.return_destination()) == "amazon.example/"sv);+ EXPECT_EQ(picked_once.rows_for("amazon.example/book/dp/123"sv), 1u);++ Scenario picked_twice(profile_with_picks(2));+ picked_twice.type("ama"sv);+ EXPECT_EQ(picked_twice.harness.display_text, "amazon.example/book/dp/123/"sv);+ EXPECT_EQ(picked_twice.harness.selection_start, 3u);+ EXPECT(walk_page_address(picked_twice.return_destination()) == "amazon.example/book/dp/123/"sv);+}+TEST_CASE(scenario_a_remote_address_of_an_unvisited_site_is_a_search){Scenario scenario({});