| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/omnibox/browser/autocomplete_result.h" | 5 #include "components/omnibox/browser/autocomplete_result.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "components/metrics/proto/omnibox_event.pb.h" | 18 #include "components/metrics/proto/omnibox_event.pb.h" |
| 18 #include "components/omnibox/browser/autocomplete_input.h" | 19 #include "components/omnibox/browser/autocomplete_input.h" |
| 19 #include "components/omnibox/browser/autocomplete_match.h" | 20 #include "components/omnibox/browser/autocomplete_match.h" |
| 20 #include "components/omnibox/browser/autocomplete_match_type.h" | 21 #include "components/omnibox/browser/autocomplete_match_type.h" |
| 21 #include "components/omnibox/browser/autocomplete_provider.h" | 22 #include "components/omnibox/browser/autocomplete_provider.h" |
| 22 #include "components/omnibox/browser/omnibox_field_trial.h" | 23 #include "components/omnibox/browser/omnibox_field_trial.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 EXPECT_EQ("http://b/", result.match_at(3)->destination_url.spec()); | 395 EXPECT_EQ("http://b/", result.match_at(3)->destination_url.spec()); |
| 395 EXPECT_EQ(1000, result.match_at(3)->relevance); | 396 EXPECT_EQ(1000, result.match_at(3)->relevance); |
| 396 } | 397 } |
| 397 | 398 |
| 398 TEST_F(AutocompleteResultTest, SortAndCullDuplicateSearchURLs) { | 399 TEST_F(AutocompleteResultTest, SortAndCullDuplicateSearchURLs) { |
| 399 // Register a template URL that corresponds to 'foo' search engine. | 400 // Register a template URL that corresponds to 'foo' search engine. |
| 400 TemplateURLData url_data; | 401 TemplateURLData url_data; |
| 401 url_data.SetShortName(base::ASCIIToUTF16("unittest")); | 402 url_data.SetShortName(base::ASCIIToUTF16("unittest")); |
| 402 url_data.SetKeyword(base::ASCIIToUTF16("foo")); | 403 url_data.SetKeyword(base::ASCIIToUTF16("foo")); |
| 403 url_data.SetURL("http://www.foo.com/s?q={searchTerms}"); | 404 url_data.SetURL("http://www.foo.com/s?q={searchTerms}"); |
| 404 template_url_service_.get()->Add(new TemplateURL(url_data)); | 405 template_url_service_.get()->Add(base::MakeUnique<TemplateURL>(url_data)); |
| 405 | 406 |
| 406 TestData data[] = { | 407 TestData data[] = { |
| 407 { 0, 1, 1300, true }, | 408 { 0, 1, 1300, true }, |
| 408 { 1, 1, 1200, true }, | 409 { 1, 1, 1200, true }, |
| 409 { 2, 1, 1100, true }, | 410 { 2, 1, 1100, true }, |
| 410 { 3, 1, 1000, true }, | 411 { 3, 1, 1000, true }, |
| 411 { 4, 2, 900, true }, | 412 { 4, 2, 900, true }, |
| 412 }; | 413 }; |
| 413 | 414 |
| 414 ACMatches matches; | 415 ACMatches matches; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 438 result.match_at(2)->destination_url.spec()); | 439 result.match_at(2)->destination_url.spec()); |
| 439 EXPECT_EQ(900, result.match_at(2)->relevance); | 440 EXPECT_EQ(900, result.match_at(2)->relevance); |
| 440 } | 441 } |
| 441 | 442 |
| 442 TEST_F(AutocompleteResultTest, SortAndCullWithMatchDups) { | 443 TEST_F(AutocompleteResultTest, SortAndCullWithMatchDups) { |
| 443 // Register a template URL that corresponds to 'foo' search engine. | 444 // Register a template URL that corresponds to 'foo' search engine. |
| 444 TemplateURLData url_data; | 445 TemplateURLData url_data; |
| 445 url_data.SetShortName(base::ASCIIToUTF16("unittest")); | 446 url_data.SetShortName(base::ASCIIToUTF16("unittest")); |
| 446 url_data.SetKeyword(base::ASCIIToUTF16("foo")); | 447 url_data.SetKeyword(base::ASCIIToUTF16("foo")); |
| 447 url_data.SetURL("http://www.foo.com/s?q={searchTerms}"); | 448 url_data.SetURL("http://www.foo.com/s?q={searchTerms}"); |
| 448 template_url_service_.get()->Add(new TemplateURL(url_data)); | 449 template_url_service_.get()->Add(base::MakeUnique<TemplateURL>(url_data)); |
| 449 | 450 |
| 450 AutocompleteMatch dup_match; | 451 AutocompleteMatch dup_match; |
| 451 dup_match.destination_url = GURL("http://www.foo.com/s?q=foo&oq=dup"); | 452 dup_match.destination_url = GURL("http://www.foo.com/s?q=foo&oq=dup"); |
| 452 std::vector<AutocompleteMatch> dups; | 453 std::vector<AutocompleteMatch> dups; |
| 453 dups.push_back(dup_match); | 454 dups.push_back(dup_match); |
| 454 | 455 |
| 455 TestData data[] = { | 456 TestData data[] = { |
| 456 { 0, 1, 1300, true, dups }, | 457 { 0, 1, 1300, true, dups }, |
| 457 { 1, 1, 1200, true }, | 458 { 1, 1, 1200, true }, |
| 458 { 2, 1, 1100, true }, | 459 { 2, 1, 1100, true }, |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 matches.clear(); | 660 matches.clear(); |
| 660 | 661 |
| 661 // Case 4: Standalone verbatim match found in AutocompleteResult. | 662 // Case 4: Standalone verbatim match found in AutocompleteResult. |
| 662 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 663 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
| 663 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | 664 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); |
| 664 result.AppendMatches(AutocompleteInput(), matches); | 665 result.AppendMatches(AutocompleteInput(), matches); |
| 665 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | 666 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); |
| 666 result.Reset(); | 667 result.Reset(); |
| 667 matches.clear(); | 668 matches.clear(); |
| 668 } | 669 } |
| OLD | NEW |