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

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

Issue 2804293003: [LargeIconService] Adding URL fallback for the server (Closed)
Patch Set: Fix the unit-test 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 | « components/favicon/core/large_icon_service.cc ('k') | 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 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/core/large_icon_service.h" 5 #include "components/favicon/core/large_icon_service.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 testing::NiceMock<MockFaviconService> mock_favicon_service_; 124 testing::NiceMock<MockFaviconService> mock_favicon_service_;
125 LargeIconService large_icon_service_; 125 LargeIconService large_icon_service_;
126 126
127 private: 127 private:
128 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); 128 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest);
129 }; 129 };
130 130
131 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { 131 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) {
132 const GURL kExpectedServerUrl( 132 const GURL kExpectedServerUrl(
133 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 133 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
134 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE" 134 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL"
135 "&url=http://www.example.com/"); 135 "&url=http://www.example.com/");
136 136
137 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); 137 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0);
138 138
139 base::MockCallback<base::Callback<void(bool success)>> callback; 139 base::MockCallback<base::Callback<void(bool success)>> callback;
140 EXPECT_CALL(*mock_image_fetcher_, 140 EXPECT_CALL(*mock_image_fetcher_,
141 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) 141 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _))
142 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( 142 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
143 CreateTestSkBitmap(64, 64, kTestColor)))); 143 CreateTestSkBitmap(64, 64, kTestColor))));
144 EXPECT_CALL(mock_favicon_service_, 144 EXPECT_CALL(mock_favicon_service_,
145 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl, 145 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl,
146 favicon_base::IconType::TOUCH_ICON, _, _)) 146 favicon_base::IconType::TOUCH_ICON, _, _))
147 .WillOnce(PostBoolReply(true)); 147 .WillOnce(PostBoolReply(true));
148 148
149 large_icon_service_ 149 large_icon_service_
150 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 150 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
151 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); 151 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get());
152 152
153 EXPECT_CALL(callback, Run(true)); 153 EXPECT_CALL(callback, Run(true));
154 base::RunLoop().RunUntilIdle(); 154 base::RunLoop().RunUntilIdle();
155 } 155 }
156 156
157 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) { 157 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) {
158 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); 158 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1");
159 const GURL kExpectedServerUrl( 159 const GURL kExpectedServerUrl(
160 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 160 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
161 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE" 161 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL"
162 "&url=http://www.example.com/"); 162 "&url=http://www.example.com/");
163 163
164 EXPECT_CALL(*mock_image_fetcher_, 164 EXPECT_CALL(*mock_image_fetcher_,
165 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) 165 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _))
166 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( 166 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
167 CreateTestSkBitmap(64, 64, kTestColor)))); 167 CreateTestSkBitmap(64, 64, kTestColor))));
168 // Verify that the non-trimmed page URL is used when writing to the database. 168 // Verify that the non-trimmed page URL is used when writing to the database.
169 EXPECT_CALL(mock_favicon_service_, 169 EXPECT_CALL(mock_favicon_service_,
170 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _)); 170 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _));
171 171
(...skipping 18 matching lines...) Expand all
190 GURL(kDummyFtpUrl), /*min_source_size_in_pixel=*/42, callback.Get()); 190 GURL(kDummyFtpUrl), /*min_source_size_in_pixel=*/42, callback.Get());
191 191
192 EXPECT_CALL(callback, Run(false)); 192 EXPECT_CALL(callback, Run(false));
193 base::RunLoop().RunUntilIdle(); 193 base::RunLoop().RunUntilIdle();
194 } 194 }
195 195
196 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) { 196 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) {
197 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); 197 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1");
198 const GURL kExpectedServerUrl( 198 const GURL kExpectedServerUrl(
199 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 199 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
200 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE" 200 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL"
201 "&url=http://www.example.com/"); 201 "&url=http://www.example.com/");
202 202
203 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) 203 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _))
204 .Times(0); 204 .Times(0);
205 205
206 base::MockCallback<base::Callback<void(bool success)>> callback; 206 base::MockCallback<base::Callback<void(bool success)>> callback;
207 EXPECT_CALL(*mock_image_fetcher_, 207 EXPECT_CALL(*mock_image_fetcher_,
208 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _)) 208 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _))
209 .WillOnce(PostFetchReply(gfx::Image())); 209 .WillOnce(PostFetchReply(gfx::Image()));
210 EXPECT_CALL(mock_favicon_service_, 210 EXPECT_CALL(mock_favicon_service_,
211 UnableToDownloadFavicon(kExpectedServerUrl)); 211 UnableToDownloadFavicon(kExpectedServerUrl));
212 212
213 large_icon_service_ 213 large_icon_service_
214 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 214 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
215 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42, callback.Get()); 215 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42, callback.Get());
216 216
217 EXPECT_CALL(callback, Run(false)); 217 EXPECT_CALL(callback, Run(false));
218 base::RunLoop().RunUntilIdle(); 218 base::RunLoop().RunUntilIdle();
219 } 219 }
220 220
221 TEST_F(LargeIconServiceTest, ShoutNotGetFromGoogleServerIfUnavailable) { 221 TEST_F(LargeIconServiceTest, ShoutNotGetFromGoogleServerIfUnavailable) {
222 ON_CALL( 222 ON_CALL(
223 mock_favicon_service_, 223 mock_favicon_service_,
224 WasUnableToDownloadFavicon(GURL( 224 WasUnableToDownloadFavicon(GURL(
225 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 225 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
226 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE" 226 "&size=64&min_size=42&max_size=128&fallback_opts=TYPE,SIZE,URL"
227 "&url=http://www.example.com/"))) 227 "&url=http://www.example.com/")))
228 .WillByDefault(Return(true)); 228 .WillByDefault(Return(true));
229 229
230 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); 230 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0);
231 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _)) 231 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _))
232 .Times(0); 232 .Times(0);
233 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) 233 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _))
234 .Times(0); 234 .Times(0);
235 235
236 base::MockCallback<base::Callback<void(bool success)>> callback; 236 base::MockCallback<base::Callback<void(bool success)>> callback;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 385
386 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g. 386 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g.
387 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image. 387 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image.
388 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap. 388 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap.
389 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name. 389 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name.
390 LargeIconServiceGetterTest, 390 LargeIconServiceGetterTest,
391 ::testing::Values(false, true)); 391 ::testing::Values(false, true));
392 392
393 } // namespace 393 } // namespace
394 } // namespace favicon 394 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/large_icon_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698