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

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

Issue 6256010: Revert 72380 - Remove wstring from autocomplete.... (Closed) Base URL: svn://svn.chromium.org/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
103 scoped_ptr<TestingProfile> profile_; 105 scoped_ptr<TestingProfile> profile_;
104 scoped_refptr<HistoryContentsProvider> provider_; 106 scoped_refptr<HistoryContentsProvider> provider_;
105 }; 107 };
106 108
107 TEST_F(HistoryContentsProviderTest, Body) { 109 TEST_F(HistoryContentsProviderTest, Body) {
108 AutocompleteInput input(ASCIIToUTF16("FOO"), string16(), true, false, true, 110 AutocompleteInput input(L"FOO", std::wstring(), true, false, true, false);
109 false);
110 RunQuery(input, false); 111 RunQuery(input, false);
111 112
112 // The results should be the first two pages, in decreasing order. 113 // The results should be the first two pages, in decreasing order.
113 const ACMatches& m = matches(); 114 const ACMatches& m = matches();
114 ASSERT_EQ(2U, m.size()); 115 ASSERT_EQ(2U, m.size());
115 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); 116 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec());
116 EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str()); 117 EXPECT_STREQ(test_entries[0].title, WideToUTF8(m[0].description).c_str());
117 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); 118 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec());
118 EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str()); 119 EXPECT_STREQ(test_entries[1].title, WideToUTF8(m[1].description).c_str());
119 } 120 }
120 121
121 TEST_F(HistoryContentsProviderTest, Title) { 122 TEST_F(HistoryContentsProviderTest, Title) {
122 AutocompleteInput input(ASCIIToUTF16("PAGEONE"), string16(), true, false, 123 AutocompleteInput input(L"PAGEONE", std::wstring(), true, false, 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, UTF16ToUTF8(m[0].description).c_str()); 130 EXPECT_STREQ(test_entries[0].title, WideToUTF8(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, UTF16ToUTF8(m[1].description).c_str()); 132 EXPECT_STREQ(test_entries[1].title, WideToUTF8(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(ASCIIToUTF16("PAGEONE"), string16(), true, false, 139 AutocompleteInput sync_input(L"PAGEONE", std::wstring(), true, false, true,
140 true, true); 140 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(ASCIIToUTF16("PAGEONE"), string16(), true, 146 AutocompleteInput async_input(L"PAGEONE", std::wstring(), true, false, true,
147 false, true, false); 147 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(ASCIIToUTF16("bar"), string16(), true, false, 170 AutocompleteInput sync_input(L"bar", std::wstring(), true, false, true, true);
171 true, true);
172 RunQuery(sync_input, false); 171 RunQuery(sync_input, false);
173 const ACMatches& m1 = matches(); 172 const ACMatches& m1 = matches();
174 ASSERT_EQ(1U, m1.size()); 173 ASSERT_EQ(1U, m1.size());
175 EXPECT_EQ(bookmark_url, m1[0].destination_url); 174 EXPECT_EQ(bookmark_url, m1[0].destination_url);
176 EXPECT_EQ(ASCIIToUTF16("bar"), m1[0].description); 175 EXPECT_EQ(L"bar", m1[0].description);
177 EXPECT_TRUE(m1[0].starred); 176 EXPECT_TRUE(m1[0].starred);
178 177
179 // Ask for async. We should get the bookmark immediately. 178 // Ask for async. We should get the bookmark immediately.
180 AutocompleteInput async_input(ASCIIToUTF16("bar"), string16(), true, false, 179 AutocompleteInput async_input(L"bar", std::wstring(), true, false, true,
181 true, false); 180 false);
182 provider()->Start(async_input, false); 181 provider()->Start(async_input, false);
183 const ACMatches& m2 = matches(); 182 const ACMatches& m2 = matches();
184 ASSERT_EQ(1U, m2.size()); 183 ASSERT_EQ(1U, m2.size());
185 EXPECT_EQ(bookmark_url, m2[0].destination_url); 184 EXPECT_EQ(bookmark_url, m2[0].destination_url);
186 185
187 // Run the message loop (needed for async history results). 186 // Run the message loop (needed for async history results).
188 MessageLoop::current()->Run(); 187 MessageLoop::current()->Run();
189 188
190 // We should have two urls now, bookmark_url and http://www.google.com/3. 189 // We should have two urls now, bookmark_url and http://www.google.com/3.
191 const ACMatches& m3 = matches(); 190 const ACMatches& m3 = matches();
192 ASSERT_EQ(2U, m3.size()); 191 ASSERT_EQ(2U, m3.size());
193 if (bookmark_url == m3[0].destination_url) { 192 if (bookmark_url == m3[0].destination_url) {
194 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); 193 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec());
195 } else { 194 } else {
196 EXPECT_EQ(bookmark_url, m3[1].destination_url); 195 EXPECT_EQ(bookmark_url, m3[1].destination_url);
197 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); 196 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec());
198 } 197 }
199 } 198 }
200 199
201 // Tests that history is deleted properly. 200 // Tests that history is deleted properly.
202 TEST_F(HistoryContentsProviderTest, DeleteMatch) { 201 TEST_F(HistoryContentsProviderTest, DeleteMatch) {
203 AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true, 202 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false);
204 false);
205 RunQuery(input, false); 203 RunQuery(input, false);
206 204
207 // Query; the result should be the third page. 205 // Query; the result should be the third page.
208 const ACMatches& m = matches(); 206 const ACMatches& m = matches();
209 ASSERT_EQ(1U, m.size()); 207 ASSERT_EQ(1U, m.size());
210 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec()); 208 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec());
211 209
212 // Now delete the match and ensure it was removed. 210 // Now delete the match and ensure it was removed.
213 provider()->DeleteMatch(m[0]); 211 provider()->DeleteMatch(m[0]);
214 EXPECT_EQ(0U, matches().size()); 212 EXPECT_EQ(0U, matches().size());
215 } 213 }
216 214
217 // Tests deleting starred results from history, not affecting bookmarks/matches. 215 // Tests deleting starred results from history, not affecting bookmarks/matches.
218 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { 216 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) {
219 profile()->CreateBookmarkModel(false); 217 profile()->CreateBookmarkModel(false);
220 profile()->BlockUntilBookmarkModelLoaded(); 218 profile()->BlockUntilBookmarkModelLoaded();
221 219
222 // Bookmark a history item. 220 // Bookmark a history item.
223 GURL bookmark_url(test_entries[2].url); 221 GURL bookmark_url(test_entries[2].url);
224 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, 222 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url,
225 ASCIIToUTF16("bar"), true); 223 ASCIIToUTF16("bar"), true);
226 224
227 // Get the match to delete its history 225 // Get the match to delete its history
228 AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true, 226 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false);
229 false);
230 RunQuery(input, false); 227 RunQuery(input, false);
231 const ACMatches& m = matches(); 228 const ACMatches& m = matches();
232 ASSERT_EQ(1U, m.size()); 229 ASSERT_EQ(1U, m.size());
233 230
234 // Now delete the match and ensure it was *not* removed. 231 // Now delete the match and ensure it was *not* removed.
235 provider()->DeleteMatch(m[0]); 232 provider()->DeleteMatch(m[0]);
236 EXPECT_EQ(1U, matches().size()); 233 EXPECT_EQ(1U, matches().size());
237 234
238 // Run a query that would only match history (but the history is deleted) 235 // Run a query that would only match history (but the history is deleted)
239 AutocompleteInput you_input(ASCIIToUTF16("you"), string16(), true, false, 236 AutocompleteInput you_input(L"you", std::wstring(), true, false, true, false);
240 true, false);
241 RunQuery(you_input, false); 237 RunQuery(you_input, false);
242 EXPECT_EQ(0U, matches().size()); 238 EXPECT_EQ(0U, matches().size());
243 239
244 // Run a query that matches the bookmark 240 // Run a query that matches the bookmark
245 RunQuery(input, false); 241 RunQuery(input, false);
246 EXPECT_EQ(1U, matches().size()); 242 EXPECT_EQ(1U, matches().size());
247 } 243 }
248 244
249 } // namespace 245 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_contents_provider.cc ('k') | chrome/browser/autocomplete/history_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698