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

Side by Side Diff: chrome/browser/autocomplete/history_quick_provider_unittest.cc

Issue 6258015: Remove wstring from autocomplete.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/history_quick_provider.h" 5 #include "chrome/browser/autocomplete/history_quick_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 void TearDown() { 89 void TearDown() {
90 provider_ = NULL; 90 provider_ = NULL;
91 } 91 }
92 92
93 // Fills test data into the history system. 93 // Fills test data into the history system.
94 void FillData(); 94 void FillData();
95 95
96 // Runs an autocomplete query on |text| and checks to see that the returned 96 // Runs an autocomplete query on |text| and checks to see that the returned
97 // results' destination URLs match those provided. |expected_urls| does not 97 // results' destination URLs match those provided. |expected_urls| does not
98 // need to be in sorted order. 98 // need to be in sorted order.
99 void RunTest(const std::wstring text, 99 void RunTest(const string16 text,
100 std::vector<std::string> expected_urls, 100 std::vector<std::string> expected_urls,
101 std::string expected_top_result); 101 std::string expected_top_result);
102 102
103 MessageLoopForUI message_loop_; 103 MessageLoopForUI message_loop_;
104 BrowserThread ui_thread_; 104 BrowserThread ui_thread_;
105 BrowserThread file_thread_; 105 BrowserThread file_thread_;
106 106
107 scoped_ptr<TestingProfile> profile_; 107 scoped_ptr<TestingProfile> profile_;
108 HistoryService* history_service_; 108 HistoryService* history_service_;
109 109
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void operator()(const std::string& expected) { 156 void operator()(const std::string& expected) {
157 EXPECT_EQ(1U, matches_.erase(expected)); 157 EXPECT_EQ(1U, matches_.erase(expected));
158 } 158 }
159 159
160 std::set<std::string> LeftOvers() const { return matches_; } 160 std::set<std::string> LeftOvers() const { return matches_; }
161 161
162 private: 162 private:
163 std::set<std::string> matches_; 163 std::set<std::string> matches_;
164 }; 164 };
165 165
166 void HistoryQuickProviderTest::RunTest(const std::wstring text, 166 void HistoryQuickProviderTest::RunTest(const string16 text,
167 std::vector<std::string> expected_urls, 167 std::vector<std::string> expected_urls,
168 std::string expected_top_result) { 168 std::string expected_top_result) {
169 std::sort(expected_urls.begin(), expected_urls.end()); 169 std::sort(expected_urls.begin(), expected_urls.end());
170 170
171 MessageLoop::current()->RunAllPending(); 171 MessageLoop::current()->RunAllPending();
172 AutocompleteInput input(text, std::wstring(), false, false, true, false); 172 AutocompleteInput input(text, string16(), false, false, true, false);
173 provider_->Start(input, false); 173 provider_->Start(input, false);
174 EXPECT_TRUE(provider_->done()); 174 EXPECT_TRUE(provider_->done());
175 175
176 ACMatches matches = provider_->matches(); 176 ACMatches matches = provider_->matches();
177 // If the number of expected and actual matches aren't equal then we need 177 // If the number of expected and actual matches aren't equal then we need
178 // test no further, but let's do anyway so that we know which URLs failed. 178 // test no further, but let's do anyway so that we know which URLs failed.
179 EXPECT_EQ(expected_urls.size(), matches.size()); 179 EXPECT_EQ(expected_urls.size(), matches.size());
180 180
181 // Verify that all expected URLs were found and that all found URLs 181 // Verify that all expected URLs were found and that all found URLs
182 // were expected. 182 // were expected.
183 std::set<std::string> leftovers = 183 std::set<std::string> leftovers =
184 for_each(expected_urls.begin(), expected_urls.end(), 184 for_each(expected_urls.begin(), expected_urls.end(),
185 SetShouldContain(matches)).LeftOvers(); 185 SetShouldContain(matches)).LeftOvers();
186 EXPECT_TRUE(leftovers.empty()); 186 EXPECT_TRUE(leftovers.empty());
187 187
188 // See if we got the expected top scorer. 188 // See if we got the expected top scorer.
189 if (!matches.empty()) { 189 if (!matches.empty()) {
190 std::partial_sort(matches.begin(), matches.begin() + 1, 190 std::partial_sort(matches.begin(), matches.begin() + 1,
191 matches.end(), AutocompleteMatch::MoreRelevant); 191 matches.end(), AutocompleteMatch::MoreRelevant);
192 EXPECT_EQ(expected_top_result, matches[0].destination_url.spec()); 192 EXPECT_EQ(expected_top_result, matches[0].destination_url.spec());
193 } 193 }
194 } 194 }
195 195
196 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { 196 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) {
197 std::wstring text(L"slashdot"); 197 string16 text(ASCIIToUTF16("slashdot"));
198 std::string expected_url("http://slashdot.org/favorite_page.html"); 198 std::string expected_url("http://slashdot.org/favorite_page.html");
199 std::vector<std::string> expected_urls; 199 std::vector<std::string> expected_urls;
200 expected_urls.push_back(expected_url); 200 expected_urls.push_back(expected_url);
201 RunTest(text, expected_urls, expected_url); 201 RunTest(text, expected_urls, expected_url);
202 } 202 }
203 203
204 TEST_F(HistoryQuickProviderTest, MultiMatch) { 204 TEST_F(HistoryQuickProviderTest, MultiMatch) {
205 std::wstring text(L"foo"); 205 string16 text(ASCIIToUTF16("foo"));
206 std::vector<std::string> expected_urls; 206 std::vector<std::string> expected_urls;
207 expected_urls.push_back("http://foo.com/"); 207 expected_urls.push_back("http://foo.com/");
208 expected_urls.push_back("http://foo.com/dir/"); 208 expected_urls.push_back("http://foo.com/dir/");
209 expected_urls.push_back("http://foo.com/dir/another/"); 209 expected_urls.push_back("http://foo.com/dir/another/");
210 expected_urls.push_back("http://foo.com/dir/another/again/"); 210 expected_urls.push_back("http://foo.com/dir/another/again/");
211 expected_urls.push_back("http://foo.com/dir/another/again/myfile.html"); 211 expected_urls.push_back("http://foo.com/dir/another/again/myfile.html");
212 expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html"); 212 expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html");
213 RunTest(text, expected_urls, "http://foo.com/"); 213 RunTest(text, expected_urls, "http://foo.com/");
214 } 214 }
215 215
216 TEST_F(HistoryQuickProviderTest, StartRelativeMatch) { 216 TEST_F(HistoryQuickProviderTest, StartRelativeMatch) {
217 std::wstring text(L"xyz"); 217 string16 text(ASCIIToUTF16("xyz"));
218 std::vector<std::string> expected_urls; 218 std::vector<std::string> expected_urls;
219 expected_urls.push_back("http://xyzabcdefghijklmnopqrstuvw.com/a"); 219 expected_urls.push_back("http://xyzabcdefghijklmnopqrstuvw.com/a");
220 expected_urls.push_back("http://abcxyzdefghijklmnopqrstuvw.com/a"); 220 expected_urls.push_back("http://abcxyzdefghijklmnopqrstuvw.com/a");
221 expected_urls.push_back("http://abcdefxyzghijklmnopqrstuvw.com/a"); 221 expected_urls.push_back("http://abcdefxyzghijklmnopqrstuvw.com/a");
222 expected_urls.push_back("http://abcdefghixyzjklmnopqrstuvw.com/a"); 222 expected_urls.push_back("http://abcdefghixyzjklmnopqrstuvw.com/a");
223 expected_urls.push_back("http://abcdefghijklxyzmnopqrstuvw.com/a"); 223 expected_urls.push_back("http://abcdefghijklxyzmnopqrstuvw.com/a");
224 RunTest(text, expected_urls, "http://xyzabcdefghijklmnopqrstuvw.com/a"); 224 RunTest(text, expected_urls, "http://xyzabcdefghijklmnopqrstuvw.com/a");
225 } 225 }
226 226
227 TEST_F(HistoryQuickProviderTest, RecencyMatch) { 227 TEST_F(HistoryQuickProviderTest, RecencyMatch) {
228 std::wstring text(L"startest"); 228 string16 text(ASCIIToUTF16("startest"));
229 std::vector<std::string> expected_urls; 229 std::vector<std::string> expected_urls;
230 expected_urls.push_back("http://startest.com/y/a"); 230 expected_urls.push_back("http://startest.com/y/a");
231 expected_urls.push_back("http://startest.com/y/b"); 231 expected_urls.push_back("http://startest.com/y/b");
232 expected_urls.push_back("http://startest.com/x/c"); 232 expected_urls.push_back("http://startest.com/x/c");
233 expected_urls.push_back("http://startest.com/x/d"); 233 expected_urls.push_back("http://startest.com/x/d");
234 expected_urls.push_back("http://startest.com/y/e"); 234 expected_urls.push_back("http://startest.com/y/e");
235 expected_urls.push_back("http://startest.com/y/f"); 235 expected_urls.push_back("http://startest.com/y/f");
236 RunTest(text, expected_urls, "http://startest.com/y/a"); 236 RunTest(text, expected_urls, "http://startest.com/y/a");
237 } 237 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_quick_provider.cc ('k') | chrome/browser/autocomplete/history_url_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698