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 bc00726e23871209405b660c0504b7d66cb379eb..3399e0a2651c928401ffc700182b3953c5029b1f 100644 |
--- a/chrome/browser/history/history_backend_unittest.cc |
+++ b/chrome/browser/history/history_backend_unittest.cc |
@@ -90,6 +90,7 @@ class HistoryBackendTestDelegate : public HistoryBackend::Delegate { |
virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {} |
virtual void SetInMemoryBackend( |
scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE; |
+ virtual void NotifyFaviconChanged(const std::set<GURL>& urls) OVERRIDE; |
virtual void BroadcastNotifications( |
int type, |
scoped_ptr<HistoryDetails> details) OVERRIDE; |
@@ -110,6 +111,7 @@ class HistoryBackendTestBase : public testing::Test { |
HistoryBackendTestBase() |
: loaded_(false), |
+ favicon_changed_notifications_(0), |
ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
virtual ~HistoryBackendTestBase() { |
@@ -117,6 +119,14 @@ class HistoryBackendTestBase : public testing::Test { |
} |
protected: |
+ int favicon_changed_notifications() const { |
+ return favicon_changed_notifications_; |
+ } |
+ |
+ void ClearFaviconChangedNotificationCounter() { |
+ favicon_changed_notifications_ = 0; |
+ } |
+ |
int num_broadcasted_notifications() const { |
return broadcasted_notifications_.size(); |
} |
@@ -133,6 +143,10 @@ class HistoryBackendTestBase : public testing::Test { |
return test_dir_; |
} |
+ void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) { |
+ ++favicon_changed_notifications_; |
+ } |
+ |
void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) { |
// Send the notifications directly to the in-memory database. |
content::Details<HistoryDetails> det(details.get()); |
@@ -178,6 +192,7 @@ class HistoryBackendTestBase : public testing::Test { |
// The types and details of notifications which were broadcasted. |
NotificationList broadcasted_notifications_; |
+ int favicon_changed_notifications_; |
base::MessageLoop message_loop_; |
base::FilePath test_dir_; |
@@ -191,6 +206,11 @@ void HistoryBackendTestDelegate::SetInMemoryBackend( |
test_->SetInMemoryBackend(backend.Pass()); |
} |
+void HistoryBackendTestDelegate::NotifyFaviconChanged( |
+ const std::set<GURL>& changed_favicons) { |
+ test_->NotifyFaviconChanged(changed_favicons); |
+} |
+ |
void HistoryBackendTestDelegate::BroadcastNotifications( |
int type, |
scoped_ptr<HistoryDetails> details) { |
@@ -1666,6 +1686,7 @@ TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) { |
const GURL page_url("http://www.google.com/"); |
const GURL icon_url("http://www.google.com/icon"); |
+ ClearFaviconChangedNotificationCounter(); |
std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; |
GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(), |
&favicon_bitmap_data); |
@@ -1724,7 +1745,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, favicon_changed_notifications()); |
} |
// Test updating a single favicon bitmap's data via SetFavicons. |
@@ -1732,6 +1753,7 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { |
const GURL page_url("http://www.google.com/"); |
const GURL icon_url("http://www.google.com/icon"); |
+ ClearFaviconChangedNotificationCounter(); |
std::vector<unsigned char> data_initial; |
data_initial.push_back('a'); |
@@ -1755,7 +1777,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, favicon_changed_notifications()); |
// Call SetFavicons() with completely identical data. |
std::vector<unsigned char> updated_data; |
@@ -1774,7 +1796,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, favicon_changed_notifications()); |
// Call SetFavicons() with identical data but a different bitmap. |
updated_data[0] = 'b'; |
@@ -1796,7 +1818,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, favicon_changed_notifications()); |
} |
// Test that if two pages share the same FaviconID, changing the favicon for |
@@ -1807,6 +1829,7 @@ TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { |
GURL page_url1("http://www.google.com"); |
GURL page_url2("http://www.google.ca"); |
+ ClearFaviconChangedNotificationCounter(); |
std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; |
GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(), |
&favicon_bitmap_data); |
@@ -1870,7 +1893,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, favicon_changed_notifications()); |
} |
// Test that no notifications are broadcast as a result of calling |
@@ -1883,13 +1906,14 @@ TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { |
GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(), |
&favicon_bitmap_data); |
+ ClearFaviconChangedNotificationCounter(); |
backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); |
favicon_base::FaviconID icon_id = |
backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
icon_url, favicon_base::FAVICON, NULL); |
EXPECT_NE(0, icon_id); |
- EXPECT_EQ(1, num_broadcasted_notifications()); |
+ EXPECT_EQ(1, favicon_changed_notifications()); |
std::vector<GURL> icon_urls; |
icon_urls.push_back(icon_url); |
@@ -1907,7 +1931,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, favicon_changed_notifications()); |
} |
// Test repeatedly calling MergeFavicon(). |page_url| is initially not known |
@@ -1963,6 +1987,7 @@ TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { |
GURL icon_url1("http:/www.google.com/favicon.ico"); |
GURL icon_url2("http://www.google.com/favicon2.ico"); |
+ ClearFaviconChangedNotificationCounter(); |
std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; |
GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(), |
&favicon_bitmap_data); |
@@ -1982,7 +2007,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, favicon_changed_notifications()); |
// 1) Merge identical favicon bitmap. |
std::vector<unsigned char> data; |
@@ -2005,7 +2030,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, favicon_changed_notifications()); |
// 2) Merge favicon bitmap of the same size. |
data[0] = 'b'; |
@@ -2079,7 +2104,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, favicon_changed_notifications()); |
} |
// Test calling MergeFavicon() when |icon_url| is known to the database but not |
@@ -2090,6 +2115,7 @@ TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { |
GURL page_url3("http://maps.google.com"); |
GURL icon_url("http:/www.google.com/favicon.ico"); |
+ ClearFaviconChangedNotificationCounter(); |
std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; |
GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(), |
&favicon_bitmap_data); |
@@ -2164,7 +2190,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, favicon_changed_notifications()); |
} |
// Test that MergeFavicon() does not add more than |