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

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

Issue 6306011: 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete.h" 9 #include "chrome/browser/autocomplete/autocomplete.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // We must quit the message loop (if running) to return control to the test. 93 // We must quit the message loop (if running) to return control to the test.
94 // Note, calling Quit() directly will checkfail if the loop isn't running, 94 // Note, calling Quit() directly will checkfail if the loop isn't running,
95 // so we post a task, which is safe for either case. 95 // so we post a task, which is safe for either case.
96 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 96 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
97 } 97 }
98 98
99 MessageLoopForUI message_loop_; 99 MessageLoopForUI message_loop_;
100 BrowserThread ui_thread_; 100 BrowserThread ui_thread_;
101 BrowserThread file_thread_; 101 BrowserThread file_thread_;
102 102
103 std::wstring history_dir_;
104
105 scoped_ptr<TestingProfile> profile_; 103 scoped_ptr<TestingProfile> profile_;
106 scoped_refptr<HistoryContentsProvider> provider_; 104 scoped_refptr<HistoryContentsProvider> provider_;
107 }; 105 };
108 106
109 TEST_F(HistoryContentsProviderTest, Body) { 107 TEST_F(HistoryContentsProviderTest, Body) {
110 AutocompleteInput input(L"FOO", std::wstring(), true, false, true, false); 108 AutocompleteInput input(ASCIIToUTF16("FOO"), string16(), true, false, true,
109 false);
111 RunQuery(input, false); 110 RunQuery(input, false);
112 111
113 // The results should be the first two pages, in decreasing order. 112 // The results should be the first two pages, in decreasing order.
114 const ACMatches& m = matches(); 113 const ACMatches& m = matches();
115 ASSERT_EQ(2U, m.size()); 114 ASSERT_EQ(2U, m.size());
116 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); 115 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec());
117 EXPECT_STREQ(test_entries[0].title, WideToUTF8(m[0].description).c_str()); 116 EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str());
118 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); 117 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec());
119 EXPECT_STREQ(test_entries[1].title, WideToUTF8(m[1].description).c_str()); 118 EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str());
120 } 119 }
121 120
122 TEST_F(HistoryContentsProviderTest, Title) { 121 TEST_F(HistoryContentsProviderTest, Title) {
123 AutocompleteInput input(L"PAGEONE", std::wstring(), true, false, true, false); 122 AutocompleteInput input(ASCIIToUTF16("PAGEONE"), string16(), true, false,
123 true, false);
124 RunQuery(input, false); 124 RunQuery(input, false);
125 125
126 // The results should be the first two pages. 126 // The results should be the first two pages.
127 const ACMatches& m = matches(); 127 const ACMatches& m = matches();
128 ASSERT_EQ(2U, m.size()); 128 ASSERT_EQ(2U, m.size());
129 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); 129 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec());
130 EXPECT_STREQ(test_entries[0].title, WideToUTF8(m[0].description).c_str()); 130 EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str());
131 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); 131 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec());
132 EXPECT_STREQ(test_entries[1].title, WideToUTF8(m[1].description).c_str()); 132 EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str());
133 } 133 }
134 134
135 // The "minimal changes" flag should mean that we don't re-query the DB. 135 // The "minimal changes" flag should mean that we don't re-query the DB.
136 TEST_F(HistoryContentsProviderTest, MinimalChanges) { 136 TEST_F(HistoryContentsProviderTest, MinimalChanges) {
137 // A minimal changes request when there have been no real queries should 137 // A minimal changes request when there have been no real queries should
138 // give us no results. 138 // give us no results.
139 AutocompleteInput sync_input(L"PAGEONE", std::wstring(), true, false, true, 139 AutocompleteInput sync_input(ASCIIToUTF16("PAGEONE"), string16(), true, false,
140 true); 140 true, true);
141 RunQuery(sync_input, true); 141 RunQuery(sync_input, true);
142 const ACMatches& m1 = matches(); 142 const ACMatches& m1 = matches();
143 EXPECT_EQ(0U, m1.size()); 143 EXPECT_EQ(0U, m1.size());
144 144
145 // Now do a "regular" query to get the results. 145 // Now do a "regular" query to get the results.
146 AutocompleteInput async_input(L"PAGEONE", std::wstring(), true, false, true, 146 AutocompleteInput async_input(ASCIIToUTF16("PAGEONE"), string16(), true,
147 false); 147 false, true, false);
148 RunQuery(async_input, false); 148 RunQuery(async_input, false);
149 const ACMatches& m2 = matches(); 149 const ACMatches& m2 = matches();
150 EXPECT_EQ(2U, m2.size()); 150 EXPECT_EQ(2U, m2.size());
151 151
152 // Now do a minimal one where we want synchronous results, and the results 152 // Now do a minimal one where we want synchronous results, and the results
153 // should still be there. 153 // should still be there.
154 RunQuery(sync_input, true); 154 RunQuery(sync_input, true);
155 const ACMatches& m3 = matches(); 155 const ACMatches& m3 = matches();
156 EXPECT_EQ(2U, m3.size()); 156 EXPECT_EQ(2U, m3.size());
157 } 157 }
158 158
159 // Tests that the BookmarkModel is queried correctly. 159 // Tests that the BookmarkModel is queried correctly.
160 TEST_F(HistoryContentsProviderTest, Bookmarks) { 160 TEST_F(HistoryContentsProviderTest, Bookmarks) {
161 profile()->CreateBookmarkModel(false); 161 profile()->CreateBookmarkModel(false);
162 profile()->BlockUntilBookmarkModelLoaded(); 162 profile()->BlockUntilBookmarkModelLoaded();
163 163
164 // Add a bookmark. 164 // Add a bookmark.
165 GURL bookmark_url("http://www.google.com/4"); 165 GURL bookmark_url("http://www.google.com/4");
166 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, 166 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url,
167 ASCIIToUTF16("bar"), true); 167 ASCIIToUTF16("bar"), true);
168 168
169 // Ask for synchronous. This should only get the bookmark. 169 // Ask for synchronous. This should only get the bookmark.
170 AutocompleteInput sync_input(L"bar", std::wstring(), true, false, true, true); 170 AutocompleteInput sync_input(ASCIIToUTF16("bar"), string16(), true, false,
171 true, true);
171 RunQuery(sync_input, false); 172 RunQuery(sync_input, false);
172 const ACMatches& m1 = matches(); 173 const ACMatches& m1 = matches();
173 ASSERT_EQ(1U, m1.size()); 174 ASSERT_EQ(1U, m1.size());
174 EXPECT_EQ(bookmark_url, m1[0].destination_url); 175 EXPECT_EQ(bookmark_url, m1[0].destination_url);
175 EXPECT_EQ(L"bar", m1[0].description); 176 EXPECT_EQ(ASCIIToUTF16("bar"), m1[0].description);
176 EXPECT_TRUE(m1[0].starred); 177 EXPECT_TRUE(m1[0].starred);
177 178
178 // Ask for async. We should get the bookmark immediately. 179 // Ask for async. We should get the bookmark immediately.
179 AutocompleteInput async_input(L"bar", std::wstring(), true, false, true, 180 AutocompleteInput async_input(ASCIIToUTF16("bar"), string16(), true, false,
180 false); 181 true, false);
181 provider()->Start(async_input, false); 182 provider()->Start(async_input, false);
182 const ACMatches& m2 = matches(); 183 const ACMatches& m2 = matches();
183 ASSERT_EQ(1U, m2.size()); 184 ASSERT_EQ(1U, m2.size());
184 EXPECT_EQ(bookmark_url, m2[0].destination_url); 185 EXPECT_EQ(bookmark_url, m2[0].destination_url);
185 186
186 // Run the message loop (needed for async history results). 187 // Run the message loop (needed for async history results).
187 MessageLoop::current()->Run(); 188 MessageLoop::current()->Run();
188 189
189 // We should have two urls now, bookmark_url and http://www.google.com/3. 190 // We should have two urls now, bookmark_url and http://www.google.com/3.
190 const ACMatches& m3 = matches(); 191 const ACMatches& m3 = matches();
191 ASSERT_EQ(2U, m3.size()); 192 ASSERT_EQ(2U, m3.size());
192 if (bookmark_url == m3[0].destination_url) { 193 if (bookmark_url == m3[0].destination_url) {
193 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); 194 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec());
194 } else { 195 } else {
195 EXPECT_EQ(bookmark_url, m3[1].destination_url); 196 EXPECT_EQ(bookmark_url, m3[1].destination_url);
196 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); 197 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec());
197 } 198 }
198 } 199 }
199 200
200 // Tests that history is deleted properly. 201 // Tests that history is deleted properly.
201 TEST_F(HistoryContentsProviderTest, DeleteMatch) { 202 TEST_F(HistoryContentsProviderTest, DeleteMatch) {
202 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); 203 AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true,
204 false);
203 RunQuery(input, false); 205 RunQuery(input, false);
204 206
205 // Query; the result should be the third page. 207 // Query; the result should be the third page.
206 const ACMatches& m = matches(); 208 const ACMatches& m = matches();
207 ASSERT_EQ(1U, m.size()); 209 ASSERT_EQ(1U, m.size());
208 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec()); 210 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec());
209 211
210 // Now delete the match and ensure it was removed. 212 // Now delete the match and ensure it was removed.
211 provider()->DeleteMatch(m[0]); 213 provider()->DeleteMatch(m[0]);
212 EXPECT_EQ(0U, matches().size()); 214 EXPECT_EQ(0U, matches().size());
213 } 215 }
214 216
215 // Tests deleting starred results from history, not affecting bookmarks/matches. 217 // Tests deleting starred results from history, not affecting bookmarks/matches.
216 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { 218 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) {
217 profile()->CreateBookmarkModel(false); 219 profile()->CreateBookmarkModel(false);
218 profile()->BlockUntilBookmarkModelLoaded(); 220 profile()->BlockUntilBookmarkModelLoaded();
219 221
220 // Bookmark a history item. 222 // Bookmark a history item.
221 GURL bookmark_url(test_entries[2].url); 223 GURL bookmark_url(test_entries[2].url);
222 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, 224 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url,
223 ASCIIToUTF16("bar"), true); 225 ASCIIToUTF16("bar"), true);
224 226
225 // Get the match to delete its history 227 // Get the match to delete its history
226 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); 228 AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true,
229 false);
227 RunQuery(input, false); 230 RunQuery(input, false);
228 const ACMatches& m = matches(); 231 const ACMatches& m = matches();
229 ASSERT_EQ(1U, m.size()); 232 ASSERT_EQ(1U, m.size());
230 233
231 // Now delete the match and ensure it was *not* removed. 234 // Now delete the match and ensure it was *not* removed.
232 provider()->DeleteMatch(m[0]); 235 provider()->DeleteMatch(m[0]);
233 EXPECT_EQ(1U, matches().size()); 236 EXPECT_EQ(1U, matches().size());
234 237
235 // Run a query that would only match history (but the history is deleted) 238 // Run a query that would only match history (but the history is deleted)
236 AutocompleteInput you_input(L"you", std::wstring(), true, false, true, false); 239 AutocompleteInput you_input(ASCIIToUTF16("you"), string16(), true, false,
240 true, false);
237 RunQuery(you_input, false); 241 RunQuery(you_input, false);
238 EXPECT_EQ(0U, matches().size()); 242 EXPECT_EQ(0U, matches().size());
239 243
240 // Run a query that matches the bookmark 244 // Run a query that matches the bookmark
241 RunQuery(input, false); 245 RunQuery(input, false);
242 EXPECT_EQ(1U, matches().size()); 246 EXPECT_EQ(1U, matches().size());
243 } 247 }
244 248
245 } // namespace 249 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698