| 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/bookmark_model_sql_handler.h" | 5 #include "chrome/browser/history/android/bookmark_model_sql_handler.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/common/chrome_constants.h" | 11 #include "chrome/common/chrome_constants.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "chrome/test/base/testing_profile_manager.h" | 14 #include "chrome/test/base/testing_profile_manager.h" |
| 15 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "components/bookmarks/test/bookmark_test_helpers.h" | 16 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 17 #include "components/history/core/browser/history_constants.h" | 17 #include "components/history/core/browser/history_constants.h" |
| 18 #include "components/history/core/browser/history_database.h" | 18 #include "components/history/core/browser/history_database.h" |
| 19 #include "components/history/core/test/test_history_database.h" | 19 #include "components/history/core/test/test_history_database.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 using bookmarks::BookmarkModel; | 25 using bookmarks::BookmarkModel; |
| 26 using bookmarks::BookmarkNode; | 26 using bookmarks::BookmarkNode; |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 | 28 |
| 29 namespace history { | 29 namespace history { |
| 30 | 30 |
| 31 class BookmarkModelSQLHandlerTest : public testing::Test { | 31 class BookmarkModelSQLHandlerTest : public testing::Test { |
| 32 public: | 32 public: |
| 33 BookmarkModelSQLHandlerTest() | 33 BookmarkModelSQLHandlerTest() |
| 34 : profile_manager_(TestingBrowserProcess::GetGlobal()), | 34 : profile_manager_(TestingBrowserProcess::GetGlobal()), |
| 35 bookmark_model_(NULL), | 35 bookmark_model_(NULL) {} |
| 36 ui_thread_(BrowserThread::UI, &message_loop_), | |
| 37 file_thread_(BrowserThread::FILE, &message_loop_) {} | |
| 38 ~BookmarkModelSQLHandlerTest() override {} | 36 ~BookmarkModelSQLHandlerTest() override {} |
| 39 | 37 |
| 40 protected: | 38 protected: |
| 41 void SetUp() override { | 39 void SetUp() override { |
| 42 // Setup the testing profile, so the bookmark_model_sql_handler could | 40 // Setup the testing profile, so the bookmark_model_sql_handler could |
| 43 // get the bookmark model from it. | 41 // get the bookmark model from it. |
| 44 ASSERT_TRUE(profile_manager_.SetUp()); | 42 ASSERT_TRUE(profile_manager_.SetUp()); |
| 45 // It seems that the name has to be chrome::kInitialProfile, so it | 43 // It seems that the name has to be chrome::kInitialProfile, so it |
| 46 // could be found by ProfileManager::GetLastUsedProfile(). | 44 // could be found by ProfileManager::GetLastUsedProfile(). |
| 47 TestingProfile* testing_profile = profile_manager_.CreateTestingProfile( | 45 TestingProfile* testing_profile = profile_manager_.CreateTestingProfile( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 63 temp_dir_.GetPath().AppendASCII(kHistoryFilename); | 61 temp_dir_.GetPath().AppendASCII(kHistoryFilename); |
| 64 history_db_.Init(history_db_name); | 62 history_db_.Init(history_db_name); |
| 65 } | 63 } |
| 66 | 64 |
| 67 // Runs the MessageLoopForUI, and return till all pending messages were | 65 // Runs the MessageLoopForUI, and return till all pending messages were |
| 68 // processed. | 66 // processed. |
| 69 void RunMessageLoopForUI() { | 67 void RunMessageLoopForUI() { |
| 70 content::RunAllPendingInMessageLoop(); | 68 content::RunAllPendingInMessageLoop(); |
| 71 } | 69 } |
| 72 | 70 |
| 71 content::TestBrowserThreadBundle thread_bundle_; |
| 72 |
| 73 TestingProfileManager profile_manager_; | 73 TestingProfileManager profile_manager_; |
| 74 BookmarkModel* bookmark_model_; | 74 BookmarkModel* bookmark_model_; |
| 75 base::MessageLoopForUI message_loop_; | |
| 76 content::TestBrowserThread ui_thread_; | |
| 77 content::TestBrowserThread file_thread_; | |
| 78 base::ScopedTempDir temp_dir_; | 75 base::ScopedTempDir temp_dir_; |
| 79 TestHistoryDatabase history_db_; | 76 TestHistoryDatabase history_db_; |
| 80 }; | 77 }; |
| 81 | 78 |
| 82 TEST_F(BookmarkModelSQLHandlerTest, InsertIntoMobileFolder) { | 79 TEST_F(BookmarkModelSQLHandlerTest, InsertIntoMobileFolder) { |
| 83 HistoryAndBookmarkRow row; | 80 HistoryAndBookmarkRow row; |
| 84 row.set_raw_url("http://bookmark.com"); | 81 row.set_raw_url("http://bookmark.com"); |
| 85 row.set_url(GURL("http://bookmark.com")); | 82 row.set_url(GURL("http://bookmark.com")); |
| 86 row.set_title(base::UTF8ToUTF16("Bookmark Title")); | 83 row.set_title(base::UTF8ToUTF16("Bookmark Title")); |
| 87 row.set_is_bookmark(true); | 84 row.set_is_bookmark(true); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 id_row.url = url1; | 244 id_row.url = url1; |
| 248 id_rows.clear(); | 245 id_rows.clear(); |
| 249 id_rows.push_back(id_row); | 246 id_rows.push_back(id_row); |
| 250 ASSERT_TRUE(handler.Delete(id_rows)); | 247 ASSERT_TRUE(handler.Delete(id_rows)); |
| 251 RunMessageLoopForUI(); | 248 RunMessageLoopForUI(); |
| 252 // All bookmarks were deleted. | 249 // All bookmarks were deleted. |
| 253 EXPECT_FALSE(bookmark_model_->HasBookmarks()); | 250 EXPECT_FALSE(bookmark_model_->HasBookmarks()); |
| 254 } | 251 } |
| 255 | 252 |
| 256 } // namespace history | 253 } // namespace history |
| OLD | NEW |