summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/autocomplete_result_unittest.cc
diff options
context:
space:
mode:
authormariakhomenko@chromium.org <mariakhomenko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 01:26:13 +0000
committermariakhomenko@chromium.org <mariakhomenko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 01:26:13 +0000
commit9caafa23ae465c8a5c0659fb0ecf06a2c62e1512 (patch)
tree4f7ee766304071a8723b49e15dc9c03ca9187009 /chrome/browser/autocomplete/autocomplete_result_unittest.cc
parent66154ec085eac6b101799bf852bcc15b5bc4eac2 (diff)
downloadchromium_src-9caafa23ae465c8a5c0659fb0ecf06a2c62e1512.zip
chromium_src-9caafa23ae465c8a5c0659fb0ecf06a2c62e1512.tar.gz
chromium_src-9caafa23ae465c8a5c0659fb0ecf06a2c62e1512.tar.bz2
Make match deletion more thorough.
Keeps track of eliminated matches during AddMatchToMap and SortAndCull and places them in duplicate_matches vector owned by the match that they were determined to be the duplicate of. When DeleteMatch is called, we delete not just the most relevant match shown to the user, but also the duplicate matches (possibly owned by other providers) to ensure we delete the suggestion from all possible sources. Adds a column to chrome://omnibox that shows the number of duplicate matches on an element, which is helpful for debugging. BUG=165765,341456 Review URL: https://codereview.chromium.org/180383003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete_result_unittest.cc')
-rw-r--r--chrome/browser/autocomplete/autocomplete_result_unittest.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_result_unittest.cc b/chrome/browser/autocomplete/autocomplete_result_unittest.cc
index 5c9be52..025c176 100644
--- a/chrome/browser/autocomplete/autocomplete_result_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_result_unittest.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/autocomplete/autocomplete_result.h"
+#include <vector>
+
#include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string_number_conversions.h"
@@ -71,6 +73,9 @@ class AutocompleteResultTest : public testing::Test {
// Relevance score.
int relevance;
+
+ // Duplicate matches.
+ std::vector<AutocompleteMatch> duplicate_matches;
};
AutocompleteResultTest() {
@@ -134,6 +139,7 @@ void AutocompleteResultTest::PopulateAutocompleteMatch(
match->destination_url = GURL("http://" + url_id);
match->relevance = data.relevance;
match->allowed_to_be_default_match = true;
+ match->duplicate_matches = data.duplicate_matches;
}
// static
@@ -352,6 +358,65 @@ TEST_F(AutocompleteResultTest, SortAndCullDuplicateSearchURLs) {
EXPECT_EQ(900, result.match_at(2)->relevance);
}
+TEST_F(AutocompleteResultTest, SortAndCullWithMatchDups) {
+ // Register a template URL that corresponds to 'foo' search engine.
+ TemplateURLData url_data;
+ url_data.short_name = base::ASCIIToUTF16("unittest");
+ url_data.SetKeyword(base::ASCIIToUTF16("foo"));
+ url_data.SetURL("http://www.foo.com/s?q={searchTerms}");
+ test_util_.model()->Add(new TemplateURL(test_util_.profile(), url_data));
+
+ AutocompleteMatch dup_match;
+ dup_match.destination_url = GURL("http://www.foo.com/s?q=foo&oq=dup");
+ std::vector<AutocompleteMatch> dups;
+ dups.push_back(dup_match);
+
+ TestData data[] = {
+ { 0, 0, 1300, dups },
+ { 1, 0, 1200 },
+ { 2, 0, 1100 },
+ { 3, 0, 1000, dups },
+ { 4, 1, 900 },
+ { 5, 0, 800 },
+ };
+
+ 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/");
+ matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f");
+
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(base::string16(), base::string16::npos,
+ base::string16(), GURL(),
+ AutocompleteInput::INVALID_SPEC, false, false, false,
+ AutocompleteInput::ALL_MATCHES);
+ result.SortAndCull(input, test_util_.profile());
+
+ // Expect 3 unique results after SortAndCull().
+ ASSERT_EQ(3U, result.size());
+
+ // Check that 3rd and 4th result got added to the first result as dups
+ // and also duplicates of the 4th match got copied.
+ ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size());
+ const AutocompleteMatch* first_match = result.match_at(0);
+ EXPECT_EQ(matches[2].destination_url,
+ first_match->duplicate_matches.at(1).destination_url);
+ EXPECT_EQ(dup_match.destination_url,
+ first_match->duplicate_matches.at(2).destination_url);
+ EXPECT_EQ(matches[3].destination_url,
+ first_match->duplicate_matches.at(3).destination_url);
+
+ // Check that 6th result started a new list of dups for the second result.
+ ASSERT_EQ(1U, result.match_at(1)->duplicate_matches.size());
+ EXPECT_EQ(matches[5].destination_url,
+ result.match_at(1)->duplicate_matches.at(0).destination_url);
+}
+
TEST_F(AutocompleteResultTest, SortAndCullWithDemotionsByType) {
// Add some matches.
ACMatches matches;