Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_tiles/icon_cacher_impl.h" | 5 #include "components/ntp_tiles/icon_cacher_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 default_loop.Run(); // Wait for the default image. | 369 default_loop.Run(); // Wait for the default image. |
| 370 EXPECT_THAT(GetCachedIconFor(site_.url, favicon_base::TOUCH_ICON).Size(), | 370 EXPECT_THAT(GetCachedIconFor(site_.url, favicon_base::TOUCH_ICON).Size(), |
| 371 Eq(gfx::Size(64, 64))); // Compares dimensions, not objects. | 371 Eq(gfx::Size(64, 64))); // Compares dimensions, not objects. |
| 372 | 372 |
| 373 // Let the fetcher continue and wait for the second call of the callback. | 373 // Let the fetcher continue and wait for the second call of the callback. |
| 374 fetch_loop.Run(); // Wait for the updated image. | 374 fetch_loop.Run(); // Wait for the updated image. |
| 375 EXPECT_THAT(GetCachedIconFor(site_.url, favicon_base::TOUCH_ICON).Size(), | 375 EXPECT_THAT(GetCachedIconFor(site_.url, favicon_base::TOUCH_ICON).Size(), |
| 376 Eq(gfx::Size(128, 128))); // Compares dimensions, not objects. | 376 Eq(gfx::Size(128, 128))); // Compares dimensions, not objects. |
| 377 } | 377 } |
| 378 | 378 |
| 379 TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchPerformedOnlyOnce) { | |
| 380 base::MockCallback<base::Closure> done; | |
| 381 base::RunLoop loop; | |
| 382 { | |
| 383 InSequence s; | |
| 384 // Image fetcher is used only once. | |
| 385 EXPECT_CALL(*image_fetcher_, | |
| 386 SetDataUseServiceName( | |
| 387 data_use_measurement::DataUseUserData::NTP_TILES)); | |
| 388 EXPECT_CALL(*image_fetcher_, SetDesiredImageFrameSize(gfx::Size(128, 128))); | |
| 389 EXPECT_CALL(*image_fetcher_, | |
| 390 StartOrQueueNetworkRequest(_, site_.large_icon_url, _)) | |
| 391 .WillOnce(PassFetch(128, 128)); | |
| 392 // Success will be notified to both requests. | |
| 393 EXPECT_CALL(done, Run()).WillOnce(Return()); | |
| 394 EXPECT_CALL(done, Run()).WillOnce(Quit(&loop)); | |
|
sfiera
2017/05/17 09:11:51
You can chain:
EXPECT_CALL(…)
.WillOnce(…)
jkrcal
2017/05/17 11:41:08
Done.
| |
| 395 } | |
| 396 | |
| 397 IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_)); | |
| 398 cacher.StartFetchPopularSites(site_, done.Get(), done.Get()); | |
| 399 cacher.StartFetchPopularSites(site_, done.Get(), done.Get()); | |
| 400 loop.Run(); | |
| 401 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON)); | |
| 402 EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON)); | |
| 403 } | |
| 404 | |
| 379 class IconCacherTestMostLikely : public IconCacherTestBase { | 405 class IconCacherTestMostLikely : public IconCacherTestBase { |
| 380 protected: | 406 protected: |
| 381 IconCacherTestMostLikely() | 407 IconCacherTestMostLikely() |
| 382 : large_icon_service_background_task_runner_( | 408 : large_icon_service_background_task_runner_( |
| 383 new base::TestSimpleTaskRunner()), | 409 new base::TestSimpleTaskRunner()), |
| 384 fetcher_for_large_icon_service_( | 410 fetcher_for_large_icon_service_( |
| 385 base::MakeUnique<::testing::StrictMock<MockImageFetcher>>()), | 411 base::MakeUnique<::testing::StrictMock<MockImageFetcher>>()), |
| 386 fetcher_for_icon_cacher_( | 412 fetcher_for_icon_cacher_( |
| 387 base::MakeUnique<::testing::StrictMock<MockImageFetcher>>()) { | 413 base::MakeUnique<::testing::StrictMock<MockImageFetcher>>()) { |
| 388 // Expect uninteresting calls here, |fetcher_for_icon_cacher_| is not | 414 // Expect uninteresting calls here, |fetcher_for_icon_cacher_| is not |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 // queue in order to finish the work. | 531 // queue in order to finish the work. |
| 506 WaitForHistoryThreadTasksToFinish(); | 532 WaitForHistoryThreadTasksToFinish(); |
| 507 large_icon_service_background_task_runner_->RunUntilIdle(); | 533 large_icon_service_background_task_runner_->RunUntilIdle(); |
| 508 WaitForMainThreadTasksToFinish(); | 534 WaitForMainThreadTasksToFinish(); |
| 509 | 535 |
| 510 // Even though the callbacks are not called, the icon gets written out. | 536 // Even though the callbacks are not called, the icon gets written out. |
| 511 EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON)); | 537 EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON)); |
| 512 EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON)); | 538 EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON)); |
| 513 } | 539 } |
| 514 | 540 |
| 541 TEST_F(IconCacherTestMostLikely, NotCachedAndFetchPerformedOnlyOnce) { | |
| 542 GURL page_url("http://www.site.com"); | |
| 543 | |
| 544 base::MockCallback<base::Closure> done; | |
| 545 base::RunLoop loop; | |
| 546 { | |
| 547 InSequence s; | |
| 548 // Image fetcher is used only once. | |
| 549 EXPECT_CALL(*fetcher_for_large_icon_service_, | |
| 550 SetDataUseServiceName( | |
| 551 data_use_measurement::DataUseUserData::LARGE_ICON_SERVICE)); | |
| 552 EXPECT_CALL(*fetcher_for_large_icon_service_, | |
| 553 StartOrQueueNetworkRequest(_, _, _)) | |
| 554 .WillOnce(PassFetch(128, 128)); | |
| 555 // Success will be notified to both requests. | |
| 556 EXPECT_CALL(done, Run()).WillOnce(Return()); | |
| 557 EXPECT_CALL(done, Run()).WillOnce(Quit(&loop)); | |
| 558 } | |
| 559 | |
| 560 favicon::LargeIconService large_icon_service( | |
| 561 &favicon_service_, large_icon_service_background_task_runner_, | |
| 562 std::move(fetcher_for_large_icon_service_)); | |
| 563 IconCacherImpl cacher(&favicon_service_, &large_icon_service, | |
| 564 std::move(fetcher_for_icon_cacher_)); | |
| 565 | |
| 566 cacher.StartFetchMostLikely(page_url, done.Get()); | |
| 567 cacher.StartFetchMostLikely(page_url, done.Get()); | |
| 568 // Both these task runners need to be flushed in order to get |done| called by | |
| 569 // running the main loop. | |
| 570 WaitForHistoryThreadTasksToFinish(); | |
| 571 large_icon_service_background_task_runner_->RunUntilIdle(); | |
| 572 | |
| 573 loop.Run(); | |
| 574 EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON)); | |
| 575 EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON)); | |
| 576 } | |
| 577 | |
| 515 } // namespace | 578 } // namespace |
| 516 } // namespace ntp_tiles | 579 } // namespace ntp_tiles |
| OLD | NEW |