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/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 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 EXPECT_EQ(0U, handler.image_urls().size()); | 1014 EXPECT_EQ(0U, handler.image_urls().size()); |
1014 | 1015 |
1015 // Verify correct icon size chosen. | 1016 // Verify correct icon size chosen. |
1016 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); | 1017 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); |
1017 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); | 1018 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); |
1018 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); | 1019 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); |
1019 EXPECT_EQ(gfx::kFaviconSize, | 1020 EXPECT_EQ(gfx::kFaviconSize, |
1020 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); | 1021 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); |
1021 } | 1022 } |
1022 | 1023 |
1024 static ProfileKeyedService* BuildFaviconService( | |
1025 content::BrowserContext* profile) { | |
1026 return new FaviconService(NULL); | |
1027 } | |
1028 | |
1029 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.
| |
1030 const GURL missing_icon_url("http://www.google.com/favicon.ico"); | |
1031 const GURL another_icon_url("http://www.youtube.com/favicon.ico"); | |
1032 | |
1033 Profile* profile = Profile::FromBrowserContext( | |
1034 web_contents()->GetBrowserContext()); | |
1035 | |
1036 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.
| |
1037 profile, BuildFaviconService); | |
1038 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | |
1039 profile, Profile::IMPLICIT_ACCESS); | |
1040 | |
1041 FaviconTabHelper::CreateForWebContents(web_contents()); | |
1042 FaviconTabHelper* favicon_tab_helper = | |
1043 FaviconTabHelper::FromWebContents(web_contents()); | |
1044 | |
1045 std::vector<SkBitmap> empty_icons; | |
1046 | |
1047 int download_id = 0; | |
1048 // Try to download missing icon. | |
1049 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | |
1050 EXPECT_NE(0, download_id); | |
1051 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | |
1052 | |
1053 // Report download failure with HTTP 503 status. | |
1054 favicon_tab_helper->DidDownloadFavicon(download_id, 503, missing_icon_url, | |
1055 0, empty_icons); | |
1056 // Icon is not marked as UnableToDownload as HTTP status is not 404. | |
1057 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | |
1058 | |
1059 // Try to download again. | |
1060 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | |
1061 EXPECT_NE(0, download_id); | |
1062 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | |
1063 | |
1064 // Report download failure with HTTP 404 status. | |
1065 favicon_tab_helper->DidDownloadFavicon(download_id, 404, missing_icon_url, | |
1066 0, empty_icons); | |
1067 // Icon is marked as UnableToDownload. | |
1068 EXPECT_TRUE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | |
1069 | |
1070 // Try to download again. | |
1071 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | |
1072 // Download is not started and Icon is still marked as UnableToDownload | |
1073 EXPECT_EQ(0, download_id); | |
1074 EXPECT_TRUE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | |
1075 | |
1076 // Try to download another icon. | |
1077 download_id = favicon_tab_helper->StartDownload(another_icon_url, 0); | |
1078 EXPECT_NE(0, download_id); | |
1079 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(another_icon_url)); | |
1080 | |
1081 // Clear the list of missing icons. | |
1082 favicon_service->ClearUnableToDownloadFavicons(); | |
1083 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | |
1084 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(another_icon_url)); | |
1085 | |
1086 // Try to download again. | |
1087 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | |
1088 EXPECT_NE(0, download_id); | |
1089 // Report download success with HTTP 200 status. | |
1090 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | |
1091 0, empty_icons); | |
1092 // Icon is not marked as UnableToDownload as HTTP status is not 404. | |
1093 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | |
1094 } | |
1095 | |
1023 } // namespace. | 1096 } // namespace. |
OLD | NEW |