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

Side by Side Diff: components/favicon/content/content_favicon_driver_unittest.cc

Issue 2728893004: Move WasUnableToDownload logic to FaviconHandler (Closed)
Patch Set: Reverted accidental changes. Created 3 years, 9 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 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 ContentFaviconDriver::FromWebContents(web_contents()); 65 ContentFaviconDriver::FromWebContents(web_contents());
66 web_contents_tester()->NavigateAndCommit(page_url); 66 web_contents_tester()->NavigateAndCommit(page_url);
67 static_cast<content::WebContentsObserver*>(favicon_driver) 67 static_cast<content::WebContentsObserver*>(favicon_driver)
68 ->DidUpdateFaviconURL(candidates); 68 ->DidUpdateFaviconURL(candidates);
69 base::RunLoop().RunUntilIdle(); 69 base::RunLoop().RunUntilIdle();
70 } 70 }
71 71
72 testing::NiceMock<MockFaviconService> favicon_service_; 72 testing::NiceMock<MockFaviconService> favicon_service_;
73 }; 73 };
74 74
75 // Test that UnableToDownloadFavicon() is not called as a result of a favicon 75 // Test that a download is initiated when there isn't a favicon in the database
76 // download with 200 status. 76 // for either the page URL or the icon URL.
77 TEST_F(ContentFaviconDriverTest, ShouldNotCallUnableToDownloadFaviconFor200) { 77 TEST_F(ContentFaviconDriverTest, ShouldCauseImageDownload) {
78 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kIconURL)).Times(0);
79 // Mimic a page load. 78 // Mimic a page load.
80 TestFetchFaviconForPage( 79 TestFetchFaviconForPage(
81 kPageURL, 80 kPageURL,
82 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, 81 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON,
83 kEmptyIconSizes)}); 82 kEmptyIconSizes)});
84 // Completing the download should not cause a call to
85 // UnableToDownloadFavicon().
86 EXPECT_TRUE(web_contents_tester()->TestDidDownloadImage( 83 EXPECT_TRUE(web_contents_tester()->TestDidDownloadImage(
87 kIconURL, 200, kEmptyIcons, kEmptyIconSizes)); 84 kIconURL, 200, kEmptyIcons, kEmptyIconSizes));
88 } 85 }
89 86
90 // Test that UnableToDownloadFavicon() is called as a result of a favicon
91 // download with 404 status.
92 TEST_F(ContentFaviconDriverTest, ShouldCallUnableToDownloadFaviconFor404) {
93 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kIconURL));
94 // Mimic a page load.
95 TestFetchFaviconForPage(
96 kPageURL,
97 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON,
98 kEmptyIconSizes)});
99 // Mimic the completion of an image download.
100 EXPECT_TRUE(web_contents_tester()->TestDidDownloadImage(
101 kIconURL, 404, kEmptyIcons, kEmptyIconSizes));
102 }
103
104 // Test that UnableToDownloadFavicon() is not called as a result of a favicon
105 // download with 503 status.
106 TEST_F(ContentFaviconDriverTest, ShouldNotCallUnableToDownloadFaviconFor503) {
107 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kIconURL)).Times(0);
108 // Mimic a page load.
109 TestFetchFaviconForPage(
110 kPageURL,
111 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON,
112 kEmptyIconSizes)});
113 // Completing the download should not cause a call to
114 // UnableToDownloadFavicon().
115 EXPECT_TRUE(web_contents_tester()->TestDidDownloadImage(
116 kIconURL, 503, kEmptyIcons, kEmptyIconSizes));
117 }
118
119 // Test that Favicon is not requested repeatedly during the same session if 87 // Test that Favicon is not requested repeatedly during the same session if
120 // the favicon is known to be unavailable (e.g. due to HTTP 404 status). 88 // the favicon is known to be unavailable (e.g. due to HTTP 404 status).
121 TEST_F(ContentFaviconDriverTest, ShouldNotRequestRepeatedlyIfUnavailable) { 89 TEST_F(ContentFaviconDriverTest, ShouldNotRequestRepeatedlyIfUnavailable) {
122 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL)) 90 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL))
123 .WillByDefault(Return(true)); 91 .WillByDefault(Return(true));
124 // Mimic a page load. 92 // Mimic a page load.
125 TestFetchFaviconForPage( 93 TestFetchFaviconForPage(
126 kPageURL, 94 kPageURL,
127 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON, 95 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON,
128 kEmptyIconSizes)}); 96 kEmptyIconSizes)});
129 // Verify that no download request is pending for the image. 97 // Verify that no download request is pending for the image.
130 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL)); 98 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL));
131 } 99 }
132 100
101 TEST_F(ContentFaviconDriverTest, ShouldDownloadSecondIfFirstUnavailable) {
102 const GURL kOtherIconURL = GURL("http://www.google.com/other-favicon.ico");
103 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL))
104 .WillByDefault(Return(true));
105 // Mimic a page load.
106 TestFetchFaviconForPage(
107 kPageURL,
108 {content::FaviconURL(kIconURL, content::FaviconURL::FAVICON,
109 kEmptyIconSizes),
110 content::FaviconURL(kOtherIconURL, content::FaviconURL::FAVICON,
111 kEmptyIconSizes)});
112 // Verify a download request is pending for the second image.
113 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL));
114 EXPECT_TRUE(web_contents_tester()->HasPendingDownloadImage(kOtherIconURL));
115 }
116
133 // Test that ContentFaviconDriver ignores updated favicon URLs if there is no 117 // Test that ContentFaviconDriver ignores updated favicon URLs if there is no
134 // last committed entry. This occurs when script is injected in about:blank. 118 // last committed entry. This occurs when script is injected in about:blank.
135 // See crbug.com/520759 for more details 119 // See crbug.com/520759 for more details
136 TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) { 120 TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) {
137 ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry()); 121 ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry());
138 122
139 std::vector<content::FaviconURL> favicon_urls; 123 std::vector<content::FaviconURL> favicon_urls;
140 favicon_urls.push_back( 124 favicon_urls.push_back(
141 content::FaviconURL(GURL("http://www.google.ca/favicon.ico"), 125 content::FaviconURL(GURL("http://www.google.ca/favicon.ico"),
142 content::FaviconURL::FAVICON, kEmptyIconSizes)); 126 content::FaviconURL::FAVICON, kEmptyIconSizes));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 base::Bucket(/*min=*/3, /*count=*/2))); 172 base::Bucket(/*min=*/3, /*count=*/2)));
189 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithDefinedSizesCount"), 173 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithDefinedSizesCount"),
190 ElementsAre(base::Bucket(/*min=*/1, /*count=*/3))); 174 ElementsAre(base::Bucket(/*min=*/1, /*count=*/3)));
191 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithTouchIconsCount"), 175 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithTouchIconsCount"),
192 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), 176 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
193 base::Bucket(/*min=*/2, /*count=*/2))); 177 base::Bucket(/*min=*/2, /*count=*/2)));
194 } 178 }
195 179
196 } // namespace 180 } // namespace
197 } // namespace favicon 181 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/content/content_favicon_driver.cc ('k') | components/favicon/core/favicon_driver_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698