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 73e9458fc8e1755c4d34d04222b549b599da71ae..788f568c121361a863b72ab6774b80ab86b49d9d 100644 |
--- a/chrome/browser/autocomplete/autocomplete_result_unittest.cc |
+++ b/chrome/browser/autocomplete/autocomplete_result_unittest.cc |
@@ -10,6 +10,10 @@ |
#include "chrome/browser/autocomplete/autocomplete_input.h" |
#include "chrome/browser/autocomplete/autocomplete_match.h" |
#include "chrome/browser/autocomplete/autocomplete_provider.h" |
+#include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
+#include "chrome/browser/search_engines/template_url_service.h" |
+#include "chrome/browser/search_engines/template_url_service_test_util.h" |
+#include "chrome/test/base/testing_profile.h" |
#include "testing/gtest/include/gtest/gtest.h" |
class AutocompleteResultTest : public testing::Test { |
@@ -28,6 +32,19 @@ class AutocompleteResultTest : public testing::Test { |
AutocompleteResultTest() {} |
+ virtual void SetUp() OVERRIDE { |
+#if defined(OS_ANDROID) |
+ TemplateURLPrepopulateData::InitCountryCode( |
+ std::string() /* unknown country code */); |
+#endif |
+ test_util_.SetUp(); |
+ test_util_.VerifyLoad(); |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ test_util_.TearDown(); |
+ } |
+ |
// Configures |match| from |data|. |
static void PopulateAutocompleteMatch(const TestData& data, |
AutocompleteMatch* match); |
@@ -48,6 +65,9 @@ class AutocompleteResultTest : public testing::Test { |
const TestData* current, size_t current_size, |
const TestData* expected, size_t expected_size); |
+ protected: |
+ TemplateURLServiceTestUtil test_util_; |
+ |
private: |
DISALLOW_COPY_AND_ASSIGN(AutocompleteResultTest); |
}; |
@@ -102,14 +122,14 @@ void AutocompleteResultTest::RunCopyOldMatchesTest( |
PopulateAutocompleteMatches(last, last_size, &last_matches); |
AutocompleteResult last_result; |
last_result.AppendMatches(last_matches); |
- last_result.SortAndCull(input); |
+ last_result.SortAndCull(input, test_util_.profile()); |
ACMatches current_matches; |
PopulateAutocompleteMatches(current, current_size, ¤t_matches); |
AutocompleteResult current_result; |
current_result.AppendMatches(current_matches); |
- current_result.SortAndCull(input); |
- current_result.CopyOldMatches(input, last_result); |
+ current_result.SortAndCull(input, test_util_.profile()); |
+ current_result.CopyOldMatches(input, last_result, test_util_.profile()); |
AssertResultMatches(current_result, expected, expected_size); |
} |
@@ -131,7 +151,7 @@ TEST_F(AutocompleteResultTest, Swap) { |
AutocompleteInput::ALL_MATCHES); |
matches.push_back(match); |
r1.AppendMatches(matches); |
- r1.SortAndCull(input); |
+ r1.SortAndCull(input, test_util_.profile()); |
EXPECT_EQ(r1.begin(), r1.default_match()); |
EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
r1.Swap(&r2); |
@@ -210,7 +230,7 @@ TEST_F(AutocompleteResultTest, SortAndCullEmptyDestinationURLs) { |
result.AppendMatches(matches); |
AutocompleteInput input(string16(), string16(), false, false, false, |
AutocompleteInput::ALL_MATCHES); |
- result.SortAndCull(input); |
+ result.SortAndCull(input, test_util_.profile()); |
// Of the two results with the same non-empty destination URL, the |
// lower-relevance one should be dropped. All of the results with empty URLs |
@@ -225,3 +245,46 @@ TEST_F(AutocompleteResultTest, SortAndCullEmptyDestinationURLs) { |
EXPECT_EQ("http://b/", result.match_at(3)->destination_url.spec()); |
EXPECT_EQ(1000, result.match_at(3)->relevance); |
} |
+ |
+TEST_F(AutocompleteResultTest, SortAndCullDuplicateSearchURLs) { |
+ // Register a template URL that corresponds to 'foo' search engine. |
+ TemplateURLData url_data; |
+ url_data.short_name = ASCIIToUTF16("unittest"); |
+ url_data.SetKeyword(ASCIIToUTF16("foo")); |
+ url_data.SetURL("http://www.foo.com/s?q={searchTerms}"); |
+ test_util_.model()->Add(new TemplateURL(test_util_.profile(), url_data)); |
+ |
+ TestData data[] = { |
+ { 0, 0, 1300 }, |
+ { 1, 0, 1200 }, |
+ { 2, 0, 1100 }, |
+ { 3, 0, 1000 }, |
+ { 4, 1, 900 }, |
+ }; |
+ |
+ ACMatches matches; |
+ PopulateAutocompleteMatches(data, arraysize(data), &matches); |
+ matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
+ matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
+ matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
+ matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
+ matches[4].destination_url = GURL("http://www.foo.com/"); |
+ |
+ AutocompleteResult result; |
+ result.AppendMatches(matches); |
+ AutocompleteInput input(string16(), string16(), false, false, false, |
+ AutocompleteInput::ALL_MATCHES); |
+ result.SortAndCull(input, test_util_.profile()); |
+ |
+ // We expect the 3rd and 4th results to be removed. |
+ ASSERT_EQ(3U, result.size()); |
+ EXPECT_EQ("http://www.foo.com/s?q=foo", |
+ result.match_at(0)->destination_url.spec()); |
+ EXPECT_EQ(1300, result.match_at(0)->relevance); |
+ EXPECT_EQ("http://www.foo.com/s?q=foo2", |
+ result.match_at(1)->destination_url.spec()); |
+ EXPECT_EQ(1200, result.match_at(1)->relevance); |
+ EXPECT_EQ("http://www.foo.com/", |
+ result.match_at(2)->destination_url.spec()); |
+ EXPECT_EQ(900, result.match_at(2)->relevance); |
+} |