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

Unified 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: Added TEST_F(FaviconHandlerTest, UnableToDownloadFavicon) 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/favicon/favicon_handler_unittest.cc
diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc
index 251aee561a371c086c76483c5e17c229a48fb0fb..c1dc5f3aa4d7b3dd6527c5357a857aaa7bfbf3f4 100644
--- a/chrome/browser/favicon/favicon_handler_unittest.cc
+++ b/chrome/browser/favicon/favicon_handler_unittest.cc
@@ -4,6 +4,7 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/favicon/favicon_handler.h"
+#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/favicon_status.h"
@@ -1020,4 +1021,76 @@ TEST_F(FaviconHandlerTest, FirstFavicon) {
handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width());
}
+static ProfileKeyedService* BuildFaviconService(
+ content::BrowserContext* profile) {
+ return new FaviconService(NULL);
+}
+
+TEST_F(FaviconHandlerTest, UnableToDownloadFavicon) {
sky 2013/05/09 14:49:47 Add a description of what this is meant to test.
mef 2013/05/09 16:24:24 Done.
+ const GURL missing_icon_url("http://www.google.com/favicon.ico");
+ const GURL another_icon_url("http://www.youtube.com/favicon.ico");
+
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents()->GetBrowserContext());
+
+ FaviconServiceFactory::GetInstance()->SetTestingFactory(
sky 2013/05/09 14:49:47 Does this need to be unset after your test (or Tea
mef 2013/05/09 16:24:24 Done.
+ profile, BuildFaviconService);
+ FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
+ profile, Profile::IMPLICIT_ACCESS);
+
+ FaviconTabHelper::CreateForWebContents(web_contents());
+ FaviconTabHelper* favicon_tab_helper =
+ FaviconTabHelper::FromWebContents(web_contents());
+
+ std::vector<SkBitmap> empty_icons;
+
+ int download_id = 0;
+ // Try to download missing icon.
+ download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
+ EXPECT_NE(0, download_id);
+ EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
+
+ // Report download failure with HTTP 503 status.
+ favicon_tab_helper->DidDownloadFavicon(download_id, 503, missing_icon_url,
+ 0, empty_icons);
+ // Icon is not marked as UnableToDownload as HTTP status is not 404.
+ EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
+
+ // Try to download again.
+ download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
+ EXPECT_NE(0, download_id);
+ EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
+
+ // Report download failure with HTTP 404 status.
+ favicon_tab_helper->DidDownloadFavicon(download_id, 404, missing_icon_url,
+ 0, empty_icons);
+ // Icon is marked as UnableToDownload.
+ EXPECT_TRUE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
+
+ // Try to download again.
+ download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
+ // Download is not started and Icon is still marked as UnableToDownload
+ EXPECT_EQ(0, download_id);
+ EXPECT_TRUE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
+
+ // Try to download another icon.
+ download_id = favicon_tab_helper->StartDownload(another_icon_url, 0);
+ EXPECT_NE(0, download_id);
+ EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(another_icon_url));
+
+ // Clear the list of missing icons.
+ favicon_service->ClearUnableToDownloadFavicons();
+ EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
+ EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(another_icon_url));
+
+ // Try to download again.
+ download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
+ EXPECT_NE(0, download_id);
+ // Report download success with HTTP 200 status.
+ favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url,
+ 0, empty_icons);
+ // Icon is not marked as UnableToDownload as HTTP status is not 404.
+ EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
+}
+
} // namespace.
« no previous file with comments | « no previous file | chrome/browser/favicon/favicon_service.h » ('j') | chrome/browser/favicon/favicon_tab_helper.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698