Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: components/omnibox/autocomplete_result_unittest.cc

Issue 879053002: Remove Omnibox Disallow Inlining Field Trial (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 TestSchemeClassifier()); 550 TestSchemeClassifier());
551 result.SortAndCull(input, template_url_service_.get()); 551 result.SortAndCull(input, template_url_service_.get());
552 ASSERT_EQ(4U, result.size()); 552 ASSERT_EQ(4U, result.size());
553 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); 553 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
554 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); 554 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
555 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); 555 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
556 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); 556 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
557 } 557 }
558 } 558 }
559 559
560
561
562 TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) {
563 TestData data[] = {
564 { 0, 0, 1300 },
565 { 1, 0, 1200 },
566 { 2, 0, 1100 },
567 { 3, 0, 1000 }
568 };
569
570 {
571 // Check that with the field trial disabled, we keep keep the first match
572 // first even if it has an inline autocompletion.
573 ACMatches matches;
574 PopulateAutocompleteMatches(data, arraysize(data), &matches);
575 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
576 AutocompleteResult result;
577 result.AppendMatches(matches);
578 AutocompleteInput input(base::string16(), base::string16::npos,
579 std::string(), GURL(),
580 OmniboxEventProto::HOME_PAGE, false, false, false,
581 true,
582 TestSchemeClassifier());
583 result.SortAndCull(input, template_url_service_.get());
584 AssertResultMatches(result, data, 4);
585 }
586
587 // Enable the field trial to disable inlining.
588 {
589 std::map<std::string, std::string> params;
590 params[OmniboxFieldTrial::kDisableInliningRule] = "true";
591 ASSERT_TRUE(variations::AssociateVariationParams(
592 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params));
593 }
594 base::FieldTrialList::CreateFieldTrial(
595 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D");
596
597 {
598 // Now the first match should be demoted past the second.
599 ACMatches matches;
600 PopulateAutocompleteMatches(data, arraysize(data), &matches);
601 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
602 AutocompleteResult result;
603 result.AppendMatches(matches);
604 AutocompleteInput input(base::string16(), base::string16::npos,
605 std::string(), GURL(),
606 OmniboxEventProto::HOME_PAGE, false, false, false,
607 true,
608 TestSchemeClassifier());
609 result.SortAndCull(input, template_url_service_.get());
610 ASSERT_EQ(4U, result.size());
611 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec());
612 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
613 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec());
614 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
615 }
616
617 {
618 // But if there was no inline autocompletion on the first match, then
619 // the order should stay the same. This is true even if there are
620 // inline autocompletions elsewhere.
621 ACMatches matches;
622 PopulateAutocompleteMatches(data, arraysize(data), &matches);
623 matches[2].inline_autocompletion = base::ASCIIToUTF16("completion");
624 AutocompleteResult result;
625 result.AppendMatches(matches);
626 AutocompleteInput input(base::string16(), base::string16::npos,
627 std::string(), GURL(),
628 OmniboxEventProto::HOME_PAGE, false, false, false,
629 true,
630 TestSchemeClassifier());
631 result.SortAndCull(input, template_url_service_.get());
632 AssertResultMatches(result, data, 4);
633 }
634
635 {
636 // Try a more complicated situation.
637 ACMatches matches;
638 PopulateAutocompleteMatches(data, arraysize(data), &matches);
639 matches[0].allowed_to_be_default_match = false;
640 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion");
641 AutocompleteResult result;
642 result.AppendMatches(matches);
643 AutocompleteInput input(base::string16(), base::string16::npos,
644 std::string(), GURL(),
645 OmniboxEventProto::HOME_PAGE, false, false, false,
646 true,
647 TestSchemeClassifier());
648 result.SortAndCull(input, template_url_service_.get());
649 ASSERT_EQ(4U, result.size());
650 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
651 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
652 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
653 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
654 }
655
656 {
657 // Try another complicated situation.
658 ACMatches matches;
659 PopulateAutocompleteMatches(data, arraysize(data), &matches);
660 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
661 matches[1].allowed_to_be_default_match = false;
662 AutocompleteResult result;
663 result.AppendMatches(matches);
664 AutocompleteInput input(base::string16(), base::string16::npos,
665 std::string(), GURL(),
666 OmniboxEventProto::HOME_PAGE, false, false, false,
667 true,
668 TestSchemeClassifier());
669 result.SortAndCull(input, template_url_service_.get());
670 ASSERT_EQ(4U, result.size());
671 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
672 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
673 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
674 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
675 }
676
677 {
678 // Check that disaster doesn't strike if we can't demote the top inline
679 // autocompletion because every match either has a completion or isn't
680 // allowed to be the default match. In this case, we should leave
681 // everything untouched.
682 ACMatches matches;
683 PopulateAutocompleteMatches(data, arraysize(data), &matches);
684 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
685 matches[1].allowed_to_be_default_match = false;
686 matches[2].allowed_to_be_default_match = false;
687 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion");
688 AutocompleteResult result;
689 result.AppendMatches(matches);
690 AutocompleteInput input(base::string16(), base::string16::npos,
691 std::string(), GURL(),
692 OmniboxEventProto::HOME_PAGE, false, false, false,
693 true,
694 TestSchemeClassifier());
695 result.SortAndCull(input, template_url_service_.get());
696 AssertResultMatches(result, data, 4);
697 }
698
699 {
700 // Check a similar situation, except in this case the top match is not
701 // allowed to the default match, so it still needs to be demoted so we
702 // get a legal default match first. That match will have an inline
703 // autocompletion because we don't have any better options.
704 ACMatches matches;
705 PopulateAutocompleteMatches(data, arraysize(data), &matches);
706 matches[0].allowed_to_be_default_match = false;
707 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion");
708 matches[2].allowed_to_be_default_match = false;
709 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion");
710 AutocompleteResult result;
711 result.AppendMatches(matches);
712 AutocompleteInput input(base::string16(), base::string16::npos,
713 std::string(), GURL(),
714 OmniboxEventProto::HOME_PAGE, false, false, false,
715 true,
716 TestSchemeClassifier());
717 result.SortAndCull(input, template_url_service_.get());
718 ASSERT_EQ(4U, result.size());
719 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec());
720 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
721 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec());
722 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
723 }
724 }
725
726 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { 560 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) {
727 base::FieldTrialList::CreateFieldTrial("InstantExtended", 561 base::FieldTrialList::CreateFieldTrial("InstantExtended",
728 "Group1 hide_verbatim:1"); 562 "Group1 hide_verbatim:1");
729 ACMatches matches; 563 ACMatches matches;
730 564
731 // Case 1: Top match is a verbatim match. 565 // Case 1: Top match is a verbatim match.
732 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); 566 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches);
733 AutocompleteResult result; 567 AutocompleteResult result;
734 result.AppendMatches(matches); 568 result.AppendMatches(matches);
735 EXPECT_TRUE(result.ShouldHideTopMatch()); 569 EXPECT_TRUE(result.ShouldHideTopMatch());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 result.Reset(); 661 result.Reset();
828 matches.clear(); 662 matches.clear();
829 663
830 // Case 5: Multiple verbatim matches found in AutocompleteResult. 664 // Case 5: Multiple verbatim matches found in AutocompleteResult.
831 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 665 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches,
832 arraysize(kVerbatimMatches), 666 arraysize(kVerbatimMatches),
833 &matches); 667 &matches);
834 result.AppendMatches(matches); 668 result.AppendMatches(matches);
835 EXPECT_FALSE(result.ShouldHideTopMatch()); 669 EXPECT_FALSE(result.ShouldHideTopMatch());
836 } 670 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698