icon_cacher_impl_unittest.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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
  3. // found in the LICENSE file.
  4. #include "components/ntp_tiles/icon_cacher_impl.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "base/bind.h"
  8. #include "base/callback_helpers.h"
  9. #include "base/containers/flat_set.h"
  10. #include "base/files/scoped_temp_dir.h"
  11. #include "base/path_service.h"
  12. #include "base/run_loop.h"
  13. #include "base/test/metrics/histogram_tester.h"
  14. #include "base/test/mock_callback.h"
  15. #include "base/test/task_environment.h"
  16. #include "base/test/test_simple_task_runner.h"
  17. #include "base/threading/thread_task_runner_handle.h"
  18. #include "build/build_config.h"
  19. #include "components/favicon/core/favicon_client.h"
  20. #include "components/favicon/core/favicon_service_impl.h"
  21. #include "components/favicon/core/favicon_util.h"
  22. #include "components/favicon/core/large_icon_service_impl.h"
  23. #include "components/favicon_base/favicon_types.h"
  24. #include "components/history/core/browser/history_database_params.h"
  25. #include "components/history/core/browser/history_service.h"
  26. #include "components/image_fetcher/core/fake_image_decoder.h"
  27. #include "components/image_fetcher/core/image_decoder.h"
  28. #include "components/image_fetcher/core/image_fetcher.h"
  29. #include "components/image_fetcher/core/mock_image_fetcher.h"
  30. #include "components/image_fetcher/core/request_metadata.h"
  31. #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
  32. #include "services/data_decoder/public/cpp/data_decoder.h"
  33. #include "testing/gmock/include/gmock/gmock.h"
  34. #include "testing/gtest/include/gtest/gtest.h"
  35. #include "ui/base/resource/mock_resource_bundle_delegate.h"
  36. #include "ui/base/resource/resource_bundle.h"
  37. #include "ui/base/ui_base_paths.h"
  38. #include "ui/gfx/image/image_unittest_util.h"
  39. using base::Bucket;
  40. using image_fetcher::ImageFetcherParams;
  41. using ::image_fetcher::MockImageFetcher;
  42. using ::testing::_;
  43. using ::testing::ElementsAre;
  44. using ::testing::Eq;
  45. using ::testing::InSequence;
  46. using ::testing::Invoke;
  47. using ::testing::IsEmpty;
  48. using ::testing::NiceMock;
  49. using ::testing::Return;
  50. using ::testing::ReturnArg;
  51. namespace ntp_tiles {
  52. namespace {
  53. const int kTestDipForServerRequests = 32;
  54. const favicon_base::IconType kTestIconTypeForServerRequests =
  55. favicon_base::IconType::kTouchIcon;
  56. const char kTestGoogleServerClientParam[] = "test_chrome";
  57. ACTION(FailFetch) {
  58. base::ThreadTaskRunnerHandle::Get()->PostTask(
  59. FROM_HERE, base::BindOnce(std::move(*arg2), gfx::Image(),
  60. image_fetcher::RequestMetadata()));
  61. }
  62. ACTION_P2(PassFetch, width, height) {
  63. base::ThreadTaskRunnerHandle::Get()->PostTask(
  64. FROM_HERE,
  65. base::BindOnce(std::move(*arg2), gfx::test::CreateImage(width, height),
  66. image_fetcher::RequestMetadata()));
  67. }
  68. ACTION_P(Quit, run_loop) {
  69. run_loop->Quit();
  70. }
  71. // TODO(jkrcal): Split off large_icon_service.h and large_icon_service_impl.h.
  72. // Use then mocks of FaviconService and LargeIconService instead of the real
  73. // things.
  74. class IconCacherTestBase : public ::testing::Test {
  75. protected:
  76. IconCacherTestBase()
  77. : favicon_service_(/*favicon_client=*/nullptr, &history_service_) {
  78. CHECK(history_dir_.CreateUniqueTempDir());
  79. CHECK(history_service_.Init(
  80. history::HistoryDatabaseParams(history_dir_.GetPath(), 0, 0)));
  81. }
  82. void PreloadIcon(const GURL& url,
  83. const GURL& icon_url,
  84. favicon_base::IconType icon_type,
  85. int width,
  86. int height) {
  87. favicon_service_.SetFavicons({url}, icon_url, icon_type,
  88. gfx::test::CreateImage(width, height));
  89. }
  90. bool IconIsCachedFor(const GURL& url, favicon_base::IconType icon_type) {
  91. return !GetCachedIconFor(url, icon_type).IsEmpty();
  92. }
  93. gfx::Image GetCachedIconFor(const GURL& url,
  94. favicon_base::IconType icon_type) {
  95. base::CancelableTaskTracker tracker;
  96. gfx::Image image;
  97. base::RunLoop loop;
  98. favicon::GetFaviconImageForPageURL(
  99. &favicon_service_, url, icon_type,
  100. base::BindOnce(
  101. [](gfx::Image* image, base::RunLoop* loop,
  102. const favicon_base::FaviconImageResult& result) {
  103. *image = result.image;
  104. loop->Quit();
  105. },
  106. &image, &loop),
  107. &tracker);
  108. loop.Run();
  109. return image;
  110. }
  111. void WaitForHistoryThreadTasksToFinish() {
  112. base::RunLoop loop;
  113. base::MockOnceClosure done;
  114. EXPECT_CALL(done, Run()).WillOnce(Quit(&loop));
  115. history_service_.FlushForTest(done.Get());
  116. loop.Run();
  117. }
  118. void WaitForMainThreadTasksToFinish() {
  119. base::RunLoop loop;
  120. loop.RunUntilIdle();
  121. }
  122. base::test::TaskEnvironment task_environment_;
  123. base::ScopedTempDir history_dir_;
  124. history::HistoryService history_service_;
  125. favicon::FaviconServiceImpl favicon_service_;
  126. };
  127. class IconCacherTestPopularSites : public IconCacherTestBase {
  128. protected:
  129. IconCacherTestPopularSites()
  130. : site_(std::u16string(), // title, unused
  131. GURL("http://url.google/"),
  132. GURL("http://url.google/icon.png"),
  133. GURL("http://url.google/favicon.ico"),
  134. TileTitleSource::UNKNOWN), // title_source, unused
  135. image_fetcher_(new ::testing::StrictMock<MockImageFetcher>),
  136. image_decoder_() {}
  137. void SetUp() override {
  138. if (ui::ResourceBundle::HasSharedInstance()) {
  139. ui::ResourceBundle::CleanupSharedInstance();
  140. }
  141. ON_CALL(mock_resource_delegate_, GetPathForResourcePack(_, _))
  142. .WillByDefault(ReturnArg<0>());
  143. ON_CALL(mock_resource_delegate_, GetPathForLocalePack(_, _))
  144. .WillByDefault(ReturnArg<0>());
  145. ui::ResourceBundle::InitSharedInstanceWithLocale(
  146. "en-US", &mock_resource_delegate_,
  147. ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
  148. }
  149. void TearDown() override {
  150. if (ui::ResourceBundle::HasSharedInstance()) {
  151. ui::ResourceBundle::CleanupSharedInstance();
  152. }
  153. base::FilePath pak_path;
  154. #if BUILDFLAG(IS_ANDROID)
  155. base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path);
  156. #else
  157. base::PathService::Get(base::DIR_ASSETS, &pak_path);
  158. #endif
  159. base::FilePath ui_test_pak_path;
  160. ASSERT_TRUE(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
  161. ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
  162. ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
  163. pak_path.AppendASCII("components_tests_resources.pak"),
  164. ui::kScaleFactorNone);
  165. }
  166. PopularSites::Site site_;
  167. std::unique_ptr<MockImageFetcher> image_fetcher_;
  168. image_fetcher::FakeImageDecoder image_decoder_;
  169. NiceMock<ui::MockResourceBundleDelegate> mock_resource_delegate_;
  170. };
  171. TEST_F(IconCacherTestPopularSites, LargeCached) {
  172. base::HistogramTester histogram_tester;
  173. base::MockOnceClosure done;
  174. EXPECT_CALL(done, Run()).Times(0);
  175. PreloadIcon(site_.url, site_.large_icon_url,
  176. favicon_base::IconType::kTouchIcon, 128, 128);
  177. IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_),
  178. nullptr);
  179. cacher.StartFetchPopularSites(site_, done.Get(), done.Get());
  180. WaitForMainThreadTasksToFinish();
  181. EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::IconType::kFavicon));
  182. EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::IconType::kTouchIcon));
  183. }
  184. TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchSucceeded) {
  185. base::HistogramTester histogram_tester;
  186. base::MockOnceClosure done;
  187. base::RunLoop loop;
  188. {
  189. InSequence s;
  190. EXPECT_CALL(*image_fetcher_,
  191. FetchImageAndData_(site_.large_icon_url, _, _, _))
  192. .WillOnce(PassFetch(128, 128));
  193. EXPECT_CALL(done, Run()).WillOnce(Quit(&loop));
  194. }
  195. IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_),
  196. nullptr);
  197. cacher.StartFetchPopularSites(site_, done.Get(), done.Get());
  198. loop.Run();
  199. EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::IconType::kFavicon));
  200. EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::IconType::kTouchIcon));
  201. }
  202. TEST_F(IconCacherTestPopularSites, SmallNotCachedAndFetchSucceeded) {
  203. site_.large_icon_url = GURL();
  204. base::MockOnceClosure done;
  205. base::RunLoop loop;
  206. {
  207. InSequence s;
  208. EXPECT_CALL(*image_fetcher_, FetchImageAndData_(site_.favicon_url, _, _, _))
  209. .WillOnce(PassFetch(128, 128));
  210. EXPECT_CALL(done, Run()).WillOnce(Quit(&loop));
  211. }
  212. IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_),
  213. nullptr);
  214. cacher.StartFetchPopularSites(site_, done.Get(), done.Get());
  215. loop.Run();
  216. EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::IconType::kFavicon));
  217. EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::IconType::kTouchIcon));
  218. }
  219. TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchFailed) {
  220. base::HistogramTester histogram_tester;
  221. base::MockOnceClosure done;
  222. EXPECT_CALL(done, Run()).Times(0);
  223. {
  224. InSequence s;
  225. EXPECT_CALL(*image_fetcher_,
  226. FetchImageAndData_(site_.large_icon_url, _, _, _))
  227. .WillOnce(FailFetch());
  228. }
  229. IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_),
  230. nullptr);
  231. cacher.StartFetchPopularSites(site_, done.Get(), done.Get());
  232. WaitForMainThreadTasksToFinish();
  233. EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::IconType::kFavicon));
  234. EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::IconType::kTouchIcon));
  235. }
  236. TEST_F(IconCacherTestPopularSites, HandlesEmptyCallbacksNicely) {
  237. base::HistogramTester histogram_tester;
  238. EXPECT_CALL(*image_fetcher_, FetchImageAndData_(_, _, _, _))
  239. .WillOnce(PassFetch(128, 128));
  240. IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_),
  241. nullptr);
  242. cacher.StartFetchPopularSites(site_, base::NullCallback(),
  243. base::NullCallback());
  244. WaitForHistoryThreadTasksToFinish(); // Writing the icon into the DB.
  245. WaitForMainThreadTasksToFinish(); // Finishing tasks after the DB write.
  246. // Even though the callbacks are not called, the icon gets written out.
  247. EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::IconType::kFavicon));
  248. EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::IconType::kTouchIcon));
  249. // The histogram gets reported despite empty callbacks.
  250. }
  251. TEST_F(IconCacherTestPopularSites, ProvidesDefaultIconAndSucceedsWithFetching) {
  252. base::HistogramTester histogram_tester;
  253. // The returned data string is not used by the mocked decoder.
  254. ON_CALL(mock_resource_delegate_, GetRawDataResource(12345, _, _))
  255. .WillByDefault(Return(""));
  256. // It's not important when the image_fetcher's decoder is used to decode the
  257. // image but it must happen at some point.
  258. EXPECT_CALL(*image_fetcher_, GetImageDecoder())
  259. .WillOnce(Return(&image_decoder_));
  260. image_decoder_.SetDecodedImage(gfx::test::CreateImage(64, 64));
  261. base::MockOnceClosure preliminary_icon_available;
  262. base::MockOnceClosure icon_available;
  263. base::RunLoop default_loop;
  264. base::RunLoop fetch_loop;
  265. {
  266. InSequence s;
  267. EXPECT_CALL(*image_fetcher_,
  268. FetchImageAndData_(site_.large_icon_url, _, _, _))
  269. .WillOnce(PassFetch(128, 128));
  270. // Both callback are called async after the request but preliminary has to
  271. // preceed icon_available.
  272. EXPECT_CALL(preliminary_icon_available, Run())
  273. .WillOnce(Quit(&default_loop));
  274. EXPECT_CALL(icon_available, Run()).WillOnce(Quit(&fetch_loop));
  275. }
  276. IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_),
  277. nullptr);
  278. site_.default_icon_resource = 12345;
  279. cacher.StartFetchPopularSites(site_, icon_available.Get(),
  280. preliminary_icon_available.Get());
  281. default_loop.Run(); // Wait for the default image.
  282. EXPECT_THAT(
  283. GetCachedIconFor(site_.url, favicon_base::IconType::kTouchIcon).Size(),
  284. Eq(gfx::Size(64, 64))); // Compares dimensions, not objects.
  285. // Let the fetcher continue and wait for the second call of the callback.
  286. fetch_loop.Run(); // Wait for the updated image.
  287. EXPECT_THAT(
  288. GetCachedIconFor(site_.url, favicon_base::IconType::kTouchIcon).Size(),
  289. Eq(gfx::Size(128, 128))); // Compares dimensions, not objects.
  290. }
  291. TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchPerformedOnlyOnce) {
  292. base::MockOnceClosure done;
  293. base::RunLoop loop;
  294. {
  295. InSequence s;
  296. EXPECT_CALL(*image_fetcher_,
  297. FetchImageAndData_(site_.large_icon_url, _, _, _))
  298. .WillOnce(PassFetch(128, 128));
  299. // Success will be notified to both requests.
  300. EXPECT_CALL(done, Run()).WillOnce(Return()).WillOnce(Quit(&loop));
  301. }
  302. IconCacherImpl cacher(&favicon_service_, nullptr, std::move(image_fetcher_),
  303. nullptr);
  304. cacher.StartFetchPopularSites(site_, done.Get(), done.Get());
  305. cacher.StartFetchPopularSites(site_, done.Get(), done.Get());
  306. loop.Run();
  307. EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::IconType::kFavicon));
  308. EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::IconType::kTouchIcon));
  309. }
  310. class IconCacherTestMostLikely : public IconCacherTestBase {
  311. protected:
  312. IconCacherTestMostLikely()
  313. : fetcher_for_large_icon_service_(
  314. std::make_unique<::testing::StrictMock<MockImageFetcher>>()),
  315. fetcher_for_icon_cacher_(
  316. std::make_unique<::testing::StrictMock<MockImageFetcher>>()) {}
  317. std::unique_ptr<MockImageFetcher> fetcher_for_large_icon_service_;
  318. std::unique_ptr<MockImageFetcher> fetcher_for_icon_cacher_;
  319. };
  320. TEST_F(IconCacherTestMostLikely, Cached) {
  321. GURL page_url("http://www.site.com");
  322. base::HistogramTester histogram_tester;
  323. GURL icon_url("http://www.site.com/favicon.png");
  324. PreloadIcon(page_url, icon_url, favicon_base::IconType::kTouchIcon, 128, 128);
  325. favicon::LargeIconServiceImpl large_icon_service(
  326. &favicon_service_, std::move(fetcher_for_large_icon_service_),
  327. kTestDipForServerRequests, kTestIconTypeForServerRequests,
  328. kTestGoogleServerClientParam);
  329. IconCacherImpl cacher(&favicon_service_, &large_icon_service,
  330. std::move(fetcher_for_icon_cacher_), nullptr);
  331. base::MockOnceClosure done;
  332. EXPECT_CALL(done, Run()).Times(0);
  333. cacher.StartFetchMostLikely(page_url, done.Get());
  334. task_environment_.RunUntilIdle();
  335. EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::IconType::kFavicon));
  336. EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::IconType::kTouchIcon));
  337. }
  338. TEST_F(IconCacherTestMostLikely, NotCachedAndFetchSucceeded) {
  339. GURL page_url("http://www.site.com");
  340. base::HistogramTester histogram_tester;
  341. base::MockOnceClosure done;
  342. base::RunLoop loop;
  343. {
  344. InSequence s;
  345. EXPECT_CALL(*fetcher_for_large_icon_service_,
  346. FetchImageAndData_(_, _, _, _))
  347. .WillOnce(PassFetch(128, 128));
  348. EXPECT_CALL(done, Run()).WillOnce(Quit(&loop));
  349. }
  350. favicon::LargeIconServiceImpl large_icon_service(
  351. &favicon_service_, std::move(fetcher_for_large_icon_service_),
  352. kTestDipForServerRequests, kTestIconTypeForServerRequests,
  353. kTestGoogleServerClientParam);
  354. IconCacherImpl cacher(&favicon_service_, &large_icon_service,
  355. std::move(fetcher_for_icon_cacher_), nullptr);
  356. cacher.StartFetchMostLikely(page_url, done.Get());
  357. // Both these task runners need to be flushed in order to get |done| called by
  358. // running the main loop.
  359. WaitForHistoryThreadTasksToFinish();
  360. task_environment_.RunUntilIdle();
  361. loop.Run();
  362. EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::IconType::kFavicon));
  363. EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::IconType::kTouchIcon));
  364. }
  365. TEST_F(IconCacherTestMostLikely, NotCachedAndFetchFailed) {
  366. GURL page_url("http://www.site.com");
  367. base::HistogramTester histogram_tester;
  368. base::MockOnceClosure done;
  369. {
  370. InSequence s;
  371. EXPECT_CALL(*fetcher_for_large_icon_service_,
  372. FetchImageAndData_(_, _, _, _))
  373. .WillOnce(FailFetch());
  374. EXPECT_CALL(done, Run()).Times(0);
  375. }
  376. favicon::LargeIconServiceImpl large_icon_service(
  377. &favicon_service_, std::move(fetcher_for_large_icon_service_),
  378. kTestDipForServerRequests, kTestIconTypeForServerRequests,
  379. kTestGoogleServerClientParam);
  380. IconCacherImpl cacher(&favicon_service_, &large_icon_service,
  381. std::move(fetcher_for_icon_cacher_), nullptr);
  382. cacher.StartFetchMostLikely(page_url, done.Get());
  383. // Both these task runners need to be flushed before flushing the main thread
  384. // queue in order to finish the work.
  385. WaitForHistoryThreadTasksToFinish();
  386. task_environment_.RunUntilIdle();
  387. EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::IconType::kFavicon));
  388. EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::IconType::kTouchIcon));
  389. }
  390. TEST_F(IconCacherTestMostLikely, HandlesEmptyCallbacksNicely) {
  391. GURL page_url("http://www.site.com");
  392. EXPECT_CALL(*fetcher_for_large_icon_service_, FetchImageAndData_(_, _, _, _))
  393. .WillOnce(PassFetch(128, 128));
  394. favicon::LargeIconServiceImpl large_icon_service(
  395. &favicon_service_, std::move(fetcher_for_large_icon_service_),
  396. kTestDipForServerRequests, kTestIconTypeForServerRequests,
  397. kTestGoogleServerClientParam);
  398. IconCacherImpl cacher(&favicon_service_, &large_icon_service,
  399. std::move(fetcher_for_icon_cacher_), nullptr);
  400. cacher.StartFetchMostLikely(page_url, base::NullCallback());
  401. // Finish the posted tasks on the main and the history thread to find out if
  402. // we can write the icon.
  403. task_environment_.RunUntilIdle();
  404. WaitForHistoryThreadTasksToFinish();
  405. // Continue with the work in large icon service - fetch and decode the data.
  406. task_environment_.RunUntilIdle();
  407. // Do the work on the history thread to write down the icon
  408. WaitForHistoryThreadTasksToFinish();
  409. // Finish the tasks on the main thread.
  410. task_environment_.RunUntilIdle();
  411. // Even though the callbacks are not called, the icon gets written out.
  412. EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::IconType::kFavicon));
  413. EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::IconType::kTouchIcon));
  414. }
  415. TEST_F(IconCacherTestMostLikely, NotCachedAndFetchPerformedOnlyOnce) {
  416. GURL page_url("http://www.site.com");
  417. base::MockOnceClosure done;
  418. base::RunLoop loop;
  419. {
  420. InSequence s;
  421. EXPECT_CALL(*fetcher_for_large_icon_service_,
  422. FetchImageAndData_(_, _, _, _))
  423. .WillOnce(PassFetch(128, 128));
  424. // Success will be notified to both requests.
  425. EXPECT_CALL(done, Run()).WillOnce(Return()).WillOnce(Quit(&loop));
  426. }
  427. favicon::LargeIconServiceImpl large_icon_service(
  428. &favicon_service_, std::move(fetcher_for_large_icon_service_),
  429. kTestDipForServerRequests, kTestIconTypeForServerRequests,
  430. kTestGoogleServerClientParam);
  431. IconCacherImpl cacher(&favicon_service_, &large_icon_service,
  432. std::move(fetcher_for_icon_cacher_), nullptr);
  433. cacher.StartFetchMostLikely(page_url, done.Get());
  434. cacher.StartFetchMostLikely(page_url, done.Get());
  435. // Finish the posted tasks on the main and the history thread to find out if
  436. // we can write the icon.
  437. task_environment_.RunUntilIdle();
  438. WaitForHistoryThreadTasksToFinish();
  439. // Continue with the work in large icon service - fetch and decode the data.
  440. task_environment_.RunUntilIdle();
  441. // Do the work on the history thread to write down the icon
  442. WaitForHistoryThreadTasksToFinish();
  443. // Finish the tasks on the main thread.
  444. loop.Run();
  445. EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::IconType::kFavicon));
  446. EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::IconType::kTouchIcon));
  447. }
  448. } // namespace
  449. } // namespace ntp_tiles