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

Side by Side Diff: chrome/browser/history/android/android_history_provider_service_unittest.cc

Issue 2315443004: Remove calls to deprecated MessageLoop methods in chrome. (Closed)
Patch Set: remove unused include Created 4 years, 3 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 "chrome/browser/history/android/android_history_provider_service.h" 5 #include "chrome/browser/history/android/android_history_provider_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/callback.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
11 #include "base/task/cancelable_task_tracker.h" 13 #include "base/task/cancelable_task_tracker.h"
12 #include "base/time/time.h" 14 #include "base/time/time.h"
13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
14 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
15 #include "chrome/test/base/testing_browser_process.h" 17 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
17 #include "chrome/test/base/testing_profile_manager.h" 19 #include "chrome/test/base/testing_profile_manager.h"
18 #include "components/bookmarks/test/bookmark_test_helpers.h" 20 #include "components/bookmarks/test/bookmark_test_helpers.h"
19 #include "components/history/core/browser/android/android_history_types.h" 21 #include "components/history/core/browser/android/android_history_types.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 98 }
97 99
98 int cursor_position() const { 100 int cursor_position() const {
99 return cursor_position_; 101 return cursor_position_;
100 } 102 }
101 103
102 int count() const { 104 int count() const {
103 return count_; 105 return count_;
104 } 106 }
105 107
108 void set_quit_when_idle_closure(const base::Closure& quit_when_idle_closure) {
109 quit_when_idle_closure_ = quit_when_idle_closure;
110 }
111
106 void OnInserted(int64_t id) { 112 void OnInserted(int64_t id) {
107 success_ = id != 0; 113 success_ = id != 0;
108 base::MessageLoop::current()->QuitWhenIdle(); 114 quit_when_idle_closure_.Run();
109 } 115 }
110 116
111 void OnQueryResult(AndroidStatement* statement) { 117 void OnQueryResult(AndroidStatement* statement) {
112 success_ = statement != nullptr; 118 success_ = statement != nullptr;
113 statement_ = statement; 119 statement_ = statement;
114 base::MessageLoop::current()->QuitWhenIdle(); 120 quit_when_idle_closure_.Run();
115 } 121 }
116 122
117 void OnUpdated(int count) { 123 void OnUpdated(int count) {
118 success_ = count != 0; 124 success_ = count != 0;
119 count_ = count; 125 count_ = count;
120 base::MessageLoop::current()->QuitWhenIdle(); 126 quit_when_idle_closure_.Run();
121 } 127 }
122 128
123 void OnDeleted(int count) { 129 void OnDeleted(int count) {
124 success_ = count != 0; 130 success_ = count != 0;
125 count_ = count; 131 count_ = count;
126 base::MessageLoop::current()->QuitWhenIdle(); 132 quit_when_idle_closure_.Run();
127 } 133 }
128 134
129 void OnStatementMoved(int cursor_position) { 135 void OnStatementMoved(int cursor_position) {
130 cursor_position_ = cursor_position; 136 cursor_position_ = cursor_position;
131 base::MessageLoop::current()->QuitWhenIdle(); 137 quit_when_idle_closure_.Run();
132 } 138 }
133 139
134 private: 140 private:
135 friend class base::RefCountedThreadSafe<CallbackHelper>; 141 friend class base::RefCountedThreadSafe<CallbackHelper>;
136 ~CallbackHelper() { 142 ~CallbackHelper() {
137 } 143 }
138 144
139 bool success_; 145 bool success_;
140 AndroidStatement* statement_; 146 AndroidStatement* statement_;
141 int cursor_position_; 147 int cursor_position_;
142 int count_; 148 int count_;
149 base::Closure quit_when_idle_closure_;
143 150
144 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); 151 DISALLOW_COPY_AND_ASSIGN(CallbackHelper);
145 }; 152 };
146 153
154 void RunMessageLoop(CallbackHelper* callback_helper) {
155 ASSERT_TRUE(callback_helper);
156 base::RunLoop run_loop;
157 callback_helper->set_quit_when_idle_closure(run_loop.QuitWhenIdleClosure());
158 run_loop.Run();
159 callback_helper->set_quit_when_idle_closure(base::Closure());
160 }
161
147 TEST_F(AndroidHistoryProviderServiceTest, TestHistoryAndBookmark) { 162 TEST_F(AndroidHistoryProviderServiceTest, TestHistoryAndBookmark) {
148 HistoryAndBookmarkRow row; 163 HistoryAndBookmarkRow row;
149 row.set_raw_url("http://www.google.com"); 164 row.set_raw_url("http://www.google.com");
150 row.set_url(GURL("http://www.google.com")); 165 row.set_url(GURL("http://www.google.com"));
151 166
152 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); 167 scoped_refptr<CallbackHelper> callback(new CallbackHelper());
153 168
154 // Insert a row and verify it succeeded. 169 // Insert a row and verify it succeeded.
155 service_->InsertHistoryAndBookmark( 170 service_->InsertHistoryAndBookmark(
156 row, 171 row,
157 Bind(&CallbackHelper::OnInserted, callback.get()), 172 Bind(&CallbackHelper::OnInserted, callback.get()),
158 &cancelable_tracker_); 173 &cancelable_tracker_);
159 174
160 base::MessageLoop::current()->Run(); 175 RunMessageLoop(callback.get());
161 EXPECT_TRUE(callback->success()); 176 EXPECT_TRUE(callback->success());
162 177
163 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 178 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
164 projections.push_back(HistoryAndBookmarkRow::ID); 179 projections.push_back(HistoryAndBookmarkRow::ID);
165 180
166 // Query the inserted row. 181 // Query the inserted row.
167 service_->QueryHistoryAndBookmarks( 182 service_->QueryHistoryAndBookmarks(
168 projections, 183 projections,
169 std::string(), 184 std::string(),
170 std::vector<base::string16>(), 185 std::vector<base::string16>(),
171 std::string(), 186 std::string(),
172 Bind(&CallbackHelper::OnQueryResult, callback.get()), 187 Bind(&CallbackHelper::OnQueryResult, callback.get()),
173 &cancelable_tracker_); 188 &cancelable_tracker_);
174 base::MessageLoop::current()->Run(); 189 RunMessageLoop(callback.get());
175 ASSERT_TRUE(callback->success()); 190 ASSERT_TRUE(callback->success());
176 191
177 // Move the cursor to the begining and verify whether we could get 192 // Move the cursor to the begining and verify whether we could get
178 // the same result. 193 // the same result.
179 AndroidStatement* statement = callback->statement(); 194 AndroidStatement* statement = callback->statement();
180 service_->MoveStatement( 195 service_->MoveStatement(
181 statement, 196 statement,
182 0, 197 0,
183 -1, 198 -1,
184 Bind(&CallbackHelper::OnStatementMoved, callback.get()), 199 Bind(&CallbackHelper::OnStatementMoved, callback.get()),
185 &cancelable_tracker_); 200 &cancelable_tracker_);
186 base::MessageLoop::current()->Run(); 201 RunMessageLoop(callback.get());
187 EXPECT_EQ(-1, callback->cursor_position()); 202 EXPECT_EQ(-1, callback->cursor_position());
188 EXPECT_TRUE(callback->statement()->statement()->Step()); 203 EXPECT_TRUE(callback->statement()->statement()->Step());
189 EXPECT_FALSE(callback->statement()->statement()->Step()); 204 EXPECT_FALSE(callback->statement()->statement()->Step());
190 service_->CloseStatement(statement); 205 service_->CloseStatement(statement);
191 206
192 // Update the row. 207 // Update the row.
193 HistoryAndBookmarkRow update_row; 208 HistoryAndBookmarkRow update_row;
194 update_row.set_visit_count(3); 209 update_row.set_visit_count(3);
195 service_->UpdateHistoryAndBookmarks( 210 service_->UpdateHistoryAndBookmarks(
196 update_row, 211 update_row,
197 std::string(), 212 std::string(),
198 std::vector<base::string16>(), 213 std::vector<base::string16>(),
199 Bind(&CallbackHelper::OnUpdated, callback.get()), 214 Bind(&CallbackHelper::OnUpdated, callback.get()),
200 &cancelable_tracker_); 215 &cancelable_tracker_);
201 base::MessageLoop::current()->Run(); 216 RunMessageLoop(callback.get());
202 EXPECT_TRUE(callback->success()); 217 EXPECT_TRUE(callback->success());
203 EXPECT_EQ(1, callback->count()); 218 EXPECT_EQ(1, callback->count());
204 219
205 // Delete the row. 220 // Delete the row.
206 service_->DeleteHistoryAndBookmarks( 221 service_->DeleteHistoryAndBookmarks(
207 std::string(), 222 std::string(),
208 std::vector<base::string16>(), 223 std::vector<base::string16>(),
209 Bind(&CallbackHelper::OnDeleted, callback.get()), 224 Bind(&CallbackHelper::OnDeleted, callback.get()),
210 &cancelable_tracker_); 225 &cancelable_tracker_);
211 base::MessageLoop::current()->Run(); 226 RunMessageLoop(callback.get());
212 EXPECT_TRUE(callback->success()); 227 EXPECT_TRUE(callback->success());
213 EXPECT_EQ(1, callback->count()); 228 EXPECT_EQ(1, callback->count());
214 } 229 }
215 230
216 TEST_F(AndroidHistoryProviderServiceTest, TestSearchTerm) { 231 TEST_F(AndroidHistoryProviderServiceTest, TestSearchTerm) {
217 SearchRow search_row; 232 SearchRow search_row;
218 search_row.set_search_term(base::UTF8ToUTF16("google")); 233 search_row.set_search_term(base::UTF8ToUTF16("google"));
219 search_row.set_url(GURL("http://google.com")); 234 search_row.set_url(GURL("http://google.com"));
220 search_row.set_keyword_id(1); 235 search_row.set_keyword_id(1);
221 search_row.set_search_time(Time::Now()); 236 search_row.set_search_time(Time::Now());
222 237
223 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); 238 scoped_refptr<CallbackHelper> callback(new CallbackHelper());
224 239
225 // Insert a row and verify it succeeded. 240 // Insert a row and verify it succeeded.
226 service_->InsertSearchTerm(search_row, 241 service_->InsertSearchTerm(search_row,
227 Bind(&CallbackHelper::OnInserted, callback.get()), 242 Bind(&CallbackHelper::OnInserted, callback.get()),
228 &cancelable_tracker_); 243 &cancelable_tracker_);
229 244
230 base::MessageLoop::current()->Run(); 245 RunMessageLoop(callback.get());
231 EXPECT_TRUE(callback->success()); 246 EXPECT_TRUE(callback->success());
232 247
233 std::vector<SearchRow::ColumnID> projections; 248 std::vector<SearchRow::ColumnID> projections;
234 projections.push_back(SearchRow::ID); 249 projections.push_back(SearchRow::ID);
235 250
236 // Query the inserted row. 251 // Query the inserted row.
237 service_->QuerySearchTerms( 252 service_->QuerySearchTerms(
238 projections, 253 projections,
239 std::string(), 254 std::string(),
240 std::vector<base::string16>(), 255 std::vector<base::string16>(),
241 std::string(), 256 std::string(),
242 Bind(&CallbackHelper::OnQueryResult, callback.get()), 257 Bind(&CallbackHelper::OnQueryResult, callback.get()),
243 &cancelable_tracker_); 258 &cancelable_tracker_);
244 base::MessageLoop::current()->Run(); 259 RunMessageLoop(callback.get());
245 ASSERT_TRUE(callback->success()); 260 ASSERT_TRUE(callback->success());
246 261
247 // Move the cursor to the begining and verify whether we could get 262 // Move the cursor to the begining and verify whether we could get
248 // the same result. 263 // the same result.
249 AndroidStatement* statement = callback->statement(); 264 AndroidStatement* statement = callback->statement();
250 service_->MoveStatement( 265 service_->MoveStatement(
251 statement, 266 statement,
252 0, 267 0,
253 -1, 268 -1,
254 Bind(&CallbackHelper::OnStatementMoved, callback.get()), 269 Bind(&CallbackHelper::OnStatementMoved, callback.get()),
255 &cancelable_tracker_); 270 &cancelable_tracker_);
256 base::MessageLoop::current()->Run(); 271 RunMessageLoop(callback.get());
257 EXPECT_EQ(-1, callback->cursor_position()); 272 EXPECT_EQ(-1, callback->cursor_position());
258 EXPECT_TRUE(callback->statement()->statement()->Step()); 273 EXPECT_TRUE(callback->statement()->statement()->Step());
259 EXPECT_FALSE(callback->statement()->statement()->Step()); 274 EXPECT_FALSE(callback->statement()->statement()->Step());
260 service_->CloseStatement(statement); 275 service_->CloseStatement(statement);
261 276
262 // Update the row. 277 // Update the row.
263 SearchRow update_row; 278 SearchRow update_row;
264 update_row.set_search_time(Time::Now()); 279 update_row.set_search_time(Time::Now());
265 service_->UpdateSearchTerms(update_row, 280 service_->UpdateSearchTerms(update_row,
266 std::string(), 281 std::string(),
267 std::vector<base::string16>(), 282 std::vector<base::string16>(),
268 Bind(&CallbackHelper::OnUpdated, callback.get()), 283 Bind(&CallbackHelper::OnUpdated, callback.get()),
269 &cancelable_tracker_); 284 &cancelable_tracker_);
270 base::MessageLoop::current()->Run(); 285 RunMessageLoop(callback.get());
271 EXPECT_TRUE(callback->success()); 286 EXPECT_TRUE(callback->success());
272 EXPECT_EQ(1, callback->count()); 287 EXPECT_EQ(1, callback->count());
273 288
274 // Delete the row. 289 // Delete the row.
275 service_->DeleteSearchTerms(std::string(), 290 service_->DeleteSearchTerms(std::string(),
276 std::vector<base::string16>(), 291 std::vector<base::string16>(),
277 Bind(&CallbackHelper::OnDeleted, callback.get()), 292 Bind(&CallbackHelper::OnDeleted, callback.get()),
278 &cancelable_tracker_); 293 &cancelable_tracker_);
279 base::MessageLoop::current()->Run(); 294 RunMessageLoop(callback.get());
280 EXPECT_TRUE(callback->success()); 295 EXPECT_TRUE(callback->success());
281 EXPECT_EQ(1, callback->count()); 296 EXPECT_EQ(1, callback->count());
282 } 297 }
283 298
284 } // namespace 299 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/menu_manager_unittest.cc ('k') | chrome/browser/history/android/sqlite_cursor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698