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" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 const TestData* expected, size_t expected_size) { | 198 const TestData* expected, size_t expected_size) { |
199 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 199 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
200 std::string(), GURL(), | 200 std::string(), GURL(), |
201 OmniboxEventProto::INVALID_SPEC, false, false, false, | 201 OmniboxEventProto::INVALID_SPEC, false, false, false, |
202 true, false, TestSchemeClassifier()); | 202 true, false, TestSchemeClassifier()); |
203 | 203 |
204 ACMatches last_matches; | 204 ACMatches last_matches; |
205 PopulateAutocompleteMatches(last, last_size, &last_matches); | 205 PopulateAutocompleteMatches(last, last_size, &last_matches); |
206 AutocompleteResult last_result; | 206 AutocompleteResult last_result; |
207 last_result.AppendMatches(input, last_matches); | 207 last_result.AppendMatches(input, last_matches); |
208 last_result.SortAndCull(input, template_url_service_.get()); | 208 last_result.SortAndCull(input, std::string(), template_url_service_.get()); |
209 | 209 |
210 ACMatches current_matches; | 210 ACMatches current_matches; |
211 PopulateAutocompleteMatches(current, current_size, ¤t_matches); | 211 PopulateAutocompleteMatches(current, current_size, ¤t_matches); |
212 AutocompleteResult current_result; | 212 AutocompleteResult current_result; |
213 current_result.AppendMatches(input, current_matches); | 213 current_result.AppendMatches(input, current_matches); |
214 current_result.SortAndCull(input, template_url_service_.get()); | 214 current_result.SortAndCull(input, std::string(), template_url_service_.get()); |
215 current_result.CopyOldMatches( | 215 current_result.CopyOldMatches( |
216 input, last_result, template_url_service_.get()); | 216 input, std::string(), last_result, template_url_service_.get()); |
217 | 217 |
218 AssertResultMatches(current_result, expected, expected_size); | 218 AssertResultMatches(current_result, expected, expected_size); |
219 } | 219 } |
220 | 220 |
221 // Assertion testing for AutocompleteResult::Swap. | 221 // Assertion testing for AutocompleteResult::Swap. |
222 TEST_F(AutocompleteResultTest, Swap) { | 222 TEST_F(AutocompleteResultTest, Swap) { |
223 AutocompleteResult r1; | 223 AutocompleteResult r1; |
224 AutocompleteResult r2; | 224 AutocompleteResult r2; |
225 | 225 |
226 // Swap with empty shouldn't do anything interesting. | 226 // Swap with empty shouldn't do anything interesting. |
227 r1.Swap(&r2); | 227 r1.Swap(&r2); |
228 EXPECT_EQ(r1.end(), r1.default_match()); | 228 EXPECT_EQ(r1.end(), r1.default_match()); |
229 EXPECT_EQ(r2.end(), r2.default_match()); | 229 EXPECT_EQ(r2.end(), r2.default_match()); |
230 | 230 |
231 // Swap with a single match. | 231 // Swap with a single match. |
232 ACMatches matches; | 232 ACMatches matches; |
233 AutocompleteMatch match; | 233 AutocompleteMatch match; |
234 match.relevance = 1; | 234 match.relevance = 1; |
235 match.allowed_to_be_default_match = true; | 235 match.allowed_to_be_default_match = true; |
236 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 236 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
237 std::string(), GURL(), | 237 std::string(), GURL(), |
238 OmniboxEventProto::INVALID_SPEC, false, false, false, | 238 OmniboxEventProto::INVALID_SPEC, false, false, false, |
239 true, false, TestSchemeClassifier()); | 239 true, false, TestSchemeClassifier()); |
240 matches.push_back(match); | 240 matches.push_back(match); |
241 r1.AppendMatches(input, matches); | 241 r1.AppendMatches(input, matches); |
242 r1.SortAndCull(input, template_url_service_.get()); | 242 r1.SortAndCull(input, std::string(), template_url_service_.get()); |
243 EXPECT_EQ(r1.begin(), r1.default_match()); | 243 EXPECT_EQ(r1.begin(), r1.default_match()); |
244 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); | 244 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
245 r1.Swap(&r2); | 245 r1.Swap(&r2); |
246 EXPECT_TRUE(r1.empty()); | 246 EXPECT_TRUE(r1.empty()); |
247 EXPECT_EQ(r1.end(), r1.default_match()); | 247 EXPECT_EQ(r1.end(), r1.default_match()); |
248 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); | 248 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); |
249 ASSERT_FALSE(r2.empty()); | 249 ASSERT_FALSE(r2.empty()); |
250 EXPECT_EQ(r2.begin(), r2.default_match()); | 250 EXPECT_EQ(r2.begin(), r2.default_match()); |
251 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec()); | 251 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec()); |
252 } | 252 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 369 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
370 matches[1].destination_url = GURL(); | 370 matches[1].destination_url = GURL(); |
371 matches[3].destination_url = GURL(); | 371 matches[3].destination_url = GURL(); |
372 matches[4].destination_url = GURL(); | 372 matches[4].destination_url = GURL(); |
373 | 373 |
374 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 374 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
375 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 375 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
376 false, true, false, TestSchemeClassifier()); | 376 false, true, false, TestSchemeClassifier()); |
377 AutocompleteResult result; | 377 AutocompleteResult result; |
378 result.AppendMatches(input, matches); | 378 result.AppendMatches(input, matches); |
379 result.SortAndCull(input, template_url_service_.get()); | 379 result.SortAndCull(input, std::string(), template_url_service_.get()); |
380 | 380 |
381 // Of the two results with the same non-empty destination URL, the | 381 // 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 | 382 // lower-relevance one should be dropped. All of the results with empty URLs |
383 // should be kept. | 383 // should be kept. |
384 ASSERT_EQ(4U, result.size()); | 384 ASSERT_EQ(4U, result.size()); |
385 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); | 385 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); |
386 EXPECT_EQ(1300, result.match_at(0)->relevance); | 386 EXPECT_EQ(1300, result.match_at(0)->relevance); |
387 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); | 387 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); |
388 EXPECT_EQ(1200, result.match_at(1)->relevance); | 388 EXPECT_EQ(1200, result.match_at(1)->relevance); |
389 EXPECT_TRUE(result.match_at(2)->destination_url.is_empty()); | 389 EXPECT_TRUE(result.match_at(2)->destination_url.is_empty()); |
(...skipping 24 matching lines...) Expand all Loading... |
414 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 414 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"); | 415 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"); | 416 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
417 matches[4].destination_url = GURL("http://www.foo.com/"); | 417 matches[4].destination_url = GURL("http://www.foo.com/"); |
418 | 418 |
419 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 419 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
420 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 420 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
421 false, true, false, TestSchemeClassifier()); | 421 false, true, false, TestSchemeClassifier()); |
422 AutocompleteResult result; | 422 AutocompleteResult result; |
423 result.AppendMatches(input, matches); | 423 result.AppendMatches(input, matches); |
424 result.SortAndCull(input, template_url_service_.get()); | 424 result.SortAndCull(input, std::string(), template_url_service_.get()); |
425 | 425 |
426 // We expect the 3rd and 4th results to be removed. | 426 // We expect the 3rd and 4th results to be removed. |
427 ASSERT_EQ(3U, result.size()); | 427 ASSERT_EQ(3U, result.size()); |
428 EXPECT_EQ("http://www.foo.com/s?q=foo", | 428 EXPECT_EQ("http://www.foo.com/s?q=foo", |
429 result.match_at(0)->destination_url.spec()); | 429 result.match_at(0)->destination_url.spec()); |
430 EXPECT_EQ(1300, result.match_at(0)->relevance); | 430 EXPECT_EQ(1300, result.match_at(0)->relevance); |
431 EXPECT_EQ("http://www.foo.com/s?q=foo2", | 431 EXPECT_EQ("http://www.foo.com/s?q=foo2", |
432 result.match_at(1)->destination_url.spec()); | 432 result.match_at(1)->destination_url.spec()); |
433 EXPECT_EQ(1200, result.match_at(1)->relevance); | 433 EXPECT_EQ(1200, result.match_at(1)->relevance); |
434 EXPECT_EQ("http://www.foo.com/", | 434 EXPECT_EQ("http://www.foo.com/", |
(...skipping 30 matching lines...) Expand all Loading... |
465 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 465 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"); | 466 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
467 matches[4].destination_url = GURL("http://www.foo.com/"); | 467 matches[4].destination_url = GURL("http://www.foo.com/"); |
468 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); | 468 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); |
469 | 469 |
470 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 470 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
471 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 471 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
472 false, true, false, TestSchemeClassifier()); | 472 false, true, false, TestSchemeClassifier()); |
473 AutocompleteResult result; | 473 AutocompleteResult result; |
474 result.AppendMatches(input, matches); | 474 result.AppendMatches(input, matches); |
475 result.SortAndCull(input, template_url_service_.get()); | 475 result.SortAndCull(input, std::string(), template_url_service_.get()); |
476 | 476 |
477 // Expect 3 unique results after SortAndCull(). | 477 // Expect 3 unique results after SortAndCull(). |
478 ASSERT_EQ(3U, result.size()); | 478 ASSERT_EQ(3U, result.size()); |
479 | 479 |
480 // Check that 3rd and 4th result got added to the first result as dups | 480 // Check that 3rd and 4th result got added to the first result as dups |
481 // and also duplicates of the 4th match got copied. | 481 // and also duplicates of the 4th match got copied. |
482 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); | 482 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); |
483 const AutocompleteMatch* first_match = result.match_at(0); | 483 const AutocompleteMatch* first_match = result.match_at(0); |
484 EXPECT_EQ(matches[2].destination_url, | 484 EXPECT_EQ(matches[2].destination_url, |
485 first_match->duplicate_matches.at(1).destination_url); | 485 first_match->duplicate_matches.at(1).destination_url); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 518 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
519 } | 519 } |
520 base::FieldTrialList::CreateFieldTrial( | 520 base::FieldTrialList::CreateFieldTrial( |
521 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 521 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
522 | 522 |
523 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 523 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
524 GURL(), OmniboxEventProto::HOME_PAGE, false, false, | 524 GURL(), OmniboxEventProto::HOME_PAGE, false, false, |
525 false, true, false, TestSchemeClassifier()); | 525 false, true, false, TestSchemeClassifier()); |
526 AutocompleteResult result; | 526 AutocompleteResult result; |
527 result.AppendMatches(input, matches); | 527 result.AppendMatches(input, matches); |
528 result.SortAndCull(input, template_url_service_.get()); | 528 result.SortAndCull(input, std::string(), template_url_service_.get()); |
529 | 529 |
530 // Check the new ordering. The history-title results should be omitted. | 530 // Check the new ordering. The history-title results should be omitted. |
531 // We cannot check relevance scores because the matches are sorted by | 531 // We cannot check relevance scores because the matches are sorted by |
532 // demoted relevance but the actual relevance scores are not modified. | 532 // demoted relevance but the actual relevance scores are not modified. |
533 ASSERT_EQ(3u, result.size()); | 533 ASSERT_EQ(3u, result.size()); |
534 EXPECT_EQ("http://search-what-you-typed/", | 534 EXPECT_EQ("http://search-what-you-typed/", |
535 result.match_at(0)->destination_url.spec()); | 535 result.match_at(0)->destination_url.spec()); |
536 EXPECT_EQ("http://history-url/", | 536 EXPECT_EQ("http://history-url/", |
537 result.match_at(1)->destination_url.spec()); | 537 result.match_at(1)->destination_url.spec()); |
538 EXPECT_EQ("http://search-history/", | 538 EXPECT_EQ("http://search-history/", |
(...skipping 24 matching lines...) Expand all Loading... |
563 base::FieldTrialList::CreateFieldTrial( | 563 base::FieldTrialList::CreateFieldTrial( |
564 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); | 564 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); |
565 | 565 |
566 { | 566 { |
567 AutocompleteInput input( | 567 AutocompleteInput input( |
568 base::string16(), base::string16::npos, std::string(), GURL(), | 568 base::string16(), base::string16::npos, std::string(), GURL(), |
569 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, | 569 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, |
570 false, false, true, false, TestSchemeClassifier()); | 570 false, false, true, false, TestSchemeClassifier()); |
571 AutocompleteResult result; | 571 AutocompleteResult result; |
572 result.AppendMatches(input, matches); | 572 result.AppendMatches(input, matches); |
573 result.SortAndCull(input, template_url_service_.get()); | 573 result.SortAndCull(input, std::string(), template_url_service_.get()); |
574 | 574 |
575 // The NAVSUGGEST dup-url stay above search-url since the navsuggest | 575 // The NAVSUGGEST dup-url stay above search-url since the navsuggest |
576 // variant should not be demoted. | 576 // variant should not be demoted. |
577 ASSERT_EQ(4u, result.size()); | 577 ASSERT_EQ(4u, result.size()); |
578 EXPECT_EQ("http://search-what-you-typed/", | 578 EXPECT_EQ("http://search-what-you-typed/", |
579 result.match_at(0)->destination_url.spec()); | 579 result.match_at(0)->destination_url.spec()); |
580 EXPECT_EQ("http://dup-url/", | 580 EXPECT_EQ("http://dup-url/", |
581 result.match_at(1)->destination_url.spec()); | 581 result.match_at(1)->destination_url.spec()); |
582 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, | 582 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, |
583 result.match_at(1)->type); | 583 result.match_at(1)->type); |
(...skipping 17 matching lines...) Expand all Loading... |
601 // is already a legal default match (which is the default from | 601 // is already a legal default match (which is the default from |
602 // PopulateAutocompleteMatches()). | 602 // PopulateAutocompleteMatches()). |
603 ACMatches matches; | 603 ACMatches matches; |
604 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 604 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
605 AutocompleteInput input(base::string16(), base::string16::npos, | 605 AutocompleteInput input(base::string16(), base::string16::npos, |
606 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 606 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
607 false, false, false, true, false, | 607 false, false, false, true, false, |
608 TestSchemeClassifier()); | 608 TestSchemeClassifier()); |
609 AutocompleteResult result; | 609 AutocompleteResult result; |
610 result.AppendMatches(input, matches); | 610 result.AppendMatches(input, matches); |
611 result.SortAndCull(input, template_url_service_.get()); | 611 result.SortAndCull(input, std::string(), template_url_service_.get()); |
612 AssertResultMatches(result, data, 4); | 612 AssertResultMatches(result, data, 4); |
613 } | 613 } |
614 | 614 |
615 { | 615 { |
616 // Check that reorder swaps up a result appropriately. | 616 // Check that reorder swaps up a result appropriately. |
617 ACMatches matches; | 617 ACMatches matches; |
618 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 618 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
619 matches[0].allowed_to_be_default_match = false; | 619 matches[0].allowed_to_be_default_match = false; |
620 matches[1].allowed_to_be_default_match = false; | 620 matches[1].allowed_to_be_default_match = false; |
621 AutocompleteInput input(base::string16(), base::string16::npos, | 621 AutocompleteInput input(base::string16(), base::string16::npos, |
622 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 622 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
623 false, false, false, true, false, | 623 false, false, false, true, false, |
624 TestSchemeClassifier()); | 624 TestSchemeClassifier()); |
625 AutocompleteResult result; | 625 AutocompleteResult result; |
626 result.AppendMatches(input, matches); | 626 result.AppendMatches(input, matches); |
627 result.SortAndCull(input, template_url_service_.get()); | 627 result.SortAndCull(input, std::string(), template_url_service_.get()); |
628 ASSERT_EQ(4U, result.size()); | 628 ASSERT_EQ(4U, result.size()); |
629 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 629 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
630 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 630 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
631 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 631 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
632 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 632 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
633 } | 633 } |
634 } | 634 } |
635 | 635 |
636 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) { | 636 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) { |
637 ACMatches matches; | 637 ACMatches matches; |
(...skipping 18 matching lines...) Expand all Loading... |
656 matches.clear(); | 656 matches.clear(); |
657 | 657 |
658 // Case 4: Standalone verbatim match found in AutocompleteResult. | 658 // Case 4: Standalone verbatim match found in AutocompleteResult. |
659 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 659 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
660 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | 660 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); |
661 result.AppendMatches(AutocompleteInput(), matches); | 661 result.AppendMatches(AutocompleteInput(), matches); |
662 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | 662 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); |
663 result.Reset(); | 663 result.Reset(); |
664 matches.clear(); | 664 matches.clear(); |
665 } | 665 } |
OLD | NEW |