| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/favicon/core/large_icon_service.h" | 5 #include "components/favicon/core/large_icon_service.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 LargeIconService large_icon_service_; | 132 LargeIconService large_icon_service_; |
| 133 base::HistogramTester histogram_tester_; | 133 base::HistogramTester histogram_tester_; |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); | 136 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { | 139 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { |
| 140 const GURL kExpectedServerUrl( | 140 const GURL kExpectedServerUrl( |
| 141 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" | 141 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 142 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL" | 142 "&size=32&min_size=42&max_size=64&fallback_opts=TYPE,SIZE,URL" |
| 143 "&url=http://www.example.com/"); | 143 "&url=http://www.example.com/"); |
| 144 | 144 |
| 145 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); | 145 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); |
| 146 | 146 |
| 147 base::MockCallback<base::Callback<void(bool success)>> callback; | 147 base::MockCallback<base::Callback<void(bool success)>> callback; |
| 148 EXPECT_CALL(*mock_image_fetcher_, | 148 EXPECT_CALL(*mock_image_fetcher_, |
| 149 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) | 149 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) |
| 150 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( | 150 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( |
| 151 CreateTestSkBitmap(64, 64, kTestColor)))); | 151 CreateTestSkBitmap(64, 64, kTestColor)))); |
| 152 EXPECT_CALL(mock_favicon_service_, | 152 EXPECT_CALL(mock_favicon_service_, |
| 153 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl, | 153 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl, |
| 154 favicon_base::IconType::TOUCH_ICON, _, _)) | 154 favicon_base::IconType::TOUCH_ICON, _, _)) |
| 155 .WillOnce(PostBoolReply(true)); | 155 .WillOnce(PostBoolReply(true)); |
| 156 | 156 |
| 157 large_icon_service_ | 157 large_icon_service_ |
| 158 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 158 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 159 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | 159 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); |
| 160 | 160 |
| 161 EXPECT_CALL(callback, Run(true)); | 161 EXPECT_CALL(callback, Run(true)); |
| 162 base::RunLoop().RunUntilIdle(); | 162 base::RunLoop().RunUntilIdle(); |
| 163 histogram_tester_.ExpectUniqueSample( | 163 histogram_tester_.ExpectUniqueSample( |
| 164 "Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1); | 164 "Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1); |
| 165 } | 165 } |
| 166 | 166 |
| 167 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) { | 167 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) { |
| 168 const GURL kExpectedServerUrl( | 168 const GURL kExpectedServerUrl( |
| 169 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" | 169 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 170 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL" | 170 "&size=32&min_size=42&max_size=64&fallback_opts=TYPE,SIZE,URL" |
| 171 "&url=http://www.example.com/"); | 171 "&url=http://www.example.com/"); |
| 172 const GURL kExpectedOriginalUrl("http://www.example.com/favicon.png"); | 172 const GURL kExpectedOriginalUrl("http://www.example.com/favicon.png"); |
| 173 | 173 |
| 174 image_fetcher::RequestMetadata expected_metadata; | 174 image_fetcher::RequestMetadata expected_metadata; |
| 175 expected_metadata.content_location_header = kExpectedOriginalUrl.spec(); | 175 expected_metadata.content_location_header = kExpectedOriginalUrl.spec(); |
| 176 EXPECT_CALL(*mock_image_fetcher_, | 176 EXPECT_CALL(*mock_image_fetcher_, |
| 177 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) | 177 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) |
| 178 .WillOnce(PostFetchReplyWithMetadata( | 178 .WillOnce(PostFetchReplyWithMetadata( |
| 179 gfx::Image::CreateFrom1xBitmap( | 179 gfx::Image::CreateFrom1xBitmap( |
| 180 CreateTestSkBitmap(64, 64, kTestColor)), | 180 CreateTestSkBitmap(64, 64, kTestColor)), |
| 181 expected_metadata)); | 181 expected_metadata)); |
| 182 EXPECT_CALL(mock_favicon_service_, | 182 EXPECT_CALL(mock_favicon_service_, |
| 183 SetLastResortFavicons(GURL(kDummyUrl), kExpectedOriginalUrl, | 183 SetLastResortFavicons(GURL(kDummyUrl), kExpectedOriginalUrl, |
| 184 favicon_base::IconType::TOUCH_ICON, _, _)) | 184 favicon_base::IconType::TOUCH_ICON, _, _)) |
| 185 .WillOnce(PostBoolReply(true)); | 185 .WillOnce(PostBoolReply(true)); |
| 186 | 186 |
| 187 base::MockCallback<base::Callback<void(bool success)>> callback; | 187 base::MockCallback<base::Callback<void(bool success)>> callback; |
| 188 large_icon_service_ | 188 large_icon_service_ |
| 189 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 189 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 190 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | 190 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); |
| 191 | 191 |
| 192 EXPECT_CALL(callback, Run(true)); | 192 EXPECT_CALL(callback, Run(true)); |
| 193 base::RunLoop().RunUntilIdle(); | 193 base::RunLoop().RunUntilIdle(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) { | 196 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) { |
| 197 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); | 197 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); |
| 198 const GURL kExpectedServerUrl( | 198 const GURL kExpectedServerUrl( |
| 199 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" | 199 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 200 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL" | 200 "&size=32&min_size=42&max_size=64&fallback_opts=TYPE,SIZE,URL" |
| 201 "&url=http://www.example.com/"); | 201 "&url=http://www.example.com/"); |
| 202 | 202 |
| 203 EXPECT_CALL(*mock_image_fetcher_, | 203 EXPECT_CALL(*mock_image_fetcher_, |
| 204 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) | 204 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) |
| 205 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( | 205 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( |
| 206 CreateTestSkBitmap(64, 64, kTestColor)))); | 206 CreateTestSkBitmap(64, 64, kTestColor)))); |
| 207 // Verify that the non-trimmed page URL is used when writing to the database. | 207 // Verify that the non-trimmed page URL is used when writing to the database. |
| 208 EXPECT_CALL(mock_favicon_service_, | 208 EXPECT_CALL(mock_favicon_service_, |
| 209 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _)); | 209 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _)); |
| 210 | 210 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 232 base::RunLoop().RunUntilIdle(); | 232 base::RunLoop().RunUntilIdle(); |
| 233 EXPECT_THAT(histogram_tester_.GetAllSamples( | 233 EXPECT_THAT(histogram_tester_.GetAllSamples( |
| 234 "Favicons.LargeIconService.DownloadedSize"), | 234 "Favicons.LargeIconService.DownloadedSize"), |
| 235 IsEmpty()); | 235 IsEmpty()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) { | 238 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) { |
| 239 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); | 239 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); |
| 240 const GURL kExpectedServerUrl( | 240 const GURL kExpectedServerUrl( |
| 241 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" | 241 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 242 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL" | 242 "&size=32&min_size=42&max_size=64&fallback_opts=TYPE,SIZE,URL" |
| 243 "&url=http://www.example.com/"); | 243 "&url=http://www.example.com/"); |
| 244 | 244 |
| 245 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) | 245 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) |
| 246 .Times(0); | 246 .Times(0); |
| 247 | 247 |
| 248 base::MockCallback<base::Callback<void(bool success)>> callback; | 248 base::MockCallback<base::Callback<void(bool success)>> callback; |
| 249 EXPECT_CALL(*mock_image_fetcher_, | 249 EXPECT_CALL(*mock_image_fetcher_, |
| 250 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) | 250 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) |
| 251 .WillOnce(PostFetchReply(gfx::Image())); | 251 .WillOnce(PostFetchReply(gfx::Image())); |
| 252 EXPECT_CALL(mock_favicon_service_, | 252 EXPECT_CALL(mock_favicon_service_, |
| 253 UnableToDownloadFavicon(kExpectedServerUrl)); | 253 UnableToDownloadFavicon(kExpectedServerUrl)); |
| 254 | 254 |
| 255 large_icon_service_ | 255 large_icon_service_ |
| 256 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 256 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 257 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42, callback.Get()); | 257 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42, callback.Get()); |
| 258 | 258 |
| 259 EXPECT_CALL(callback, Run(false)); | 259 EXPECT_CALL(callback, Run(false)); |
| 260 base::RunLoop().RunUntilIdle(); | 260 base::RunLoop().RunUntilIdle(); |
| 261 // Verify that download failure gets recorded. | 261 // Verify that download failure gets recorded. |
| 262 histogram_tester_.ExpectUniqueSample( | 262 histogram_tester_.ExpectUniqueSample( |
| 263 "Favicons.LargeIconService.DownloadedSize", 0, /*expected_count=*/1); | 263 "Favicons.LargeIconService.DownloadedSize", 0, /*expected_count=*/1); |
| 264 } | 264 } |
| 265 | 265 |
| 266 TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfUnavailable) { | 266 TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfUnavailable) { |
| 267 ON_CALL( | 267 ON_CALL( |
| 268 mock_favicon_service_, | 268 mock_favicon_service_, |
| 269 WasUnableToDownloadFavicon(GURL( | 269 WasUnableToDownloadFavicon(GURL( |
| 270 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" | 270 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 271 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL" | 271 "&size=32&min_size=42&max_size=64&fallback_opts=TYPE,SIZE,URL" |
| 272 "&url=http://www.example.com/"))) | 272 "&url=http://www.example.com/"))) |
| 273 .WillByDefault(Return(true)); | 273 .WillByDefault(Return(true)); |
| 274 | 274 |
| 275 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); | 275 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); |
| 276 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _)) | 276 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _)) |
| 277 .Times(0); | 277 .Times(0); |
| 278 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) | 278 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) |
| 279 .Times(0); | 279 .Times(0); |
| 280 | 280 |
| 281 base::MockCallback<base::Callback<void(bool success)>> callback; | 281 base::MockCallback<base::Callback<void(bool success)>> callback; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 443 |
| 444 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g. | 444 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g. |
| 445 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image. | 445 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image. |
| 446 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap. | 446 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap. |
| 447 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name. | 447 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name. |
| 448 LargeIconServiceGetterTest, | 448 LargeIconServiceGetterTest, |
| 449 ::testing::Values(false, true)); | 449 ::testing::Values(false, true)); |
| 450 | 450 |
| 451 } // namespace | 451 } // namespace |
| 452 } // namespace favicon | 452 } // namespace favicon |
| OLD | NEW |