| 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/task/cancelable_task_tracker.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 void OnDeleted(AndroidHistoryProviderService::Handle handle, | 129 void OnDeleted(AndroidHistoryProviderService::Handle handle, |
| 130 bool success, | 130 bool success, |
| 131 int count) { | 131 int count) { |
| 132 success_ = success; | 132 success_ = success; |
| 133 count_ = count; | 133 count_ = count; |
| 134 base::MessageLoop::current()->Quit(); | 134 base::MessageLoop::current()->Quit(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void OnStatementMoved(AndroidHistoryProviderService::Handle handle, | 137 void OnStatementMoved(int cursor_position) { |
| 138 int cursor_position) { | |
| 139 cursor_position_ = cursor_position; | 138 cursor_position_ = cursor_position; |
| 140 base::MessageLoop::current()->Quit(); | 139 base::MessageLoop::current()->Quit(); |
| 141 } | 140 } |
| 142 | 141 |
| 143 private: | 142 private: |
| 144 friend class base::RefCountedThreadSafe<CallbackHelper>; | 143 friend class base::RefCountedThreadSafe<CallbackHelper>; |
| 145 ~CallbackHelper() { | 144 ~CallbackHelper() { |
| 146 } | 145 } |
| 147 | 146 |
| 148 bool success_; | 147 bool success_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 177 std::vector<base::string16>(), | 176 std::vector<base::string16>(), |
| 178 std::string(), | 177 std::string(), |
| 179 Bind(&CallbackHelper::OnQueryResult, callback.get()), | 178 Bind(&CallbackHelper::OnQueryResult, callback.get()), |
| 180 &cancelable_tracker_); | 179 &cancelable_tracker_); |
| 181 base::MessageLoop::current()->Run(); | 180 base::MessageLoop::current()->Run(); |
| 182 ASSERT_TRUE(callback->success()); | 181 ASSERT_TRUE(callback->success()); |
| 183 | 182 |
| 184 // Move the cursor to the begining and verify whether we could get | 183 // Move the cursor to the begining and verify whether we could get |
| 185 // the same result. | 184 // the same result. |
| 186 AndroidStatement* statement = callback->statement(); | 185 AndroidStatement* statement = callback->statement(); |
| 187 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_, | 186 service_->MoveStatement( |
| 188 Bind(&CallbackHelper::OnStatementMoved, callback.get())); | 187 statement, |
| 188 0, |
| 189 -1, |
| 190 Bind(&CallbackHelper::OnStatementMoved, callback.get()), |
| 191 &cancelable_tracker_); |
| 189 base::MessageLoop::current()->Run(); | 192 base::MessageLoop::current()->Run(); |
| 190 EXPECT_EQ(-1, callback->cursor_position()); | 193 EXPECT_EQ(-1, callback->cursor_position()); |
| 191 EXPECT_TRUE(callback->statement()->statement()->Step()); | 194 EXPECT_TRUE(callback->statement()->statement()->Step()); |
| 192 EXPECT_FALSE(callback->statement()->statement()->Step()); | 195 EXPECT_FALSE(callback->statement()->statement()->Step()); |
| 193 service_->CloseStatement(statement); | 196 service_->CloseStatement(statement); |
| 194 | 197 |
| 195 // Update the row. | 198 // Update the row. |
| 196 HistoryAndBookmarkRow update_row; | 199 HistoryAndBookmarkRow update_row; |
| 197 update_row.set_visit_count(3); | 200 update_row.set_visit_count(3); |
| 198 service_->UpdateHistoryAndBookmarks(update_row, std::string(), | 201 service_->UpdateHistoryAndBookmarks(update_row, std::string(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 std::vector<base::string16>(), | 240 std::vector<base::string16>(), |
| 238 std::string(), | 241 std::string(), |
| 239 Bind(&CallbackHelper::OnQueryResult, callback.get()), | 242 Bind(&CallbackHelper::OnQueryResult, callback.get()), |
| 240 &cancelable_tracker_); | 243 &cancelable_tracker_); |
| 241 base::MessageLoop::current()->Run(); | 244 base::MessageLoop::current()->Run(); |
| 242 ASSERT_TRUE(callback->success()); | 245 ASSERT_TRUE(callback->success()); |
| 243 | 246 |
| 244 // Move the cursor to the begining and verify whether we could get | 247 // Move the cursor to the begining and verify whether we could get |
| 245 // the same result. | 248 // the same result. |
| 246 AndroidStatement* statement = callback->statement(); | 249 AndroidStatement* statement = callback->statement(); |
| 247 service_->MoveStatement(statement, 0, -1, &cancelable_consumer_, | 250 service_->MoveStatement( |
| 248 Bind(&CallbackHelper::OnStatementMoved, callback.get())); | 251 statement, |
| 252 0, |
| 253 -1, |
| 254 Bind(&CallbackHelper::OnStatementMoved, callback.get()), |
| 255 &cancelable_tracker_); |
| 249 base::MessageLoop::current()->Run(); | 256 base::MessageLoop::current()->Run(); |
| 250 EXPECT_EQ(-1, callback->cursor_position()); | 257 EXPECT_EQ(-1, callback->cursor_position()); |
| 251 EXPECT_TRUE(callback->statement()->statement()->Step()); | 258 EXPECT_TRUE(callback->statement()->statement()->Step()); |
| 252 EXPECT_FALSE(callback->statement()->statement()->Step()); | 259 EXPECT_FALSE(callback->statement()->statement()->Step()); |
| 253 service_->CloseStatement(statement); | 260 service_->CloseStatement(statement); |
| 254 | 261 |
| 255 // Update the row. | 262 // Update the row. |
| 256 SearchRow update_row; | 263 SearchRow update_row; |
| 257 update_row.set_search_time(Time::Now()); | 264 update_row.set_search_time(Time::Now()); |
| 258 service_->UpdateSearchTerms(update_row, std::string(), | 265 service_->UpdateSearchTerms(update_row, std::string(), |
| 259 std::vector<base::string16>(), &cancelable_consumer_, | 266 std::vector<base::string16>(), &cancelable_consumer_, |
| 260 Bind(&CallbackHelper::OnUpdated, callback.get())); | 267 Bind(&CallbackHelper::OnUpdated, callback.get())); |
| 261 base::MessageLoop::current()->Run(); | 268 base::MessageLoop::current()->Run(); |
| 262 EXPECT_TRUE(callback->success()); | 269 EXPECT_TRUE(callback->success()); |
| 263 EXPECT_EQ(1, callback->count()); | 270 EXPECT_EQ(1, callback->count()); |
| 264 | 271 |
| 265 // Delete the row. | 272 // Delete the row. |
| 266 service_->DeleteSearchTerms(std::string(), std::vector<base::string16>(), | 273 service_->DeleteSearchTerms(std::string(), std::vector<base::string16>(), |
| 267 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get())); | 274 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get())); |
| 268 base::MessageLoop::current()->Run(); | 275 base::MessageLoop::current()->Run(); |
| 269 EXPECT_TRUE(callback->success()); | 276 EXPECT_TRUE(callback->success()); |
| 270 EXPECT_EQ(1, callback->count()); | 277 EXPECT_EQ(1, callback->count()); |
| 271 } | 278 } |
| 272 | 279 |
| 273 } // namespace | 280 } // namespace |
| OLD | NEW |