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

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

Issue 2891333002: Introduce dedicated enum value for icons from Web Manifests (Closed)
Patch Set: Put browsertest behind #if. 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
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 20 matching lines...) Expand all
31 #include "ui/gfx/favicon_size.h" 31 #include "ui/gfx/favicon_size.h"
32 #include "ui/gfx/image/image.h" 32 #include "ui/gfx/image/image.h"
33 33
34 namespace favicon { 34 namespace favicon {
35 namespace { 35 namespace {
36 36
37 using favicon_base::FAVICON; 37 using favicon_base::FAVICON;
38 using favicon_base::FaviconRawBitmapResult; 38 using favicon_base::FaviconRawBitmapResult;
39 using favicon_base::TOUCH_ICON; 39 using favicon_base::TOUCH_ICON;
40 using favicon_base::TOUCH_PRECOMPOSED_ICON; 40 using favicon_base::TOUCH_PRECOMPOSED_ICON;
41 using favicon_base::WEB_MANIFEST_ICON;
41 using testing::AnyNumber; 42 using testing::AnyNumber;
42 using testing::Assign; 43 using testing::Assign;
43 using testing::Contains; 44 using testing::Contains;
44 using testing::ElementsAre; 45 using testing::ElementsAre;
45 using testing::InSequence; 46 using testing::InSequence;
46 using testing::Invoke; 47 using testing::Invoke;
47 using testing::IsEmpty; 48 using testing::IsEmpty;
48 using testing::Not; 49 using testing::Not;
49 using testing::Return; 50 using testing::Return;
50 using testing::_; 51 using testing::_;
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerManifestsEnabledTest); 1485 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerManifestsEnabledTest);
1485 }; 1486 };
1486 1487
1487 // Test that a favicon corresponding to a web manifest is reported when: 1488 // Test that a favicon corresponding to a web manifest is reported when:
1488 // - There is data in the favicon database for the manifest URL. 1489 // - There is data in the favicon database for the manifest URL.
1489 // AND 1490 // AND
1490 // - FaviconService::OnFaviconDataForManifestFromFaviconService() runs before 1491 // - FaviconService::OnFaviconDataForManifestFromFaviconService() runs before
1491 // FaviconHandler::OnUpdateCandidates() is called. 1492 // FaviconHandler::OnUpdateCandidates() is called.
1492 TEST_F(FaviconHandlerManifestsEnabledTest, 1493 TEST_F(FaviconHandlerManifestsEnabledTest,
1493 GetFaviconFromManifestInHistoryIfCandidatesSlower) { 1494 GetFaviconFromManifestInHistoryIfCandidatesSlower) {
1494 favicon_service_.fake()->Store(kPageURL, kManifestURL, 1495 favicon_service_.fake()->Store(
1495 CreateRawBitmapResult(kManifestURL)); 1496 kPageURL, kManifestURL,
1497 CreateRawBitmapResult(kManifestURL, WEB_MANIFEST_ICON));
1496 1498
1497 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); 1499 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0);
1498 1500
1499 EXPECT_CALL(favicon_service_, 1501 EXPECT_CALL(favicon_service_,
1500 UpdateFaviconMappingsAndFetch(_, kManifestURL, FAVICON, 1502 UpdateFaviconMappingsAndFetch(_, kManifestURL, WEB_MANIFEST_ICON,
1501 /*desired_size_in_dip=*/16, _, _)); 1503 /*desired_size_in_dip=*/16, _, _));
1502 EXPECT_CALL(delegate_, 1504 EXPECT_CALL(delegate_,
1503 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_16_DIP, 1505 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_16_DIP,
1504 kManifestURL, _, _)); 1506 kManifestURL, _, _));
1505 1507
1506 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); 1508 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL);
1507 EXPECT_THAT(favicon_service_.fake()->db_requests(), 1509 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1508 ElementsAre(kPageURL, kManifestURL)); 1510 ElementsAre(kPageURL, kManifestURL));
1509 EXPECT_THAT(delegate_.downloads(), IsEmpty()); 1511 EXPECT_THAT(delegate_.downloads(), IsEmpty());
1510 } 1512 }
1511 1513
1512 // Test that a favicon corresponding to a web manifest is reported when: 1514 // Test that a favicon corresponding to a web manifest is reported when:
1513 // - There is data in the favicon database for the manifest URL. 1515 // - There is data in the favicon database for the manifest URL.
1514 // AND 1516 // AND
1515 // - FaviconHandler::OnUpdateCandidates() is called before 1517 // - FaviconHandler::OnUpdateCandidates() is called before
1516 // FaviconService::OnFaviconDataForManifestFromFaviconService() runs. 1518 // FaviconService::OnFaviconDataForManifestFromFaviconService() runs.
1517 TEST_F(FaviconHandlerManifestsEnabledTest, 1519 TEST_F(FaviconHandlerManifestsEnabledTest,
1518 GetFaviconFromManifestInHistoryIfCandidatesFaster) { 1520 GetFaviconFromManifestInHistoryIfCandidatesFaster) {
1519 favicon_service_.fake()->Store(kPageURL, kManifestURL, 1521 favicon_service_.fake()->Store(
1520 CreateRawBitmapResult(kManifestURL)); 1522 kPageURL, kManifestURL,
1523 CreateRawBitmapResult(kManifestURL, WEB_MANIFEST_ICON));
1521 // Defer the database lookup completion to control the exact timing. 1524 // Defer the database lookup completion to control the exact timing.
1522 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kManifestURL); 1525 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kManifestURL);
1523 1526
1524 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); 1527 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0);
1525 1528
1526 EXPECT_CALL(favicon_service_, 1529 EXPECT_CALL(favicon_service_,
1527 UpdateFaviconMappingsAndFetch(_, kManifestURL, FAVICON, 1530 UpdateFaviconMappingsAndFetch(_, kManifestURL, WEB_MANIFEST_ICON,
1528 /*desired_size_in_dip=*/16, _, _)); 1531 /*desired_size_in_dip=*/16, _, _));
1529 EXPECT_CALL(delegate_, 1532 EXPECT_CALL(delegate_,
1530 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_16_DIP, 1533 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_16_DIP,
1531 kManifestURL, _, _)); 1534 kManifestURL, _, _));
1532 1535
1533 std::unique_ptr<FaviconHandler> handler = 1536 std::unique_ptr<FaviconHandler> handler =
1534 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); 1537 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL);
1535 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); 1538 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback());
1536 1539
1537 // Complete the lookup. 1540 // Complete the lookup.
1538 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); 1541 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually());
1539 base::RunLoop().RunUntilIdle(); 1542 base::RunLoop().RunUntilIdle();
1540 1543
1541 EXPECT_THAT(favicon_service_.fake()->db_requests(), 1544 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1542 ElementsAre(kPageURL, kManifestURL)); 1545 ElementsAre(kPageURL, kManifestURL));
1543 EXPECT_THAT(delegate_.downloads(), IsEmpty()); 1546 EXPECT_THAT(delegate_.downloads(), IsEmpty());
1544 } 1547 }
1545 1548
1546 // Test that a favicon corresponding to a web manifest is reported when there is 1549 // Test that a favicon corresponding to a web manifest is reported when there is
1547 // data in the database for neither the page URL nor the manifest URL. 1550 // data in the database for neither the page URL nor the manifest URL.
1548 TEST_F(FaviconHandlerManifestsEnabledTest, GetFaviconFromUnknownManifest) { 1551 TEST_F(FaviconHandlerManifestsEnabledTest, GetFaviconFromUnknownManifest) {
1549 const std::vector<favicon::FaviconURL> kManifestIcons = { 1552 const std::vector<favicon::FaviconURL> kManifestIcons = {
1550 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), 1553 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes),
1551 }; 1554 };
1552 1555
1553 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); 1556 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons);
1554 1557
1555 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); 1558 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0);
1556 1559
1557 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, FAVICON, _)); 1560 EXPECT_CALL(favicon_service_,
1561 SetFavicons(_, kManifestURL, WEB_MANIFEST_ICON, _));
1558 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)); 1562 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _));
1559 1563
1560 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); 1564 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL);
1561 EXPECT_THAT(favicon_service_.fake()->db_requests(), 1565 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1562 ElementsAre(kPageURL, kManifestURL)); 1566 ElementsAre(kPageURL, kManifestURL));
1563 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL16x16)); 1567 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL16x16));
1564 } 1568 }
1565 1569
1566 // Test that the manifest and icon are redownloaded if the icon cached for the 1570 // Test that the manifest and icon are redownloaded if the icon cached for the
1567 // page URL expired. 1571 // page URL expired.
1568 TEST_F(FaviconHandlerManifestsEnabledTest, GetFaviconFromExpiredManifest) { 1572 TEST_F(FaviconHandlerManifestsEnabledTest, GetFaviconFromExpiredManifest) {
1569 const std::vector<favicon::FaviconURL> kManifestIcons = { 1573 const std::vector<favicon::FaviconURL> kManifestIcons = {
1570 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), 1574 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes),
1571 }; 1575 };
1572 1576
1573 favicon_service_.fake()->Store(kPageURL, kManifestURL, 1577 favicon_service_.fake()->Store(
1574 CreateRawBitmapResult(kManifestURL, FAVICON, 1578 kPageURL, kManifestURL,
1575 /*expired=*/true)); 1579 CreateRawBitmapResult(kManifestURL, WEB_MANIFEST_ICON,
1580 /*expired=*/true));
1576 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); 1581 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons);
1577 1582
1578 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)).Times(2); 1583 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)).Times(2);
1579 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, _, _)); 1584 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, _, _));
1580 1585
1581 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); 1586 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL);
1582 EXPECT_THAT(favicon_service_.fake()->db_requests(), 1587 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1583 ElementsAre(kPageURL, kManifestURL)); 1588 ElementsAre(kPageURL, kManifestURL));
1584 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64)); 1589 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64));
1585 } 1590 }
1586 1591
1587 // Test that the manifest and icon are redownloaded if the icon cached for the 1592 // Test that the manifest and icon are redownloaded if the icon cached for the
1588 // manifest URL expired, which was observed during a visit to a different page 1593 // manifest URL expired, which was observed during a visit to a different page
1589 // URL. 1594 // URL.
1590 TEST_F(FaviconHandlerManifestsEnabledTest, 1595 TEST_F(FaviconHandlerManifestsEnabledTest,
1591 GetFaviconFromExpiredManifestLinkedFromOtherPage) { 1596 GetFaviconFromExpiredManifestLinkedFromOtherPage) {
1592 const GURL kSomePreviousPageURL("https://www.google.com/previous"); 1597 const GURL kSomePreviousPageURL("https://www.google.com/previous");
1593 const std::vector<favicon::FaviconURL> kManifestIcons = { 1598 const std::vector<favicon::FaviconURL> kManifestIcons = {
1594 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), 1599 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes),
1595 }; 1600 };
1596 1601
1597 favicon_service_.fake()->Store(kSomePreviousPageURL, kManifestURL, 1602 favicon_service_.fake()->Store(
1598 CreateRawBitmapResult(kManifestURL, FAVICON, 1603 kSomePreviousPageURL, kManifestURL,
1599 /*expired=*/true)); 1604 CreateRawBitmapResult(kManifestURL, WEB_MANIFEST_ICON,
1605 /*expired=*/true));
1600 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); 1606 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons);
1601 1607
1602 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)).Times(2); 1608 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)).Times(2);
1603 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, _, _)); 1609 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, _, _));
1604 1610
1605 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); 1611 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL);
1606 EXPECT_THAT(favicon_service_.fake()->db_requests(), 1612 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1607 ElementsAre(kPageURL, kManifestURL)); 1613 ElementsAre(kPageURL, kManifestURL));
1608 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64)); 1614 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64));
1609 } 1615 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 // - The page doesn't initially link to a Web Manifest. 1852 // - The page doesn't initially link to a Web Manifest.
1847 // - The page has an icon URL provided via a <link rel="icon"> tag. 1853 // - The page has an icon URL provided via a <link rel="icon"> tag.
1848 // - The database does not know about the page URL or icon URL. 1854 // - The database does not know about the page URL or icon URL.
1849 // - While the icon is being downloaded, the page uses Javascript to add a 1855 // - While the icon is being downloaded, the page uses Javascript to add a
1850 // <link rel="manifest"> tag. 1856 // <link rel="manifest"> tag.
1851 // - The database has bitmap data for the manifest URL. 1857 // - The database has bitmap data for the manifest URL.
1852 TEST_F(FaviconHandlerManifestsEnabledTest, 1858 TEST_F(FaviconHandlerManifestsEnabledTest,
1853 AddKnownManifestViaJavascriptWhileImageDownload) { 1859 AddKnownManifestViaJavascriptWhileImageDownload) {
1854 const GURL kSomePreviousPageURL("https://www.google.com/previous"); 1860 const GURL kSomePreviousPageURL("https://www.google.com/previous");
1855 1861
1856 favicon_service_.fake()->Store(kSomePreviousPageURL, kManifestURL, 1862 favicon_service_.fake()->Store(
1857 CreateRawBitmapResult(kManifestURL)); 1863 kSomePreviousPageURL, kManifestURL,
1864 CreateRawBitmapResult(kManifestURL, WEB_MANIFEST_ICON));
1858 1865
1859 // Defer the image download completion to control the exact timing. 1866 // Defer the image download completion to control the exact timing.
1860 delegate_.fake_image_downloader().SetRunCallbackManuallyForUrl(kIconURL16x16); 1867 delegate_.fake_image_downloader().SetRunCallbackManuallyForUrl(kIconURL16x16);
1861 1868
1862 std::unique_ptr<FaviconHandler> handler = 1869 std::unique_ptr<FaviconHandler> handler =
1863 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); 1870 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16});
1864 1871
1865 ASSERT_TRUE(VerifyAndClearExpectations()); 1872 ASSERT_TRUE(VerifyAndClearExpectations());
1866 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); 1873 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback());
1867 1874
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 1966
1960 // Complete the download. 1967 // Complete the download.
1961 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL2, _, _)); 1968 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL2, _, _));
1962 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL2, _, _)); 1969 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL2, _, _));
1963 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); 1970 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually());
1964 base::RunLoop().RunUntilIdle(); 1971 base::RunLoop().RunUntilIdle();
1965 } 1972 }
1966 1973
1967 } // namespace 1974 } // namespace
1968 } // namespace favicon 1975 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/favicon_handler.cc ('k') | components/favicon/core/large_icon_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698