| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 large_icon_service_.GetLargeIconOrFallbackStyle( | 262 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 263 GURL(kDummyUrl), 32, 24, | 263 GURL(kDummyUrl), 32, 24, |
| 264 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 264 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 265 &cancelable_task_tracker_); | 265 &cancelable_task_tracker_); |
| 266 base::RunLoop().RunUntilIdle(); | 266 base::RunLoop().RunUntilIdle(); |
| 267 EXPECT_TRUE(is_callback_invoked_); | 267 EXPECT_TRUE(is_callback_invoked_); |
| 268 } | 268 } |
| 269 | 269 |
| 270 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { | 270 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { |
| 271 const GURL kExpectedServerUrl( | 271 const GURL kExpectedServerUrl( |
| 272 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" | 272 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 273 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE" | 273 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE" |
| 274 "&url=http://www.example.com/"); | 274 "&url=http://www.example.com/"); |
| 275 | 275 |
| 276 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); | 276 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); |
| 277 | 277 |
| 278 base::MockCallback<base::Callback<void(bool success)>> callback; | 278 base::MockCallback<base::Callback<void(bool success)>> callback; |
| 279 EXPECT_CALL(*mock_image_fetcher_, | 279 EXPECT_CALL(*mock_image_fetcher_, |
| 280 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) | 280 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) |
| 281 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( | 281 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( |
| 282 CreateTestSkBitmap(64, 64, kTestColor)))); | 282 CreateTestSkBitmap(64, 64, kTestColor)))); |
| 283 EXPECT_CALL(mock_favicon_service_, | 283 EXPECT_CALL(mock_favicon_service_, |
| 284 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl, | 284 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl, |
| 285 favicon_base::IconType::TOUCH_ICON, _, _)) | 285 favicon_base::IconType::TOUCH_ICON, _, _)) |
| 286 .WillOnce(PostBoolReply(true)); | 286 .WillOnce(PostBoolReply(true)); |
| 287 | 287 |
| 288 large_icon_service_ | 288 large_icon_service_ |
| 289 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 289 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 290 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | 290 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); |
| 291 | 291 |
| 292 EXPECT_CALL(callback, Run(true)); | 292 EXPECT_CALL(callback, Run(true)); |
| 293 base::RunLoop().RunUntilIdle(); | 293 base::RunLoop().RunUntilIdle(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) { | 296 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) { |
| 297 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); | 297 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); |
| 298 const GURL kExpectedServerUrl( | 298 const GURL kExpectedServerUrl( |
| 299 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" | 299 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 300 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE" | 300 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE" |
| 301 "&url=http://www.example.com/"); | 301 "&url=http://www.example.com/"); |
| 302 | 302 |
| 303 EXPECT_CALL(*mock_image_fetcher_, | 303 EXPECT_CALL(*mock_image_fetcher_, |
| 304 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) | 304 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) |
| 305 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( | 305 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( |
| 306 CreateTestSkBitmap(64, 64, kTestColor)))); | 306 CreateTestSkBitmap(64, 64, kTestColor)))); |
| 307 // Verify that the non-trimmed page URL is used when writing to the database. | 307 // Verify that the non-trimmed page URL is used when writing to the database. |
| 308 EXPECT_CALL(mock_favicon_service_, | 308 EXPECT_CALL(mock_favicon_service_, |
| 309 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _)); | 309 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _)); |
| 310 | 310 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 328 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 328 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 329 GURL(kDummyFtpUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | 329 GURL(kDummyFtpUrl), /*min_source_size_in_pixel=*/42, callback.Get()); |
| 330 | 330 |
| 331 EXPECT_CALL(callback, Run(false)); | 331 EXPECT_CALL(callback, Run(false)); |
| 332 base::RunLoop().RunUntilIdle(); | 332 base::RunLoop().RunUntilIdle(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) { | 335 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) { |
| 336 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); | 336 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); |
| 337 const GURL kExpectedServerUrl( | 337 const GURL kExpectedServerUrl( |
| 338 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" | 338 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 339 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE" | 339 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE" |
| 340 "&url=http://www.example.com/"); | 340 "&url=http://www.example.com/"); |
| 341 | 341 |
| 342 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) | 342 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) |
| 343 .Times(0); | 343 .Times(0); |
| 344 | 344 |
| 345 base::MockCallback<base::Callback<void(bool success)>> callback; | 345 base::MockCallback<base::Callback<void(bool success)>> callback; |
| 346 EXPECT_CALL(*mock_image_fetcher_, | 346 EXPECT_CALL(*mock_image_fetcher_, |
| 347 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) | 347 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) |
| 348 .WillOnce(PostFetchReply(gfx::Image())); | 348 .WillOnce(PostFetchReply(gfx::Image())); |
| 349 EXPECT_CALL(mock_favicon_service_, | 349 EXPECT_CALL(mock_favicon_service_, |
| 350 UnableToDownloadFavicon(kExpectedServerUrl)); | 350 UnableToDownloadFavicon(kExpectedServerUrl)); |
| 351 | 351 |
| 352 large_icon_service_ | 352 large_icon_service_ |
| 353 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 353 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 354 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42, callback.Get()); | 354 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42, callback.Get()); |
| 355 | 355 |
| 356 EXPECT_CALL(callback, Run(false)); | 356 EXPECT_CALL(callback, Run(false)); |
| 357 base::RunLoop().RunUntilIdle(); | 357 base::RunLoop().RunUntilIdle(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST_F(LargeIconServiceTest, ShoutNotGetFromGoogleServerIfUnavailable) { | 360 TEST_F(LargeIconServiceTest, ShoutNotGetFromGoogleServerIfUnavailable) { |
| 361 ON_CALL(mock_favicon_service_, | 361 ON_CALL( |
| 362 WasUnableToDownloadFavicon(GURL( | 362 mock_favicon_service_, |
| 363 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" | 363 WasUnableToDownloadFavicon(GURL( |
| 364 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE" | 364 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" |
| 365 "&url=http://www.example.com/"))) | 365 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE" |
| 366 "&url=http://www.example.com/"))) |
| 366 .WillByDefault(Return(true)); | 367 .WillByDefault(Return(true)); |
| 367 | 368 |
| 368 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); | 369 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); |
| 369 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _)) | 370 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _)) |
| 370 .Times(0); | 371 .Times(0); |
| 371 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) | 372 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) |
| 372 .Times(0); | 373 .Times(0); |
| 373 | 374 |
| 374 base::MockCallback<base::Callback<void(bool success)>> callback; | 375 base::MockCallback<base::Callback<void(bool success)>> callback; |
| 375 large_icon_service_ | 376 large_icon_service_ |
| 376 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 377 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 377 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | 378 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); |
| 378 | 379 |
| 379 EXPECT_CALL(callback, Run(false)); | 380 EXPECT_CALL(callback, Run(false)); |
| 380 base::RunLoop().RunUntilIdle(); | 381 base::RunLoop().RunUntilIdle(); |
| 381 } | 382 } |
| 382 | 383 |
| 383 } // namespace | 384 } // namespace |
| 384 } // namespace favicon | 385 } // namespace favicon |
| OLD | NEW |