Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/content/content_favicon_driver.h" | 5 #include "components/favicon/content/content_favicon_driver.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 ContentFaviconDriver::FromWebContents(web_contents()); | 63 ContentFaviconDriver::FromWebContents(web_contents()); |
| 64 web_contents_tester()->NavigateAndCommit(page_url); | 64 web_contents_tester()->NavigateAndCommit(page_url); |
| 65 static_cast<content::WebContentsObserver*>(favicon_driver) | 65 static_cast<content::WebContentsObserver*>(favicon_driver) |
| 66 ->DidUpdateFaviconURL(candidates); | 66 ->DidUpdateFaviconURL(candidates); |
| 67 base::RunLoop().RunUntilIdle(); | 67 base::RunLoop().RunUntilIdle(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 testing::NiceMock<MockFaviconService> favicon_service_; | 70 testing::NiceMock<MockFaviconService> favicon_service_; |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // Test that UnableToDownloadFavicon() is not called as a result of a favicon | 73 // Test that events are propagated until the FaviconHandler which should in turn |
| 74 // download with 200 status. | 74 // start a download. |
|
pkotwicz
2017/03/02 21:20:26
How about: Test that a download is initiated when
mastiz
2017/03/03 14:21:13
Done.
| |
| 75 TEST_F(ContentFaviconDriverTest, ShouldNotCallUnableToDownloadFaviconFor200) { | 75 TEST_F(ContentFaviconDriverTest, ShouldCauseImageDownload) { |
| 76 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kIconURL)).Times(0); | |
| 77 // Mimic a page load. | 76 // Mimic a page load. |
| 78 TestFetchFaviconForPage( | 77 TestFetchFaviconForPage( |
| 79 kPageURL, | 78 kPageURL, |
| 80 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, | 79 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, |
| 81 kEmptyIconSizes)}); | 80 kEmptyIconSizes)}); |
| 82 // Completing the download should not cause a call to | |
| 83 // UnableToDownloadFavicon(). | |
| 84 EXPECT_TRUE(web_contents_tester()->TestDidDownloadImage( | 81 EXPECT_TRUE(web_contents_tester()->TestDidDownloadImage( |
| 85 kIconURL, 200, kEmptyIcons, kEmptyIconSizes)); | 82 kIconURL, 200, kEmptyIcons, kEmptyIconSizes)); |
| 86 } | 83 } |
| 87 | 84 |
| 88 // Test that UnableToDownloadFavicon() is called as a result of a favicon | |
| 89 // download with 404 status. | |
| 90 TEST_F(ContentFaviconDriverTest, ShouldCallUnableToDownloadFaviconFor404) { | |
| 91 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kIconURL)); | |
| 92 // Mimic a page load. | |
| 93 TestFetchFaviconForPage( | |
| 94 kPageURL, | |
| 95 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, | |
| 96 kEmptyIconSizes)}); | |
| 97 // Mimic the completion of an image download. | |
| 98 EXPECT_TRUE(web_contents_tester()->TestDidDownloadImage( | |
| 99 kIconURL, 404, kEmptyIcons, kEmptyIconSizes)); | |
| 100 } | |
| 101 | |
| 102 // Test that UnableToDownloadFavicon() is not called as a result of a favicon | |
| 103 // download with 503 status. | |
| 104 TEST_F(ContentFaviconDriverTest, ShouldNotCallUnableToDownloadFaviconFor503) { | |
| 105 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kIconURL)).Times(0); | |
| 106 // Mimic a page load. | |
| 107 TestFetchFaviconForPage( | |
| 108 kPageURL, | |
| 109 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, | |
| 110 kEmptyIconSizes)}); | |
| 111 // Completing the download should not cause a call to | |
| 112 // UnableToDownloadFavicon(). | |
| 113 EXPECT_TRUE(web_contents_tester()->TestDidDownloadImage( | |
| 114 kIconURL, 503, kEmptyIcons, kEmptyIconSizes)); | |
| 115 } | |
| 116 | |
| 117 // Test that Favicon is not requested repeatedly during the same session if | 85 // Test that Favicon is not requested repeatedly during the same session if |
| 118 // the favicon is known to be unavailable (e.g. due to HTTP 404 status). | 86 // the favicon is known to be unavailable (e.g. due to HTTP 404 status). |
| 119 TEST_F(ContentFaviconDriverTest, ShouldNotRequestRepeatedlyIfUnavailable) { | 87 TEST_F(ContentFaviconDriverTest, ShouldNotRequestRepeatedlyIfUnavailable) { |
| 120 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL)) | 88 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL)) |
| 121 .WillByDefault(Return(true)); | 89 .WillByDefault(Return(true)); |
| 122 // Mimic a page load. | 90 // Mimic a page load. |
| 123 TestFetchFaviconForPage( | 91 TestFetchFaviconForPage( |
| 124 kPageURL, | 92 kPageURL, |
| 125 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, | 93 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, |
| 126 kEmptyIconSizes)}); | 94 kEmptyIconSizes)}); |
| 127 // Verify that no download request is pending for the image. | 95 // Verify that no download request is pending for the image. |
| 128 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL)); | 96 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL)); |
| 129 } | 97 } |
| 130 | 98 |
| 99 TEST_F(ContentFaviconDriverTest, ShouldDownloadSecondIfFirstUnavailable) { | |
| 100 const GURL kOtherIconURL = GURL("http://www.google.com/other-favicon.ico"); | |
| 101 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL)) | |
| 102 .WillByDefault(Return(true)); | |
| 103 // Mimic a page load. | |
| 104 TestFetchFaviconForPage( | |
| 105 kPageURL, | |
| 106 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, | |
| 107 kEmptyIconSizes), | |
| 108 content::FaviconURL(kOtherIconURL, content::FaviconURL::FAVICON, | |
| 109 kEmptyIconSizes)}); | |
| 110 // Verify a download request is pending for the second image. | |
| 111 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL)); | |
| 112 EXPECT_TRUE(web_contents_tester()->HasPendingDownloadImage(kOtherIconURL)); | |
| 113 } | |
| 114 | |
| 131 // Test that ContentFaviconDriver ignores updated favicon URLs if there is no | 115 // Test that ContentFaviconDriver ignores updated favicon URLs if there is no |
| 132 // last committed entry. This occurs when script is injected in about:blank. | 116 // last committed entry. This occurs when script is injected in about:blank. |
| 133 // See crbug.com/520759 for more details | 117 // See crbug.com/520759 for more details |
| 134 TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) { | 118 TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) { |
| 135 ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry()); | 119 ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry()); |
| 136 | 120 |
| 137 std::vector<content::FaviconURL> favicon_urls; | 121 std::vector<content::FaviconURL> favicon_urls; |
| 138 favicon_urls.push_back(content::FaviconURL( | 122 favicon_urls.push_back(content::FaviconURL( |
| 139 GURL("http://www.google.ca/favicon.ico"), content::FaviconURL::FAVICON, | 123 GURL("http://www.google.ca/favicon.ico"), content::FaviconURL::FAVICON, |
| 140 std::vector<gfx::Size>())); | 124 std::vector<gfx::Size>())); |
| 141 favicon::ContentFaviconDriver* driver = | 125 favicon::ContentFaviconDriver* driver = |
| 142 favicon::ContentFaviconDriver::FromWebContents(web_contents()); | 126 favicon::ContentFaviconDriver::FromWebContents(web_contents()); |
| 143 static_cast<content::WebContentsObserver*>(driver) | 127 static_cast<content::WebContentsObserver*>(driver) |
| 144 ->DidUpdateFaviconURL(favicon_urls); | 128 ->DidUpdateFaviconURL(favicon_urls); |
| 145 | 129 |
| 146 // Test that ContentFaviconDriver ignored the favicon url update. | 130 // Test that ContentFaviconDriver ignored the favicon url update. |
| 147 EXPECT_TRUE(driver->favicon_urls().empty()); | 131 EXPECT_TRUE(driver->favicon_urls().empty()); |
| 148 } | 132 } |
| 149 | 133 |
| 150 } // namespace | 134 } // namespace |
| 151 } // namespace favicon | 135 } // namespace favicon |
| OLD | NEW |