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

Side by Side Diff: components/omnibox/browser/shortcuts_provider_unittest.cc

Issue 1655933004: Refactor to share code between shortcuts tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shortcuts
Patch Set: Created 4 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 (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 14 matching lines...) Expand all
25 #include "components/history/core/browser/url_database.h" 25 #include "components/history/core/browser/url_database.h"
26 #include "components/history/core/test/history_service_test_util.h" 26 #include "components/history/core/test/history_service_test_util.h"
27 #include "components/metrics/proto/omnibox_event.pb.h" 27 #include "components/metrics/proto/omnibox_event.pb.h"
28 #include "components/omnibox/browser/autocomplete_input.h" 28 #include "components/omnibox/browser/autocomplete_input.h"
29 #include "components/omnibox/browser/autocomplete_match.h" 29 #include "components/omnibox/browser/autocomplete_match.h"
30 #include "components/omnibox/browser/autocomplete_provider.h" 30 #include "components/omnibox/browser/autocomplete_provider.h"
31 #include "components/omnibox/browser/autocomplete_result.h" 31 #include "components/omnibox/browser/autocomplete_result.h"
32 #include "components/omnibox/browser/in_memory_url_index.h" 32 #include "components/omnibox/browser/in_memory_url_index.h"
33 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" 33 #include "components/omnibox/browser/mock_autocomplete_provider_client.h"
34 #include "components/omnibox/browser/shortcuts_backend.h" 34 #include "components/omnibox/browser/shortcuts_backend.h"
35 #include "components/omnibox/browser/shortcuts_provider_test_util.h"
35 #include "components/omnibox/browser/test_scheme_classifier.h" 36 #include "components/omnibox/browser/test_scheme_classifier.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
37 38
38 using base::ASCIIToUTF16; 39 using base::ASCIIToUTF16;
39 40
40 // TestShortcutInfo ----------------------------------------------------------- 41 // TestShortcutInfo -----------------------------------------------------------
41 42
42 namespace { 43 namespace {
43 44
44 struct TestShortcutInfo { 45 struct TestShortcutInfo shortcut_test_db[] = {
45 std::string guid; 46 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E0", "goog", "www.google.com",
46 std::string text; 47 "http://www.google.com/", "Google", "0,1,4,0", "Google", "0,3,4,1",
47 std::string fill_into_edit; 48 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
48 std::string destination_url; 49 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E1", "slash", "slashdot.org",
49 std::string contents; 50 "http://slashdot.org/", "slashdot.org", "0,3,5,1",
50 std::string contents_class; 51 "Slashdot - News for nerds, stuff that matters", "0,2,5,0",
51 std::string description; 52 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 0, 100},
52 std::string description_class; 53 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E2", "news", "slashdot.org",
53 ui::PageTransition transition; 54 "http://slashdot.org/", "slashdot.org", "0,1",
54 AutocompleteMatch::Type type; 55 "Slashdot - News for nerds, stuff that matters", "0,0,11,2,15,0",
55 std::string keyword; 56 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 0, 5},
56 int days_from_now; 57 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E3", "news", "sports.yahoo.com",
57 int number_of_hits; 58 "http://sports.yahoo.com/", "sports.yahoo.com", "0,1",
58 } shortcut_test_db[] = { 59 "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more",
59 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E0", "goog", "www.google.com", 60 "0,0,23,2,27,0", ui::PAGE_TRANSITION_TYPED,
60 "http://www.google.com/", "Google", "0,1,4,0", "Google", "0,3,4,1", 61 AutocompleteMatchType::HISTORY_TITLE, "", 2, 5},
61 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 62 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E4", "news weather",
62 100 }, 63 "www.cnn.com/index.html", "http://www.cnn.com/index.html",
63 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E1", "slash", "slashdot.org", 64 "www.cnn.com/index.html", "0,1",
64 "http://slashdot.org/", "slashdot.org", "0,3,5,1", 65 "CNN.com - Breaking News, U.S., World, Weather, Entertainment & Video",
65 "Slashdot - News for nerds, stuff that matters", "0,2,5,0", 66 "0,0,19,2,23,0,38,2,45,0", ui::PAGE_TRANSITION_TYPED,
66 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 0, 67 AutocompleteMatchType::HISTORY_TITLE, "", 1, 10},
67 100 }, 68 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E5", "nhl scores", "sports.yahoo.com",
68 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E2", "news", "slashdot.org", 69 "http://sports.yahoo.com/", "sports.yahoo.com", "0,1",
69 "http://slashdot.org/", "slashdot.org", "0,1", 70 "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more",
70 "Slashdot - News for nerds, stuff that matters", "0,0,11,2,15,0", 71 "0,0,29,2,35,0", ui::PAGE_TRANSITION_TYPED,
71 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 0, 72 AutocompleteMatchType::HISTORY_BODY, "", 1, 10},
72 5 }, 73 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E6", "nhl scores",
73 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E3", "news", "sports.yahoo.com", 74 "www.nhl.com/scores/index.html", "http://www.nhl.com/scores/index.html",
74 "http://sports.yahoo.com/", "sports.yahoo.com", "0,1", 75 "www.nhl.com/scores/index.html", "0,1,4,3,7,1",
75 "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more", 76 "January 13, 2010 - NHL.com - Scores", "0,0,19,2,22,0,29,2,35,0",
76 "0,0,23,2,27,0", ui::PAGE_TRANSITION_TYPED, 77 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 5, 1},
77 AutocompleteMatchType::HISTORY_TITLE, "", 2, 5 }, 78 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E7", "just", "www.testsite.com/a.html",
78 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E4", "news weather", 79 "http://www.testsite.com/a.html", "www.testsite.com/a.html", "0,1",
79 "www.cnn.com/index.html", "http://www.cnn.com/index.html", 80 "Test - site - just a test", "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
80 "www.cnn.com/index.html", "0,1", 81 AutocompleteMatchType::HISTORY_TITLE, "", 5, 1},
81 "CNN.com - Breaking News, U.S., World, Weather, Entertainment & Video", 82 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E8", "just", "www.testsite.com/b.html",
82 "0,0,19,2,23,0,38,2,45,0", ui::PAGE_TRANSITION_TYPED, 83 "http://www.testsite.com/b.html", "www.testsite.com/b.html", "0,1",
83 AutocompleteMatchType::HISTORY_TITLE, "", 1, 10 }, 84 "Test - site - just a test", "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
84 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E5", "nhl scores", "sports.yahoo.com", 85 AutocompleteMatchType::HISTORY_TITLE, "", 5, 2},
85 "http://sports.yahoo.com/", "sports.yahoo.com", "0,1", 86 {"BD85DBA2-8C29-49F9-84AE-48E1E90880E9", "just", "www.testsite.com/c.html",
86 "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more", 87 "http://www.testsite.com/c.html", "www.testsite.com/c.html", "0,1",
87 "0,0,29,2,35,0", ui::PAGE_TRANSITION_TYPED, 88 "Test - site - just a test", "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
88 AutocompleteMatchType::HISTORY_BODY, "", 1, 10 }, 89 AutocompleteMatchType::HISTORY_TITLE, "", 8, 1},
89 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E6", "nhl scores", 90 {"BD85DBA2-8C29-49F9-84AE-48E1E90880EA", "just a",
90 "www.nhl.com/scores/index.html", "http://www.nhl.com/scores/index.html", 91 "www.testsite.com/d.html", "http://www.testsite.com/d.html",
91 "www.nhl.com/scores/index.html", "0,1,4,3,7,1", 92 "www.testsite.com/d.html", "0,1", "Test - site - just a test",
92 "January 13, 2010 - NHL.com - Scores", "0,0,19,2,22,0,29,2,35,0", 93 "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
93 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 5, 94 AutocompleteMatchType::HISTORY_TITLE, "", 12, 1},
94 1 }, 95 {"BD85DBA2-8C29-49F9-84AE-48E1E90880EB", "just a t",
95 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E7", "just", "www.testsite.com/a.html", 96 "www.testsite.com/e.html", "http://www.testsite.com/e.html",
96 "http://www.testsite.com/a.html", "www.testsite.com/a.html", "0,1", 97 "www.testsite.com/e.html", "0,1", "Test - site - just a test",
97 "Test - site - just a test", "0,0,14,2,18,0", 98 "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
98 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 5, 99 AutocompleteMatchType::HISTORY_TITLE, "", 12, 1},
99 1 }, 100 {"BD85DBA2-8C29-49F9-84AE-48E1E90880EC", "just a te",
100 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E8", "just", "www.testsite.com/b.html", 101 "www.testsite.com/f.html", "http://www.testsite.com/f.html",
101 "http://www.testsite.com/b.html", "www.testsite.com/b.html", "0,1", 102 "www.testsite.com/f.html", "0,1", "Test - site - just a test",
102 "Test - site - just a test", "0,0,14,2,18,0", 103 "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
103 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 5, 104 AutocompleteMatchType::HISTORY_TITLE, "", 12, 1},
104 2 }, 105 {"BD85DBA2-8C29-49F9-84AE-48E1E90880ED", "ago",
105 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E9", "just", "www.testsite.com/c.html", 106 "www.daysagotest.com/a.html", "http://www.daysagotest.com/a.html",
106 "http://www.testsite.com/c.html", "www.testsite.com/c.html", "0,1", 107 "www.daysagotest.com/a.html", "0,1,8,3,11,1", "Test - site", "0,0",
107 "Test - site - just a test", "0,0,14,2,18,0", 108 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 1},
108 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 8, 109 {"BD85DBA2-8C29-49F9-84AE-48E1E90880EE", "ago",
109 1 }, 110 "www.daysagotest.com/b.html", "http://www.daysagotest.com/b.html",
110 { "BD85DBA2-8C29-49F9-84AE-48E1E90880EA", "just a", "www.testsite.com/d.html", 111 "www.daysagotest.com/b.html", "0,1,8,3,11,1", "Test - site", "0,0",
111 "http://www.testsite.com/d.html", "www.testsite.com/d.html", "0,1", 112 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 2, 1},
112 "Test - site - just a test", "0,0,14,2,18,0", 113 {"BD85DBA2-8C29-49F9-84AE-48E1E90880EF", "ago",
113 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 114 "www.daysagotest.com/c.html", "http://www.daysagotest.com/c.html",
114 12, 1 }, 115 "www.daysagotest.com/c.html", "0,1,8,3,11,1", "Test - site", "0,0",
115 { "BD85DBA2-8C29-49F9-84AE-48E1E90880EB", "just a t", 116 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 3, 1},
116 "www.testsite.com/e.html", "http://www.testsite.com/e.html", 117 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F0", "ago",
117 "www.testsite.com/e.html", "0,1", "Test - site - just a test", 118 "www.daysagotest.com/d.html", "http://www.daysagotest.com/d.html",
118 "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED, 119 "www.daysagotest.com/d.html", "0,1,8,3,11,1", "Test - site", "0,0",
119 AutocompleteMatchType::HISTORY_TITLE, "", 12, 1 }, 120 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 4, 1},
120 { "BD85DBA2-8C29-49F9-84AE-48E1E90880EC", "just a te", 121 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F2", "abcdef.com", "http://abcdef.com",
121 "www.testsite.com/f.html", "http://www.testsite.com/f.html", 122 "http://abcdef.com/", "Abcdef", "0,1,4,0", "Abcdef", "0,3,4,1",
122 "www.testsite.com/f.html", "0,1", "Test - site - just a test", 123 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
123 "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED, 124 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F3", "query", "query",
124 AutocompleteMatchType::HISTORY_TITLE, "", 12, 1 }, 125 "https://www.google.com/search?q=query", "query", "0,0", "Google Search",
125 { "BD85DBA2-8C29-49F9-84AE-48E1E90880ED", "ago", "www.daysagotest.com/a.html", 126 "0,4", ui::PAGE_TRANSITION_GENERATED,
126 "http://www.daysagotest.com/a.html", "www.daysagotest.com/a.html", 127 AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100},
127 "0,1,8,3,11,1", "Test - site", "0,0", ui::PAGE_TRANSITION_TYPED, 128 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F4", "word", "www.word",
128 AutocompleteMatchType::HISTORY_URL, "", 1, 1 }, 129 "https://www.google.com/search?q=www.word", "www.word", "0,0",
129 { "BD85DBA2-8C29-49F9-84AE-48E1E90880EE", "ago", "www.daysagotest.com/b.html", 130 "Google Search", "0,4", ui::PAGE_TRANSITION_GENERATED,
130 "http://www.daysagotest.com/b.html", "www.daysagotest.com/b.html", 131 AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100},
131 "0,1,8,3,11,1", "Test - site", "0,0", ui::PAGE_TRANSITION_TYPED, 132 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F5", "about:o", "chrome://omnibox",
132 AutocompleteMatchType::HISTORY_URL, "", 2, 1 }, 133 "chrome://omnibox/", "about:omnibox", "0,3,10,1", "", "",
133 { "BD85DBA2-8C29-49F9-84AE-48E1E90880EF", "ago", "www.daysagotest.com/c.html", 134 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::NAVSUGGEST, "", 1, 100},
134 "http://www.daysagotest.com/c.html", "www.daysagotest.com/c.html", 135 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F6", "www/real sp",
135 "0,1,8,3,11,1", "Test - site", "0,0", ui::PAGE_TRANSITION_TYPED, 136 "http://www/real space/long-url-with-space.html",
136 AutocompleteMatchType::HISTORY_URL, "", 3, 1 }, 137 "http://www/real%20space/long-url-with-space.html",
137 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F0", "ago", "www.daysagotest.com/d.html", 138 "www/real space/long-url-with-space.html", "0,3,11,1",
138 "http://www.daysagotest.com/d.html", "www.daysagotest.com/d.html", 139 "Page With Space; Input with Space", "0,0", ui::PAGE_TRANSITION_TYPED,
139 "0,1,8,3,11,1", "Test - site", "0,0", ui::PAGE_TRANSITION_TYPED, 140 AutocompleteMatchType::HISTORY_URL, "", 1, 100},
140 AutocompleteMatchType::HISTORY_URL, "", 4, 1 }, 141 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F7", "duplicate",
141 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F2", "abcdef.com", "http://abcdef.com", 142 "http://duplicate.com", "http://duplicate.com/", "Duplicate", "0,1",
142 "http://abcdef.com/", "Abcdef", "0,1,4,0", "Abcdef", "0,3,4,1", 143 "Duplicate", "0,1", ui::PAGE_TRANSITION_TYPED,
143 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 144 AutocompleteMatchType::HISTORY_URL, "", 1, 100},
144 100 }, 145 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F8", "dupl", "http://duplicate.com",
145 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F3", "query", "query", 146 "http://duplicate.com/", "Duplicate", "0,1", "Duplicate", "0,1",
146 "https://www.google.com/search?q=query", "query", "0,0", 147 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
147 "Google Search", "0,4", ui::PAGE_TRANSITION_GENERATED, 148 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F9", "notrailing.com/",
148 AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 }, 149 "http://notrailing.com", "http://notrailing.com/", "No Trailing Slash",
149 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F4", "word", "www.word", 150 "0,1", "No Trailing Slash on fill_into_edit", "0,1",
150 "https://www.google.com/search?q=www.word", "www.word", "0,0", 151 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
151 "Google Search", "0,4", ui::PAGE_TRANSITION_GENERATED, 152 {"BD85DBA2-8C29-49F9-84AE-48E1E90880FA", "http:///foo.com",
152 AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 }, 153 "http://foo.com", "http://foo.com/", "Foo - Typo in Input", "0,1",
153 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F5", "about:o", "chrome://omnibox", 154 "Foo - Typo in Input Corrected in fill_into_edit", "0,1",
154 "chrome://omnibox/", "about:omnibox", "0,3,10,1", "", "", 155 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
155 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::NAVSUGGEST, "", 156 {"BD85DBA2-8C29-49F9-84AE-48E1E90880FB", "trailing1 ",
156 1, 100 }, 157 "http://trailing1.com", "http://trailing1.com/",
157 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F6", "www/real sp", 158 "Trailing1 - Space in Shortcut", "0,1", "Trailing1 - Space in Shortcut",
158 "http://www/real space/long-url-with-space.html", 159 "0,1", ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
159 "http://www/real%20space/long-url-with-space.html", 160 1, 100},
160 "www/real space/long-url-with-space.html", "0,3,11,1", 161 {"BD85DBA2-8C29-49F9-84AE-48E1E90880FC", "about:trailing2 ",
161 "Page With Space; Input with Space", "0,0", 162 "chrome://trailing2blah", "chrome://trailing2blah/",
162 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 163 "Trailing2 - Space in Shortcut", "0,1", "Trailing2 - Space in Shortcut",
163 1, 100 }, 164 "0,1", ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
164 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F7", "duplicate", "http://duplicate.com", 165 1, 100},
165 "http://duplicate.com/", "Duplicate", "0,1", "Duplicate", "0,1",
166 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1,
167 100 },
168 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F8", "dupl", "http://duplicate.com",
169 "http://duplicate.com/", "Duplicate", "0,1", "Duplicate", "0,1",
170 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1,
171 100 },
172 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F9", "notrailing.com/",
173 "http://notrailing.com", "http://notrailing.com/", "No Trailing Slash",
174 "0,1", "No Trailing Slash on fill_into_edit", "0,1",
175 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
176 1, 100 },
177 { "BD85DBA2-8C29-49F9-84AE-48E1E90880FA", "http:///foo.com",
178 "http://foo.com", "http://foo.com/", "Foo - Typo in Input",
179 "0,1", "Foo - Typo in Input Corrected in fill_into_edit", "0,1",
180 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
181 1, 100 },
182 { "BD85DBA2-8C29-49F9-84AE-48E1E90880FB", "trailing1 ",
183 "http://trailing1.com", "http://trailing1.com/",
184 "Trailing1 - Space in Shortcut", "0,1",
185 "Trailing1 - Space in Shortcut", "0,1", ui::PAGE_TRANSITION_TYPED,
186 AutocompleteMatchType::HISTORY_URL, "", 1, 100 },
187 { "BD85DBA2-8C29-49F9-84AE-48E1E90880FC", "about:trailing2 ",
188 "chrome://trailing2blah", "chrome://trailing2blah/",
189 "Trailing2 - Space in Shortcut", "0,1",
190 "Trailing2 - Space in Shortcut", "0,1", ui::PAGE_TRANSITION_TYPED,
191 AutocompleteMatchType::HISTORY_URL, "", 1, 100 },
192 }; 166 };
193 167
194 class FakeAutocompleteProviderClient 168 class FakeAutocompleteProviderClient
195 : public testing::NiceMock<MockAutocompleteProviderClient> { 169 : public testing::NiceMock<MockAutocompleteProviderClient> {
196 public: 170 public:
197 FakeAutocompleteProviderClient() 171 FakeAutocompleteProviderClient()
198 : db_thread_("Test DB thread"), 172 : db_thread_("Test DB thread"),
199 pool_owner_(3, "Background Pool") { 173 pool_owner_(3, "Background Pool") {
200 set_template_url_service( 174 set_template_url_service(
201 make_scoped_ptr(new TemplateURLService(nullptr, 0))); 175 make_scoped_ptr(new TemplateURLService(nullptr, 0)));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 ShortcutsProvider::CreateWordMapForString(find_text), text_, matches_); 244 ShortcutsProvider::CreateWordMapForString(find_text), text_, matches_);
271 } 245 }
272 246
273 // ShortcutsProviderTest ------------------------------------------------------ 247 // ShortcutsProviderTest ------------------------------------------------------
274 248
275 class ShortcutsProviderTest : public testing::Test { 249 class ShortcutsProviderTest : public testing::Test {
276 public: 250 public:
277 ShortcutsProviderTest(); 251 ShortcutsProviderTest();
278 252
279 protected: 253 protected:
280 typedef std::pair<std::string, bool> ExpectedURLAndAllowedToBeDefault;
281 typedef std::vector<ExpectedURLAndAllowedToBeDefault> ExpectedURLs;
282
283 class SetShouldContain
284 : public std::unary_function<const ExpectedURLAndAllowedToBeDefault&,
285 std::set<std::string> > {
286 public:
287 explicit SetShouldContain(const ACMatches& matched_urls);
288
289 void operator()(const ExpectedURLAndAllowedToBeDefault& expected);
290 std::set<ExpectedURLAndAllowedToBeDefault> Leftovers() const {
291 return matches_;
292 }
293
294 private:
295 std::set<ExpectedURLAndAllowedToBeDefault> matches_;
296 };
297
298 void SetUp() override; 254 void SetUp() override;
299 void TearDown() override; 255 void TearDown() override;
300 256
301 // Fills test data into the provider.
302 void FillData(TestShortcutInfo* db, size_t db_size);
303
304 // Runs an autocomplete query on |text| with the provided
305 // |prevent_inline_autocomplete| setting and checks to see that the returned
306 // results' destination URLs match those provided. |expected_urls| does not
307 // need to be in sorted order, but |expected_top_result| should be the top
308 // match, and it should have inline autocompletion
309 // |top_result_inline_autocompletion|.
310 void RunTest(const base::string16 text,
311 bool prevent_inline_autocomplete,
312 const ExpectedURLs& expected_urls,
313 std::string expected_top_result,
314 base::string16 top_result_inline_autocompletion);
315
316 // Passthrough to the private function in provider_. 257 // Passthrough to the private function in provider_.
317 int CalculateScore(const std::string& terms, 258 int CalculateScore(const std::string& terms,
318 const ShortcutsDatabase::Shortcut& shortcut, 259 const ShortcutsDatabase::Shortcut& shortcut,
319 int max_relevance); 260 int max_relevance);
320 261
321 base::MessageLoop message_loop_; 262 base::MessageLoop message_loop_;
322 scoped_ptr<FakeAutocompleteProviderClient> client_; 263 scoped_ptr<FakeAutocompleteProviderClient> client_;
323 scoped_refptr<ShortcutsProvider> provider_; 264 scoped_refptr<ShortcutsProvider> provider_;
324
325 ACMatches ac_matches_; // The resulting matches after running RunTest.
326 }; 265 };
327 266
328 ShortcutsProviderTest::ShortcutsProviderTest() { 267 ShortcutsProviderTest::ShortcutsProviderTest() {
329 } 268 }
330 269
331 void ShortcutsProviderTest::SetUp() { 270 void ShortcutsProviderTest::SetUp() {
332 client_.reset(new FakeAutocompleteProviderClient()); 271 client_.reset(new FakeAutocompleteProviderClient());
333 272
334 ASSERT_TRUE(client_->GetShortcutsBackend()); 273 ASSERT_TRUE(client_->GetShortcutsBackend());
335 provider_ = new ShortcutsProvider(client_.get()); 274 provider_ = new ShortcutsProvider(client_.get());
336 FillData(shortcut_test_db, arraysize(shortcut_test_db)); 275 PopulateShortcutsBackendWithTestShortcutData(client_->GetShortcutsBackend(),
276 shortcut_test_db,
277 arraysize(shortcut_test_db));
337 } 278 }
338 279
339 void ShortcutsProviderTest::TearDown() { 280 void ShortcutsProviderTest::TearDown() {
340 // Run all pending tasks or else some threads hold on to the message loop 281 // Run all pending tasks or else some threads hold on to the message loop
341 // and prevent it from being deleted. 282 // and prevent it from being deleted.
342 message_loop_.RunUntilIdle(); 283 message_loop_.RunUntilIdle();
343 provider_ = NULL; 284 provider_ = NULL;
344 } 285 }
345 286
346 void ShortcutsProviderTest::FillData(TestShortcutInfo* db, size_t db_size) {
347 DCHECK(provider_.get());
348 scoped_refptr<ShortcutsBackend> backend = client_->GetShortcutsBackend();
349 size_t expected_size = backend->shortcuts_map().size() + db_size;
350 for (size_t i = 0; i < db_size; ++i) {
351 const TestShortcutInfo& cur = db[i];
352 ShortcutsDatabase::Shortcut shortcut(
353 cur.guid, ASCIIToUTF16(cur.text),
354 ShortcutsDatabase::Shortcut::MatchCore(
355 ASCIIToUTF16(cur.fill_into_edit), GURL(cur.destination_url),
356 ASCIIToUTF16(cur.contents), cur.contents_class,
357 ASCIIToUTF16(cur.description), cur.description_class,
358 cur.transition, cur.type, ASCIIToUTF16(cur.keyword)),
359 base::Time::Now() - base::TimeDelta::FromDays(cur.days_from_now),
360 cur.number_of_hits);
361 backend->AddShortcut(shortcut);
362 }
363 EXPECT_EQ(expected_size, backend->shortcuts_map().size());
364 }
365
366 ShortcutsProviderTest::SetShouldContain::SetShouldContain(
367 const ACMatches& matched_urls) {
368 for (ACMatches::const_iterator iter = matched_urls.begin();
369 iter != matched_urls.end(); ++iter)
370 matches_.insert(ExpectedURLAndAllowedToBeDefault(
371 iter->destination_url.spec(), iter->allowed_to_be_default_match));
372 }
373
374 void ShortcutsProviderTest::SetShouldContain::operator()(
375 const ExpectedURLAndAllowedToBeDefault& expected) {
376 EXPECT_EQ(1U, matches_.erase(expected));
377 }
378
379 void ShortcutsProviderTest::RunTest(
380 const base::string16 text,
381 bool prevent_inline_autocomplete,
382 const ExpectedURLs& expected_urls,
383 std::string expected_top_result,
384 base::string16 top_result_inline_autocompletion) {
385 base::MessageLoop::current()->RunUntilIdle();
386 AutocompleteInput input(text, base::string16::npos, std::string(), GURL(),
387 metrics::OmniboxEventProto::INVALID_SPEC,
388 prevent_inline_autocomplete, false, true, true, false,
389 TestSchemeClassifier());
390 provider_->Start(input, false);
391 EXPECT_TRUE(provider_->done());
392
393 ac_matches_ = provider_->matches();
394
395 // We should have gotten back at most AutocompleteProvider::kMaxMatches.
396 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches);
397
398 // If the number of expected and actual matches aren't equal then we need
399 // test no further, but let's do anyway so that we know which URLs failed.
400 EXPECT_EQ(expected_urls.size(), ac_matches_.size());
401
402 // Verify that all expected URLs were found and that all found URLs
403 // were expected.
404 std::set<ExpectedURLAndAllowedToBeDefault> Leftovers =
405 for_each(expected_urls.begin(), expected_urls.end(),
406 SetShouldContain(ac_matches_)).Leftovers();
407 EXPECT_EQ(0U, Leftovers.size());
408
409 // See if we got the expected top scorer.
410 if (!ac_matches_.empty()) {
411 std::partial_sort(ac_matches_.begin(), ac_matches_.begin() + 1,
412 ac_matches_.end(), AutocompleteMatch::MoreRelevant);
413 EXPECT_EQ(expected_top_result, ac_matches_[0].destination_url.spec());
414 EXPECT_EQ(top_result_inline_autocompletion,
415 ac_matches_[0].inline_autocompletion);
416 }
417 }
418
419 int ShortcutsProviderTest::CalculateScore( 287 int ShortcutsProviderTest::CalculateScore(
420 const std::string& terms, 288 const std::string& terms,
421 const ShortcutsDatabase::Shortcut& shortcut, 289 const ShortcutsDatabase::Shortcut& shortcut,
422 int max_relevance) { 290 int max_relevance) {
423 return provider_->CalculateScore(ASCIIToUTF16(terms), shortcut, 291 return provider_->CalculateScore(ASCIIToUTF16(terms), shortcut,
424 max_relevance); 292 max_relevance);
425 } 293 }
426 294
427 // Actual tests --------------------------------------------------------------- 295 // Actual tests ---------------------------------------------------------------
428 296
429 TEST_F(ShortcutsProviderTest, SimpleSingleMatch) { 297 TEST_F(ShortcutsProviderTest, SimpleSingleMatch) {
430 base::string16 text(ASCIIToUTF16("go")); 298 base::string16 text(ASCIIToUTF16("go"));
431 std::string expected_url("http://www.google.com/"); 299 std::string expected_url("http://www.google.com/");
432 ExpectedURLs expected_urls; 300 ShortcutExpectedURLs expected_urls;
433 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 301 expected_urls.push_back(
434 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("ogle.com")); 302 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
303 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
304 ASCIIToUTF16("ogle.com"));
435 305
436 // Same test with prevent inline autocomplete. 306 // Same test with prevent inline autocomplete.
437 expected_urls.clear(); 307 expected_urls.clear();
438 expected_urls.push_back( 308 expected_urls.push_back(
439 ExpectedURLAndAllowedToBeDefault(expected_url, false)); 309 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
440 // The match will have an |inline_autocompletion| set, but the value will not 310 // The match will have an |inline_autocompletion| set, but the value will not
441 // be used because |allowed_to_be_default_match| will be false. 311 // be used because |allowed_to_be_default_match| will be false.
442 RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("ogle.com")); 312 RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
313 ASCIIToUTF16("ogle.com"));
443 314
444 // A pair of analogous tests where the shortcut ends at the end of 315 // A pair of analogous tests where the shortcut ends at the end of
445 // |fill_into_edit|. This exercises the inline autocompletion and default 316 // |fill_into_edit|. This exercises the inline autocompletion and default
446 // match code. 317 // match code.
447 text = ASCIIToUTF16("abcdef.com"); 318 text = ASCIIToUTF16("abcdef.com");
448 expected_url = "http://abcdef.com/"; 319 expected_url = "http://abcdef.com/";
449 expected_urls.clear(); 320 expected_urls.clear();
450 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 321 expected_urls.push_back(
451 RunTest(text, false, expected_urls, expected_url, base::string16()); 322 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
323 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
324 base::string16());
452 // With prevent inline autocomplete, the suggestion should be the same 325 // With prevent inline autocomplete, the suggestion should be the same
453 // (because there is no completion). 326 // (because there is no completion).
454 RunTest(text, true, expected_urls, expected_url, base::string16()); 327 RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
328 base::string16());
455 329
456 // Another test, simply for a query match type, not a navigation URL match 330 // Another test, simply for a query match type, not a navigation URL match
457 // type. 331 // type.
458 text = ASCIIToUTF16("que"); 332 text = ASCIIToUTF16("que");
459 expected_url = "https://www.google.com/search?q=query"; 333 expected_url = "https://www.google.com/search?q=query";
460 expected_urls.clear(); 334 expected_urls.clear();
461 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 335 expected_urls.push_back(
462 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("ry")); 336 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
337 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
338 ASCIIToUTF16("ry"));
463 339
464 // Same test with prevent inline autocomplete. 340 // Same test with prevent inline autocomplete.
465 expected_urls.clear(); 341 expected_urls.clear();
466 expected_urls.push_back( 342 expected_urls.push_back(
467 ExpectedURLAndAllowedToBeDefault(expected_url, false)); 343 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
468 // The match will have an |inline_autocompletion| set, but the value will not 344 // The match will have an |inline_autocompletion| set, but the value will not
469 // be used because |allowed_to_be_default_match| will be false. 345 // be used because |allowed_to_be_default_match| will be false.
470 RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("ry")); 346 RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
347 ASCIIToUTF16("ry"));
471 348
472 // A pair of analogous tests where the shortcut ends at the end of 349 // A pair of analogous tests where the shortcut ends at the end of
473 // |fill_into_edit|. This exercises the inline autocompletion and default 350 // |fill_into_edit|. This exercises the inline autocompletion and default
474 // match code. 351 // match code.
475 text = ASCIIToUTF16("query"); 352 text = ASCIIToUTF16("query");
476 expected_urls.clear(); 353 expected_urls.clear();
477 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 354 expected_urls.push_back(
478 RunTest(text, false, expected_urls, expected_url, base::string16()); 355 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
356 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
357 base::string16());
479 // With prevent inline autocomplete, the suggestion should be the same 358 // With prevent inline autocomplete, the suggestion should be the same
480 // (because there is no completion). 359 // (because there is no completion).
481 RunTest(text, true, expected_urls, expected_url, base::string16()); 360 RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
361 base::string16());
482 362
483 // Now the shortcut ends at the end of |fill_into_edit| but has a 363 // Now the shortcut ends at the end of |fill_into_edit| but has a
484 // non-droppable prefix. ("www.", for instance, is not droppable for 364 // non-droppable prefix. ("www.", for instance, is not droppable for
485 // queries.) 365 // queries.)
486 text = ASCIIToUTF16("word"); 366 text = ASCIIToUTF16("word");
487 expected_url = "https://www.google.com/search?q=www.word"; 367 expected_url = "https://www.google.com/search?q=www.word";
488 expected_urls.clear(); 368 expected_urls.clear();
489 expected_urls.push_back( 369 expected_urls.push_back(
490 ExpectedURLAndAllowedToBeDefault(expected_url, false)); 370 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
491 RunTest(text, false, expected_urls, expected_url, base::string16()); 371 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
372 base::string16());
492 } 373 }
493 374
494 // These tests are like those in SimpleSingleMatch but more complex, 375 // These tests are like those in SimpleSingleMatch but more complex,
495 // involving URLs that need to be fixed up to match properly. 376 // involving URLs that need to be fixed up to match properly.
496 TEST_F(ShortcutsProviderTest, TrickySingleMatch) { 377 TEST_F(ShortcutsProviderTest, TrickySingleMatch) {
497 // Test that about: URLs are fixed up/transformed to chrome:// URLs. 378 // Test that about: URLs are fixed up/transformed to chrome:// URLs.
498 base::string16 text(ASCIIToUTF16("about:o")); 379 base::string16 text(ASCIIToUTF16("about:o"));
499 std::string expected_url("chrome://omnibox/"); 380 std::string expected_url("chrome://omnibox/");
500 ExpectedURLs expected_urls; 381 ShortcutExpectedURLs expected_urls;
501 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 382 expected_urls.push_back(
502 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("mnibox")); 383 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
384 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
385 ASCIIToUTF16("mnibox"));
503 386
504 // Same test with prevent inline autocomplete. 387 // Same test with prevent inline autocomplete.
505 expected_urls.clear(); 388 expected_urls.clear();
506 expected_urls.push_back( 389 expected_urls.push_back(
507 ExpectedURLAndAllowedToBeDefault(expected_url, false)); 390 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
508 // The match will have an |inline_autocompletion| set, but the value will not 391 // The match will have an |inline_autocompletion| set, but the value will not
509 // be used because |allowed_to_be_default_match| will be false. 392 // be used because |allowed_to_be_default_match| will be false.
510 RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("mnibox")); 393 RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
394 ASCIIToUTF16("mnibox"));
511 395
512 // Test that an input with a space can match URLs with a (escaped) space. 396 // Test that an input with a space can match URLs with a (escaped) space.
513 // This would fail if we didn't try to lookup the un-fixed-up string. 397 // This would fail if we didn't try to lookup the un-fixed-up string.
514 text = ASCIIToUTF16("www/real sp"); 398 text = ASCIIToUTF16("www/real sp");
515 expected_url = "http://www/real%20space/long-url-with-space.html"; 399 expected_url = "http://www/real%20space/long-url-with-space.html";
516 expected_urls.clear(); 400 expected_urls.clear();
517 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 401 expected_urls.push_back(
518 RunTest(text, false, expected_urls, expected_url, 402 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
519 ASCIIToUTF16("ace/long-url-with-space.html")); 403 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
404 ASCIIToUTF16("ace/long-url-with-space.html"));
520 405
521 // Same test with prevent inline autocomplete. 406 // Same test with prevent inline autocomplete.
522 expected_urls.clear(); 407 expected_urls.clear();
523 expected_urls.push_back( 408 expected_urls.push_back(
524 ExpectedURLAndAllowedToBeDefault(expected_url, false)); 409 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
525 // The match will have an |inline_autocompletion| set, but the value will not 410 // The match will have an |inline_autocompletion| set, but the value will not
526 // be used because |allowed_to_be_default_match| will be false. 411 // be used because |allowed_to_be_default_match| will be false.
527 RunTest(text, true, expected_urls, expected_url, 412 RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
528 ASCIIToUTF16("ace/long-url-with-space.html")); 413 ASCIIToUTF16("ace/long-url-with-space.html"));
529 414
530 // Test when the user input has a trailing slash but fill_into_edit does 415 // Test when the user input has a trailing slash but fill_into_edit does
531 // not. This should still be allowed to be default. 416 // not. This should still be allowed to be default.
532 text = ASCIIToUTF16("notrailing.com/"); 417 text = ASCIIToUTF16("notrailing.com/");
533 expected_url = "http://notrailing.com/"; 418 expected_url = "http://notrailing.com/";
534 expected_urls.clear(); 419 expected_urls.clear();
535 expected_urls.push_back( 420 expected_urls.push_back(
536 ExpectedURLAndAllowedToBeDefault(expected_url, true)); 421 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
537 RunTest(text, true, expected_urls, expected_url, base::string16()); 422 RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
423 base::string16());
538 424
539 // Test when the user input has a typo that can be fixed up for matching 425 // Test when the user input has a typo that can be fixed up for matching
540 // fill_into_edit. This should still be allowed to be default. 426 // fill_into_edit. This should still be allowed to be default.
541 text = ASCIIToUTF16("http:///foo.com"); 427 text = ASCIIToUTF16("http:///foo.com");
542 expected_url = "http://foo.com/"; 428 expected_url = "http://foo.com/";
543 expected_urls.clear(); 429 expected_urls.clear();
544 expected_urls.push_back( 430 expected_urls.push_back(
545 ExpectedURLAndAllowedToBeDefault(expected_url, true)); 431 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
546 RunTest(text, true, expected_urls, expected_url, base::string16()); 432 RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
433 base::string16());
547 434
548 // A foursome of tests to verify that trailing spaces prevent the shortcut 435 // A foursome of tests to verify that trailing spaces prevent the shortcut
549 // from being allowed to be the default match. For each of two tests, we 436 // from being allowed to be the default match. For each of two tests, we
550 // first verify that the match is allowed to be default without the trailing 437 // first verify that the match is allowed to be default without the trailing
551 // space but is not allowed to be default with the trailing space. In both 438 // space but is not allowed to be default with the trailing space. In both
552 // of these with-trailing-space cases, we actually get an 439 // of these with-trailing-space cases, we actually get an
553 // inline_autocompletion, though it's never used because the match is 440 // inline_autocompletion, though it's never used because the match is
554 // prohibited from being default. 441 // prohibited from being default.
555 text = ASCIIToUTF16("trailing1"); 442 text = ASCIIToUTF16("trailing1");
556 expected_url = "http://trailing1.com/"; 443 expected_url = "http://trailing1.com/";
557 expected_urls.clear(); 444 expected_urls.clear();
558 expected_urls.push_back( 445 expected_urls.push_back(
559 ExpectedURLAndAllowedToBeDefault(expected_url, true)); 446 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
560 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com")); 447 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
448 ASCIIToUTF16(".com"));
561 text = ASCIIToUTF16("trailing1 "); 449 text = ASCIIToUTF16("trailing1 ");
562 expected_urls.clear(); 450 expected_urls.clear();
563 expected_urls.push_back( 451 expected_urls.push_back(
564 ExpectedURLAndAllowedToBeDefault(expected_url, false)); 452 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
565 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com")); 453 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
454 ASCIIToUTF16(".com"));
566 text = ASCIIToUTF16("about:trailing2"); 455 text = ASCIIToUTF16("about:trailing2");
567 expected_url = "chrome://trailing2blah/"; 456 expected_url = "chrome://trailing2blah/";
568 expected_urls.clear(); 457 expected_urls.clear();
569 expected_urls.push_back( 458 expected_urls.push_back(
570 ExpectedURLAndAllowedToBeDefault(expected_url, true)); 459 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
571 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah")); 460 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
461 ASCIIToUTF16("blah"));
572 text = ASCIIToUTF16("about:trailing2 "); 462 text = ASCIIToUTF16("about:trailing2 ");
573 expected_urls.clear(); 463 expected_urls.clear();
574 expected_urls.push_back( 464 expected_urls.push_back(
575 ExpectedURLAndAllowedToBeDefault(expected_url, false)); 465 ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
576 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah")); 466 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
467 ASCIIToUTF16("blah"));
577 } 468 }
578 469
579 TEST_F(ShortcutsProviderTest, MultiMatch) { 470 TEST_F(ShortcutsProviderTest, MultiMatch) {
580 base::string16 text(ASCIIToUTF16("NEWS")); 471 base::string16 text(ASCIIToUTF16("NEWS"));
581 ExpectedURLs expected_urls; 472 ShortcutExpectedURLs expected_urls;
582 // Scores high because of completion length. 473 // Scores high because of completion length.
583 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 474 expected_urls.push_back(
584 "http://slashdot.org/", false)); 475 ShortcutExpectedURLAndAllowedToBeDefault("http://slashdot.org/", false));
585 // Scores high because of visit count. 476 // Scores high because of visit count.
586 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 477 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
587 "http://sports.yahoo.com/", false)); 478 "http://sports.yahoo.com/", false));
588 // Scores high because of visit count but less match span, 479 // Scores high because of visit count but less match span,
589 // which is more important. 480 // which is more important.
590 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 481 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
591 "http://www.cnn.com/index.html", false)); 482 "http://www.cnn.com/index.html", false));
592 RunTest(text, false, expected_urls, "http://slashdot.org/", base::string16()); 483 RunShortcutsProviderTest(provider_, text, false, expected_urls,
484 "http://slashdot.org/", base::string16());
593 } 485 }
594 486
595 TEST_F(ShortcutsProviderTest, RemoveDuplicates) { 487 TEST_F(ShortcutsProviderTest, RemoveDuplicates) {
596 base::string16 text(ASCIIToUTF16("dupl")); 488 base::string16 text(ASCIIToUTF16("dupl"));
597 ExpectedURLs expected_urls; 489 ShortcutExpectedURLs expected_urls;
598 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 490 expected_urls.push_back(
599 "http://duplicate.com/", true)); 491 ShortcutExpectedURLAndAllowedToBeDefault("http://duplicate.com/", true));
600 // Make sure the URL only appears once in the output list. 492 // Make sure the URL only appears once in the output list.
601 RunTest(text, false, expected_urls, "http://duplicate.com/", 493 RunShortcutsProviderTest(provider_, text, false, expected_urls,
602 ASCIIToUTF16("icate.com")); 494 "http://duplicate.com/", ASCIIToUTF16("icate.com"));
603 } 495 }
604 496
605 TEST_F(ShortcutsProviderTest, TypedCountMatches) { 497 TEST_F(ShortcutsProviderTest, TypedCountMatches) {
606 base::string16 text(ASCIIToUTF16("just")); 498 base::string16 text(ASCIIToUTF16("just"));
607 ExpectedURLs expected_urls; 499 ShortcutExpectedURLs expected_urls;
608 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 500 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
609 "http://www.testsite.com/b.html", false)); 501 "http://www.testsite.com/b.html", false));
610 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 502 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
611 "http://www.testsite.com/a.html", false)); 503 "http://www.testsite.com/a.html", false));
612 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 504 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
613 "http://www.testsite.com/c.html", false)); 505 "http://www.testsite.com/c.html", false));
614 RunTest(text, false, expected_urls, "http://www.testsite.com/b.html", 506 RunShortcutsProviderTest(provider_, text, false, expected_urls,
615 base::string16()); 507 "http://www.testsite.com/b.html", base::string16());
616 } 508 }
617 509
618 TEST_F(ShortcutsProviderTest, FragmentLengthMatches) { 510 TEST_F(ShortcutsProviderTest, FragmentLengthMatches) {
619 base::string16 text(ASCIIToUTF16("just a")); 511 base::string16 text(ASCIIToUTF16("just a"));
620 ExpectedURLs expected_urls; 512 ShortcutExpectedURLs expected_urls;
621 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 513 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
622 "http://www.testsite.com/d.html", false)); 514 "http://www.testsite.com/d.html", false));
623 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 515 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
624 "http://www.testsite.com/e.html", false)); 516 "http://www.testsite.com/e.html", false));
625 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 517 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
626 "http://www.testsite.com/f.html", false)); 518 "http://www.testsite.com/f.html", false));
627 RunTest(text, false, expected_urls, "http://www.testsite.com/d.html", 519 RunShortcutsProviderTest(provider_, text, false, expected_urls,
628 base::string16()); 520 "http://www.testsite.com/d.html", base::string16());
629 } 521 }
630 522
631 TEST_F(ShortcutsProviderTest, DaysAgoMatches) { 523 TEST_F(ShortcutsProviderTest, DaysAgoMatches) {
632 base::string16 text(ASCIIToUTF16("ago")); 524 base::string16 text(ASCIIToUTF16("ago"));
633 ExpectedURLs expected_urls; 525 ShortcutExpectedURLs expected_urls;
634 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 526 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
635 "http://www.daysagotest.com/a.html", false)); 527 "http://www.daysagotest.com/a.html", false));
636 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 528 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
637 "http://www.daysagotest.com/b.html", false)); 529 "http://www.daysagotest.com/b.html", false));
638 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 530 expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
639 "http://www.daysagotest.com/c.html", false)); 531 "http://www.daysagotest.com/c.html", false));
640 RunTest(text, false, expected_urls, "http://www.daysagotest.com/a.html", 532 RunShortcutsProviderTest(provider_, text, false, expected_urls,
641 base::string16()); 533 "http://www.daysagotest.com/a.html",
534 base::string16());
642 } 535 }
643 536
644 TEST_F(ShortcutsProviderTest, ClassifyAllMatchesInString) { 537 TEST_F(ShortcutsProviderTest, ClassifyAllMatchesInString) {
645 ACMatchClassifications matches = 538 ACMatchClassifications matches =
646 AutocompleteMatch::ClassificationsFromString("0,0"); 539 AutocompleteMatch::ClassificationsFromString("0,0");
647 ClassifyTest classify_test(ASCIIToUTF16("A man, a plan, a canal Panama"), 540 ClassifyTest classify_test(ASCIIToUTF16("A man, a plan, a canal Panama"),
648 matches); 541 matches);
649 542
650 ACMatchClassifications spans_a = classify_test.RunTest(ASCIIToUTF16("man")); 543 ACMatchClassifications spans_a = classify_test.RunTest(ASCIIToUTF16("man"));
651 // ACMatch spans should be: '--MMM------------------------' 544 // ACMatch spans should be: '--MMM------------------------'
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 AutocompleteMatchType::HISTORY_TITLE, "", 1, 1}, 698 AutocompleteMatchType::HISTORY_TITLE, "", 1, 1},
806 { "BD85DBA2-8C29-49F9-84AE-48E1E90881F4", "delete", "www.deletetest.com/2", 699 { "BD85DBA2-8C29-49F9-84AE-48E1E90881F4", "delete", "www.deletetest.com/2",
807 "http://www.deletetest.com/2", "http://www.deletetest.com/2", "0,2", 700 "http://www.deletetest.com/2", "http://www.deletetest.com/2", "0,2",
808 "Erase this shortcut!", "0,0", ui::PAGE_TRANSITION_TYPED, 701 "Erase this shortcut!", "0,0", ui::PAGE_TRANSITION_TYPED,
809 AutocompleteMatchType::HISTORY_URL, "", 1, 1}, 702 AutocompleteMatchType::HISTORY_URL, "", 1, 1},
810 }; 703 };
811 704
812 scoped_refptr<ShortcutsBackend> backend = client_->GetShortcutsBackend(); 705 scoped_refptr<ShortcutsBackend> backend = client_->GetShortcutsBackend();
813 size_t original_shortcuts_count = backend->shortcuts_map().size(); 706 size_t original_shortcuts_count = backend->shortcuts_map().size();
814 707
815 FillData(shortcuts_to_test_delete, arraysize(shortcuts_to_test_delete)); 708 PopulateShortcutsBackendWithTestShortcutData(
709 client_->GetShortcutsBackend(), shortcuts_to_test_delete,
710 arraysize(shortcuts_to_test_delete));
816 711
817 EXPECT_EQ(original_shortcuts_count + 4, backend->shortcuts_map().size()); 712 EXPECT_EQ(original_shortcuts_count + 4, backend->shortcuts_map().size());
818 EXPECT_FALSE(backend->shortcuts_map().end() == 713 EXPECT_FALSE(backend->shortcuts_map().end() ==
819 backend->shortcuts_map().find(ASCIIToUTF16("delete"))); 714 backend->shortcuts_map().find(ASCIIToUTF16("delete")));
820 EXPECT_FALSE(backend->shortcuts_map().end() == 715 EXPECT_FALSE(backend->shortcuts_map().end() ==
821 backend->shortcuts_map().find(ASCIIToUTF16("erase"))); 716 backend->shortcuts_map().find(ASCIIToUTF16("erase")));
822 717
823 AutocompleteMatch match( 718 AutocompleteMatch match(
824 provider_.get(), 1200, true, AutocompleteMatchType::HISTORY_TITLE); 719 provider_.get(), 1200, true, AutocompleteMatchType::HISTORY_TITLE);
825 720
(...skipping 23 matching lines...) Expand all
849 } 744 }
850 745
851 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) { 746 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) {
852 AutocompleteInput input( 747 AutocompleteInput input(
853 ASCIIToUTF16("about:o"), base::string16::npos, std::string(), GURL(), 748 ASCIIToUTF16("about:o"), base::string16::npos, std::string(), GURL(),
854 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, 749 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true,
855 TestSchemeClassifier()); 750 TestSchemeClassifier());
856 provider_->Start(input, false); 751 provider_->Start(input, false);
857 EXPECT_TRUE(provider_->matches().empty()); 752 EXPECT_TRUE(provider_->matches().empty());
858 } 753 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698