OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/omnibox/browser/shortcut_match.h" | |
6 | |
7 #include <algorithm> | |
8 #include <string> | |
9 | |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "components/omnibox/browser/shortcuts_backend.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 class ShortcutMatchTest : public testing::Test { | |
15 protected: | |
16 ShortcutMatch CreateShortcutMatch(int relevance, | |
17 const GURL& stripped_destination_url, | |
18 const std::string& contents); | |
19 | |
20 const base::string16& GetMatchContents(const ShortcutMatch& match); | |
21 | |
22 std::vector<std::unique_ptr<ShortcutsDatabase::Shortcut>> db_shortcuts_; | |
23 }; | |
24 | |
25 ShortcutMatch ShortcutMatchTest::CreateShortcutMatch( | |
26 int relevance, | |
27 const GURL& stripped_destination_url, | |
28 const std::string& contents) { | |
29 // Create ShortcutsDatabase::Shortcut object and intialize its contents | |
30 // field only. Store it in db_shortcuts vector. | |
Peter Kasting
2016/04/12 00:55:08
Why do we need a vector to hold one object? And w
Alexander Yashkin
2016/04/12 09:09:20
Redone, removed vector of ShortcutMatches. It rema
| |
31 db_shortcuts_.emplace_back(new ShortcutsDatabase::Shortcut()); | |
32 db_shortcuts_.back()->match_core.contents = base::ASCIIToUTF16(contents); | |
33 return ShortcutMatch(relevance, stripped_destination_url, | |
34 db_shortcuts_.back().get()); | |
35 } | |
36 | |
37 const base::string16& ShortcutMatchTest::GetMatchContents( | |
38 const ShortcutMatch& match) { | |
39 return match.shortcut->match_core.contents; | |
40 } | |
41 | |
42 TEST_F(ShortcutMatchTest, DedupShortcutMatchesByDestination) { | |
43 ShortcutMatches matches; | |
44 matches.push_back( | |
45 CreateShortcutMatch(42, GURL("http://www.abc.com"), "123")); | |
46 matches.push_back( | |
47 CreateShortcutMatch(43, GURL("http://www.abcd.com"), "123")); | |
48 matches.push_back( | |
49 CreateShortcutMatch(42, GURL("http://www.abcde.com"), "123")); | |
50 matches.push_back( | |
51 CreateShortcutMatch(41, GURL("http://www.abcd.com"), "DEADBEEF")); | |
52 matches.push_back( | |
53 CreateShortcutMatch(42, GURL("http://www.abcde.com"), "234")); | |
54 matches.push_back( | |
55 CreateShortcutMatch(42, GURL("http://www.abc.com"), "123")); | |
56 | |
57 ShortcutMatch::DedupShortcutMatchesByDestination( | |
58 metrics::OmniboxEventProto::INVALID_SPEC, &matches); | |
59 // Expect deduplicated matches to be sorted by destination. | |
60 // Matches with higher relevance are left from duplicates. | |
Peter Kasting
2016/04/12 00:55:08
Nit: How about:
...The remaining match out of eac
Alexander Yashkin
2016/04/12 09:09:20
Done.
| |
61 EXPECT_EQ(matches.size(), 3U); | |
62 EXPECT_EQ(matches[0].stripped_destination_url, GURL("http://www.abc.com")); | |
63 EXPECT_EQ(matches[0].relevance, 42); | |
64 EXPECT_EQ(GetMatchContents(matches[0]), base::ASCIIToUTF16("123")); | |
65 EXPECT_EQ(matches[1].stripped_destination_url, GURL("http://www.abcd.com")); | |
66 EXPECT_EQ(matches[1].relevance, 43); | |
67 EXPECT_EQ(GetMatchContents(matches[1]), base::ASCIIToUTF16("123")); | |
68 EXPECT_EQ(matches[2].stripped_destination_url, GURL("http://www.abcde.com")); | |
69 EXPECT_EQ(matches[2].relevance, 42); | |
70 EXPECT_EQ(GetMatchContents(matches[2]), base::ASCIIToUTF16("123")); | |
71 } | |
OLD | NEW |