Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/history/android/sqlite_cursor_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 71
72 virtual void TearDown() OVERRIDE { 72 virtual void TearDown() OVERRIDE {
73 testing_profile_->DestroyHistoryService(); 73 testing_profile_->DestroyHistoryService();
74 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile); 74 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile);
75 testing_profile_ = NULL; 75 testing_profile_ = NULL;
76 } 76 }
77 77
78 // Override SQLiteCursor::TestObserver. 78 // Override SQLiteCursor::TestObserver.
79 virtual void OnPostMoveToTask() OVERRIDE { 79 virtual void OnPostMoveToTask() OVERRIDE {
80 MessageLoop::current()->Run(); 80 base::MessageLoop::current()->Run();
81 } 81 }
82 82
83 virtual void OnGetMoveToResult() OVERRIDE { 83 virtual void OnGetMoveToResult() OVERRIDE {
84 MessageLoop::current()->Quit(); 84 base::MessageLoop::current()->Quit();
85 } 85 }
86 86
87 virtual void OnPostGetFaviconTask() OVERRIDE { 87 virtual void OnPostGetFaviconTask() OVERRIDE {
88 MessageLoop::current()->Run(); 88 base::MessageLoop::current()->Run();
89 } 89 }
90 90
91 virtual void OnGetFaviconResult() OVERRIDE { 91 virtual void OnGetFaviconResult() OVERRIDE {
92 MessageLoop::current()->Quit(); 92 base::MessageLoop::current()->Quit();
93 } 93 }
94 94
95 protected: 95 protected:
96 TestingProfileManager profile_manager_; 96 TestingProfileManager profile_manager_;
97 MessageLoop message_loop_; 97 base::MessageLoop message_loop_;
98 content::TestBrowserThread ui_thread_; 98 content::TestBrowserThread ui_thread_;
99 content::TestBrowserThread file_thread_; 99 content::TestBrowserThread file_thread_;
100 scoped_ptr<AndroidHistoryProviderService> service_; 100 scoped_ptr<AndroidHistoryProviderService> service_;
101 CancelableRequestConsumer cancelable_consumer_; 101 CancelableRequestConsumer cancelable_consumer_;
102 TestingProfile* testing_profile_; 102 TestingProfile* testing_profile_;
103 HistoryService* hs_; 103 HistoryService* hs_;
104 104
105 105
106 private: 106 private:
107 DISALLOW_COPY_AND_ASSIGN(SQLiteCursorTest); 107 DISALLOW_COPY_AND_ASSIGN(SQLiteCursorTest);
(...skipping 11 matching lines...) Expand all
119 } 119 }
120 120
121 AndroidStatement* statement() const { 121 AndroidStatement* statement() const {
122 return statement_; 122 return statement_;
123 } 123 }
124 124
125 void OnInserted(AndroidHistoryProviderService::Handle handle, 125 void OnInserted(AndroidHistoryProviderService::Handle handle,
126 bool success, 126 bool success,
127 int64 id) { 127 int64 id) {
128 success_ = success; 128 success_ = success;
129 MessageLoop::current()->Quit(); 129 base::MessageLoop::current()->Quit();
130 } 130 }
131 131
132 void OnQueryResult(AndroidHistoryProviderService::Handle handle, 132 void OnQueryResult(AndroidHistoryProviderService::Handle handle,
133 bool success, 133 bool success,
134 AndroidStatement* statement) { 134 AndroidStatement* statement) {
135 success_ = success; 135 success_ = success;
136 statement_ = statement; 136 statement_ = statement;
137 MessageLoop::current()->Quit(); 137 base::MessageLoop::current()->Quit();
138 } 138 }
139 139
140 private: 140 private:
141 friend class base::RefCountedThreadSafe<CallbackHelper>; 141 friend class base::RefCountedThreadSafe<CallbackHelper>;
142 ~CallbackHelper() { 142 ~CallbackHelper() {
143 } 143 }
144 144
145 bool success_; 145 bool success_;
146 AndroidStatement* statement_; 146 AndroidStatement* statement_;
147 147
(...skipping 13 matching lines...) Expand all
161 row.set_favicon(data_bytes); 161 row.set_favicon(data_bytes);
162 row.set_last_visit_time(Time::Now()); 162 row.set_last_visit_time(Time::Now());
163 row.set_visit_count(2); 163 row.set_visit_count(2);
164 row.set_title(UTF8ToUTF16("cnn")); 164 row.set_title(UTF8ToUTF16("cnn"));
165 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); 165 scoped_refptr<CallbackHelper> callback(new CallbackHelper());
166 166
167 // Insert a row and verify it succeeded. 167 // Insert a row and verify it succeeded.
168 service_->InsertHistoryAndBookmark(row, &cancelable_consumer_, 168 service_->InsertHistoryAndBookmark(row, &cancelable_consumer_,
169 Bind(&CallbackHelper::OnInserted, callback.get())); 169 Bind(&CallbackHelper::OnInserted, callback.get()));
170 170
171 MessageLoop::current()->Run(); 171 base::MessageLoop::current()->Run();
172 EXPECT_TRUE(callback->success()); 172 EXPECT_TRUE(callback->success());
173 173
174 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 174 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
175 projections.push_back(HistoryAndBookmarkRow::URL); 175 projections.push_back(HistoryAndBookmarkRow::URL);
176 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); 176 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME);
177 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); 177 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT);
178 projections.push_back(HistoryAndBookmarkRow::FAVICON); 178 projections.push_back(HistoryAndBookmarkRow::FAVICON);
179 179
180 // Query the inserted row. 180 // Query the inserted row.
181 service_->QueryHistoryAndBookmarks(projections, std::string(), 181 service_->QueryHistoryAndBookmarks(projections, std::string(),
182 std::vector<string16>(), std::string(), &cancelable_consumer_, 182 std::vector<string16>(), std::string(), &cancelable_consumer_,
183 Bind(&CallbackHelper::OnQueryResult, callback.get())); 183 Bind(&CallbackHelper::OnQueryResult, callback.get()));
184 MessageLoop::current()->Run(); 184 base::MessageLoop::current()->Run();
185 ASSERT_TRUE(callback->success()); 185 ASSERT_TRUE(callback->success());
186 186
187 AndroidStatement* statement = callback->statement(); 187 AndroidStatement* statement = callback->statement();
188 std::vector<std::string> column_names; 188 std::vector<std::string> column_names;
189 column_names.push_back( 189 column_names.push_back(
190 HistoryAndBookmarkRow::GetAndroidName(HistoryAndBookmarkRow::URL)); 190 HistoryAndBookmarkRow::GetAndroidName(HistoryAndBookmarkRow::URL));
191 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( 191 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName(
192 HistoryAndBookmarkRow::LAST_VISIT_TIME)); 192 HistoryAndBookmarkRow::LAST_VISIT_TIME));
193 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName( 193 column_names.push_back(HistoryAndBookmarkRow::GetAndroidName(
194 HistoryAndBookmarkRow::VISIT_COUNT)); 194 HistoryAndBookmarkRow::VISIT_COUNT));
(...skipping 20 matching lines...) Expand all
215 std::vector<uint8> out; 215 std::vector<uint8> out;
216 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); 216 base::android::JavaByteArrayToByteVector(env, data.obj(), &out);
217 EXPECT_EQ(data_bytes->data().size(), out.size()); 217 EXPECT_EQ(data_bytes->data().size(), out.size());
218 EXPECT_EQ(data_bytes->data()[0], out[0]); 218 EXPECT_EQ(data_bytes->data()[0], out[0]);
219 } 219 }
220 220
221 // Cursor's destructor post the task in UI thread, run Message loop to release 221 // Cursor's destructor post the task in UI thread, run Message loop to release
222 // the statement etc. 222 // the statement etc.
223 content::RunAllPendingInMessageLoop(); 223 content::RunAllPendingInMessageLoop();
224 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698