Index: chrome/browser/favicon/favicon_tab_helper_unittest.cc |
diff --git a/chrome/browser/favicon/favicon_tab_helper_unittest.cc b/chrome/browser/favicon/favicon_tab_helper_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0a7fafe3ef32c97851ac20f023d0fde7e21dc4ac |
--- /dev/null |
+++ b/chrome/browser/favicon/favicon_tab_helper_unittest.cc |
@@ -0,0 +1,73 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/favicon/favicon_tab_helper.h" |
sky
2012/10/16 23:00:17
newline between 5/6.
|
+#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
+#include "content/public/browser/favicon_status.h" |
+#include "content/public/browser/navigation_entry.h" |
+#include "content/public/browser/notification_types.h" |
+#include "content/public/test/test_notification_tracker.h" |
+#include "content/public/test/test_renderer_host.h" |
+#include "ui/gfx/image/image_skia.h" |
+ |
+typedef ChromeRenderViewHostTestHarness FaviconTabHelperTest; |
+ |
+// Ensure that the default favicon is used for pages without favicons. |
+// This test checks that this is the case when the page is navigated to via a |
+// client redirect. (crbug.com/28515) |
+TEST_F(FaviconTabHelperTest, ClearFaviconOnRedirect) { |
+ const GURL kPageWithFavicon("http://withfavicon.html"); |
+ const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
+ const GURL kIconURL("http://withfavicon.ico"); |
+ const gfx::ImageSkia default_favicon = |
+ content::FaviconStatus().image.AsImageSkia(); |
+ |
+ content::NavigationController& controller = web_contents()->GetController(); |
+ content::TestNotificationTracker notifications; |
+ notifications.ListenFor( |
+ content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
+ content::Source<content::NavigationController>(&controller)); |
+ |
+ // Navigate to a page with a 'simulated' favicon. |
+ rvh_tester()->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 the favicon being set as a result of |
+ // FaviconTabHelper::FetchFavicon(). |
+ SkBitmap bitmap; |
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
+ bitmap.allocPixels(); |
+ |
+ content::FaviconStatus& favicon_status = |
+ controller.GetLastCommittedEntry()->GetFavicon(); |
+ favicon_status.image = gfx::Image(bitmap); |
+ favicon_status.url = kIconURL; |
+ favicon_status.valid = true; |
+ |
+ FaviconTabHelper::CreateForWebContents(web_contents()); |
+ FaviconTabHelper* favicon_tab_helper = |
+ FaviconTabHelper::FromWebContents(web_contents()); |
+ gfx::ImageSkia favicon = favicon_tab_helper->GetFavicon().AsImageSkia(); |
+ EXPECT_FALSE(favicon.BackedBySameObjectAs(default_favicon)); |
+ |
+ // Redirect to a page without a favicon. |
+ rvh_tester()->SendNavigateWithTransition( |
+ 0, |
+ 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()); |
+ |
+ favicon = favicon_tab_helper->GetFavicon().AsImageSkia(); |
+ EXPECT_TRUE(favicon.BackedBySameObjectAs(default_favicon)); |
+} |