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

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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 // NavigationControllerTest ---------------------------------------------------- 102 // NavigationControllerTest ----------------------------------------------------
103 103
104 class NavigationControllerTest : public RenderViewHostImplTestHarness { 104 class NavigationControllerTest : public RenderViewHostImplTestHarness {
105 public: 105 public:
106 NavigationControllerTest() {} 106 NavigationControllerTest() {}
107 107
108 NavigationControllerImpl& controller_impl() { 108 NavigationControllerImpl& controller_impl() {
109 return static_cast<NavigationControllerImpl&>(controller()); 109 return static_cast<NavigationControllerImpl&>(controller());
110 } 110 }
111
112 bool DoImagesMatch(const gfx::Image& a, const gfx::Image& b) {
113 // Assume that if the 1x bitmaps match, the images match.
114 SkBitmap a_bitmap = a.AsBitmap();
115 SkBitmap b_bitmap = b.AsBitmap();
116
117 if (a_bitmap.width() != b_bitmap.width() ||
118 a_bitmap.height() != b_bitmap.height()) {
119 return false;
120 }
121
122 SkAutoLockPixels a_bitmap_lock(a_bitmap);
123 SkAutoLockPixels b_bitmap_lock(b_bitmap);
124
125 return memcmp(a_bitmap.getPixels(),
126 b_bitmap.getPixels(),
127 b_bitmap.getSize()) == 0;
128
129 }
111 }; 130 };
112 131
113 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, 132 void RegisterForAllNavNotifications(TestNotificationTracker* tracker,
114 NavigationController* controller) { 133 NavigationController* controller) {
115 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_COMMITTED, 134 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_COMMITTED,
116 Source<NavigationController>(controller)); 135 Source<NavigationController>(controller));
117 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, 136 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED,
118 Source<NavigationController>(controller)); 137 Source<NavigationController>(controller));
119 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, 138 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED,
120 Source<NavigationController>(controller)); 139 Source<NavigationController>(controller));
(...skipping 2761 matching lines...) Expand 10 before | Expand all | Expand 10 after
2882 EXPECT_FALSE(controller.IsInitialNavigation()); 2901 EXPECT_FALSE(controller.IsInitialNavigation());
2883 2902
2884 const GURL url1("http://foo1"); 2903 const GURL url1("http://foo1");
2885 test_rvh()->SendNavigate(0, url1); 2904 test_rvh()->SendNavigate(0, url1);
2886 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); 2905 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED));
2887 2906
2888 // After commit, it stays false. 2907 // After commit, it stays false.
2889 EXPECT_FALSE(controller.IsInitialNavigation()); 2908 EXPECT_FALSE(controller.IsInitialNavigation());
2890 } 2909 }
2891 2910
2911 // Check that the favicon is not reused across a client redirect.
2912 // (crbug.com/28515)
2913 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) {
2914 const GURL kPageWithFavicon("http://withfavicon.html");
2915 const GURL kPageWithoutFavicon("http://withoutfavicon.html");
2916 const GURL kIconURL("http://withfavicon.ico");
2917 const gfx::Image kDefaultFavicon = content::FaviconStatus().image;
2918
2919 NavigationControllerImpl& controller = controller_impl();
2920 content::TestNotificationTracker notifications;
2921 RegisterForAllNavNotifications(&notifications, &controller);
2922
2923 test_rvh()->SendNavigate(0, kPageWithFavicon);
2924 EXPECT_TRUE(notifications.Check1AndReset(
2925 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
2926
2927 content::NavigationEntry* entry = controller.GetLastCommittedEntry();
2928 EXPECT_TRUE(entry);
2929 EXPECT_EQ(kPageWithFavicon, entry->GetURL());
2930
2931 // Simulate Chromium having set the favicon for |kPageWithFavicon|.
2932 SkBitmap bitmap;
2933 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
2934 bitmap.allocPixels();
2935
2936 content::FaviconStatus& favicon_status = entry->GetFavicon();
2937 favicon_status.image = gfx::Image(bitmap);
2938 favicon_status.url = kIconURL;
2939 favicon_status.valid = true;
2940 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image));
2941
2942 test_rvh()->SendNavigateWithTransition(
2943 0, // same page ID.
2944 kPageWithoutFavicon,
2945 content::PAGE_TRANSITION_CLIENT_REDIRECT);
2946 EXPECT_TRUE(notifications.Check1AndReset(
2947 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
2948
2949 entry = controller.GetLastCommittedEntry();
2950 EXPECT_TRUE(entry);
2951 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL());
2952
2953 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image));
2954 }
2955
2956 // Check that the favicon is not cleared for NavigationEntries which were
2957 // previously navigated to.
2958 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) {
2959 const GURL kUrl1("http://www.a.com/1");
2960 const GURL kUrl2("http://www.a.com/2");
2961 const GURL kIconURL("http://www.a.com/1/favicon.ico");
2962
2963 NavigationControllerImpl& controller = controller_impl();
2964 content::TestNotificationTracker notifications;
2965 RegisterForAllNavNotifications(&notifications, &controller);
2966
2967 test_rvh()->SendNavigate(0, kUrl1);
2968 EXPECT_TRUE(notifications.Check1AndReset(
2969 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
2970
2971 // Simulate Chromium having set the favicon for |kUrl1|.
2972 SkBitmap favicon_bitmap;
2973 favicon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
2974 favicon_bitmap.allocPixels();
2975
2976 content::NavigationEntry* entry = controller.GetLastCommittedEntry();
2977 EXPECT_TRUE(entry);
2978 content::FaviconStatus& favicon_status = entry->GetFavicon();
2979 favicon_status.image = gfx::Image(favicon_bitmap);
2980 favicon_status.url = kIconURL;
2981 favicon_status.valid = true;
2982
2983 // Navigate to another page and go back to the original page.
2984 test_rvh()->SendNavigate(1, kUrl2);
2985 EXPECT_TRUE(notifications.Check1AndReset(
2986 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
2987 test_rvh()->SendNavigateWithTransition(
2988 0,
2989 kUrl1,
2990 content::PAGE_TRANSITION_FORWARD_BACK);
2991 EXPECT_TRUE(notifications.Check1AndReset(
2992 content::NOTIFICATION_NAV_ENTRY_COMMITTED));
2993
2994 // Verify that the favicon for the page at |kUrl1| was not cleared.
2995 gfx::Image favicon_after_back;
2996 entry = controller.GetEntryAtIndex(0);
2997 EXPECT_TRUE(entry);
2998 EXPECT_EQ(kUrl1, entry->GetURL());
2999 EXPECT_TRUE(DoImagesMatch(gfx::Image(favicon_bitmap),
3000 entry->GetFavicon().image));
3001 }
3002
2892 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot 3003 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot
2893 (but not Vista) cleaning up the directory after they run. 3004 (but not Vista) cleaning up the directory after they run.
2894 This should be fixed. 3005 This should be fixed.
2895 3006
2896 // NavigationControllerHistoryTest --------------------------------------------- 3007 // NavigationControllerHistoryTest ---------------------------------------------
2897 3008
2898 class NavigationControllerHistoryTest : public NavigationControllerTest { 3009 class NavigationControllerHistoryTest : public NavigationControllerTest {
2899 public: 3010 public:
2900 NavigationControllerHistoryTest() 3011 NavigationControllerHistoryTest()
2901 : url0("http://foo1"), 3012 : url0("http://foo1"),
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
3061 PAGE_TRANSITION_LINK); 3172 PAGE_TRANSITION_LINK);
3062 session_helper_.AssertNavigationEquals(nav, 3173 session_helper_.AssertNavigationEquals(nav,
3063 windows_[0]->tabs[0]->navigations[0]); 3174 windows_[0]->tabs[0]->navigations[0]);
3064 nav.set_url(url2); 3175 nav.set_url(url2);
3065 session_helper_.AssertNavigationEquals(nav, 3176 session_helper_.AssertNavigationEquals(nav,
3066 windows_[0]->tabs[0]->navigations[1]); 3177 windows_[0]->tabs[0]->navigations[1]);
3067 } 3178 }
3068 */ 3179 */
3069 3180
3070 } // namespace content 3181 } // namespace content
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