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

Side by Side Diff: components/favicon/core/favicon_handler_unittest.cc

Issue 2797143002: Add FaviconHandler test for UpdateFaviconMappingsAndFetch() (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/favicon_handler.h" 5 #include "components/favicon/core/favicon_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 CreateRawBitmapResult(kIconURL)); 388 CreateRawBitmapResult(kIconURL));
389 389
390 EXPECT_CALL(delegate_, OnFaviconUpdated( 390 EXPECT_CALL(delegate_, OnFaviconUpdated(
391 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, 391 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP,
392 kIconURL, /*icon_url_changed=*/true, _)); 392 kIconURL, /*icon_url_changed=*/true, _));
393 393
394 RunHandlerWithSimpleFaviconCandidates({kIconURL}); 394 RunHandlerWithSimpleFaviconCandidates({kIconURL});
395 EXPECT_THAT(delegate_.downloads(), IsEmpty()); 395 EXPECT_THAT(delegate_.downloads(), IsEmpty());
396 } 396 }
397 397
398 // Test that UpdateFaviconsAndFetch() is called with the appropriate parameters
399 // when there is data in the database for neither the page URL nor the icon URL.
400 TEST_F(FaviconHandlerTest, UpdateFaviconMappingsAndFetch) {
401 EXPECT_CALL(favicon_service_, UpdateFaviconMappingsAndFetch(
402 kPageURL, URLVector{kIconURL16x16}, FAVICON,
403 /*desired_size_in_dip=*/16, _, _));
404
405 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16});
406 }
407
398 // Test that the FaviconHandler process finishes when: 408 // Test that the FaviconHandler process finishes when:
399 // - There is data in the database for neither the page URL nor the icon URL. 409 // - There is data in the database for neither the page URL nor the icon URL.
400 // AND 410 // AND
401 // - FaviconService::GetFaviconForPageURL() callback returns before 411 // - FaviconService::GetFaviconForPageURL() callback returns before
402 // FaviconHandler::OnUpdateFaviconURL() is called. 412 // FaviconHandler::OnUpdateFaviconURL() is called.
403 // TODO(mastiz): Add test to verify UpdateFaviconMappingsAndFetch().
404 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { 413 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) {
405 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, 414 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON,
406 ImageSizeIs(16, 16))); 415 ImageSizeIs(16, 16)));
407 EXPECT_CALL(delegate_, OnFaviconUpdated( 416 EXPECT_CALL(delegate_, OnFaviconUpdated(
408 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, 417 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP,
409 kIconURL16x16, /*icon_url_changed=*/true, _)); 418 kIconURL16x16, /*icon_url_changed=*/true, _));
410 419
411 FaviconHandler handler(&favicon_service_, &delegate_, 420 FaviconHandler handler(&favicon_service_, &delegate_,
412 FaviconDriverObserver::NON_TOUCH_16_DIP); 421 FaviconDriverObserver::NON_TOUCH_16_DIP);
413 handler.FetchFavicon(kPageURL); 422 handler.FetchFavicon(kPageURL);
414 // Causes FaviconService lookups be faster than OnUpdateFaviconURL(). 423 // Causes FaviconService lookups be faster than OnUpdateFaviconURL().
415 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
416 handler.OnUpdateFaviconURL(kPageURL, 425 handler.OnUpdateFaviconURL(kPageURL,
417 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); 426 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)});
418 base::RunLoop().RunUntilIdle(); 427 base::RunLoop().RunUntilIdle();
419 428
420 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); 429 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16));
421 EXPECT_THAT(favicon_service_.fake()->db_requests(), 430 EXPECT_THAT(favicon_service_.fake()->db_requests(),
422 ElementsAre(kPageURL, kIconURL16x16)); 431 ElementsAre(kPageURL, kIconURL16x16));
423 } 432 }
424 433
425 // Test that the FaviconHandler process finishes when: 434 // Test that the FaviconHandler process finishes when:
426 // - There is no data in the database for neither the page URL nor the icon URL. 435 // - There is no data in the database for neither the page URL nor the icon URL.
pkotwicz 2017/04/05 15:16:57 Nit: "There is no data" -> "There is data"
mastiz 2017/04/06 08:13:53 Done.
427 // AND 436 // AND
428 // - FaviconService::GetFaviconForPageURL() callback returns after 437 // - FaviconService::GetFaviconForPageURL() callback returns after
429 // FaviconHandler::OnUpdateFaviconURL() is called. 438 // FaviconHandler::OnUpdateFaviconURL() is called.
430 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) { 439 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) {
431 InSequence seq;
432 EXPECT_CALL(favicon_service_,
433 UpdateFaviconMappingsAndFetch(kPageURL, URLVector{kIconURL16x16},
434 FAVICON, _, _, _));
435 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, 440 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON,
436 ImageSizeIs(16, 16))); 441 ImageSizeIs(16, 16)));
437 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)); 442 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _));
438 443
439 FaviconHandler handler(&favicon_service_, &delegate_, 444 FaviconHandler handler(&favicon_service_, &delegate_,
440 FaviconDriverObserver::NON_TOUCH_16_DIP); 445 FaviconDriverObserver::NON_TOUCH_16_DIP);
441 handler.FetchFavicon(kPageURL); 446 handler.FetchFavicon(kPageURL);
442 ASSERT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kPageURL)); 447 ASSERT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kPageURL));
443 448
444 // Feed in favicons without processing posted tasks (RunUntilIdle()). 449 // Feed in favicons without processing posted tasks (RunUntilIdle()).
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 1011
1007 RunHandlerWithCandidates( 1012 RunHandlerWithCandidates(
1008 FaviconDriverObserver::NON_TOUCH_LARGEST, 1013 FaviconDriverObserver::NON_TOUCH_LARGEST,
1009 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), 1014 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}),
1010 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), 1015 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}),
1011 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); 1016 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)});
1012 } 1017 }
1013 1018
1014 } // namespace 1019 } // namespace
1015 } // namespace favicon 1020 } // namespace favicon
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698