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 "components/omnibox/browser/shortcuts_provider.h" | 5 #include "components/omnibox/browser/shortcuts_provider.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 } | 743 } |
744 | 744 |
745 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) { | 745 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) { |
746 AutocompleteInput input(ASCIIToUTF16("about:o"), base::string16::npos, | 746 AutocompleteInput input(ASCIIToUTF16("about:o"), base::string16::npos, |
747 std::string(), GURL(), | 747 std::string(), GURL(), |
748 metrics::OmniboxEventProto::INVALID_SPEC, false, | 748 metrics::OmniboxEventProto::INVALID_SPEC, false, |
749 false, true, true, true, TestSchemeClassifier()); | 749 false, true, true, true, TestSchemeClassifier()); |
750 provider_->Start(input, false); | 750 provider_->Start(input, false); |
751 EXPECT_TRUE(provider_->matches().empty()); | 751 EXPECT_TRUE(provider_->matches().empty()); |
752 } | 752 } |
753 | |
754 TEST_F(ShortcutsProviderTest, SortAndDedupMatches) { | |
755 using ShortcutMatch = ShortcutsProvider::ShortcutMatch; | |
756 // Create empty ShortcutsDatabase::Shortcut object that will be used to | |
757 // initialize ShortcutMatch objects. | |
758 ShortcutsDatabase::Shortcut::MatchCore db_match_core( | |
759 base::string16(), GURL(), base::string16(), std::string(), | |
760 base::string16(), std::string(), 0, 0, base::string16()); | |
761 // Object used only for ShortcutMatch initialization. | |
762 ShortcutsDatabase::Shortcut db_shortcut(std::string(), base::string16(), | |
763 db_match_core, base::Time(), 0); | |
764 | |
765 std::vector<ShortcutMatch> matches; | |
766 db_shortcut.match_core.contents = base::ASCIIToUTF16("123"); | |
Peter Kasting
2016/04/14 23:52:34
Nit: Set this value in the constructor above, push
Alexander Yashkin
2016/04/15 09:14:15
I removed unittest for SortAndDedupMatches entire
| |
767 matches.push_back( | |
Peter Kasting
2016/04/14 23:52:34
Nit: While normally push_back() is more readable,
Alexander Yashkin
2016/04/15 09:14:15
Removed test entirely.
| |
768 ShortcutMatch(42, GURL("http://www.abc.com"), &db_shortcut)); | |
769 db_shortcut.match_core.contents = base::ASCIIToUTF16("123"); | |
770 matches.push_back( | |
771 ShortcutMatch(43, GURL("http://www.abcd.com"), &db_shortcut)); | |
772 db_shortcut.match_core.contents = base::ASCIIToUTF16("123"); | |
773 matches.push_back( | |
774 ShortcutMatch(42, GURL("http://www.abcde.com"), &db_shortcut)); | |
775 db_shortcut.match_core.contents = base::ASCIIToUTF16("DEADBEEF"); | |
776 matches.push_back( | |
777 ShortcutMatch(41, GURL("http://www.abcd.com"), &db_shortcut)); | |
778 db_shortcut.match_core.contents = base::ASCIIToUTF16("234"); | |
779 matches.push_back( | |
780 ShortcutMatch(42, GURL("http://www.abcde.com"), &db_shortcut)); | |
781 db_shortcut.match_core.contents = base::ASCIIToUTF16("123"); | |
782 matches.push_back( | |
783 ShortcutMatch(42, GURL("http://www.abc.com"), &db_shortcut)); | |
784 | |
785 ShortcutsProvider::SortAndDedupMatches( | |
786 metrics::OmniboxEventProto::INVALID_SPEC, &matches); | |
787 // Expect deduplicated matches to be sorted by destination. | |
788 // The remaining match out of each set of duplicates should be the one with | |
789 // the highest relevance. | |
790 EXPECT_EQ(3U, matches.size()); | |
791 EXPECT_EQ(matches[0].stripped_destination_url, GURL("http://www.abc.com")); | |
Peter Kasting
2016/04/14 23:52:34
Nit: (expected, actual) (many places)
Alexander Yashkin
2016/04/15 09:14:15
Removed test entirely.
| |
792 EXPECT_EQ(matches[0].relevance, 42); | |
793 EXPECT_EQ(matches[0].contents, base::ASCIIToUTF16("123")); | |
794 EXPECT_EQ(matches[1].stripped_destination_url, GURL("http://www.abcd.com")); | |
795 EXPECT_EQ(matches[1].relevance, 43); | |
796 EXPECT_EQ(matches[1].contents, base::ASCIIToUTF16("123")); | |
797 EXPECT_EQ(matches[2].stripped_destination_url, GURL("http://www.abcde.com")); | |
798 EXPECT_EQ(matches[2].relevance, 42); | |
799 EXPECT_EQ(matches[2].contents, base::ASCIIToUTF16("123")); | |
800 } | |
OLD | NEW |