diff options
author | bartn@chromium.org <bartn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-30 00:20:26 +0000 |
---|---|---|
committer | bartn@chromium.org <bartn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-30 00:20:26 +0000 |
commit | dbff44658056494b320b593c986cd719173681e7 (patch) | |
tree | 123e38ad3214b7f130c9bd53da4fdc1f0d11d960 /chrome/browser/autocomplete/autocomplete_result_unittest.cc | |
parent | 2dbcad1cd7537645456400c42d8b69782f80bfc4 (diff) | |
download | chromium_src-dbff44658056494b320b593c986cd719173681e7.zip chromium_src-dbff44658056494b320b593c986cd719173681e7.tar.gz chromium_src-dbff44658056494b320b593c986cd719173681e7.tar.bz2 |
Initial implementation of dedupping search provider's URLs.
There are two main sources of such URLs:
(1) search provider itself
(2) history URL providers (after visiting a previously suggested URL).
A search provider URL may contain time/position specific CGI params,
which if left, may prevent from dedupping.
BUG=146551
TEST=AutocompleteResultTest::SortAndCullDuplicateSearchURLs
Review URL: https://chromiumcodereview.appspot.com/11198074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164790 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete_result_unittest.cc')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_result_unittest.cc | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_result_unittest.cc b/chrome/browser/autocomplete/autocomplete_result_unittest.cc index 73e9458..788f568 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); +} |