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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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) 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 "base/time.h" 7 #include "base/time.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/history/android/android_history_types.h" 9 #include "chrome/browser/history/android/android_history_types.h"
10 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 virtual void TearDown() OVERRIDE { 60 virtual void TearDown() OVERRIDE {
61 testing_profile_->DestroyHistoryService(); 61 testing_profile_->DestroyHistoryService();
62 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile); 62 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile);
63 testing_profile_=NULL; 63 testing_profile_=NULL;
64 } 64 }
65 65
66 protected: 66 protected:
67 TestingProfileManager profile_manager_; 67 TestingProfileManager profile_manager_;
68 MessageLoop message_loop_; 68 base::MessageLoop message_loop_;
69 content::TestBrowserThread ui_thread_; 69 content::TestBrowserThread ui_thread_;
70 content::TestBrowserThread file_thread_; 70 content::TestBrowserThread file_thread_;
71 scoped_ptr<AndroidHistoryProviderService> service_; 71 scoped_ptr<AndroidHistoryProviderService> service_;
72 CancelableRequestConsumer cancelable_consumer_; 72 CancelableRequestConsumer cancelable_consumer_;
73 TestingProfile* testing_profile_; 73 TestingProfile* testing_profile_;
74 74
75 private: 75 private:
76 DISALLOW_COPY_AND_ASSIGN(AndroidHistoryProviderServiceTest); 76 DISALLOW_COPY_AND_ASSIGN(AndroidHistoryProviderServiceTest);
77 }; 77 };
78 78
(...skipping 19 matching lines...) Expand all
98 } 98 }
99 99
100 int count() const { 100 int count() const {
101 return count_; 101 return count_;
102 } 102 }
103 103
104 void OnInserted(AndroidHistoryProviderService::Handle handle, 104 void OnInserted(AndroidHistoryProviderService::Handle handle,
105 bool success, 105 bool success,
106 int64 id) { 106 int64 id) {
107 success_ = success; 107 success_ = success;
108 MessageLoop::current()->Quit(); 108 base::MessageLoop::current()->Quit();
109 } 109 }
110 110
111 void OnQueryResult(AndroidHistoryProviderService::Handle handle, 111 void OnQueryResult(AndroidHistoryProviderService::Handle handle,
112 bool success, 112 bool success,
113 AndroidStatement* statement) { 113 AndroidStatement* statement) {
114 success_ = success; 114 success_ = success;
115 statement_ = statement; 115 statement_ = statement;
116 MessageLoop::current()->Quit(); 116 base::MessageLoop::current()->Quit();
117 } 117 }
118 118
119 void OnUpdated(AndroidHistoryProviderService::Handle handle, 119 void OnUpdated(AndroidHistoryProviderService::Handle handle,
120 bool success, 120 bool success,
121 int count) { 121 int count) {
122 success_ = success; 122 success_ = success;
123 count_ = count; 123 count_ = count;
124 MessageLoop::current()->Quit(); 124 base::MessageLoop::current()->Quit();
125 } 125 }
126 126
127 void OnDeleted(AndroidHistoryProviderService::Handle handle, 127 void OnDeleted(AndroidHistoryProviderService::Handle handle,
128 bool success, 128 bool success,
129 int count) { 129 int count) {
130 success_ = success; 130 success_ = success;
131 count_ = count; 131 count_ = count;
132 MessageLoop::current()->Quit(); 132 base::MessageLoop::current()->Quit();
133 } 133 }
134 134
135 void OnStatementMoved(AndroidHistoryProviderService::Handle handle, 135 void OnStatementMoved(AndroidHistoryProviderService::Handle handle,
136 int cursor_position) { 136 int cursor_position) {
137 cursor_position_ = cursor_position; 137 cursor_position_ = cursor_position;
138 MessageLoop::current()->Quit(); 138 base::MessageLoop::current()->Quit();
139 } 139 }
140 140
141 private: 141 private:
142 friend class base::RefCountedThreadSafe<CallbackHelper>; 142 friend class base::RefCountedThreadSafe<CallbackHelper>;
143 ~CallbackHelper() { 143 ~CallbackHelper() {
144 } 144 }
145 145
146 bool success_; 146 bool success_;
147 AndroidStatement* statement_; 147 AndroidStatement* statement_;
148 int cursor_position_; 148 int cursor_position_;
149 int count_; 149 int count_;
150 150
151 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); 151 DISALLOW_COPY_AND_ASSIGN(CallbackHelper);
152 }; 152 };
153 153
154 TEST_F(AndroidHistoryProviderServiceTest, TestHistoryAndBookmark) { 154 TEST_F(AndroidHistoryProviderServiceTest, TestHistoryAndBookmark) {
155 HistoryAndBookmarkRow row; 155 HistoryAndBookmarkRow row;
156 row.set_raw_url("http://www.google.com"); 156 row.set_raw_url("http://www.google.com");
157 row.set_url(GURL("http://www.google.com")); 157 row.set_url(GURL("http://www.google.com"));
158 158
159 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); 159 scoped_refptr<CallbackHelper> callback(new CallbackHelper());
160 160
161 // Insert a row and verify it succeeded. 161 // Insert a row and verify it succeeded.
162 service_->InsertHistoryAndBookmark(row, &cancelable_consumer_, 162 service_->InsertHistoryAndBookmark(row, &cancelable_consumer_,
163 Bind(&CallbackHelper::OnInserted, callback.get())); 163 Bind(&CallbackHelper::OnInserted, callback.get()));
164 164
165 MessageLoop::current()->Run(); 165 base::MessageLoop::current()->Run();
166 EXPECT_TRUE(callback->success()); 166 EXPECT_TRUE(callback->success());
167 167
168 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 168 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
169 projections.push_back(HistoryAndBookmarkRow::ID); 169 projections.push_back(HistoryAndBookmarkRow::ID);
170 170
171 // Query the inserted row. 171 // Query the inserted row.
172 service_->QueryHistoryAndBookmarks(projections, std::string(), 172 service_->QueryHistoryAndBookmarks(projections, std::string(),
173 std::vector<string16>(), std::string(), &cancelable_consumer_, 173 std::vector<string16>(), std::string(), &cancelable_consumer_,
174 Bind(&CallbackHelper::OnQueryResult, callback.get())); 174 Bind(&CallbackHelper::OnQueryResult, callback.get()));
175 MessageLoop::current()->Run(); 175 base::MessageLoop::current()->Run();
176 ASSERT_TRUE(callback->success()); 176 ASSERT_TRUE(callback->success());
177 177
178 // Move the cursor to the begining and verify whether we could get 178 // Move the cursor to the begining and verify whether we could get
179 // the same result. 179 // the same result.
180 AndroidStatement* statement = callback->statement(); 180 AndroidStatement* statement = callback->statement();
181 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_, 181 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_,
182 Bind(&CallbackHelper::OnStatementMoved, callback.get())); 182 Bind(&CallbackHelper::OnStatementMoved, callback.get()));
183 MessageLoop::current()->Run(); 183 base::MessageLoop::current()->Run();
184 EXPECT_EQ(-1, callback->cursor_position()); 184 EXPECT_EQ(-1, callback->cursor_position());
185 EXPECT_TRUE(callback->statement()->statement()->Step()); 185 EXPECT_TRUE(callback->statement()->statement()->Step());
186 EXPECT_FALSE(callback->statement()->statement()->Step()); 186 EXPECT_FALSE(callback->statement()->statement()->Step());
187 service_->CloseStatement(statement); 187 service_->CloseStatement(statement);
188 188
189 // Update the row. 189 // Update the row.
190 HistoryAndBookmarkRow update_row; 190 HistoryAndBookmarkRow update_row;
191 update_row.set_visit_count(3); 191 update_row.set_visit_count(3);
192 service_->UpdateHistoryAndBookmarks(update_row, std::string(), 192 service_->UpdateHistoryAndBookmarks(update_row, std::string(),
193 std::vector<string16>(), &cancelable_consumer_, 193 std::vector<string16>(), &cancelable_consumer_,
194 Bind(&CallbackHelper::OnUpdated, callback.get())); 194 Bind(&CallbackHelper::OnUpdated, callback.get()));
195 MessageLoop::current()->Run(); 195 base::MessageLoop::current()->Run();
196 EXPECT_TRUE(callback->success()); 196 EXPECT_TRUE(callback->success());
197 EXPECT_EQ(1, callback->count()); 197 EXPECT_EQ(1, callback->count());
198 198
199 // Delete the row. 199 // Delete the row.
200 service_->DeleteHistoryAndBookmarks(std::string(), std::vector<string16>(), 200 service_->DeleteHistoryAndBookmarks(std::string(), std::vector<string16>(),
201 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get())); 201 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get()));
202 MessageLoop::current()->Run(); 202 base::MessageLoop::current()->Run();
203 EXPECT_TRUE(callback->success()); 203 EXPECT_TRUE(callback->success());
204 EXPECT_EQ(1, callback->count()); 204 EXPECT_EQ(1, callback->count());
205 } 205 }
206 206
207 TEST_F(AndroidHistoryProviderServiceTest, TestSearchTerm) { 207 TEST_F(AndroidHistoryProviderServiceTest, TestSearchTerm) {
208 SearchRow search_row; 208 SearchRow search_row;
209 search_row.set_search_term(UTF8ToUTF16("google")); 209 search_row.set_search_term(UTF8ToUTF16("google"));
210 search_row.set_url(GURL("http://google.com")); 210 search_row.set_url(GURL("http://google.com"));
211 search_row.set_template_url_id(1); 211 search_row.set_template_url_id(1);
212 search_row.set_search_time(Time::Now()); 212 search_row.set_search_time(Time::Now());
213 213
214 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); 214 scoped_refptr<CallbackHelper> callback(new CallbackHelper());
215 215
216 // Insert a row and verify it succeeded. 216 // Insert a row and verify it succeeded.
217 service_->InsertSearchTerm(search_row, &cancelable_consumer_, 217 service_->InsertSearchTerm(search_row, &cancelable_consumer_,
218 Bind(&CallbackHelper::OnInserted, callback.get())); 218 Bind(&CallbackHelper::OnInserted, callback.get()));
219 219
220 MessageLoop::current()->Run(); 220 base::MessageLoop::current()->Run();
221 EXPECT_TRUE(callback->success()); 221 EXPECT_TRUE(callback->success());
222 222
223 std::vector<SearchRow::ColumnID> projections; 223 std::vector<SearchRow::ColumnID> projections;
224 projections.push_back(SearchRow::ID); 224 projections.push_back(SearchRow::ID);
225 225
226 // Query the inserted row. 226 // Query the inserted row.
227 service_->QuerySearchTerms(projections, std::string(), 227 service_->QuerySearchTerms(projections, std::string(),
228 std::vector<string16>(), std::string(), &cancelable_consumer_, 228 std::vector<string16>(), std::string(), &cancelable_consumer_,
229 Bind(&CallbackHelper::OnQueryResult, callback.get())); 229 Bind(&CallbackHelper::OnQueryResult, callback.get()));
230 MessageLoop::current()->Run(); 230 base::MessageLoop::current()->Run();
231 ASSERT_TRUE(callback->success()); 231 ASSERT_TRUE(callback->success());
232 232
233 // Move the cursor to the begining and verify whether we could get 233 // Move the cursor to the begining and verify whether we could get
234 // the same result. 234 // the same result.
235 AndroidStatement* statement = callback->statement(); 235 AndroidStatement* statement = callback->statement();
236 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_, 236 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_,
237 Bind(&CallbackHelper::OnStatementMoved, callback.get())); 237 Bind(&CallbackHelper::OnStatementMoved, callback.get()));
238 MessageLoop::current()->Run(); 238 base::MessageLoop::current()->Run();
239 EXPECT_EQ(-1, callback->cursor_position()); 239 EXPECT_EQ(-1, callback->cursor_position());
240 EXPECT_TRUE(callback->statement()->statement()->Step()); 240 EXPECT_TRUE(callback->statement()->statement()->Step());
241 EXPECT_FALSE(callback->statement()->statement()->Step()); 241 EXPECT_FALSE(callback->statement()->statement()->Step());
242 service_->CloseStatement(statement); 242 service_->CloseStatement(statement);
243 243
244 // Update the row. 244 // Update the row.
245 SearchRow update_row; 245 SearchRow update_row;
246 update_row.set_search_time(Time::Now()); 246 update_row.set_search_time(Time::Now());
247 service_->UpdateSearchTerms(update_row, std::string(), 247 service_->UpdateSearchTerms(update_row, std::string(),
248 std::vector<string16>(), &cancelable_consumer_, 248 std::vector<string16>(), &cancelable_consumer_,
249 Bind(&CallbackHelper::OnUpdated, callback.get())); 249 Bind(&CallbackHelper::OnUpdated, callback.get()));
250 MessageLoop::current()->Run(); 250 base::MessageLoop::current()->Run();
251 EXPECT_TRUE(callback->success()); 251 EXPECT_TRUE(callback->success());
252 EXPECT_EQ(1, callback->count()); 252 EXPECT_EQ(1, callback->count());
253 253
254 // Delete the row. 254 // Delete the row.
255 service_->DeleteSearchTerms(std::string(), std::vector<string16>(), 255 service_->DeleteSearchTerms(std::string(), std::vector<string16>(),
256 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get())); 256 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get()));
257 MessageLoop::current()->Run(); 257 base::MessageLoop::current()->Run();
258 EXPECT_TRUE(callback->success()); 258 EXPECT_TRUE(callback->success());
259 EXPECT_EQ(1, callback->count()); 259 EXPECT_EQ(1, callback->count());
260 } 260 }
261 261
262 } // namespace 262 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/test_util.cc ('k') | chrome/browser/history/android/android_provider_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698