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