Chromium Code Reviews| Index: content/browser/web_contents/navigation_controller_impl_unittest.cc |
| diff --git a/content/browser/web_contents/navigation_controller_impl_unittest.cc b/content/browser/web_contents/navigation_controller_impl_unittest.cc |
| index 3d399e260e62f95735f2401ffbe95e483c4d8f05..a4614aee5cf27ab31ea060a3589e8ebd1062f7ce 100644 |
| --- a/content/browser/web_contents/navigation_controller_impl_unittest.cc |
| +++ b/content/browser/web_contents/navigation_controller_impl_unittest.cc |
| @@ -116,6 +116,25 @@ class NavigationControllerTest : public RenderViewHostImplTestHarness { |
| NavigationControllerImpl& controller_impl() { |
| return static_cast<NavigationControllerImpl&>(controller()); |
| } |
| + |
| + bool DoImagesMatch(const gfx::Image& a, const gfx::Image& b) { |
| + // Assume that if the 1x bitmaps match, the images match. |
| + SkBitmap a_bitmap = a.AsBitmap(); |
| + SkBitmap b_bitmap = b.AsBitmap(); |
| + |
| + if (a_bitmap.width() != b_bitmap.width() || |
| + a_bitmap.height() != b_bitmap.height()) { |
| + return false; |
| + } |
| + |
| + SkAutoLockPixels a_bitmap_lock(a_bitmap); |
| + SkAutoLockPixels b_bitmap_lock(b_bitmap); |
| + |
| + return memcmp(a_bitmap.getPixels(), |
| + b_bitmap.getPixels(), |
| + b_bitmap.getSize()) == 0; |
| + |
| + } |
| }; |
| void RegisterForAllNavNotifications(TestNotificationTracker* tracker, |
| @@ -2989,6 +3008,97 @@ TEST_F(NavigationControllerTest, IsInitialNavigation) { |
| EXPECT_FALSE(controller.IsInitialNavigation()); |
| } |
| +// Check that the favicon is not reused accross a client redirect. |
|
Charlie Reis
2012/10/23 04:53:22
nit: across
|
| +// (crbug.com/28515) |
| +TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { |
| + const GURL kPageWithFavicon("http://withfavicon.html"); |
| + const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
| + const GURL kIconURL("http://withfavicon.ico"); |
| + const gfx::Image kDefaultFavicon = content::FaviconStatus().image; |
| + |
| + NavigationControllerImpl& controller = controller_impl(); |
| + content::TestNotificationTracker notifications; |
| + RegisterForAllNavNotifications(¬ifications, &controller); |
| + |
| + test_rvh()->SendNavigate(0, kPageWithFavicon); |
| + EXPECT_TRUE(notifications.Check1AndReset( |
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| + |
| + content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| + EXPECT_TRUE(entry); |
| + EXPECT_EQ(kPageWithFavicon, entry->GetURL()); |
| + |
| + // Simulate Chromium having set the favicon for |kPageWithFavicon|. |
| + SkBitmap bitmap; |
| + bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| + bitmap.allocPixels(); |
| + |
| + content::FaviconStatus& favicon_status = entry->GetFavicon(); |
| + favicon_status.image = gfx::Image(bitmap); |
| + favicon_status.url = kIconURL; |
| + favicon_status.valid = true; |
|
Charlie Reis
2012/10/23 04:53:22
Should probably test that DoImagesMatch is false h
|
| + |
| + test_rvh()->SendNavigateWithTransition( |
| + 0, // same page ID. |
| + kPageWithoutFavicon, |
| + content::PAGE_TRANSITION_CLIENT_REDIRECT); |
| + EXPECT_TRUE(notifications.Check1AndReset( |
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| + |
| + entry = controller.GetLastCommittedEntry(); |
| + EXPECT_TRUE(entry); |
| + EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); |
| + |
| + EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
| +} |
| + |
| +// Check that the favicon is not cleared for NavigationEntrys which were |
|
Charlie Reis
2012/10/23 04:53:22
nit: NavigationEntries
|
| +// previously navigated to. |
| +TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { |
| + const GURL kUrl1("http://www.a.com/1"); |
| + const GURL kUrl2("http://www.a.com/2"); |
| + const GURL kIconURL("http://withfavicon.ico"); |
| + |
| + NavigationControllerImpl& controller = controller_impl(); |
| + content::TestNotificationTracker notifications; |
| + RegisterForAllNavNotifications(¬ifications, &controller); |
| + |
| + test_rvh()->SendNavigate(0, kUrl1); |
| + EXPECT_TRUE(notifications.Check1AndReset( |
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| + |
| + // Simulate Chromium having set the favicon for |kUrl1|. |
| + SkBitmap favicon_bitmap; |
| + favicon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| + favicon_bitmap.allocPixels(); |
| + |
| + content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| + EXPECT_TRUE(entry); |
| + content::FaviconStatus& favicon_status = entry->GetFavicon(); |
| + favicon_status.image = gfx::Image(favicon_bitmap); |
| + favicon_status.url = kIconURL; |
| + favicon_status.valid = true; |
| + |
| + // Navigate to another page and go back to the original page. |
| + test_rvh()->SendNavigate(1, kUrl2); |
| + EXPECT_TRUE(notifications.Check1AndReset( |
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| + test_rvh()->SendNavigateWithTransition( |
| + 0, |
| + kUrl1, |
| + content::PAGE_TRANSITION_FORWARD_BACK); |
| + EXPECT_TRUE(notifications.Check1AndReset( |
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| + |
| + // Verify that the favicon for the page at |kUrl1| was not cleared. |
| + gfx::Image favicon_after_back; |
| + entry = controller.GetEntryAtIndex(0); |
| + EXPECT_TRUE(entry); |
| + EXPECT_EQ(kUrl1, entry->GetURL()); |
| + EXPECT_TRUE(DoImagesMatch(gfx::Image(favicon_bitmap), |
| + entry->GetFavicon().image)); |
| +} |
| + |
| /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot |
| (but not Vista) cleaning up the directory after they run. |
| This should be fixed. |