Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: content/browser/web_contents/navigation_controller_impl_unittest.cc

Issue 11198007: Clear the favicon of a tab when navigating to a url on a different host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/web_contents/navigation_controller_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 // NavigationControllerTest ---------------------------------------------------- 110 // NavigationControllerTest ----------------------------------------------------
111 111
112 class NavigationControllerTest : public RenderViewHostImplTestHarness { 112 class NavigationControllerTest : public RenderViewHostImplTestHarness {
113 public: 113 public:
114 NavigationControllerTest() {} 114 NavigationControllerTest() {}
115 115
116 NavigationControllerImpl& controller_impl() { 116 NavigationControllerImpl& controller_impl() {
117 return static_cast<NavigationControllerImpl&>(controller()); 117 return static_cast<NavigationControllerImpl&>(controller());
118 } 118 }
119
120 bool DoImagesMatch(const gfx::Image& a, const gfx::Image& b) {
121 // Assume that if the 1x bitmaps match, the images match.
122 SkBitmap a_bitmap = a.AsBitmap();
123 SkBitmap b_bitmap = b.AsBitmap();
124
125 if (a_bitmap.width() != b_bitmap.width() ||
126 a_bitmap.height() != b_bitmap.height()) {
127 return false;
128 }
129
130 SkAutoLockPixels a_bitmap_lock(a_bitmap);
131 SkAutoLockPixels b_bitmap_lock(b_bitmap);
132
133 return memcmp(a_bitmap.getPixels(),
134 b_bitmap.getPixels(),
135 b_bitmap.getSize()) == 0;
136
137 }
119 }; 138 };
120 139
121 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, 140 void RegisterForAllNavNotifications(TestNotificationTracker* tracker,
122 NavigationController* controller) { 141 NavigationController* controller) {
123 tracker->ListenFor(content::NOTIFICATION_NAV_ENTRY_COMMITTED, 142 tracker->ListenFor(content::NOTIFICATION_NAV_ENTRY_COMMITTED,
124 content::Source<NavigationController>( 143 content::Source<NavigationController>(
125 controller)); 144 controller));
126 tracker->ListenFor(content::NOTIFICATION_NAV_LIST_PRUNED, 145 tracker->ListenFor(content::NOTIFICATION_NAV_LIST_PRUNED,
127 content::Source<NavigationController>( 146 content::Source<NavigationController>(
128 controller)); 147 controller));
(...skipping 2853 matching lines...) Expand 10 before | Expand all | Expand 10 after
2982 3001
2983 const GURL url1("http://foo1"); 3002 const GURL url1("http://foo1");
2984 test_rvh()->SendNavigate(0, url1); 3003 test_rvh()->SendNavigate(0, url1);
2985 EXPECT_TRUE(notifications.Check1AndReset( 3004 EXPECT_TRUE(notifications.Check1AndReset(
2986 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); 3005 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
2987 3006
2988 // After commit, it stays false. 3007 // After commit, it stays false.
2989 EXPECT_FALSE(controller.IsInitialNavigation()); 3008 EXPECT_FALSE(controller.IsInitialNavigation());
2990 } 3009 }
2991 3010
3011 // Check that the favicon is not reused accross a client redirect.
Charlie Reis 2012/10/23 04:53:22 nit: across
3012 // (crbug.com/28515)
3013 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) {
3014 const GURL kPageWithFavicon("http://withfavicon.html");
3015 const GURL kPageWithoutFavicon("http://withoutfavicon.html");
3016 const GURL kIconURL("http://withfavicon.ico");
3017 const gfx::Image kDefaultFavicon = content::FaviconStatus().image;
3018
3019 NavigationControllerImpl& controller = controller_impl();
3020 content::TestNotificationTracker notifications;
3021 RegisterForAllNavNotifications(&notifications, &controller);
3022
3023 test_rvh()->SendNavigate(0, kPageWithFavicon);
3024 EXPECT_TRUE(notifications.Check1AndReset(
3025 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
3026
3027 content::NavigationEntry* entry = controller.GetLastCommittedEntry();
3028 EXPECT_TRUE(entry);
3029 EXPECT_EQ(kPageWithFavicon, entry->GetURL());
3030
3031 // Simulate Chromium having set the favicon for |kPageWithFavicon|.
3032 SkBitmap bitmap;
3033 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
3034 bitmap.allocPixels();
3035
3036 content::FaviconStatus& favicon_status = entry->GetFavicon();
3037 favicon_status.image = gfx::Image(bitmap);
3038 favicon_status.url = kIconURL;
3039 favicon_status.valid = true;
Charlie Reis 2012/10/23 04:53:22 Should probably test that DoImagesMatch is false h
3040
3041 test_rvh()->SendNavigateWithTransition(
3042 0, // same page ID.
3043 kPageWithoutFavicon,
3044 content::PAGE_TRANSITION_CLIENT_REDIRECT);
3045 EXPECT_TRUE(notifications.Check1AndReset(
3046 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
3047
3048 entry = controller.GetLastCommittedEntry();
3049 EXPECT_TRUE(entry);
3050 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL());
3051
3052 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image));
3053 }
3054
3055 // Check that the favicon is not cleared for NavigationEntrys which were
Charlie Reis 2012/10/23 04:53:22 nit: NavigationEntries
3056 // previously navigated to.
3057 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) {
3058 const GURL kUrl1("http://www.a.com/1");
3059 const GURL kUrl2("http://www.a.com/2");
3060 const GURL kIconURL("http://withfavicon.ico");
3061
3062 NavigationControllerImpl& controller = controller_impl();
3063 content::TestNotificationTracker notifications;
3064 RegisterForAllNavNotifications(&notifications, &controller);
3065
3066 test_rvh()->SendNavigate(0, kUrl1);
3067 EXPECT_TRUE(notifications.Check1AndReset(
3068 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
3069
3070 // Simulate Chromium having set the favicon for |kUrl1|.
3071 SkBitmap favicon_bitmap;
3072 favicon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
3073 favicon_bitmap.allocPixels();
3074
3075 content::NavigationEntry* entry = controller.GetLastCommittedEntry();
3076 EXPECT_TRUE(entry);
3077 content::FaviconStatus& favicon_status = entry->GetFavicon();
3078 favicon_status.image = gfx::Image(favicon_bitmap);
3079 favicon_status.url = kIconURL;
3080 favicon_status.valid = true;
3081
3082 // Navigate to another page and go back to the original page.
3083 test_rvh()->SendNavigate(1, kUrl2);
3084 EXPECT_TRUE(notifications.Check1AndReset(
3085 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
3086 test_rvh()->SendNavigateWithTransition(
3087 0,
3088 kUrl1,
3089 content::PAGE_TRANSITION_FORWARD_BACK);
3090 EXPECT_TRUE(notifications.Check1AndReset(
3091 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
3092
3093 // Verify that the favicon for the page at |kUrl1| was not cleared.
3094 gfx::Image favicon_after_back;
3095 entry = controller.GetEntryAtIndex(0);
3096 EXPECT_TRUE(entry);
3097 EXPECT_EQ(kUrl1, entry->GetURL());
3098 EXPECT_TRUE(DoImagesMatch(gfx::Image(favicon_bitmap),
3099 entry->GetFavicon().image));
3100 }
3101
2992 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot 3102 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot
2993 (but not Vista) cleaning up the directory after they run. 3103 (but not Vista) cleaning up the directory after they run.
2994 This should be fixed. 3104 This should be fixed.
2995 3105
2996 // NavigationControllerHistoryTest --------------------------------------------- 3106 // NavigationControllerHistoryTest ---------------------------------------------
2997 3107
2998 class NavigationControllerHistoryTest : public NavigationControllerTest { 3108 class NavigationControllerHistoryTest : public NavigationControllerTest {
2999 public: 3109 public:
3000 NavigationControllerHistoryTest() 3110 NavigationControllerHistoryTest()
3001 : url0("http://foo1"), 3111 : url0("http://foo1"),
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3159 TabNavigation nav(0, url0, GURL(), string16(), 3269 TabNavigation nav(0, url0, GURL(), string16(),
3160 webkit_glue::CreateHistoryStateForURL(url0), 3270 webkit_glue::CreateHistoryStateForURL(url0),
3161 content::PAGE_TRANSITION_LINK); 3271 content::PAGE_TRANSITION_LINK);
3162 session_helper_.AssertNavigationEquals(nav, 3272 session_helper_.AssertNavigationEquals(nav,
3163 windows_[0]->tabs[0]->navigations[0]); 3273 windows_[0]->tabs[0]->navigations[0]);
3164 nav.set_url(url2); 3274 nav.set_url(url2);
3165 session_helper_.AssertNavigationEquals(nav, 3275 session_helper_.AssertNavigationEquals(nav,
3166 windows_[0]->tabs[0]->navigations[1]); 3276 windows_[0]->tabs[0]->navigations[1]);
3167 } 3277 }
3168 */ 3278 */
OLDNEW
« no previous file with comments | « content/browser/web_contents/navigation_controller_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698