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/sqlite_cursor.h" | 5 #include "chrome/browser/history/android/sqlite_cursor.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/task/cancelable_task_tracker.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
15 #include "chrome/browser/favicon/chrome_favicon_client.h" | 16 #include "chrome/browser/favicon/chrome_favicon_client.h" |
16 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" | 17 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" |
17 #include "chrome/browser/favicon/favicon_service.h" | 18 #include "chrome/browser/favicon/favicon_service.h" |
18 #include "chrome/browser/history/android/android_history_provider_service.h" | 19 #include "chrome/browser/history/android/android_history_provider_service.h" |
19 #include "chrome/browser/history/android/android_history_types.h" | 20 #include "chrome/browser/history/android/android_history_types.h" |
20 #include "chrome/browser/history/android/android_time.h" | 21 #include "chrome/browser/history/android/android_time.h" |
21 #include "chrome/browser/history/history_service.h" | 22 #include "chrome/browser/history/history_service.h" |
22 #include "chrome/browser/history/history_service_factory.h" | 23 #include "chrome/browser/history/history_service_factory.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 virtual void OnGetFaviconResult() OVERRIDE { | 97 virtual void OnGetFaviconResult() OVERRIDE { |
97 base::MessageLoop::current()->Quit(); | 98 base::MessageLoop::current()->Quit(); |
98 } | 99 } |
99 | 100 |
100 protected: | 101 protected: |
101 TestingProfileManager profile_manager_; | 102 TestingProfileManager profile_manager_; |
102 base::MessageLoop message_loop_; | 103 base::MessageLoop message_loop_; |
103 content::TestBrowserThread ui_thread_; | 104 content::TestBrowserThread ui_thread_; |
104 content::TestBrowserThread file_thread_; | 105 content::TestBrowserThread file_thread_; |
105 scoped_ptr<AndroidHistoryProviderService> service_; | 106 scoped_ptr<AndroidHistoryProviderService> service_; |
| 107 base::CancelableTaskTracker cancelable_tracker_; |
106 CancelableRequestConsumer cancelable_consumer_; | 108 CancelableRequestConsumer cancelable_consumer_; |
107 TestingProfile* testing_profile_; | 109 TestingProfile* testing_profile_; |
108 HistoryService* hs_; | 110 HistoryService* hs_; |
109 | 111 |
110 | 112 |
111 private: | 113 private: |
112 DISALLOW_COPY_AND_ASSIGN(SQLiteCursorTest); | 114 DISALLOW_COPY_AND_ASSIGN(SQLiteCursorTest); |
113 }; | 115 }; |
114 | 116 |
115 class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> { | 117 class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> { |
(...skipping 11 matching lines...) Expand all Loading... |
127 return statement_; | 129 return statement_; |
128 } | 130 } |
129 | 131 |
130 void OnInserted(AndroidHistoryProviderService::Handle handle, | 132 void OnInserted(AndroidHistoryProviderService::Handle handle, |
131 bool success, | 133 bool success, |
132 int64 id) { | 134 int64 id) { |
133 success_ = success; | 135 success_ = success; |
134 base::MessageLoop::current()->Quit(); | 136 base::MessageLoop::current()->Quit(); |
135 } | 137 } |
136 | 138 |
137 void OnQueryResult(AndroidHistoryProviderService::Handle handle, | 139 void OnQueryResult(AndroidStatement* statement) { |
138 bool success, | 140 success_ = statement != NULL; |
139 AndroidStatement* statement) { | |
140 success_ = success; | |
141 statement_ = statement; | 141 statement_ = statement; |
142 base::MessageLoop::current()->Quit(); | 142 base::MessageLoop::current()->Quit(); |
143 } | 143 } |
144 | 144 |
145 private: | 145 private: |
146 friend class base::RefCountedThreadSafe<CallbackHelper>; | 146 friend class base::RefCountedThreadSafe<CallbackHelper>; |
147 ~CallbackHelper() { | 147 ~CallbackHelper() { |
148 } | 148 } |
149 | 149 |
150 bool success_; | 150 bool success_; |
(...skipping 25 matching lines...) Expand all Loading... |
176 base::MessageLoop::current()->Run(); | 176 base::MessageLoop::current()->Run(); |
177 EXPECT_TRUE(callback->success()); | 177 EXPECT_TRUE(callback->success()); |
178 | 178 |
179 std::vector<HistoryAndBookmarkRow::ColumnID> projections; | 179 std::vector<HistoryAndBookmarkRow::ColumnID> projections; |
180 projections.push_back(HistoryAndBookmarkRow::URL); | 180 projections.push_back(HistoryAndBookmarkRow::URL); |
181 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); | 181 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); |
182 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); | 182 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); |
183 projections.push_back(HistoryAndBookmarkRow::FAVICON); | 183 projections.push_back(HistoryAndBookmarkRow::FAVICON); |
184 | 184 |
185 // Query the inserted row. | 185 // Query the inserted row. |
186 service_->QueryHistoryAndBookmarks(projections, std::string(), | 186 service_->QueryHistoryAndBookmarks( |
187 std::vector<base::string16>(), std::string(), &cancelable_consumer_, | 187 projections, |
188 Bind(&CallbackHelper::OnQueryResult, callback.get())); | 188 std::string(), |
| 189 std::vector<base::string16>(), |
| 190 std::string(), |
| 191 Bind(&CallbackHelper::OnQueryResult, callback.get()), |
| 192 &cancelable_tracker_); |
189 base::MessageLoop::current()->Run(); | 193 base::MessageLoop::current()->Run(); |
190 ASSERT_TRUE(callback->success()); | 194 ASSERT_TRUE(callback->success()); |
191 | 195 |
192 AndroidStatement* statement = callback->statement(); | 196 AndroidStatement* statement = callback->statement(); |
193 std::vector<std::string> column_names; | 197 std::vector<std::string> column_names; |
194 column_names.push_back( | 198 column_names.push_back( |
195 HistoryAndBookmarkRow::GetAndroidName(HistoryAndBookmarkRow::URL)); | 199 HistoryAndBookmarkRow::GetAndroidName(HistoryAndBookmarkRow::URL)); |
196 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( | 200 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( |
197 HistoryAndBookmarkRow::LAST_VISIT_TIME)); | 201 HistoryAndBookmarkRow::LAST_VISIT_TIME)); |
198 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( | 202 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( |
(...skipping 21 matching lines...) Expand all Loading... |
220 cursor->GetBlob(env, NULL, 3); | 224 cursor->GetBlob(env, NULL, 3); |
221 std::vector<uint8> out; | 225 std::vector<uint8> out; |
222 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); | 226 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); |
223 EXPECT_EQ(data_bytes->data().size(), out.size()); | 227 EXPECT_EQ(data_bytes->data().size(), out.size()); |
224 EXPECT_EQ(data_bytes->data()[0], out[0]); | 228 EXPECT_EQ(data_bytes->data()[0], out[0]); |
225 cursor->Destroy(env, NULL); | 229 cursor->Destroy(env, NULL); |
226 // Cursor::Destroy posts the task in UI thread, run Message loop to release | 230 // Cursor::Destroy posts the task in UI thread, run Message loop to release |
227 // the statement, delete SQLiteCursor itself etc. | 231 // the statement, delete SQLiteCursor itself etc. |
228 content::RunAllPendingInMessageLoop(); | 232 content::RunAllPendingInMessageLoop(); |
229 } | 233 } |
OLD | NEW |