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 2c8f15960e76cc497e4daba9f5a48004508337a8..f0bb15effbe113068490df660e2f1fafca6b18e8 100644 |
--- a/chrome/browser/history/history_backend_unittest.cc |
+++ b/chrome/browser/history/history_backend_unittest.cc |
@@ -19,10 +19,14 @@ |
#include "base/strings/string_number_conversions.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/bookmarks/bookmark_model.h" |
+#include "chrome/browser/bookmarks/bookmark_model_factory.h" |
#include "chrome/browser/bookmarks/bookmark_utils.h" |
+#include "chrome/browser/favicon/favicon_changed_details.h" |
#include "chrome/browser/favicon/imported_favicon_usage.h" |
#include "chrome/browser/history/history_backend.h" |
#include "chrome/browser/history/history_notifications.h" |
+#include "chrome/browser/history/history_service.h" |
+#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/history/in_memory_database.h" |
#include "chrome/browser/history/in_memory_history_backend.h" |
#include "chrome/browser/history/visit_filter.h" |
@@ -30,9 +34,12 @@ |
#include "chrome/common/chrome_paths.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/thumbnail_score.h" |
+#include "chrome/test/base/testing_profile.h" |
+#include "chrome/test/base/ui_test_utils.h" |
#include "chrome/tools/profiles/thumbnail-inl.h" |
#include "content/public/browser/notification_details.h" |
#include "content/public/browser/notification_source.h" |
+#include "content/public/test/test_browser_thread.h" |
#include "googleurl/src/gurl.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
@@ -85,6 +92,8 @@ class HistoryBackendTestDelegate : public HistoryBackend::Delegate { |
sql::InitStatus init_status) OVERRIDE {} |
virtual void SetInMemoryBackend(int backend_id, |
InMemoryHistoryBackend* backend) OVERRIDE; |
+ virtual void SendFaviconChangedNotification( |
+ chrome::FaviconChangedDetails* details) OVERRIDE; |
virtual void BroadcastNotifications(int type, |
HistoryDetails* details) OVERRIDE; |
virtual void DBLoaded(int backend_id) OVERRIDE; |
@@ -118,7 +127,9 @@ class HistoryBackendTest : public testing::Test { |
HistoryBackendTest() |
: bookmark_model_(NULL), |
loaded_(false), |
- num_broadcasted_notifications_(0) { |
+ num_favicon_notifications_(0), |
+ num_broadcasted_notifications_(0), |
+ ui_thread_(content::BrowserThread::UI, &message_loop_) { |
} |
virtual ~HistoryBackendTest() { |
@@ -144,6 +155,8 @@ class HistoryBackendTest : public testing::Test { |
return filtered_list_; |
} |
+ int num_favicon_notifications() const { return num_favicon_notifications_; } |
+ |
int num_broadcasted_notifications() const { |
return num_broadcasted_notifications_; |
} |
@@ -391,6 +404,12 @@ class HistoryBackendTest : public testing::Test { |
mem_backend_.reset(backend); |
} |
+ void SendFaviconChangedNotification(chrome::FaviconChangedDetails* details) { |
+ ++num_favicon_notifications_; |
+ // The backend passes ownership of the details pointer to us. |
+ delete details; |
+ } |
+ |
void BroadcastNotifications(int type, |
HistoryDetails* details) { |
++num_broadcasted_notifications_; |
@@ -403,10 +422,15 @@ class HistoryBackendTest : public testing::Test { |
delete details; |
} |
+ // The number of chrome::NOTIFICATION_FAVICON_CHANGED notifications that were |
+ // dispatched. |
+ int num_favicon_notifications_; |
+ |
// The number of notifications which were broadcasted. |
int num_broadcasted_notifications_; |
MessageLoop message_loop_; |
+ content::TestBrowserThread ui_thread_; |
base::FilePath test_dir_; |
history::MostVisitedURLList most_visited_list_; |
history::FilteredURLList filtered_list_; |
@@ -417,6 +441,11 @@ void HistoryBackendTestDelegate::SetInMemoryBackend(int backend_id, |
test_->SetInMemoryBackend(backend_id, backend); |
} |
+void HistoryBackendTestDelegate::SendFaviconChangedNotification( |
+ chrome::FaviconChangedDetails* details) { |
+ test_->SendFaviconChangedNotification(details); |
+} |
+ |
void HistoryBackendTestDelegate::BroadcastNotifications( |
int type, |
HistoryDetails* details) { |
@@ -1476,7 +1505,7 @@ TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) { |
&icon_mappings)); |
// Notifications should have been broadcast for each call to SetFavicons(). |
- EXPECT_EQ(3, num_broadcasted_notifications()); |
+ EXPECT_EQ(3, num_favicon_notifications()); |
} |
// Test updating a single favicon bitmap's data via SetFavicons. |
@@ -1507,7 +1536,7 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { |
GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap)); |
EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data)); |
- EXPECT_EQ(1, num_broadcasted_notifications()); |
+ EXPECT_EQ(1, num_favicon_notifications()); |
// Call SetFavicons() with completely identical data. |
std::vector<unsigned char> updated_data; |
@@ -1526,7 +1555,7 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { |
// Because the bitmap data is byte equivalent, no notifications should have |
// been broadcasted. |
- EXPECT_EQ(1, num_broadcasted_notifications()); |
+ EXPECT_EQ(1, num_favicon_notifications()); |
// Call SetFavicons() with identical data but a different bitmap. |
updated_data[0] = 'b'; |
@@ -1549,7 +1578,7 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { |
// A notification should have been broadcasted as the favicon bitmap data has |
// changed. |
- EXPECT_EQ(2, num_broadcasted_notifications()); |
+ EXPECT_EQ(2, num_favicon_notifications()); |
} |
// Test that if two pages share the same FaviconID, changing the favicon for |
@@ -1621,7 +1650,7 @@ TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { |
// A notification should have been broadcast for each call to SetFavicons() |
// and each call to UpdateFaviconMappingsAndFetch(). |
- EXPECT_EQ(3, num_broadcasted_notifications()); |
+ EXPECT_EQ(3, num_favicon_notifications()); |
} |
// Test that no notifications are broadcast as a result of calling |
@@ -1639,7 +1668,7 @@ TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { |
backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
icon_url, chrome::FAVICON, NULL); |
EXPECT_NE(0, icon_id); |
- EXPECT_EQ(1, num_broadcasted_notifications()); |
+ EXPECT_EQ(1, num_favicon_notifications()); |
std::vector<GURL> icon_urls; |
icon_urls.push_back(icon_url); |
@@ -1654,7 +1683,7 @@ TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { |
// No notification should have been broadcast as no icon mapping, favicon, |
// or favicon bitmap was updated, added or removed. |
- EXPECT_EQ(1, num_broadcasted_notifications()); |
+ EXPECT_EQ(1, num_favicon_notifications()); |
} |
// Test repeatedly calling MergeFavicon(). |page_url| is initially not known |
@@ -1729,7 +1758,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { |
EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); |
EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
- EXPECT_EQ(1, num_broadcasted_notifications()); |
+ EXPECT_EQ(1, num_favicon_notifications()); |
// 1) Merge identical favicon bitmap. |
std::vector<unsigned char> data; |
@@ -1752,7 +1781,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { |
EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); |
EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
- EXPECT_EQ(1, num_broadcasted_notifications()); |
+ EXPECT_EQ(1, num_favicon_notifications()); |
// 2) Merge favicon bitmap of the same size. |
data[0] = 'b'; |
@@ -1826,7 +1855,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { |
// A notification should have been broadcast for each call to SetFavicons() |
// and MergeFavicon(). |
- EXPECT_EQ(4, num_broadcasted_notifications()); |
+ EXPECT_EQ(4, num_favicon_notifications()); |
} |
// Test calling MergeFavicon() when |icon_url| is known to the database but not |
@@ -1911,7 +1940,7 @@ TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { |
// A notification should have been broadcast for each call to SetFavicons() |
// and MergeFavicon(). |
- EXPECT_EQ(3, num_broadcasted_notifications()); |
+ EXPECT_EQ(3, num_favicon_notifications()); |
} |
// Test that MergeFavicon() does not add more than |
@@ -2781,4 +2810,35 @@ TEST_F(HistoryBackendSegmentDurationTest, SegmentDuration) { |
EXPECT_EQ(segment1_time_delta.InHours(), data[1]->duration().InHours()); |
} |
+// Simple test that removes a bookmark. This test exercises the code paths in |
+// History that block till bookmark bar model is loaded. |
+TEST_F(HistoryBackendTest, RemoveNotification) { |
+ scoped_ptr<TestingProfile> profile(new TestingProfile()); |
+ profile->CreateHistoryService(false, false); |
+ profile->CreateBookmarkModel(true); |
+ |
+ BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile.get()); |
+ ui_test_utils::WaitForBookmarkModelToLoad(model); |
+ |
+ // Add a URL. |
+ GURL url("http://www.google.com"); |
+ bookmark_utils::AddIfNotBookmarked(model, url, string16()); |
+ |
+ HistoryService* service = HistoryServiceFactory::GetForProfile( |
+ profile.get(), Profile::EXPLICIT_ACCESS); |
+ service->AddPage(url, |
+ base::Time::Now(), |
+ NULL, |
+ 1, |
+ GURL(), |
+ RedirectList(), |
+ content::PAGE_TRANSITION_TYPED, |
+ SOURCE_BROWSED, |
+ false); |
+ |
+ // This won't actually delete the URL, rather it'll empty out the visits. |
+ // This triggers blocking on the BookmarkModel. |
+ service->DeleteURL(url); |
+} |
+ |
} // namespace history |