Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/autocomplete_result.h" | 5 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 AutocompleteInput::HOME_PAGE, false, false, false, | 479 AutocompleteInput::HOME_PAGE, false, false, false, |
| 480 AutocompleteInput::ALL_MATCHES); | 480 AutocompleteInput::ALL_MATCHES); |
| 481 result.SortAndCull(input, test_util_.profile()); | 481 result.SortAndCull(input, test_util_.profile()); |
| 482 ASSERT_EQ(4U, result.size()); | 482 ASSERT_EQ(4U, result.size()); |
| 483 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 483 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 484 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 484 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 485 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 485 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 486 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 486 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | |
| 490 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { | |
| 491 // Add some matches. | |
| 492 ACMatches matches; | |
| 493 { | |
|
Mark P
2013/12/12 23:13:07
Not required but please seriously consider that al
kmadhusu
2013/12/13 01:00:29
Done.
| |
| 494 AutocompleteMatch match; | |
| 495 match.destination_url = GURL("http://search-what-you-typed/"); | |
| 496 match.relevance = 1300; | |
| 497 match.allowed_to_be_default_match = true; | |
| 498 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; | |
| 499 matches.push_back(match); | |
| 500 } | |
| 501 { | |
| 502 AutocompleteMatch match; | |
| 503 match.destination_url = GURL("http://history-title/"); | |
| 504 match.relevance = 1200; | |
| 505 match.allowed_to_be_default_match = true; | |
| 506 match.type = AutocompleteMatchType::HISTORY_TITLE; | |
| 507 matches.push_back(match); | |
| 508 } | |
| 509 { | |
| 510 AutocompleteMatch match; | |
| 511 match.destination_url = GURL("http://search-history/"); | |
| 512 match.relevance = 500; | |
| 513 match.allowed_to_be_default_match = true; | |
| 514 match.type = AutocompleteMatchType::SEARCH_HISTORY; | |
| 515 matches.push_back(match); | |
| 516 } | |
| 517 | |
| 518 base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
| 519 "Group1 hide_verbatim:1"); | |
| 520 AutocompleteResult result; | |
| 521 result.AppendMatches(matches); | |
| 522 EXPECT_TRUE(result.ShouldHideTopMatch()); | |
| 523 } | |
| 524 | |
| 525 TEST_F(AutocompleteResultTest, DoNotHideTopMatch) { | |
| 526 ACMatches matches; | |
| 527 { | |
| 528 AutocompleteMatch match; | |
| 529 match.destination_url = GURL("http://search-what-you-typed/"); | |
| 530 match.relevance = 1300; | |
| 531 match.allowed_to_be_default_match = true; | |
| 532 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; | |
| 533 matches.push_back(match); | |
| 534 } | |
| 535 { | |
| 536 AutocompleteMatch match; | |
| 537 match.destination_url = GURL("http://search-what-you-typed_url/"); | |
|
Mark P
2013/12/12 23:13:07
I'm sure you meant url-what-you-typed. Please fix
Mark P
2013/12/12 23:13:07
nit: no _ in hostnames
here and below
kmadhusu
2013/12/13 01:00:29
Done.
kmadhusu
2013/12/13 01:00:29
I was just adding a dummy url. Updated the destina
| |
| 538 match.relevance = 1240; | |
| 539 match.allowed_to_be_default_match = true; | |
| 540 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; | |
|
Mark P
2013/12/12 23:13:07
Did you mean this to be URL_WHAT_YOU_TYPED?
here
kmadhusu
2013/12/13 01:00:29
I didn't mean that. Now that you mentioned, I have
| |
| 541 matches.push_back(match); | |
| 542 } | |
| 543 { | |
| 544 AutocompleteMatch match; | |
| 545 match.destination_url = GURL("http://history-title/"); | |
| 546 match.relevance = 1200; | |
| 547 match.allowed_to_be_default_match = true; | |
| 548 match.type = AutocompleteMatchType::HISTORY_TITLE; | |
| 549 matches.push_back(match); | |
| 550 } | |
| 551 { | |
| 552 AutocompleteMatch match; | |
| 553 match.destination_url = GURL("http://search-history/"); | |
| 554 match.relevance = 500; | |
| 555 match.allowed_to_be_default_match = true; | |
| 556 match.type = AutocompleteMatchType::SEARCH_HISTORY; | |
| 557 matches.push_back(match); | |
| 558 } | |
| 559 | |
| 560 base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
| 561 "Group1 hide_verbatim:1"); | |
| 562 AutocompleteResult result; | |
| 563 result.AppendMatches(matches); | |
| 564 // If the verbatim first match is followed by another verbatim match, don't | |
| 565 // hide the top verbatim match. | |
| 566 EXPECT_FALSE(result.ShouldHideTopMatch()); | |
| 567 } | |
| 568 | |
| 569 TEST_F(AutocompleteResultTest, DoNotHideTopMatch_TopMatchIsNotVerbatim) { | |
| 570 ACMatches matches; | |
| 571 { | |
| 572 AutocompleteMatch match; | |
| 573 match.destination_url = GURL("http://search-history/"); | |
| 574 match.relevance = 500; | |
|
Mark P
2013/12/12 23:13:07
500 here is extremely misleading. Did you mean 13
kmadhusu
2013/12/13 01:00:29
Yes. My bad (copy paste error). Fixed.
| |
| 575 match.allowed_to_be_default_match = true; | |
| 576 match.type = AutocompleteMatchType::SEARCH_HISTORY; | |
| 577 matches.push_back(match); | |
| 578 } | |
| 579 { | |
| 580 AutocompleteMatch match; | |
| 581 match.destination_url = GURL("http://search-what-you-typed_url/"); | |
| 582 match.relevance = 1240; | |
| 583 match.allowed_to_be_default_match = true; | |
| 584 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; | |
| 585 matches.push_back(match); | |
| 586 } | |
| 587 { | |
| 588 AutocompleteMatch match; | |
| 589 match.destination_url = GURL("http://history-title/"); | |
| 590 match.relevance = 1200; | |
| 591 match.allowed_to_be_default_match = true; | |
| 592 match.type = AutocompleteMatchType::HISTORY_TITLE; | |
| 593 matches.push_back(match); | |
| 594 } | |
| 595 | |
| 596 base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
| 597 "Group1 hide_verbatim:1"); | |
| 598 AutocompleteResult result; | |
| 599 result.AppendMatches(matches); | |
| 600 // Top match is not a verbatim type match. Do not hide the top match. | |
| 601 EXPECT_FALSE(result.ShouldHideTopMatch()); | |
| 602 } | |
| 603 | |
| 604 TEST_F(AutocompleteResultTest, DoNotHideTopMatch_FieldTrialFlagDisabled) { | |
|
Mark P
2013/12/12 23:13:07
Please use an identical config to ShouldHideTopMat
kmadhusu
2013/12/13 01:00:29
Done.
| |
| 605 ACMatches matches; | |
| 606 { | |
| 607 AutocompleteMatch match; | |
| 608 match.destination_url = GURL("http://search-what-you-typed_url/"); | |
| 609 match.relevance = 1240; | |
| 610 match.allowed_to_be_default_match = true; | |
| 611 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; | |
| 612 matches.push_back(match); | |
| 613 } | |
| 614 { | |
| 615 AutocompleteMatch match; | |
| 616 match.destination_url = GURL("http://history-title/"); | |
| 617 match.relevance = 1200; | |
| 618 match.allowed_to_be_default_match = true; | |
| 619 match.type = AutocompleteMatchType::HISTORY_TITLE; | |
| 620 matches.push_back(match); | |
| 621 } | |
| 622 | |
| 623 base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
| 624 "Group1 hide_verbatim:0"); | |
| 625 AutocompleteResult result; | |
| 626 result.AppendMatches(matches); | |
| 627 // Field trial flag "hide_verbatim" is disabled. Do not hide top match. | |
| 628 EXPECT_FALSE(result.ShouldHideTopMatch()); | |
| 629 } | |
| 630 | |
| 631 TEST_F(AutocompleteResultTest, | |
| 632 TopMatchIsVerbatimAndHasNoConsecutiveVerbatimMatches) { | |
| 633 ACMatches matches; | |
| 634 { | |
| 635 AutocompleteMatch match; | |
| 636 match.destination_url = GURL("http://search-what-you-typed_url/"); | |
| 637 match.relevance = 1240; | |
| 638 match.allowed_to_be_default_match = true; | |
| 639 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; | |
| 640 matches.push_back(match); | |
| 641 } | |
| 642 { | |
| 643 AutocompleteMatch match; | |
| 644 match.destination_url = GURL("http://history-title/"); | |
| 645 match.relevance = 1200; | |
| 646 match.allowed_to_be_default_match = true; | |
| 647 match.type = AutocompleteMatchType::HISTORY_TITLE; | |
| 648 matches.push_back(match); | |
| 649 } | |
| 650 AutocompleteResult result; | |
| 651 result.AppendMatches(matches); | |
| 652 EXPECT_TRUE(result.TopMatchIsVerbatimAndHasNoConsecutiveVerbatimMatches()); | |
| 653 } | |
| 654 | |
| 655 TEST_F(AutocompleteResultTest, | |
| 656 TopMatchIsVerbatimAndHasConsecutiveVerbatimMatches) { | |
| 657 ACMatches matches; | |
| 658 { | |
| 659 AutocompleteMatch match; | |
| 660 match.destination_url = GURL("http://search-what-you-typed_url/"); | |
| 661 match.relevance = 1240; | |
| 662 match.allowed_to_be_default_match = true; | |
| 663 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; | |
| 664 matches.push_back(match); | |
| 665 } | |
| 666 { | |
| 667 AutocompleteMatch match; | |
| 668 match.destination_url = GURL("http://search-what-you-typed_url_1/"); | |
| 669 match.relevance = 1220; | |
| 670 match.allowed_to_be_default_match = true; | |
| 671 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; | |
| 672 matches.push_back(match); | |
| 673 } | |
| 674 { | |
| 675 AutocompleteMatch match; | |
| 676 match.destination_url = GURL("http://history-title/"); | |
| 677 match.relevance = 1200; | |
| 678 match.allowed_to_be_default_match = true; | |
| 679 match.type = AutocompleteMatchType::HISTORY_TITLE; | |
| 680 matches.push_back(match); | |
| 681 } | |
| 682 AutocompleteResult result; | |
| 683 result.AppendMatches(matches); | |
| 684 EXPECT_FALSE(result.TopMatchIsVerbatimAndHasNoConsecutiveVerbatimMatches()); | |
| 685 } | |
| 686 | |
| 687 TEST_F(AutocompleteResultTest, TopMatchIsNotVerbatim) { | |
| 688 ACMatches matches; | |
| 689 AutocompleteResult result; | |
| 690 result.AppendMatches(matches); | |
| 691 | |
| 692 // Result set is empty. | |
| 693 EXPECT_FALSE(result.TopMatchIsVerbatimAndHasNoConsecutiveVerbatimMatches()); | |
| 694 | |
| 695 // Add a non-verbatim match to the result. | |
| 696 { | |
| 697 AutocompleteMatch match; | |
| 698 match.destination_url = GURL("http://history-title/"); | |
| 699 match.relevance = 1200; | |
| 700 match.allowed_to_be_default_match = true; | |
| 701 match.type = AutocompleteMatchType::HISTORY_TITLE; | |
| 702 matches.push_back(match); | |
| 703 } | |
| 704 result.AppendMatches(matches); | |
| 705 EXPECT_FALSE(result.TopMatchIsVerbatimAndHasNoConsecutiveVerbatimMatches()); | |
| 706 } | |
|
Mark P
2013/12/12 23:13:07
please add a test somewhere that TopMatchIsVerbati
kmadhusu
2013/12/13 01:00:29
I am sorry, can you explain why that function shou
| |
| OLD | NEW |