OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
sky
2012/10/16 23:00:17
newline between 5/6.
| |
6 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
7 #include "content/public/browser/favicon_status.h" | |
8 #include "content/public/browser/navigation_entry.h" | |
9 #include "content/public/browser/notification_types.h" | |
10 #include "content/public/test/test_notification_tracker.h" | |
11 #include "content/public/test/test_renderer_host.h" | |
12 #include "ui/gfx/image/image_skia.h" | |
13 | |
14 typedef ChromeRenderViewHostTestHarness FaviconTabHelperTest; | |
15 | |
16 // Ensure that the default favicon is used for pages without favicons. | |
17 // This test checks that this is the case when the page is navigated to via a | |
18 // client redirect. (crbug.com/28515) | |
19 TEST_F(FaviconTabHelperTest, ClearFaviconOnRedirect) { | |
20 const GURL kPageWithFavicon("http://withfavicon.html"); | |
21 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); | |
22 const GURL kIconURL("http://withfavicon.ico"); | |
23 const gfx::ImageSkia default_favicon = | |
24 content::FaviconStatus().image.AsImageSkia(); | |
25 | |
26 content::NavigationController& controller = web_contents()->GetController(); | |
27 content::TestNotificationTracker notifications; | |
28 notifications.ListenFor( | |
29 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
30 content::Source<content::NavigationController>(&controller)); | |
31 | |
32 // Navigate to a page with a 'simulated' favicon. | |
33 rvh_tester()->SendNavigate(0, kPageWithFavicon); | |
34 EXPECT_TRUE(notifications.Check1AndReset( | |
35 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
36 | |
37 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | |
38 EXPECT_TRUE(entry); | |
39 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); | |
40 | |
41 // Simulate the favicon being set as a result of | |
42 // FaviconTabHelper::FetchFavicon(). | |
43 SkBitmap bitmap; | |
44 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | |
45 bitmap.allocPixels(); | |
46 | |
47 content::FaviconStatus& favicon_status = | |
48 controller.GetLastCommittedEntry()->GetFavicon(); | |
49 favicon_status.image = gfx::Image(bitmap); | |
50 favicon_status.url = kIconURL; | |
51 favicon_status.valid = true; | |
52 | |
53 FaviconTabHelper::CreateForWebContents(web_contents()); | |
54 FaviconTabHelper* favicon_tab_helper = | |
55 FaviconTabHelper::FromWebContents(web_contents()); | |
56 gfx::ImageSkia favicon = favicon_tab_helper->GetFavicon().AsImageSkia(); | |
57 EXPECT_FALSE(favicon.BackedBySameObjectAs(default_favicon)); | |
58 | |
59 // Redirect to a page without a favicon. | |
60 rvh_tester()->SendNavigateWithTransition( | |
61 0, | |
62 kPageWithoutFavicon, | |
63 content::PAGE_TRANSITION_CLIENT_REDIRECT); | |
64 EXPECT_TRUE(notifications.Check1AndReset( | |
65 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
66 | |
67 entry = controller.GetLastCommittedEntry(); | |
68 EXPECT_TRUE(entry); | |
69 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); | |
70 | |
71 favicon = favicon_tab_helper->GetFavicon().AsImageSkia(); | |
72 EXPECT_TRUE(favicon.BackedBySameObjectAs(default_favicon)); | |
73 } | |
OLD | NEW |