Index: chrome/browser/history/history_backend_unittest.cc |
diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc |
index 5ab9a3a94bc152349b25b67aef4750a7bdef9cfb..5d0704b3e28952da8530c5d580b5f209cf4b1ad1 100644 |
--- a/chrome/browser/history/history_backend_unittest.cc |
+++ b/chrome/browser/history/history_backend_unittest.cc |
@@ -20,7 +20,6 @@ |
#include "base/strings/string16.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
-#include "chrome/browser/bookmarks/bookmark_model_factory.h" |
#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/history/history_notifications.h" |
#include "chrome/browser/history/history_service.h" |
@@ -32,13 +31,11 @@ |
#include "chrome/common/chrome_paths.h" |
#include "chrome/common/importer/imported_favicon_usage.h" |
#include "chrome/test/base/testing_profile.h" |
-#include "components/bookmarks/browser/bookmark_model.h" |
-#include "components/bookmarks/browser/bookmark_utils.h" |
-#include "components/bookmarks/test/bookmark_test_helpers.h" |
-#include "components/bookmarks/test/test_bookmark_client.h" |
+#include "components/history/core/test/history_client_fake_bookmarks.h" |
#include "content/public/browser/notification_details.h" |
#include "content/public/browser/notification_source.h" |
#include "content/public/test/test_browser_thread.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "url/gurl.h" |
@@ -67,6 +64,11 @@ bool FaviconBitmapLessThan(const history::FaviconBitmap& a, |
return a.pixel_size.GetArea() < b.pixel_size.GetArea(); |
} |
+class HistoryClientMock : public history::HistoryClientFakeBookmarks { |
+ public: |
+ MOCK_METHOD0(BlockUntilBookmarksLoaded, void()); |
+}; |
+ |
} // namespace |
namespace history { |
@@ -116,8 +118,7 @@ class HistoryBackendTestBase : public testing::Test { |
typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; |
HistoryBackendTestBase() |
- : bookmark_model_(bookmark_client_.CreateModel(false)), |
- loaded_(false), |
+ : loaded_(false), |
ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
virtual ~HistoryBackendTestBase() { |
@@ -152,10 +153,9 @@ class HistoryBackendTestBase : public testing::Test { |
std::make_pair(type, details.release())); |
} |
- test::TestBookmarkClient bookmark_client_; |
+ history::HistoryClientFakeBookmarks history_client_; |
scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. |
scoped_ptr<InMemoryHistoryBackend> mem_backend_; |
- scoped_ptr<BookmarkModel> bookmark_model_; |
bool loaded_; |
private: |
@@ -167,7 +167,7 @@ class HistoryBackendTestBase : public testing::Test { |
&test_dir_)) |
return; |
backend_ = new HistoryBackend( |
- test_dir_, new HistoryBackendTestDelegate(this), bookmark_model_.get()); |
+ test_dir_, new HistoryBackendTestDelegate(this), &history_client_); |
backend_->Init(std::string(), false); |
} |
@@ -178,6 +178,7 @@ class HistoryBackendTestBase : public testing::Test { |
mem_backend_.reset(); |
base::DeleteFile(test_dir_, true); |
base::RunLoop().RunUntilIdle(); |
+ history_client_.ClearAllBookmarks(); |
} |
void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { |
@@ -611,8 +612,7 @@ TEST_F(HistoryBackendTest, DeleteAll) { |
EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL)); |
// Star row1. |
- bookmark_model_->AddURL( |
- bookmark_model_->bookmark_bar_node(), 0, base::string16(), row1.url()); |
+ history_client_.AddBookmark(row1.url()); |
// Now finally clear all history. |
ClearBroadcastedNotifications(); |
@@ -676,7 +676,7 @@ TEST_F(HistoryBackendTest, DeleteAll) { |
EXPECT_EQ(out_favicon1, mappings[0].icon_id); |
// The first URL should still be bookmarked. |
- EXPECT_TRUE(bookmark_model_->IsBookmarked(row1.url())); |
+ EXPECT_TRUE(history_client_.IsBookmarked(row1.url())); |
// Check that we fire the notification about all history having been deleted. |
ASSERT_EQ(1u, broadcasted_notifications().size()); |
@@ -774,10 +774,8 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { |
URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL); |
// Star the two URLs. |
- bookmark_utils::AddIfNotBookmarked( |
- bookmark_model_.get(), row1.url(), base::string16()); |
- bookmark_utils::AddIfNotBookmarked( |
- bookmark_model_.get(), row2.url(), base::string16()); |
+ history_client_.AddBookmark(row1.url()); |
+ history_client_.AddBookmark(row2.url()); |
// Delete url 2. Because url 2 is starred this won't delete the URL, only |
// the visits. |
@@ -795,7 +793,7 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { |
favicon_url2, favicon_base::FAVICON, NULL)); |
// Unstar row2. |
- bookmark_utils::RemoveAllBookmarks(bookmark_model_.get(), row2.url()); |
+ history_client_.DelBookmark(row2.url()); |
// Tell the backend it was unstarred. We have to explicitly do this as |
// BookmarkModel isn't wired up to the backend during testing. |
@@ -811,7 +809,8 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { |
favicon_url2, favicon_base::FAVICON, NULL)); |
// Unstar row 1. |
- bookmark_utils::RemoveAllBookmarks(bookmark_model_.get(), row1.url()); |
+ history_client_.DelBookmark(row1.url()); |
+ |
// Tell the backend it was unstarred. We have to explicitly do this as |
// BookmarkModel isn't wired up to the backend during testing. |
unstarred_urls.clear(); |
@@ -1083,8 +1082,7 @@ TEST_F(HistoryBackendTest, ImportedFaviconsTest) { |
EXPECT_TRUE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); |
// If the URL is bookmarked, it should get added to history with 0 visits. |
- bookmark_model_->AddURL( |
- bookmark_model_->bookmark_bar_node(), 0, base::string16(), url3); |
+ history_client_.AddBookmark(url3); |
backend_->SetImportedFavicons(favicons); |
EXPECT_FALSE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); |
EXPECT_TRUE(url_row3.visit_count() == 0); |
@@ -1484,9 +1482,8 @@ TEST_F(HistoryBackendTest, MigrationVisitSource) { |
new_history_path.Append(chrome::kHistoryFilename); |
ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); |
- backend_ = new HistoryBackend(new_history_path, |
- new HistoryBackendTestDelegate(this), |
- bookmark_model_.get()); |
+ backend_ = new HistoryBackend( |
+ new_history_path, new HistoryBackendTestDelegate(this), &history_client_); |
backend_->Init(std::string(), false); |
backend_->Closing(); |
backend_ = NULL; |
@@ -2887,9 +2884,8 @@ TEST_F(HistoryBackendTest, MigrationVisitDuration) { |
ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); |
ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file)); |
- backend_ = new HistoryBackend(new_history_path, |
- new HistoryBackendTestDelegate(this), |
- bookmark_model_.get()); |
+ backend_ = new HistoryBackend( |
+ new_history_path, new HistoryBackendTestDelegate(this), &history_client_); |
backend_->Init(std::string(), false); |
backend_->Closing(); |
backend_ = NULL; |
@@ -3125,17 +3121,13 @@ TEST_F(HistoryBackendTest, DeleteMatchingUrlsForKeyword) { |
TEST_F(HistoryBackendTest, RemoveNotification) { |
scoped_ptr<TestingProfile> profile(new TestingProfile()); |
- ASSERT_TRUE(profile->CreateHistoryService(false, false)); |
- profile->CreateBookmarkModel(true); |
- BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile.get()); |
- test::WaitForBookmarkModelToLoad(model); |
- |
// Add a URL. |
GURL url("http://www.google.com"); |
- bookmark_utils::AddIfNotBookmarked(model, url, base::string16()); |
- |
- HistoryService* service = HistoryServiceFactory::GetForProfile( |
- profile.get(), Profile::EXPLICIT_ACCESS); |
+ HistoryClientMock history_client; |
+ history_client.AddBookmark(url); |
+ scoped_ptr<HistoryService> service( |
+ new HistoryService(&history_client, profile.get())); |
+ EXPECT_TRUE(service->Init(profile->GetPath())); |
service->AddPage( |
url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), |
@@ -3143,6 +3135,7 @@ TEST_F(HistoryBackendTest, RemoveNotification) { |
// This won't actually delete the URL, rather it'll empty out the visits. |
// This triggers blocking on the BookmarkModel. |
+ EXPECT_CALL(history_client, BlockUntilBookmarksLoaded()); |
service->DeleteURL(url); |
} |