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

Side by Side Diff: chrome/browser/favicon/favicon_handler_unittest.cc

Issue 14322023: Don't request missing favicon on every page request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync up to r199996 Created 7 years, 7 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 | « android_webview/browser/icon_helper.cc ('k') | chrome/browser/favicon/favicon_service.h » ('j') | 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/favicon/favicon_handler.h" 6 #include "chrome/browser/favicon/favicon_handler.h"
7 #include "chrome/browser/favicon/favicon_service_factory.h"
7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
9 #include "content/public/browser/favicon_status.h" 10 #include "content/public/browser/favicon_status.h"
10 #include "content/public/browser/invalidate_type.h" 11 #include "content/public/browser/invalidate_type.h"
11 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/codec/png_codec.h" 15 #include "ui/gfx/codec/png_codec.h"
15 #include "ui/gfx/favicon_size.h" 16 #include "ui/gfx/favicon_size.h"
16 #include "ui/gfx/image/image.h" 17 #include "ui/gfx/image/image.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). 346 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon().
346 // Force the values of the scale factors so that the tests produce the same 347 // Force the values of the scale factors so that the tests produce the same
347 // results on all platforms. 348 // results on all platforms.
348 std::vector<ui::ScaleFactor> scale_factors; 349 std::vector<ui::ScaleFactor> scale_factors;
349 scale_factors.push_back(ui::SCALE_FACTOR_100P); 350 scale_factors.push_back(ui::SCALE_FACTOR_100P);
350 ui::test::SetSupportedScaleFactors(scale_factors); 351 ui::test::SetSupportedScaleFactors(scale_factors);
351 352
352 ChromeRenderViewHostTestHarness::SetUp(); 353 ChromeRenderViewHostTestHarness::SetUp();
353 } 354 }
354 355
356 virtual void TearDown() OVERRIDE {
357 Profile* profile = Profile::FromBrowserContext(
358 web_contents()->GetBrowserContext());
359 FaviconServiceFactory::GetInstance()->SetTestingFactory(
360 profile, NULL);
361 ChromeRenderViewHostTestHarness::TearDown();
362 }
363
355 private: 364 private:
356 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); 365 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest);
357 }; 366 };
358 367
359 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { 368 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) {
360 const GURL page_url("http://www.google.com"); 369 const GURL page_url("http://www.google.com");
361 const GURL icon_url("http://www.google.com/favicon"); 370 const GURL icon_url("http://www.google.com/favicon");
362 371
363 TestFaviconHandlerDelegate delegate(web_contents()); 372 TestFaviconHandlerDelegate delegate(web_contents());
364 Profile* profile = Profile::FromBrowserContext( 373 Profile* profile = Profile::FromBrowserContext(
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 EXPECT_EQ(0U, handler.image_urls().size()); 1022 EXPECT_EQ(0U, handler.image_urls().size());
1014 1023
1015 // Verify correct icon size chosen. 1024 // Verify correct icon size chosen.
1016 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); 1025 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url);
1017 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); 1026 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid);
1018 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); 1027 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty());
1019 EXPECT_EQ(gfx::kFaviconSize, 1028 EXPECT_EQ(gfx::kFaviconSize,
1020 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); 1029 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width());
1021 } 1030 }
1022 1031
1032 static ProfileKeyedService* BuildFaviconService(
1033 content::BrowserContext* profile) {
1034 return new FaviconService(NULL);
1035 }
1036
1037 // Test that Favicon is not requested repeatedly during the same session if
1038 // server returns HTTP 404 status.
1039 TEST_F(FaviconHandlerTest, UnableToDownloadFavicon) {
1040 const GURL missing_icon_url("http://www.google.com/favicon.ico");
1041 const GURL another_icon_url("http://www.youtube.com/favicon.ico");
1042
1043 Profile* profile = Profile::FromBrowserContext(
1044 web_contents()->GetBrowserContext());
1045
1046 FaviconServiceFactory::GetInstance()->SetTestingFactory(
1047 profile, BuildFaviconService);
1048 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
1049 profile, Profile::IMPLICIT_ACCESS);
1050
1051 FaviconTabHelper::CreateForWebContents(web_contents());
1052 FaviconTabHelper* favicon_tab_helper =
1053 FaviconTabHelper::FromWebContents(web_contents());
1054
1055 std::vector<SkBitmap> empty_icons;
1056 int download_id = 0;
1057
1058 // Try to download missing icon.
1059 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
1060 EXPECT_NE(0, download_id);
1061 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
1062
1063 // Report download failure with HTTP 503 status.
1064 favicon_tab_helper->DidDownloadFavicon(download_id, 503, missing_icon_url,
1065 0, empty_icons);
1066 // Icon is not marked as UnableToDownload as HTTP status is not 404.
1067 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
1068
1069 // Try to download again.
1070 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
1071 EXPECT_NE(0, download_id);
1072 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
1073
1074 // Report download failure with HTTP 404 status.
1075 favicon_tab_helper->DidDownloadFavicon(download_id, 404, missing_icon_url,
1076 0, empty_icons);
1077 // Icon is marked as UnableToDownload.
1078 EXPECT_TRUE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
1079
1080 // Try to download again.
1081 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
1082 // Download is not started and Icon is still marked as UnableToDownload.
1083 EXPECT_EQ(0, download_id);
1084 EXPECT_TRUE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
1085
1086 // Try to download another icon.
1087 download_id = favicon_tab_helper->StartDownload(another_icon_url, 0);
1088 // Download is started as another icon URL is not same as missing_icon_url.
1089 EXPECT_NE(0, download_id);
1090 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(another_icon_url));
1091
1092 // Clear the list of missing icons.
1093 favicon_service->ClearUnableToDownloadFavicons();
1094 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
1095 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(another_icon_url));
1096
1097 // Try to download again.
1098 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
1099 EXPECT_NE(0, download_id);
1100 // Report download success with HTTP 200 status.
1101 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url,
1102 0, empty_icons);
1103 // Icon is not marked as UnableToDownload as HTTP status is not 404.
1104 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
1105 }
1106
1023 } // namespace. 1107 } // namespace.
OLDNEW
« no previous file with comments | « android_webview/browser/icon_helper.cc ('k') | chrome/browser/favicon/favicon_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698