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

Side by Side Diff: components/ntp_tiles/icon_cacher_impl_unittest.cc

Issue 2873403002: [NTP Tiles] Avoid duplicate requests from IconCacherImpl (Closed)
Patch Set: Fix build for windows Created 3 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 unified diff | Download patch
« no previous file with comments | « components/ntp_tiles/icon_cacher_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()).WillOnce(Quit(&loop));
394 }
395
396 IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_));
397 cacher.StartFetchPopularSites(site_, done.Get(), done.Get());
398 cacher.StartFetchPopularSites(site_, done.Get(), done.Get());
399 loop.Run();
400 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
401 EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
402 }
403
379 class IconCacherTestMostLikely : public IconCacherTestBase { 404 class IconCacherTestMostLikely : public IconCacherTestBase {
380 protected: 405 protected:
381 IconCacherTestMostLikely() 406 IconCacherTestMostLikely()
382 : large_icon_service_background_task_runner_( 407 : large_icon_service_background_task_runner_(
383 new base::TestSimpleTaskRunner()), 408 new base::TestSimpleTaskRunner()),
384 fetcher_for_large_icon_service_( 409 fetcher_for_large_icon_service_(
385 base::MakeUnique<::testing::StrictMock<MockImageFetcher>>()), 410 base::MakeUnique<::testing::StrictMock<MockImageFetcher>>()),
386 fetcher_for_icon_cacher_( 411 fetcher_for_icon_cacher_(
387 base::MakeUnique<::testing::StrictMock<MockImageFetcher>>()) { 412 base::MakeUnique<::testing::StrictMock<MockImageFetcher>>()) {
388 // Expect uninteresting calls here, |fetcher_for_icon_cacher_| is not 413 // Expect uninteresting calls here, |fetcher_for_icon_cacher_| is not
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // queue in order to finish the work. 530 // queue in order to finish the work.
506 WaitForHistoryThreadTasksToFinish(); 531 WaitForHistoryThreadTasksToFinish();
507 large_icon_service_background_task_runner_->RunUntilIdle(); 532 large_icon_service_background_task_runner_->RunUntilIdle();
508 WaitForMainThreadTasksToFinish(); 533 WaitForMainThreadTasksToFinish();
509 534
510 // Even though the callbacks are not called, the icon gets written out. 535 // Even though the callbacks are not called, the icon gets written out.
511 EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON)); 536 EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON));
512 EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON)); 537 EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON));
513 } 538 }
514 539
540 TEST_F(IconCacherTestMostLikely, NotCachedAndFetchPerformedOnlyOnce) {
541 GURL page_url("http://www.site.com");
542
543 base::MockCallback<base::Closure> done;
544 base::RunLoop loop;
545 {
546 InSequence s;
547 // Image fetcher is used only once.
548 EXPECT_CALL(*fetcher_for_large_icon_service_,
549 SetDataUseServiceName(
550 data_use_measurement::DataUseUserData::LARGE_ICON_SERVICE));
551 EXPECT_CALL(*fetcher_for_large_icon_service_,
552 StartOrQueueNetworkRequest(_, _, _))
553 .WillOnce(PassFetch(128, 128));
554 // Success will be notified to both requests.
555 EXPECT_CALL(done, Run()).WillOnce(Return()).WillOnce(Quit(&loop));
556 }
557
558 favicon::LargeIconService large_icon_service(
559 &favicon_service_, large_icon_service_background_task_runner_,
560 std::move(fetcher_for_large_icon_service_));
561 IconCacherImpl cacher(&favicon_service_, &large_icon_service,
562 std::move(fetcher_for_icon_cacher_));
563
564 cacher.StartFetchMostLikely(page_url, done.Get());
565 cacher.StartFetchMostLikely(page_url, done.Get());
566 // Both these task runners need to be flushed in order to get |done| called by
567 // running the main loop.
568 WaitForHistoryThreadTasksToFinish();
569 large_icon_service_background_task_runner_->RunUntilIdle();
570
571 loop.Run();
572 EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON));
573 EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON));
574 }
575
515 } // namespace 576 } // namespace
516 } // namespace ntp_tiles 577 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/icon_cacher_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698