Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: chrome/browser/autocomplete/autocomplete_result_unittest.cc

Issue 303013002: Omnibox: Create Disable-Inlining Experiment (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Peter's comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_result.cc ('k') | chrome/browser/omnibox/omnibox_field_trial.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/autocomplete_result_unittest.cc
diff --git a/chrome/browser/autocomplete/autocomplete_result_unittest.cc b/chrome/browser/autocomplete/autocomplete_result_unittest.cc
index 56a51adbed7fc1052825e04755cc867366f2f6b4..28ab9a50c577c544012b23f83fbaf312cf1c064c 100644
--- a/chrome/browser/autocomplete/autocomplete_result_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_result_unittest.cc
@@ -557,6 +557,165 @@ TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) {
}
}
+
+
+TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) {
+ TestData data[] = {
+ { 0, 0, 1300 },
+ { 1, 0, 1200 },
+ { 2, 0, 1100 },
+ { 3, 0, 1000 }
+ };
+
+ {
+ // Check that with the field trial disabled, we keep keep the first match
+ // first even if it has an inline autocompletion.
+ ACMatches matches;
+ PopulateAutocompleteMatches(data, arraysize(data), &matches);
+ matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(base::string16(), base::string16::npos,
+ base::string16(), GURL(),
+ AutocompleteInput::HOME_PAGE, false, false, false,
+ true);
+ result.SortAndCull(input, test_util_.profile());
+ AssertResultMatches(result, data, 4);
+ }
+
+ // Enable the field trial to disable inlining.
+ {
+ std::map<std::string, std::string> params;
+ params[OmniboxFieldTrial::kDisableInliningRule] = "true";
+ ASSERT_TRUE(chrome_variations::AssociateVariationParams(
+ OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params));
+ }
+ base::FieldTrialList::CreateFieldTrial(
+ OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D");
+
+ {
+ // Now the first match should be demoted past the second.
+ ACMatches matches;
+ PopulateAutocompleteMatches(data, arraysize(data), &matches);
+ matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(base::string16(), base::string16::npos,
+ base::string16(), GURL(),
+ AutocompleteInput::HOME_PAGE, false, false, false,
+ true);
+ result.SortAndCull(input, test_util_.profile());
+ ASSERT_EQ(4U, result.size());
+ EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec());
+ EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
+ EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec());
+ EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
+ }
+
+ {
+ // But if there was no inline autocompletion on the first match, then
+ // the order should stay the same. This is true even if there are
+ // inline autocompletions elsewhere.
+ ACMatches matches;
+ PopulateAutocompleteMatches(data, arraysize(data), &matches);
+ matches[2].inline_autocompletion = base::ASCIIToUTF16("completion");
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(base::string16(), base::string16::npos,
+ base::string16(), GURL(),
+ AutocompleteInput::HOME_PAGE, false, false, false,
+ true);
+ result.SortAndCull(input, test_util_.profile());
+ AssertResultMatches(result, data, 4);
+ }
+
+ {
+ // Try a more complicated situation.
+ ACMatches matches;
+ PopulateAutocompleteMatches(data, arraysize(data), &matches);
+ matches[0].allowed_to_be_default_match = false;
+ matches[1].inline_autocompletion = base::ASCIIToUTF16("completion");
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(base::string16(), base::string16::npos,
+ base::string16(), GURL(),
+ AutocompleteInput::HOME_PAGE, false, false, false,
+ true);
+ result.SortAndCull(input, test_util_.profile());
+ ASSERT_EQ(4U, result.size());
+ EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
+ EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
+ EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
+ EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
+ }
+
+ {
+ // Try another complicated situation.
+ ACMatches matches;
+ PopulateAutocompleteMatches(data, arraysize(data), &matches);
+ matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
+ matches[1].allowed_to_be_default_match = false;
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(base::string16(), base::string16::npos,
+ base::string16(), GURL(),
+ AutocompleteInput::HOME_PAGE, false, false, false,
+ true);
+ result.SortAndCull(input, test_util_.profile());
+ ASSERT_EQ(4U, result.size());
+ EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
+ EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
+ EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
+ EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
+ }
+
+ {
+ // Check that disaster doesn't strike if we can't demote the top inline
+ // autocompletion because every match either has a completion or isn't
+ // allowed to be the default match. In this case, we should leave
+ // everything untouched.
+ ACMatches matches;
+ PopulateAutocompleteMatches(data, arraysize(data), &matches);
+ matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
+ matches[1].allowed_to_be_default_match = false;
+ matches[2].allowed_to_be_default_match = false;
+ matches[3].inline_autocompletion = base::ASCIIToUTF16("completion");
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(base::string16(), base::string16::npos,
+ base::string16(), GURL(),
+ AutocompleteInput::HOME_PAGE, false, false, false,
+ true);
+ result.SortAndCull(input, test_util_.profile());
+ AssertResultMatches(result, data, 4);
+ }
+
+ {
+ // Check a similar situation, except in this case the top match is not
+ // allowed to the default match, so it still needs to be demoted so we
+ // get a legal default match first. That match will have an inline
+ // autocompletion because we don't have any better options.
+ ACMatches matches;
+ PopulateAutocompleteMatches(data, arraysize(data), &matches);
+ matches[0].allowed_to_be_default_match = false;
+ matches[1].inline_autocompletion = base::ASCIIToUTF16("completion");
+ matches[2].allowed_to_be_default_match = false;
+ matches[3].inline_autocompletion = base::ASCIIToUTF16("completion");
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(base::string16(), base::string16::npos,
+ base::string16(), GURL(),
+ AutocompleteInput::HOME_PAGE, false, false, false,
+ true);
+ result.SortAndCull(input, test_util_.profile());
+ ASSERT_EQ(4U, result.size());
+ EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec());
+ EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
+ EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec());
+ EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
+ }
+}
+
TEST_F(AutocompleteResultTest, ShouldHideTopMatch) {
base::FieldTrialList::CreateFieldTrial("InstantExtended",
"Group1 hide_verbatim:1");
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_result.cc ('k') | chrome/browser/omnibox/omnibox_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698