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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 | 99 |
100 int cursor_position() const { | 100 int cursor_position() const { |
101 return cursor_position_; | 101 return cursor_position_; |
102 } | 102 } |
103 | 103 |
104 int count() const { | 104 int count() const { |
105 return count_; | 105 return count_; |
106 } | 106 } |
107 | 107 |
108 void OnInserted(AndroidHistoryProviderService::Handle handle, | 108 void OnInserted(int64 id) { |
109 bool success, | 109 success_ = id != 0; |
110 int64 id) { | |
111 success_ = success; | |
112 base::MessageLoop::current()->Quit(); | 110 base::MessageLoop::current()->Quit(); |
113 } | 111 } |
114 | 112 |
115 void OnQueryResult(AndroidStatement* statement) { | 113 void OnQueryResult(AndroidStatement* statement) { |
116 success_ = statement != NULL; | 114 success_ = statement != NULL; |
117 statement_ = statement; | 115 statement_ = statement; |
118 base::MessageLoop::current()->Quit(); | 116 base::MessageLoop::current()->Quit(); |
119 } | 117 } |
120 | 118 |
121 void OnUpdated(AndroidHistoryProviderService::Handle handle, | 119 void OnUpdated(AndroidHistoryProviderService::Handle handle, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 }; | 151 }; |
154 | 152 |
155 TEST_F(AndroidHistoryProviderServiceTest, TestHistoryAndBookmark) { | 153 TEST_F(AndroidHistoryProviderServiceTest, TestHistoryAndBookmark) { |
156 HistoryAndBookmarkRow row; | 154 HistoryAndBookmarkRow row; |
157 row.set_raw_url("http://www.google.com"); | 155 row.set_raw_url("http://www.google.com"); |
158 row.set_url(GURL("http://www.google.com")); | 156 row.set_url(GURL("http://www.google.com")); |
159 | 157 |
160 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); | 158 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); |
161 | 159 |
162 // Insert a row and verify it succeeded. | 160 // Insert a row and verify it succeeded. |
163 service_->InsertHistoryAndBookmark(row, &cancelable_consumer_, | 161 service_->InsertHistoryAndBookmark( |
164 Bind(&CallbackHelper::OnInserted, callback.get())); | 162 row, |
| 163 Bind(&CallbackHelper::OnInserted, callback.get()), |
| 164 &cancelable_tracker_); |
165 | 165 |
166 base::MessageLoop::current()->Run(); | 166 base::MessageLoop::current()->Run(); |
167 EXPECT_TRUE(callback->success()); | 167 EXPECT_TRUE(callback->success()); |
168 | 168 |
169 std::vector<HistoryAndBookmarkRow::ColumnID> projections; | 169 std::vector<HistoryAndBookmarkRow::ColumnID> projections; |
170 projections.push_back(HistoryAndBookmarkRow::ID); | 170 projections.push_back(HistoryAndBookmarkRow::ID); |
171 | 171 |
172 // Query the inserted row. | 172 // Query the inserted row. |
173 service_->QueryHistoryAndBookmarks( | 173 service_->QueryHistoryAndBookmarks( |
174 projections, | 174 projections, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 TEST_F(AndroidHistoryProviderServiceTest, TestSearchTerm) { | 217 TEST_F(AndroidHistoryProviderServiceTest, TestSearchTerm) { |
218 SearchRow search_row; | 218 SearchRow search_row; |
219 search_row.set_search_term(base::UTF8ToUTF16("google")); | 219 search_row.set_search_term(base::UTF8ToUTF16("google")); |
220 search_row.set_url(GURL("http://google.com")); | 220 search_row.set_url(GURL("http://google.com")); |
221 search_row.set_keyword_id(1); | 221 search_row.set_keyword_id(1); |
222 search_row.set_search_time(Time::Now()); | 222 search_row.set_search_time(Time::Now()); |
223 | 223 |
224 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); | 224 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); |
225 | 225 |
226 // Insert a row and verify it succeeded. | 226 // Insert a row and verify it succeeded. |
227 service_->InsertSearchTerm(search_row, &cancelable_consumer_, | 227 service_->InsertSearchTerm(search_row, |
228 Bind(&CallbackHelper::OnInserted, callback.get())); | 228 Bind(&CallbackHelper::OnInserted, callback.get()), |
| 229 &cancelable_tracker_); |
229 | 230 |
230 base::MessageLoop::current()->Run(); | 231 base::MessageLoop::current()->Run(); |
231 EXPECT_TRUE(callback->success()); | 232 EXPECT_TRUE(callback->success()); |
232 | 233 |
233 std::vector<SearchRow::ColumnID> projections; | 234 std::vector<SearchRow::ColumnID> projections; |
234 projections.push_back(SearchRow::ID); | 235 projections.push_back(SearchRow::ID); |
235 | 236 |
236 // Query the inserted row. | 237 // Query the inserted row. |
237 service_->QuerySearchTerms( | 238 service_->QuerySearchTerms( |
238 projections, | 239 projections, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 272 |
272 // Delete the row. | 273 // Delete the row. |
273 service_->DeleteSearchTerms(std::string(), std::vector<base::string16>(), | 274 service_->DeleteSearchTerms(std::string(), std::vector<base::string16>(), |
274 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get())); | 275 &cancelable_consumer_, Bind(&CallbackHelper::OnDeleted, callback.get())); |
275 base::MessageLoop::current()->Run(); | 276 base::MessageLoop::current()->Run(); |
276 EXPECT_TRUE(callback->success()); | 277 EXPECT_TRUE(callback->success()); |
277 EXPECT_EQ(1, callback->count()); | 278 EXPECT_EQ(1, callback->count()); |
278 } | 279 } |
279 | 280 |
280 } // namespace | 281 } // namespace |
OLD | NEW |