| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // covered in Java tests. | 41 // covered in Java tests. |
| 42 class SQLiteCursorTest : public testing::Test, | 42 class SQLiteCursorTest : public testing::Test, |
| 43 public SQLiteCursor::TestObserver { | 43 public SQLiteCursor::TestObserver { |
| 44 public: | 44 public: |
| 45 SQLiteCursorTest() | 45 SQLiteCursorTest() |
| 46 : profile_manager_( | 46 : profile_manager_( |
| 47 TestingBrowserProcess::GetGlobal()), | 47 TestingBrowserProcess::GetGlobal()), |
| 48 ui_thread_(BrowserThread::UI, &message_loop_), | 48 ui_thread_(BrowserThread::UI, &message_loop_), |
| 49 file_thread_(BrowserThread::FILE, &message_loop_) { | 49 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 50 } | 50 } |
| 51 virtual ~SQLiteCursorTest() { | 51 ~SQLiteCursorTest() override {} |
| 52 } | |
| 53 | 52 |
| 54 protected: | 53 protected: |
| 55 virtual void SetUp() override { | 54 void SetUp() override { |
| 56 // Setup the testing profile, so the bookmark_model_sql_handler could | 55 // Setup the testing profile, so the bookmark_model_sql_handler could |
| 57 // get the bookmark model from it. | 56 // get the bookmark model from it. |
| 58 ASSERT_TRUE(profile_manager_.SetUp()); | 57 ASSERT_TRUE(profile_manager_.SetUp()); |
| 59 // It seems that the name has to be chrome::kInitialProfile, so it | 58 // It seems that the name has to be chrome::kInitialProfile, so it |
| 60 // could be found by ProfileManager::GetLastUsedProfile(). | 59 // could be found by ProfileManager::GetLastUsedProfile(). |
| 61 testing_profile_ = profile_manager_.CreateTestingProfile( | 60 testing_profile_ = profile_manager_.CreateTestingProfile( |
| 62 chrome::kInitialProfile); | 61 chrome::kInitialProfile); |
| 63 | 62 |
| 64 testing_profile_->CreateBookmarkModel(true); | 63 testing_profile_->CreateBookmarkModel(true); |
| 65 bookmarks::test::WaitForBookmarkModelToLoad( | 64 bookmarks::test::WaitForBookmarkModelToLoad( |
| 66 BookmarkModelFactory::GetForProfile(testing_profile_)); | 65 BookmarkModelFactory::GetForProfile(testing_profile_)); |
| 67 | 66 |
| 68 testing_profile_->CreateFaviconService(); | 67 testing_profile_->CreateFaviconService(); |
| 69 ASSERT_TRUE(testing_profile_->CreateHistoryService(true, false)); | 68 ASSERT_TRUE(testing_profile_->CreateHistoryService(true, false)); |
| 70 service_.reset(new AndroidHistoryProviderService(testing_profile_)); | 69 service_.reset(new AndroidHistoryProviderService(testing_profile_)); |
| 71 hs_ = HistoryServiceFactory::GetForProfile( | 70 hs_ = HistoryServiceFactory::GetForProfile( |
| 72 testing_profile_, ServiceAccessType::EXPLICIT_ACCESS); | 71 testing_profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 73 } | 72 } |
| 74 | 73 |
| 75 virtual void TearDown() override { | 74 void TearDown() override { |
| 76 testing_profile_->DestroyHistoryService(); | 75 testing_profile_->DestroyHistoryService(); |
| 77 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile); | 76 profile_manager_.DeleteTestingProfile(chrome::kInitialProfile); |
| 78 testing_profile_ = NULL; | 77 testing_profile_ = NULL; |
| 79 } | 78 } |
| 80 | 79 |
| 81 // Override SQLiteCursor::TestObserver. | 80 // Override SQLiteCursor::TestObserver. |
| 82 virtual void OnPostMoveToTask() override { | 81 void OnPostMoveToTask() override { base::MessageLoop::current()->Run(); } |
| 83 base::MessageLoop::current()->Run(); | |
| 84 } | |
| 85 | 82 |
| 86 virtual void OnGetMoveToResult() override { | 83 void OnGetMoveToResult() override { base::MessageLoop::current()->Quit(); } |
| 87 base::MessageLoop::current()->Quit(); | |
| 88 } | |
| 89 | 84 |
| 90 virtual void OnPostGetFaviconTask() override { | 85 void OnPostGetFaviconTask() override { base::MessageLoop::current()->Run(); } |
| 91 base::MessageLoop::current()->Run(); | |
| 92 } | |
| 93 | 86 |
| 94 virtual void OnGetFaviconResult() override { | 87 void OnGetFaviconResult() override { base::MessageLoop::current()->Quit(); } |
| 95 base::MessageLoop::current()->Quit(); | |
| 96 } | |
| 97 | 88 |
| 98 protected: | 89 protected: |
| 99 TestingProfileManager profile_manager_; | 90 TestingProfileManager profile_manager_; |
| 100 base::MessageLoop message_loop_; | 91 base::MessageLoop message_loop_; |
| 101 content::TestBrowserThread ui_thread_; | 92 content::TestBrowserThread ui_thread_; |
| 102 content::TestBrowserThread file_thread_; | 93 content::TestBrowserThread file_thread_; |
| 103 scoped_ptr<AndroidHistoryProviderService> service_; | 94 scoped_ptr<AndroidHistoryProviderService> service_; |
| 104 base::CancelableTaskTracker cancelable_tracker_; | 95 base::CancelableTaskTracker cancelable_tracker_; |
| 105 TestingProfile* testing_profile_; | 96 TestingProfile* testing_profile_; |
| 106 HistoryService* hs_; | 97 HistoryService* hs_; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 cursor->GetBlob(env, NULL, 3); | 206 cursor->GetBlob(env, NULL, 3); |
| 216 std::vector<uint8> out; | 207 std::vector<uint8> out; |
| 217 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); | 208 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); |
| 218 EXPECT_EQ(data_bytes->data().size(), out.size()); | 209 EXPECT_EQ(data_bytes->data().size(), out.size()); |
| 219 EXPECT_EQ(data_bytes->data()[0], out[0]); | 210 EXPECT_EQ(data_bytes->data()[0], out[0]); |
| 220 cursor->Destroy(env, NULL); | 211 cursor->Destroy(env, NULL); |
| 221 // Cursor::Destroy posts the task in UI thread, run Message loop to release | 212 // Cursor::Destroy posts the task in UI thread, run Message loop to release |
| 222 // the statement, delete SQLiteCursor itself etc. | 213 // the statement, delete SQLiteCursor itself etc. |
| 223 content::RunAllPendingInMessageLoop(); | 214 content::RunAllPendingInMessageLoop(); |
| 224 } | 215 } |
| OLD | NEW |