OLD | NEW |
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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/task/cancelable_task_tracker.h" |
8 #include "base/time/time.h" | 9 #include "base/time/time.h" |
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #include "chrome/browser/history/android/android_history_types.h" | 11 #include "chrome/browser/history/android/android_history_types.h" |
11 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
12 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
14 #include "chrome/test/base/testing_profile_manager.h" | 15 #include "chrome/test/base/testing_profile_manager.h" |
15 #include "components/bookmarks/test/bookmark_test_helpers.h" | 16 #include "components/bookmarks/test/bookmark_test_helpers.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile); | 65 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile); |
65 testing_profile_=NULL; | 66 testing_profile_=NULL; |
66 } | 67 } |
67 | 68 |
68 protected: | 69 protected: |
69 TestingProfileManager profile_manager_; | 70 TestingProfileManager profile_manager_; |
70 base::MessageLoop message_loop_; | 71 base::MessageLoop message_loop_; |
71 content::TestBrowserThread ui_thread_; | 72 content::TestBrowserThread ui_thread_; |
72 content::TestBrowserThread file_thread_; | 73 content::TestBrowserThread file_thread_; |
73 scoped_ptr<AndroidHistoryProviderService> service_; | 74 scoped_ptr<AndroidHistoryProviderService> service_; |
| 75 base::CancelableTaskTracker cancelable_tracker_; |
74 CancelableRequestConsumer cancelable_consumer_; | 76 CancelableRequestConsumer cancelable_consumer_; |
75 TestingProfile* testing_profile_; | 77 TestingProfile* testing_profile_; |
76 | 78 |
77 private: | 79 private: |
78 DISALLOW_COPY_AND_ASSIGN(AndroidHistoryProviderServiceTest); | 80 DISALLOW_COPY_AND_ASSIGN(AndroidHistoryProviderServiceTest); |
79 }; | 81 }; |
80 | 82 |
81 class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> { | 83 class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> { |
82 public: | 84 public: |
83 CallbackHelper() | 85 CallbackHelper() |
(...skipping 19 matching lines...) Expand all Loading... |
103 return count_; | 105 return count_; |
104 } | 106 } |
105 | 107 |
106 void OnInserted(AndroidHistoryProviderService::Handle handle, | 108 void OnInserted(AndroidHistoryProviderService::Handle handle, |
107 bool success, | 109 bool success, |
108 int64 id) { | 110 int64 id) { |
109 success_ = success; | 111 success_ = success; |
110 base::MessageLoop::current()->Quit(); | 112 base::MessageLoop::current()->Quit(); |
111 } | 113 } |
112 | 114 |
113 void OnQueryResult(AndroidHistoryProviderService::Handle handle, | 115 void OnQueryResult(AndroidStatement* statement) { |
114 bool success, | 116 success_ = statement != NULL; |
115 AndroidStatement* statement) { | |
116 success_ = success; | |
117 statement_ = statement; | 117 statement_ = statement; |
118 base::MessageLoop::current()->Quit(); | 118 base::MessageLoop::current()->Quit(); |
119 } | 119 } |
120 | 120 |
121 void OnUpdated(AndroidHistoryProviderService::Handle handle, | 121 void OnUpdated(AndroidHistoryProviderService::Handle handle, |
122 bool success, | 122 bool success, |
123 int count) { | 123 int count) { |
124 success_ = success; | 124 success_ = success; |
125 count_ = count; | 125 count_ = count; |
126 base::MessageLoop::current()->Quit(); | 126 base::MessageLoop::current()->Quit(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 service_->InsertHistoryAndBookmark(row, &cancelable_consumer_, | 164 service_->InsertHistoryAndBookmark(row, &cancelable_consumer_, |
165 Bind(&CallbackHelper::OnInserted, callback.get())); | 165 Bind(&CallbackHelper::OnInserted, callback.get())); |
166 | 166 |
167 base::MessageLoop::current()->Run(); | 167 base::MessageLoop::current()->Run(); |
168 EXPECT_TRUE(callback->success()); | 168 EXPECT_TRUE(callback->success()); |
169 | 169 |
170 std::vector<HistoryAndBookmarkRow::ColumnID> projections; | 170 std::vector<HistoryAndBookmarkRow::ColumnID> projections; |
171 projections.push_back(HistoryAndBookmarkRow::ID); | 171 projections.push_back(HistoryAndBookmarkRow::ID); |
172 | 172 |
173 // Query the inserted row. | 173 // Query the inserted row. |
174 service_->QueryHistoryAndBookmarks(projections, std::string(), | 174 service_->QueryHistoryAndBookmarks( |
175 std::vector<base::string16>(), std::string(), &cancelable_consumer_, | 175 projections, |
176 Bind(&CallbackHelper::OnQueryResult, callback.get())); | 176 std::string(), |
| 177 std::vector<base::string16>(), |
| 178 std::string(), |
| 179 Bind(&CallbackHelper::OnQueryResult, callback.get()), |
| 180 &cancelable_tracker_); |
177 base::MessageLoop::current()->Run(); | 181 base::MessageLoop::current()->Run(); |
178 ASSERT_TRUE(callback->success()); | 182 ASSERT_TRUE(callback->success()); |
179 | 183 |
180 // Move the cursor to the begining and verify whether we could get | 184 // Move the cursor to the begining and verify whether we could get |
181 // the same result. | 185 // the same result. |
182 AndroidStatement* statement = callback->statement(); | 186 AndroidStatement* statement = callback->statement(); |
183 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_, | 187 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_, |
184 Bind(&CallbackHelper::OnStatementMoved, callback.get())); | 188 Bind(&CallbackHelper::OnStatementMoved, callback.get())); |
185 base::MessageLoop::current()->Run(); | 189 base::MessageLoop::current()->Run(); |
186 EXPECT_EQ(-1, callback->cursor_position()); | 190 EXPECT_EQ(-1, callback->cursor_position()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 service_->InsertSearchTerm(search_row, &cancelable_consumer_, | 224 service_->InsertSearchTerm(search_row, &cancelable_consumer_, |
221 Bind(&CallbackHelper::OnInserted, callback.get())); | 225 Bind(&CallbackHelper::OnInserted, callback.get())); |
222 | 226 |
223 base::MessageLoop::current()->Run(); | 227 base::MessageLoop::current()->Run(); |
224 EXPECT_TRUE(callback->success()); | 228 EXPECT_TRUE(callback->success()); |
225 | 229 |
226 std::vector<SearchRow::ColumnID> projections; | 230 std::vector<SearchRow::ColumnID> projections; |
227 projections.push_back(SearchRow::ID); | 231 projections.push_back(SearchRow::ID); |
228 | 232 |
229 // Query the inserted row. | 233 // Query the inserted row. |
230 service_->QuerySearchTerms(projections, std::string(), | 234 service_->QuerySearchTerms( |
231 std::vector<base::string16>(), std::string(), &cancelable_consumer_, | 235 projections, |
232 Bind(&CallbackHelper::OnQueryResult, callback.get())); | 236 std::string(), |
| 237 std::vector<base::string16>(), |
| 238 std::string(), |
| 239 Bind(&CallbackHelper::OnQueryResult, callback.get()), |
| 240 &cancelable_tracker_); |
233 base::MessageLoop::current()->Run(); | 241 base::MessageLoop::current()->Run(); |
234 ASSERT_TRUE(callback->success()); | 242 ASSERT_TRUE(callback->success()); |
235 | 243 |
236 // Move the cursor to the begining and verify whether we could get | 244 // Move the cursor to the begining and verify whether we could get |
237 // the same result. | 245 // the same result. |
238 AndroidStatement* statement = callback->statement(); | 246 AndroidStatement* statement = callback->statement(); |
239 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_, | 247 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_, |
240 Bind(&CallbackHelper::OnStatementMoved, callback.get())); | 248 Bind(&CallbackHelper::OnStatementMoved, callback.get())); |
241 base::MessageLoop::current()->Run(); | 249 base::MessageLoop::current()->Run(); |
242 EXPECT_EQ(-1, callback->cursor_position()); | 250 EXPECT_EQ(-1, callback->cursor_position()); |
(...skipping 13 matching lines...) Expand all Loading... |
256 | 264 |
257 // Delete the row. | 265 // Delete the row. |
258 service_->DeleteSearchTerms(std::string(), std::vector<base::string16>(), | 266 service_->DeleteSearchTerms(std::string(), std::vector<base::string16>(), |
259 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get())); | 267 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get())); |
260 base::MessageLoop::current()->Run(); | 268 base::MessageLoop::current()->Run(); |
261 EXPECT_TRUE(callback->success()); | 269 EXPECT_TRUE(callback->success()); |
262 EXPECT_EQ(1, callback->count()); | 270 EXPECT_EQ(1, callback->count()); |
263 } | 271 } |
264 | 272 |
265 } // namespace | 273 } // namespace |
OLD | NEW |