Skip to content

Commit

Permalink
[Omnibox]: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fallaciousreasoning committed Mar 4, 2025
1 parent eecbecf commit f1a80a5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions components/omnibox/browser/brave_bookmark_provider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,58 @@ TEST_F(BraveBookmarkProviderTest, SuggestionsEnabledHasResults) {
provider_->Start(CreateAutocompleteInput("Hello"), true);
EXPECT_FALSE(provider_->matches().empty());
}

TEST_F(BraveBookmarkProviderTest, TitleContainsQueryCanBeDefaultMatch) {
prefs()->SetBoolean(omnibox::kBookmarkSuggestionsEnabled, true);
provider_->Start(CreateAutocompleteInput("Hello"), true);
EXPECT_FALSE(provider_->matches().empty());
EXPECT_TRUE(provider_->matches()[0].allowed_to_be_default_match);
}

TEST_F(BraveBookmarkProviderTest, URLContainsQueryCanBeDefaultMatch) {
prefs()->SetBoolean(omnibox::kBookmarkSuggestionsEnabled, true);
provider_->Start(CreateAutocompleteInput("example"), true);
EXPECT_FALSE(provider_->matches().empty());
EXPECT_TRUE(provider_->matches()[0].allowed_to_be_default_match);
}

TEST_F(BraveBookmarkProviderTest, ContainsIsCaseInsensitive) {
prefs()->SetBoolean(omnibox::kBookmarkSuggestionsEnabled, true);
provider_->Start(CreateAutocompleteInput("EXAMPLE"), true);
EXPECT_FALSE(provider_->matches().empty());
EXPECT_TRUE(provider_->matches()[0].allowed_to_be_default_match);

provider_->Start(CreateAutocompleteInput("HELLO"), true);
EXPECT_FALSE(provider_->matches().empty());
EXPECT_TRUE(provider_->matches()[0].allowed_to_be_default_match);
}

TEST_F(BraveBookmarkProviderTest, QueryIsNotExactCannotBeDefaultMatch) {
prefs()->SetBoolean(omnibox::kBookmarkSuggestionsEnabled, true);
provider_->Start(CreateAutocompleteInput("Hello example"), true);
EXPECT_FALSE(provider_->matches().empty());
EXPECT_FALSE(provider_->matches()[0].allowed_to_be_default_match);
}

TEST_F(BraveBookmarkProviderTest, DontBumpContainsQueryIfKeywordIsUsed) {
prefs()->SetBoolean(omnibox::kBookmarkSuggestionsEnabled, true);
auto input = CreateAutocompleteInput("Hello");
input.set_keyword_mode_entry_method(
metrics::OmniboxEventProto::KeywordModeEntryMethod::
OmniboxEventProto_KeywordModeEntryMethod_KEYBOARD_SHORTCUT);
input.set_prefer_keyword(true);
input.set_allow_exact_keyword_match(true);
provider_->Start(input, true);

EXPECT_FALSE(provider_->matches().empty());
EXPECT_FALSE(provider_->matches()[0].allowed_to_be_default_match);
}

TEST_F(BraveBookmarkProviderTest, ContainsQueryBumpsRelevance) {
prefs()->SetBoolean(omnibox::kBookmarkSuggestionsEnabled, true);
provider_->Start(CreateAutocompleteInput("Hello"), true);
EXPECT_FALSE(provider_->matches().empty());
EXPECT_TRUE(provider_->matches()[0].allowed_to_be_default_match);
// Note: 1199 is the max relevance score for a bookmark upstream.
EXPECT_GT(provider_->matches()[0].relevance, 1199);
}

0 comments on commit f1a80a5

Please sign in to comment.