| Index: components/ntp_tiles/icon_cacher_impl_unittest.cc
|
| diff --git a/components/ntp_tiles/icon_cacher_impl_unittest.cc b/components/ntp_tiles/icon_cacher_impl_unittest.cc
|
| index f80289c8ae14b2fb75deb14249304bdab0ab18c4..18e20b8ec7b56ac80f8ca6eec0abd99f2f6a4067 100644
|
| --- a/components/ntp_tiles/icon_cacher_impl_unittest.cc
|
| +++ b/components/ntp_tiles/icon_cacher_impl_unittest.cc
|
| @@ -18,6 +18,7 @@
|
| #include "components/image_fetcher/image_fetcher.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/image/image_unittest_util.h"
|
|
|
| using ::testing::_;
|
| @@ -41,6 +42,45 @@ class MockImageFetcher : public image_fetcher::ImageFetcher {
|
| const gfx::Image& image)> callback));
|
| };
|
|
|
| +// This class provides methods to inject an image resource where a real resource
|
| +// would be necessary otherwise. All other methods have return values that allow
|
| +// the normal implementation to proceed.
|
| +class MockResourceDelegate : public ui::ResourceBundle::Delegate {
|
| + public:
|
| + ~MockResourceDelegate() override {}
|
| + base::FilePath GetPathForResourcePack(const base::FilePath& pack_path,
|
| + ui::ScaleFactor scale_factor) override {
|
| + return pack_path; // Continue Loading pack file.
|
| + }
|
| +
|
| + base::FilePath GetPathForLocalePack(const base::FilePath& pack_path,
|
| + const std::string& locale) override {
|
| + return pack_path; // Continue Loading pack file.
|
| + }
|
| +
|
| + MOCK_METHOD1(GetImageNamed, gfx::Image(int));
|
| +
|
| + gfx::Image GetNativeImageNamed(int resource_id) override {
|
| + return gfx::Image(); // Attempt retrieval of the default resource.
|
| + }
|
| +
|
| + base::RefCountedMemory* LoadDataResourceBytes(
|
| + int resource_id,
|
| + ui::ScaleFactor scale_factor) override {
|
| + return nullptr; // Attempt retrieval of the default resource.
|
| + }
|
| +
|
| + bool GetRawDataResource(int resource_id,
|
| + ui::ScaleFactor scale_factor,
|
| + base::StringPiece* value) override {
|
| + return false; // Attempt retrieval of the default resource.
|
| + }
|
| +
|
| + bool GetLocalizedString(int message_id, base::string16* value) override {
|
| + return false; // Attempt retrieval of the default resource.
|
| + }
|
| +};
|
| +
|
| class IconCacherTest : public ::testing::Test {
|
| protected:
|
| IconCacherTest()
|
| @@ -195,5 +235,43 @@ TEST_F(IconCacherTest, LargeNotCachedAndFetchFailed) {
|
| EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
|
| }
|
|
|
| +TEST_F(IconCacherTest, ProvidesDefaultIconAndSucceedsWithFetching) {
|
| + if (ui::ResourceBundle::HasSharedInstance()) {
|
| + ui::ResourceBundle::CleanupSharedInstance();
|
| + }
|
| +
|
| + // Returns true after the global resource loader instance has been created.
|
| + MockResourceDelegate mock_resource;
|
| + ui::ResourceBundle::InitSharedInstanceWithLocale(
|
| + "en-US", &mock_resource, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
| + MockFunction<void(bool)> done;
|
| + base::RunLoop loop_for_static;
|
| + base::RunLoop loop_for_fetch;
|
| + {
|
| + InSequence s;
|
| + EXPECT_CALL(*image_fetcher_,
|
| + SetDataUseServiceName(
|
| + data_use_measurement::DataUseUserData::NTP_TILES));
|
| + EXPECT_CALL(mock_resource, GetImageNamed(12345))
|
| + .WillOnce(Return(gfx::test::CreateImage(64, 64)));
|
| + EXPECT_CALL(done, Call(true)).WillOnce(Quit(&loop_for_static));
|
| + EXPECT_CALL(*image_fetcher_,
|
| + StartOrQueueNetworkRequest(_, site_.large_icon_url, _))
|
| + .WillOnce(PassFetch(128, 128));
|
| + EXPECT_CALL(done, Call(true)).WillOnce(Quit(&loop_for_fetch));
|
| + }
|
| +
|
| + IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_));
|
| + cacher.AddDefaultImage(site_, /*image_resource_id=*/12345);
|
| + cacher.StartFetch(site_, BindMockFunction(&done));
|
| +
|
| + loop_for_static.Run(); // Wait for the default image.
|
| + EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
|
| +
|
| + // Let the fetcher continue and wait for the second call of the callback.
|
| + loop_for_fetch.Run(); // Wait for the updated image.
|
| + EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
|
| +}
|
| +
|
| } // namespace
|
| } // namespace ntp_tiles
|
|
|