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 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
11 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/run_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/task/cancelable_task_tracker.h" | 16 #include "base/task/cancelable_task_tracker.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_factory.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/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
20 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
22 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
23 #include "chrome/test/base/testing_profile_manager.h" | 24 #include "chrome/test/base/testing_profile_manager.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 testing_profile_, ServiceAccessType::EXPLICIT_ACCESS); | 74 testing_profile_, ServiceAccessType::EXPLICIT_ACCESS); |
74 } | 75 } |
75 | 76 |
76 void TearDown() override { | 77 void TearDown() override { |
77 testing_profile_->DestroyHistoryService(); | 78 testing_profile_->DestroyHistoryService(); |
78 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile); | 79 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile); |
79 testing_profile_ = NULL; | 80 testing_profile_ = NULL; |
80 } | 81 } |
81 | 82 |
82 // Override SQLiteCursor::TestObserver. | 83 // Override SQLiteCursor::TestObserver. |
83 void OnPostMoveToTask() override { base::MessageLoop::current()->Run(); } | 84 void OnPostMoveToTask() override { |
| 85 ASSERT_FALSE(run_loop_); |
| 86 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 87 run_loop_->Run(); |
| 88 run_loop_ = nullptr; |
| 89 } |
84 | 90 |
85 void OnGetMoveToResult() override { | 91 void OnGetMoveToResult() override { |
86 base::MessageLoop::current()->QuitWhenIdle(); | 92 ASSERT_TRUE(run_loop_); |
| 93 run_loop_->QuitWhenIdle(); |
87 } | 94 } |
88 | 95 |
89 void OnPostGetFaviconTask() override { base::MessageLoop::current()->Run(); } | 96 void OnPostGetFaviconTask() override { |
| 97 ASSERT_FALSE(run_loop_); |
| 98 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 99 run_loop_->Run(); |
| 100 run_loop_ = nullptr; |
| 101 } |
90 | 102 |
91 void OnGetFaviconResult() override { | 103 void OnGetFaviconResult() override { |
92 base::MessageLoop::current()->QuitWhenIdle(); | 104 ASSERT_TRUE(run_loop_); |
| 105 run_loop_->QuitWhenIdle(); |
93 } | 106 } |
94 | 107 |
95 protected: | 108 protected: |
96 TestingProfileManager profile_manager_; | 109 TestingProfileManager profile_manager_; |
97 base::MessageLoop message_loop_; | 110 base::MessageLoop message_loop_; |
98 content::TestBrowserThread ui_thread_; | 111 content::TestBrowserThread ui_thread_; |
99 content::TestBrowserThread file_thread_; | 112 content::TestBrowserThread file_thread_; |
100 std::unique_ptr<AndroidHistoryProviderService> service_; | 113 std::unique_ptr<AndroidHistoryProviderService> service_; |
101 base::CancelableTaskTracker cancelable_tracker_; | 114 base::CancelableTaskTracker cancelable_tracker_; |
102 TestingProfile* testing_profile_; | 115 TestingProfile* testing_profile_; |
103 history::HistoryService* hs_; | 116 history::HistoryService* hs_; |
| 117 std::unique_ptr<base::RunLoop> run_loop_; |
104 | 118 |
105 private: | 119 private: |
106 DISALLOW_COPY_AND_ASSIGN(SQLiteCursorTest); | 120 DISALLOW_COPY_AND_ASSIGN(SQLiteCursorTest); |
107 }; | 121 }; |
108 | 122 |
109 class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> { | 123 class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> { |
110 public: | 124 public: |
111 CallbackHelper() | 125 CallbackHelper() |
112 : success_(false), | 126 : success_(false), |
113 statement_(NULL) { | 127 statement_(NULL) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 row.set_visit_count(2); | 172 row.set_visit_count(2); |
159 row.set_title(base::UTF8ToUTF16("cnn")); | 173 row.set_title(base::UTF8ToUTF16("cnn")); |
160 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); | 174 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); |
161 | 175 |
162 // Insert a row and verify it succeeded. | 176 // Insert a row and verify it succeeded. |
163 service_->InsertHistoryAndBookmark( | 177 service_->InsertHistoryAndBookmark( |
164 row, | 178 row, |
165 Bind(&CallbackHelper::OnInserted, callback.get()), | 179 Bind(&CallbackHelper::OnInserted, callback.get()), |
166 &cancelable_tracker_); | 180 &cancelable_tracker_); |
167 | 181 |
168 base::MessageLoop::current()->Run(); | 182 base::RunLoop().Run(); |
169 EXPECT_TRUE(callback->success()); | 183 EXPECT_TRUE(callback->success()); |
170 | 184 |
171 std::vector<HistoryAndBookmarkRow::ColumnID> projections; | 185 std::vector<HistoryAndBookmarkRow::ColumnID> projections; |
172 projections.push_back(HistoryAndBookmarkRow::URL); | 186 projections.push_back(HistoryAndBookmarkRow::URL); |
173 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); | 187 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); |
174 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); | 188 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); |
175 projections.push_back(HistoryAndBookmarkRow::FAVICON); | 189 projections.push_back(HistoryAndBookmarkRow::FAVICON); |
176 | 190 |
177 // Query the inserted row. | 191 // Query the inserted row. |
178 service_->QueryHistoryAndBookmarks( | 192 service_->QueryHistoryAndBookmarks( |
179 projections, | 193 projections, |
180 std::string(), | 194 std::string(), |
181 std::vector<base::string16>(), | 195 std::vector<base::string16>(), |
182 std::string(), | 196 std::string(), |
183 Bind(&CallbackHelper::OnQueryResult, callback.get()), | 197 Bind(&CallbackHelper::OnQueryResult, callback.get()), |
184 &cancelable_tracker_); | 198 &cancelable_tracker_); |
185 base::MessageLoop::current()->Run(); | 199 base::RunLoop().Run(); |
186 ASSERT_TRUE(callback->success()); | 200 ASSERT_TRUE(callback->success()); |
187 | 201 |
188 AndroidStatement* statement = callback->statement(); | 202 AndroidStatement* statement = callback->statement(); |
189 std::vector<std::string> column_names; | 203 std::vector<std::string> column_names; |
190 column_names.push_back( | 204 column_names.push_back( |
191 HistoryAndBookmarkRow::GetAndroidName(HistoryAndBookmarkRow::URL)); | 205 HistoryAndBookmarkRow::GetAndroidName(HistoryAndBookmarkRow::URL)); |
192 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( | 206 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( |
193 HistoryAndBookmarkRow::LAST_VISIT_TIME)); | 207 HistoryAndBookmarkRow::LAST_VISIT_TIME)); |
194 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( | 208 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( |
195 HistoryAndBookmarkRow::VISIT_COUNT)); | 209 HistoryAndBookmarkRow::VISIT_COUNT)); |
(...skipping 15 matching lines...) Expand all Loading... |
211 cursor->GetBlob(env, NULL, 3); | 225 cursor->GetBlob(env, NULL, 3); |
212 std::vector<uint8_t> out; | 226 std::vector<uint8_t> out; |
213 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); | 227 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); |
214 EXPECT_EQ(data_bytes->data().size(), out.size()); | 228 EXPECT_EQ(data_bytes->data().size(), out.size()); |
215 EXPECT_EQ(data_bytes->data()[0], out[0]); | 229 EXPECT_EQ(data_bytes->data()[0], out[0]); |
216 cursor->Destroy(env, NULL); | 230 cursor->Destroy(env, NULL); |
217 // Cursor::Destroy posts the task in UI thread, run Message loop to release | 231 // Cursor::Destroy posts the task in UI thread, run Message loop to release |
218 // the statement, delete SQLiteCursor itself etc. | 232 // the statement, delete SQLiteCursor itself etc. |
219 content::RunAllPendingInMessageLoop(); | 233 content::RunAllPendingInMessageLoop(); |
220 } | 234 } |
OLD | NEW |