| 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/autocomplete_result.h" | 5 #include "components/omnibox/autocomplete_result.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/metrics/proto/omnibox_event.pb.h" | 14 #include "components/metrics/proto/omnibox_event.pb.h" |
| 15 #include "components/omnibox/autocomplete_input.h" | 15 #include "components/omnibox/autocomplete_input.h" |
| 16 #include "components/omnibox/autocomplete_match.h" | 16 #include "components/omnibox/autocomplete_match.h" |
| 17 #include "components/omnibox/autocomplete_match_type.h" | 17 #include "components/omnibox/autocomplete_match_type.h" |
| 18 #include "components/omnibox/autocomplete_provider.h" | 18 #include "components/omnibox/autocomplete_provider.h" |
| 19 #include "components/omnibox/mock_autocomplete_provider_client.h" |
| 19 #include "components/omnibox/omnibox_field_trial.h" | 20 #include "components/omnibox/omnibox_field_trial.h" |
| 20 #include "components/omnibox/test_scheme_classifier.h" | 21 #include "components/omnibox/test_scheme_classifier.h" |
| 21 #include "components/search_engines/template_url_service.h" | 22 #include "components/search_engines/template_url_service.h" |
| 22 #include "components/variations/entropy_provider.h" | 23 #include "components/variations/entropy_provider.h" |
| 23 #include "components/variations/variations_associated_data.h" | 24 #include "components/variations/variations_associated_data.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 using metrics::OmniboxEventProto; | 27 using metrics::OmniboxEventProto; |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // Create the list of mock providers. 5 is enough. | 105 // Create the list of mock providers. 5 is enough. |
| 105 for (size_t i = 0; i < 5; ++i) { | 106 for (size_t i = 0; i < 5; ++i) { |
| 106 mock_provider_list_.push_back(new MockAutocompleteProvider( | 107 mock_provider_list_.push_back(new MockAutocompleteProvider( |
| 107 static_cast<AutocompleteProvider::Type>(i))); | 108 static_cast<AutocompleteProvider::Type>(i))); |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 | 111 |
| 111 void SetUp() override { | 112 void SetUp() override { |
| 112 template_url_service_.reset(new TemplateURLService(NULL, 0)); | 113 template_url_service_.reset(new TemplateURLService(NULL, 0)); |
| 113 template_url_service_->Load(); | 114 template_url_service_->Load(); |
| 115 client_.reset(new MockAutocompleteProviderClient()); |
| 114 } | 116 } |
| 115 | 117 |
| 116 // Configures |match| from |data|. | 118 // Configures |match| from |data|. |
| 117 void PopulateAutocompleteMatch(const TestData& data, | 119 void PopulateAutocompleteMatch(const TestData& data, |
| 118 AutocompleteMatch* match); | 120 AutocompleteMatch* match); |
| 119 | 121 |
| 120 // Adds |count| AutocompleteMatches to |matches|. | 122 // Adds |count| AutocompleteMatches to |matches|. |
| 121 void PopulateAutocompleteMatches(const TestData* data, | 123 void PopulateAutocompleteMatches(const TestData* data, |
| 122 size_t count, | 124 size_t count, |
| 123 ACMatches* matches); | 125 ACMatches* matches); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 134 const TestData* expected, size_t expected_size); | 136 const TestData* expected, size_t expected_size); |
| 135 | 137 |
| 136 // Returns a (mock) AutocompleteProvider of given |provider_id|. | 138 // Returns a (mock) AutocompleteProvider of given |provider_id|. |
| 137 MockAutocompleteProvider* GetProvider(int provider_id) { | 139 MockAutocompleteProvider* GetProvider(int provider_id) { |
| 138 EXPECT_LT(provider_id, static_cast<int>(mock_provider_list_.size())); | 140 EXPECT_LT(provider_id, static_cast<int>(mock_provider_list_.size())); |
| 139 return mock_provider_list_[provider_id].get(); | 141 return mock_provider_list_[provider_id].get(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 protected: | 144 protected: |
| 143 scoped_ptr<TemplateURLService> template_url_service_; | 145 scoped_ptr<TemplateURLService> template_url_service_; |
| 146 scoped_ptr<MockAutocompleteProviderClient> client_; |
| 144 | 147 |
| 145 private: | 148 private: |
| 146 scoped_ptr<base::FieldTrialList> field_trial_list_; | 149 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 147 | 150 |
| 148 // For every provider mentioned in TestData, we need a mock provider. | 151 // For every provider mentioned in TestData, we need a mock provider. |
| 149 std::vector<scoped_refptr<MockAutocompleteProvider> > mock_provider_list_; | 152 std::vector<scoped_refptr<MockAutocompleteProvider> > mock_provider_list_; |
| 150 | 153 |
| 151 DISALLOW_COPY_AND_ASSIGN(AutocompleteResultTest); | 154 DISALLOW_COPY_AND_ASSIGN(AutocompleteResultTest); |
| 152 }; | 155 }; |
| 153 | 156 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 const TestData* last, size_t last_size, | 199 const TestData* last, size_t last_size, |
| 197 const TestData* current, size_t current_size, | 200 const TestData* current, size_t current_size, |
| 198 const TestData* expected, size_t expected_size) { | 201 const TestData* expected, size_t expected_size) { |
| 199 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 202 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 200 std::string(), GURL(), | 203 std::string(), GURL(), |
| 201 OmniboxEventProto::INVALID_SPEC, false, false, false, | 204 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 202 true, false, TestSchemeClassifier()); | 205 true, false, TestSchemeClassifier()); |
| 203 | 206 |
| 204 ACMatches last_matches; | 207 ACMatches last_matches; |
| 205 PopulateAutocompleteMatches(last, last_size, &last_matches); | 208 PopulateAutocompleteMatches(last, last_size, &last_matches); |
| 206 AutocompleteResult last_result; | 209 AutocompleteResult last_result(client_.get()); |
| 207 last_result.AppendMatches(input, last_matches); | 210 last_result.AppendMatches(input, last_matches); |
| 208 last_result.SortAndCull(input, template_url_service_.get()); | 211 last_result.SortAndCull(input, template_url_service_.get()); |
| 209 | 212 |
| 210 ACMatches current_matches; | 213 ACMatches current_matches; |
| 211 PopulateAutocompleteMatches(current, current_size, ¤t_matches); | 214 PopulateAutocompleteMatches(current, current_size, ¤t_matches); |
| 212 AutocompleteResult current_result; | 215 AutocompleteResult current_result(client_.get()); |
| 213 current_result.AppendMatches(input, current_matches); | 216 current_result.AppendMatches(input, current_matches); |
| 214 current_result.SortAndCull(input, template_url_service_.get()); | 217 current_result.SortAndCull(input, template_url_service_.get()); |
| 215 current_result.CopyOldMatches( | 218 current_result.CopyOldMatches( |
| 216 input, last_result, template_url_service_.get()); | 219 input, last_result, template_url_service_.get()); |
| 217 | 220 |
| 218 AssertResultMatches(current_result, expected, expected_size); | 221 AssertResultMatches(current_result, expected, expected_size); |
| 219 } | 222 } |
| 220 | 223 |
| 221 // Assertion testing for AutocompleteResult::Swap. | 224 // Assertion testing for AutocompleteResult::Swap. |
| 222 TEST_F(AutocompleteResultTest, Swap) { | 225 TEST_F(AutocompleteResultTest, Swap) { |
| 223 AutocompleteResult r1; | 226 AutocompleteResult r1(client_.get()); |
| 224 AutocompleteResult r2; | 227 AutocompleteResult r2(client_.get()); |
| 225 | 228 |
| 226 // Swap with empty shouldn't do anything interesting. | 229 // Swap with empty shouldn't do anything interesting. |
| 227 r1.Swap(&r2); | 230 r1.Swap(&r2); |
| 228 EXPECT_EQ(r1.end(), r1.default_match()); | 231 EXPECT_EQ(r1.end(), r1.default_match()); |
| 229 EXPECT_EQ(r2.end(), r2.default_match()); | 232 EXPECT_EQ(r2.end(), r2.default_match()); |
| 230 | 233 |
| 231 // Swap with a single match. | 234 // Swap with a single match. |
| 232 ACMatches matches; | 235 ACMatches matches; |
| 233 AutocompleteMatch match; | 236 AutocompleteMatch match; |
| 234 match.relevance = 1; | 237 match.relevance = 1; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 370 |
| 368 ACMatches matches; | 371 ACMatches matches; |
| 369 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 372 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 370 matches[1].destination_url = GURL(); | 373 matches[1].destination_url = GURL(); |
| 371 matches[3].destination_url = GURL(); | 374 matches[3].destination_url = GURL(); |
| 372 matches[4].destination_url = GURL(); | 375 matches[4].destination_url = GURL(); |
| 373 | 376 |
| 374 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 377 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
| 375 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 378 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
| 376 false, true, false, TestSchemeClassifier()); | 379 false, true, false, TestSchemeClassifier()); |
| 377 AutocompleteResult result; | 380 AutocompleteResult result(client_.get()); |
| 378 result.AppendMatches(input, matches); | 381 result.AppendMatches(input, matches); |
| 379 result.SortAndCull(input, template_url_service_.get()); | 382 result.SortAndCull(input, template_url_service_.get()); |
| 380 | 383 |
| 381 // Of the two results with the same non-empty destination URL, the | 384 // Of the two results with the same non-empty destination URL, the |
| 382 // lower-relevance one should be dropped. All of the results with empty URLs | 385 // lower-relevance one should be dropped. All of the results with empty URLs |
| 383 // should be kept. | 386 // should be kept. |
| 384 ASSERT_EQ(4U, result.size()); | 387 ASSERT_EQ(4U, result.size()); |
| 385 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); | 388 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); |
| 386 EXPECT_EQ(1300, result.match_at(0)->relevance); | 389 EXPECT_EQ(1300, result.match_at(0)->relevance); |
| 387 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); | 390 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 412 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 415 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 413 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 416 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
| 414 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 417 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
| 415 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 418 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
| 416 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 419 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 417 matches[4].destination_url = GURL("http://www.foo.com/"); | 420 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 418 | 421 |
| 419 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 422 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
| 420 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 423 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
| 421 false, true, false, TestSchemeClassifier()); | 424 false, true, false, TestSchemeClassifier()); |
| 422 AutocompleteResult result; | 425 AutocompleteResult result(client_.get()); |
| 423 result.AppendMatches(input, matches); | 426 result.AppendMatches(input, matches); |
| 424 result.SortAndCull(input, template_url_service_.get()); | 427 result.SortAndCull(input, template_url_service_.get()); |
| 425 | 428 |
| 426 // We expect the 3rd and 4th results to be removed. | 429 // We expect the 3rd and 4th results to be removed. |
| 427 ASSERT_EQ(3U, result.size()); | 430 ASSERT_EQ(3U, result.size()); |
| 428 EXPECT_EQ("http://www.foo.com/s?q=foo", | 431 EXPECT_EQ("http://www.foo.com/s?q=foo", |
| 429 result.match_at(0)->destination_url.spec()); | 432 result.match_at(0)->destination_url.spec()); |
| 430 EXPECT_EQ(1300, result.match_at(0)->relevance); | 433 EXPECT_EQ(1300, result.match_at(0)->relevance); |
| 431 EXPECT_EQ("http://www.foo.com/s?q=foo2", | 434 EXPECT_EQ("http://www.foo.com/s?q=foo2", |
| 432 result.match_at(1)->destination_url.spec()); | 435 result.match_at(1)->destination_url.spec()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 463 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 466 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
| 464 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 467 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
| 465 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 468 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
| 466 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 469 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 467 matches[4].destination_url = GURL("http://www.foo.com/"); | 470 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 468 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); | 471 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); |
| 469 | 472 |
| 470 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 473 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
| 471 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 474 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
| 472 false, true, false, TestSchemeClassifier()); | 475 false, true, false, TestSchemeClassifier()); |
| 473 AutocompleteResult result; | 476 AutocompleteResult result(client_.get()); |
| 474 result.AppendMatches(input, matches); | 477 result.AppendMatches(input, matches); |
| 475 result.SortAndCull(input, template_url_service_.get()); | 478 result.SortAndCull(input, template_url_service_.get()); |
| 476 | 479 |
| 477 // Expect 3 unique results after SortAndCull(). | 480 // Expect 3 unique results after SortAndCull(). |
| 478 ASSERT_EQ(3U, result.size()); | 481 ASSERT_EQ(3U, result.size()); |
| 479 | 482 |
| 480 // Check that 3rd and 4th result got added to the first result as dups | 483 // Check that 3rd and 4th result got added to the first result as dups |
| 481 // and also duplicates of the 4th match got copied. | 484 // and also duplicates of the 4th match got copied. |
| 482 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); | 485 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); |
| 483 const AutocompleteMatch* first_match = result.match_at(0); | 486 const AutocompleteMatch* first_match = result.match_at(0); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 "1:50,7:100,2:0"; // 3 == HOME_PAGE | 519 "1:50,7:100,2:0"; // 3 == HOME_PAGE |
| 517 ASSERT_TRUE(variations::AssociateVariationParams( | 520 ASSERT_TRUE(variations::AssociateVariationParams( |
| 518 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 521 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
| 519 } | 522 } |
| 520 base::FieldTrialList::CreateFieldTrial( | 523 base::FieldTrialList::CreateFieldTrial( |
| 521 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 524 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
| 522 | 525 |
| 523 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 526 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
| 524 GURL(), OmniboxEventProto::HOME_PAGE, false, false, | 527 GURL(), OmniboxEventProto::HOME_PAGE, false, false, |
| 525 false, true, false, TestSchemeClassifier()); | 528 false, true, false, TestSchemeClassifier()); |
| 526 AutocompleteResult result; | 529 AutocompleteResult result(client_.get()); |
| 527 result.AppendMatches(input, matches); | 530 result.AppendMatches(input, matches); |
| 528 result.SortAndCull(input, template_url_service_.get()); | 531 result.SortAndCull(input, template_url_service_.get()); |
| 529 | 532 |
| 530 // Check the new ordering. The history-title results should be omitted. | 533 // Check the new ordering. The history-title results should be omitted. |
| 531 // We cannot check relevance scores because the matches are sorted by | 534 // We cannot check relevance scores because the matches are sorted by |
| 532 // demoted relevance but the actual relevance scores are not modified. | 535 // demoted relevance but the actual relevance scores are not modified. |
| 533 ASSERT_EQ(3u, result.size()); | 536 ASSERT_EQ(3u, result.size()); |
| 534 EXPECT_EQ("http://search-what-you-typed/", | 537 EXPECT_EQ("http://search-what-you-typed/", |
| 535 result.match_at(0)->destination_url.spec()); | 538 result.match_at(0)->destination_url.spec()); |
| 536 EXPECT_EQ("http://history-url/", | 539 EXPECT_EQ("http://history-url/", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 561 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); | 564 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); |
| 562 } | 565 } |
| 563 base::FieldTrialList::CreateFieldTrial( | 566 base::FieldTrialList::CreateFieldTrial( |
| 564 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); | 567 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); |
| 565 | 568 |
| 566 { | 569 { |
| 567 AutocompleteInput input( | 570 AutocompleteInput input( |
| 568 base::string16(), base::string16::npos, std::string(), GURL(), | 571 base::string16(), base::string16::npos, std::string(), GURL(), |
| 569 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, | 572 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, |
| 570 false, false, true, false, TestSchemeClassifier()); | 573 false, false, true, false, TestSchemeClassifier()); |
| 571 AutocompleteResult result; | 574 AutocompleteResult result(client_.get()); |
| 572 result.AppendMatches(input, matches); | 575 result.AppendMatches(input, matches); |
| 573 result.SortAndCull(input, template_url_service_.get()); | 576 result.SortAndCull(input, template_url_service_.get()); |
| 574 | 577 |
| 575 // The NAVSUGGEST dup-url stay above search-url since the navsuggest | 578 // The NAVSUGGEST dup-url stay above search-url since the navsuggest |
| 576 // variant should not be demoted. | 579 // variant should not be demoted. |
| 577 ASSERT_EQ(4u, result.size()); | 580 ASSERT_EQ(4u, result.size()); |
| 578 EXPECT_EQ("http://search-what-you-typed/", | 581 EXPECT_EQ("http://search-what-you-typed/", |
| 579 result.match_at(0)->destination_url.spec()); | 582 result.match_at(0)->destination_url.spec()); |
| 580 EXPECT_EQ("http://dup-url/", | 583 EXPECT_EQ("http://dup-url/", |
| 581 result.match_at(1)->destination_url.spec()); | 584 result.match_at(1)->destination_url.spec()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 599 { | 602 { |
| 600 // Check that reorder doesn't do anything if the top result | 603 // Check that reorder doesn't do anything if the top result |
| 601 // is already a legal default match (which is the default from | 604 // is already a legal default match (which is the default from |
| 602 // PopulateAutocompleteMatches()). | 605 // PopulateAutocompleteMatches()). |
| 603 ACMatches matches; | 606 ACMatches matches; |
| 604 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 607 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 605 AutocompleteInput input(base::string16(), base::string16::npos, | 608 AutocompleteInput input(base::string16(), base::string16::npos, |
| 606 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 609 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
| 607 false, false, false, true, false, | 610 false, false, false, true, false, |
| 608 TestSchemeClassifier()); | 611 TestSchemeClassifier()); |
| 609 AutocompleteResult result; | 612 AutocompleteResult result(client_.get()); |
| 610 result.AppendMatches(input, matches); | 613 result.AppendMatches(input, matches); |
| 611 result.SortAndCull(input, template_url_service_.get()); | 614 result.SortAndCull(input, template_url_service_.get()); |
| 612 AssertResultMatches(result, data, 4); | 615 AssertResultMatches(result, data, 4); |
| 613 } | 616 } |
| 614 | 617 |
| 615 { | 618 { |
| 616 // Check that reorder swaps up a result appropriately. | 619 // Check that reorder swaps up a result appropriately. |
| 617 ACMatches matches; | 620 ACMatches matches; |
| 618 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 621 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 619 matches[0].allowed_to_be_default_match = false; | 622 matches[0].allowed_to_be_default_match = false; |
| 620 matches[1].allowed_to_be_default_match = false; | 623 matches[1].allowed_to_be_default_match = false; |
| 621 AutocompleteInput input(base::string16(), base::string16::npos, | 624 AutocompleteInput input(base::string16(), base::string16::npos, |
| 622 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 625 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
| 623 false, false, false, true, false, | 626 false, false, false, true, false, |
| 624 TestSchemeClassifier()); | 627 TestSchemeClassifier()); |
| 625 AutocompleteResult result; | 628 AutocompleteResult result(client_.get()); |
| 626 result.AppendMatches(input, matches); | 629 result.AppendMatches(input, matches); |
| 627 result.SortAndCull(input, template_url_service_.get()); | 630 result.SortAndCull(input, template_url_service_.get()); |
| 628 ASSERT_EQ(4U, result.size()); | 631 ASSERT_EQ(4U, result.size()); |
| 629 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 632 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 630 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 633 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 631 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 634 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 632 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 635 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 633 } | 636 } |
| 634 } | 637 } |
| 635 | 638 |
| 636 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) { | 639 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) { |
| 637 ACMatches matches; | 640 ACMatches matches; |
| 638 AutocompleteResult result; | 641 AutocompleteResult result(client_.get()); |
| 639 result.AppendMatches(AutocompleteInput(), matches); | 642 result.AppendMatches(AutocompleteInput(), matches); |
| 640 | 643 |
| 641 // Case 1: Result set is empty. | 644 // Case 1: Result set is empty. |
| 642 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch()); | 645 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch()); |
| 643 | 646 |
| 644 // Case 2: Top match is not a verbatim match. | 647 // Case 2: Top match is not a verbatim match. |
| 645 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | 648 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); |
| 646 result.AppendMatches(AutocompleteInput(), matches); | 649 result.AppendMatches(AutocompleteInput(), matches); |
| 647 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch()); | 650 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch()); |
| 648 result.Reset(); | 651 result.Reset(); |
| 649 matches.clear(); | 652 matches.clear(); |
| 650 | 653 |
| 651 // Case 3: Top match is a verbatim match. | 654 // Case 3: Top match is a verbatim match. |
| 652 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 655 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
| 653 result.AppendMatches(AutocompleteInput(), matches); | 656 result.AppendMatches(AutocompleteInput(), matches); |
| 654 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | 657 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); |
| 655 result.Reset(); | 658 result.Reset(); |
| 656 matches.clear(); | 659 matches.clear(); |
| 657 | 660 |
| 658 // Case 4: Standalone verbatim match found in AutocompleteResult. | 661 // Case 4: Standalone verbatim match found in AutocompleteResult. |
| 659 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 662 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
| 660 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | 663 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); |
| 661 result.AppendMatches(AutocompleteInput(), matches); | 664 result.AppendMatches(AutocompleteInput(), matches); |
| 662 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | 665 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); |
| 663 result.Reset(); | 666 result.Reset(); |
| 664 matches.clear(); | 667 matches.clear(); |
| 665 } | 668 } |
| OLD | NEW |