Chromium Code Reviews| 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..f441e17009b79b5ddb5a7b3beeefbc6c85cdfa25 100644 |
| --- a/chrome/browser/autocomplete/autocomplete_result_unittest.cc |
| +++ b/chrome/browser/autocomplete/autocomplete_result_unittest.cc |
| @@ -10,6 +10,7 @@ |
| #include "chrome/browser/autocomplete/autocomplete_input.h" |
| #include "chrome/browser/autocomplete/autocomplete_match.h" |
| #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| +#include "chrome/test/base/testing_profile.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| class AutocompleteResultTest : public testing::Test { |
| @@ -26,7 +27,7 @@ class AutocompleteResultTest : public testing::Test { |
| int relevance; |
| }; |
| - AutocompleteResultTest() {} |
| + AutocompleteResultTest() : profile_(new TestingProfile()) {} |
| // Configures |match| from |data|. |
| static void PopulateAutocompleteMatch(const TestData& data, |
| @@ -48,6 +49,9 @@ class AutocompleteResultTest : public testing::Test { |
| const TestData* current, size_t current_size, |
| const TestData* expected, size_t expected_size); |
| + protected: |
| + scoped_ptr<TestingProfile> profile_; |
|
Peter Kasting
2012/10/26 22:13:49
Nit: Does this need to be heap-allocated? Seems l
Bart N.
2012/10/26 23:36:55
Yup. Done.
|
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(AutocompleteResultTest); |
| }; |
| @@ -102,14 +106,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, profile_.get()); |
| 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, profile_.get()); |
| + current_result.CopyOldMatches(input, last_result, profile_.get()); |
| AssertResultMatches(current_result, expected, expected_size); |
| } |
| @@ -131,7 +135,7 @@ TEST_F(AutocompleteResultTest, Swap) { |
| AutocompleteInput::ALL_MATCHES); |
| matches.push_back(match); |
| r1.AppendMatches(matches); |
| - r1.SortAndCull(input); |
| + r1.SortAndCull(input, profile_.get()); |
| EXPECT_EQ(r1.begin(), r1.default_match()); |
| EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
| r1.Swap(&r2); |
| @@ -210,7 +214,7 @@ TEST_F(AutocompleteResultTest, SortAndCullEmptyDestinationURLs) { |
| result.AppendMatches(matches); |
| AutocompleteInput input(string16(), string16(), false, false, false, |
| AutocompleteInput::ALL_MATCHES); |
| - result.SortAndCull(input); |
| + result.SortAndCull(input, profile_.get()); |
| // 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 +229,39 @@ 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) { |
| + 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.google.com/search?q=foo"); |
| + matches[1].destination_url = GURL("http://www.google.com/search?q=foo2"); |
| + matches[2].destination_url = GURL("http://www.google.com/search?q=foo&oq=f"); |
| + matches[3].destination_url = GURL("http://www.google.com/search?q=foo&aqs=0"); |
| + matches[4].destination_url = GURL("http://www.google.com/"); |
|
Peter Kasting
2012/10/26 22:13:49
This seems like it relies on the test data having
Bart N.
2012/10/26 23:36:55
Yes - I'll update it in the followup CL.
|
| + |
| + AutocompleteResult result; |
| + result.AppendMatches(matches); |
| + AutocompleteInput input(string16(), string16(), false, false, false, |
| + AutocompleteInput::ALL_MATCHES); |
| + result.SortAndCull(input, profile_.get()); |
| + |
| + // We expect the 3rd and 4th results to be removed. |
| + ASSERT_EQ(3U, result.size()); |
| + EXPECT_EQ("http://www.google.com/search?q=foo", |
| + result.match_at(0)->destination_url.spec()); |
| + EXPECT_EQ(1300, result.match_at(0)->relevance); |
| + EXPECT_EQ("http://www.google.com/search?q=foo2", |
| + result.match_at(1)->destination_url.spec()); |
| + EXPECT_EQ(1200, result.match_at(1)->relevance); |
| + EXPECT_EQ("http://www.google.com/", |
| + result.match_at(2)->destination_url.spec()); |
| + EXPECT_EQ(900, result.match_at(2)->relevance); |
| +} |