| OLD | NEW |
| 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 2896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2907 // After commit, it stays false. | 2907 // After commit, it stays false. |
| 2908 EXPECT_FALSE(controller.IsInitialNavigation()); | 2908 EXPECT_FALSE(controller.IsInitialNavigation()); |
| 2909 } | 2909 } |
| 2910 | 2910 |
| 2911 // Check that the favicon is not reused across a client redirect. | 2911 // Check that the favicon is not reused across a client redirect. |
| 2912 // (crbug.com/28515) | 2912 // (crbug.com/28515) |
| 2913 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { | 2913 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { |
| 2914 const GURL kPageWithFavicon("http://withfavicon.html"); | 2914 const GURL kPageWithFavicon("http://withfavicon.html"); |
| 2915 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); | 2915 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
| 2916 const GURL kIconURL("http://withfavicon.ico"); | 2916 const GURL kIconURL("http://withfavicon.ico"); |
| 2917 const gfx::Image kDefaultFavicon = content::FaviconStatus().image; | 2917 const gfx::Image kDefaultFavicon = FaviconStatus().image; |
| 2918 | 2918 |
| 2919 NavigationControllerImpl& controller = controller_impl(); | 2919 NavigationControllerImpl& controller = controller_impl(); |
| 2920 content::TestNotificationTracker notifications; | 2920 TestNotificationTracker notifications; |
| 2921 RegisterForAllNavNotifications(¬ifications, &controller); | 2921 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2922 | 2922 |
| 2923 test_rvh()->SendNavigate(0, kPageWithFavicon); | 2923 test_rvh()->SendNavigate(0, kPageWithFavicon); |
| 2924 EXPECT_TRUE(notifications.Check1AndReset( | 2924 EXPECT_TRUE(notifications.Check1AndReset( |
| 2925 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 2925 NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 2926 | 2926 |
| 2927 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 2927 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 2928 EXPECT_TRUE(entry); | 2928 EXPECT_TRUE(entry); |
| 2929 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); | 2929 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); |
| 2930 | 2930 |
| 2931 // Simulate Chromium having set the favicon for |kPageWithFavicon|. | 2931 // Simulate Chromium having set the favicon for |kPageWithFavicon|. |
| 2932 SkBitmap bitmap; | 2932 SkBitmap bitmap; |
| 2933 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 2933 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| 2934 bitmap.allocPixels(); | 2934 bitmap.allocPixels(); |
| 2935 | 2935 |
| 2936 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 2936 FaviconStatus& favicon_status = entry->GetFavicon(); |
| 2937 favicon_status.image = gfx::Image(bitmap); | 2937 favicon_status.image = gfx::Image(bitmap); |
| 2938 favicon_status.url = kIconURL; | 2938 favicon_status.url = kIconURL; |
| 2939 favicon_status.valid = true; | 2939 favicon_status.valid = true; |
| 2940 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 2940 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
| 2941 | 2941 |
| 2942 test_rvh()->SendNavigateWithTransition( | 2942 test_rvh()->SendNavigateWithTransition( |
| 2943 0, // same page ID. | 2943 0, // same page ID. |
| 2944 kPageWithoutFavicon, | 2944 kPageWithoutFavicon, |
| 2945 content::PAGE_TRANSITION_CLIENT_REDIRECT); | 2945 PAGE_TRANSITION_CLIENT_REDIRECT); |
| 2946 EXPECT_TRUE(notifications.Check1AndReset( | 2946 EXPECT_TRUE(notifications.Check1AndReset( |
| 2947 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 2947 NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 2948 | 2948 |
| 2949 entry = controller.GetLastCommittedEntry(); | 2949 entry = controller.GetLastCommittedEntry(); |
| 2950 EXPECT_TRUE(entry); | 2950 EXPECT_TRUE(entry); |
| 2951 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); | 2951 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); |
| 2952 | 2952 |
| 2953 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 2953 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
| 2954 } | 2954 } |
| 2955 | 2955 |
| 2956 // Check that the favicon is not cleared for NavigationEntries which were | 2956 // Check that the favicon is not cleared for NavigationEntries which were |
| 2957 // previously navigated to. | 2957 // previously navigated to. |
| 2958 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { | 2958 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { |
| 2959 const GURL kUrl1("http://www.a.com/1"); | 2959 const GURL kUrl1("http://www.a.com/1"); |
| 2960 const GURL kUrl2("http://www.a.com/2"); | 2960 const GURL kUrl2("http://www.a.com/2"); |
| 2961 const GURL kIconURL("http://www.a.com/1/favicon.ico"); | 2961 const GURL kIconURL("http://www.a.com/1/favicon.ico"); |
| 2962 | 2962 |
| 2963 NavigationControllerImpl& controller = controller_impl(); | 2963 NavigationControllerImpl& controller = controller_impl(); |
| 2964 content::TestNotificationTracker notifications; | 2964 TestNotificationTracker notifications; |
| 2965 RegisterForAllNavNotifications(¬ifications, &controller); | 2965 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2966 | 2966 |
| 2967 test_rvh()->SendNavigate(0, kUrl1); | 2967 test_rvh()->SendNavigate(0, kUrl1); |
| 2968 EXPECT_TRUE(notifications.Check1AndReset( | 2968 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 2969 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
| 2970 | 2969 |
| 2971 // Simulate Chromium having set the favicon for |kUrl1|. | 2970 // Simulate Chromium having set the favicon for |kUrl1|. |
| 2972 SkBitmap favicon_bitmap; | 2971 SkBitmap favicon_bitmap; |
| 2973 favicon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 2972 favicon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| 2974 favicon_bitmap.allocPixels(); | 2973 favicon_bitmap.allocPixels(); |
| 2975 | 2974 |
| 2976 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 2975 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 2977 EXPECT_TRUE(entry); | 2976 EXPECT_TRUE(entry); |
| 2978 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 2977 FaviconStatus& favicon_status = entry->GetFavicon(); |
| 2979 favicon_status.image = gfx::Image(favicon_bitmap); | 2978 favicon_status.image = gfx::Image(favicon_bitmap); |
| 2980 favicon_status.url = kIconURL; | 2979 favicon_status.url = kIconURL; |
| 2981 favicon_status.valid = true; | 2980 favicon_status.valid = true; |
| 2982 | 2981 |
| 2983 // Navigate to another page and go back to the original page. | 2982 // Navigate to another page and go back to the original page. |
| 2984 test_rvh()->SendNavigate(1, kUrl2); | 2983 test_rvh()->SendNavigate(1, kUrl2); |
| 2985 EXPECT_TRUE(notifications.Check1AndReset( | 2984 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 2986 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
| 2987 test_rvh()->SendNavigateWithTransition( | 2985 test_rvh()->SendNavigateWithTransition( |
| 2988 0, | 2986 0, |
| 2989 kUrl1, | 2987 kUrl1, |
| 2990 content::PAGE_TRANSITION_FORWARD_BACK); | 2988 PAGE_TRANSITION_FORWARD_BACK); |
| 2991 EXPECT_TRUE(notifications.Check1AndReset( | 2989 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 2992 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
| 2993 | 2990 |
| 2994 // Verify that the favicon for the page at |kUrl1| was not cleared. | 2991 // Verify that the favicon for the page at |kUrl1| was not cleared. |
| 2995 gfx::Image favicon_after_back; | 2992 gfx::Image favicon_after_back; |
| 2996 entry = controller.GetEntryAtIndex(0); | 2993 entry = controller.GetEntryAtIndex(0); |
| 2997 EXPECT_TRUE(entry); | 2994 EXPECT_TRUE(entry); |
| 2998 EXPECT_EQ(kUrl1, entry->GetURL()); | 2995 EXPECT_EQ(kUrl1, entry->GetURL()); |
| 2999 EXPECT_TRUE(DoImagesMatch(gfx::Image(favicon_bitmap), | 2996 EXPECT_TRUE(DoImagesMatch(gfx::Image(favicon_bitmap), |
| 3000 entry->GetFavicon().image)); | 2997 entry->GetFavicon().image)); |
| 3001 } | 2998 } |
| 3002 | 2999 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3172 PAGE_TRANSITION_LINK); | 3169 PAGE_TRANSITION_LINK); |
| 3173 session_helper_.AssertNavigationEquals(nav, | 3170 session_helper_.AssertNavigationEquals(nav, |
| 3174 windows_[0]->tabs[0]->navigations[0]); | 3171 windows_[0]->tabs[0]->navigations[0]); |
| 3175 nav.set_url(url2); | 3172 nav.set_url(url2); |
| 3176 session_helper_.AssertNavigationEquals(nav, | 3173 session_helper_.AssertNavigationEquals(nav, |
| 3177 windows_[0]->tabs[0]->navigations[1]); | 3174 windows_[0]->tabs[0]->navigations[1]); |
| 3178 } | 3175 } |
| 3179 */ | 3176 */ |
| 3180 | 3177 |
| 3181 } // namespace content | 3178 } // namespace content |
| OLD | NEW |