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

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

Issue 2896803002: [LargeIconService] Make check_seen param optional for fetching (Closed)
Patch Set: Fix compilation 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 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( 152 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
153 CreateTestSkBitmap(64, 64, kTestColor)))); 153 CreateTestSkBitmap(64, 64, kTestColor))));
154 EXPECT_CALL(mock_favicon_service_, 154 EXPECT_CALL(mock_favicon_service_,
155 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl, 155 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl,
156 favicon_base::IconType::TOUCH_ICON, _, _)) 156 favicon_base::IconType::TOUCH_ICON, _, _))
157 .WillOnce(PostBoolReply(true)); 157 .WillOnce(PostBoolReply(true));
158 158
159 large_icon_service_ 159 large_icon_service_
160 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 160 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
161 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, 161 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42,
162 /*desired_size_in_pixel=*/61, callback.Get()); 162 /*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true,
163 callback.Get());
163 164
164 EXPECT_CALL(callback, Run(true)); 165 EXPECT_CALL(callback, Run(true));
165 base::RunLoop().RunUntilIdle(); 166 base::RunLoop().RunUntilIdle();
166 histogram_tester_.ExpectUniqueSample( 167 histogram_tester_.ExpectUniqueSample(
167 "Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1); 168 "Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1);
168 } 169 }
169 170
170 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithCustomUrl) { 171 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithCustomUrl) {
171 variations::testing::VariationParamsManager variation_params( 172 variations::testing::VariationParamsManager variation_params(
172 "LargeIconServiceFetching", 173 "LargeIconServiceFetching",
173 {{"request_format", 174 {{"request_format",
174 "https://t0.gstatic.com/" 175 "https://t0.gstatic.com/"
175 "faviconV2?size=%d&min_size=%d&max_size=%d&url=%s"}, 176 "faviconV2?%ssize=%d&min_size=%d&max_size=%d&url=%s"},
176 {"enforced_min_size_in_pixel", "43"}, 177 {"enforced_min_size_in_pixel", "43"},
177 {"desired_to_max_size_factor", "1.5"}}, 178 {"desired_to_max_size_factor", "1.5"}},
178 {"LargeIconServiceFetching"}); 179 {"LargeIconServiceFetching"});
179 const GURL kExpectedServerUrl( 180 const GURL kExpectedServerUrl(
180 "https://t0.gstatic.com/" 181 "https://t0.gstatic.com/faviconV2?check_seen=true&"
181 "faviconV2?size=61&min_size=43&max_size=91&url=http://www.example.com/"); 182 "size=61&min_size=43&max_size=91&url=http://www.example.com/");
182 183
183 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); 184 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0);
184 185
185 base::MockCallback<base::Callback<void(bool success)>> callback; 186 base::MockCallback<base::Callback<void(bool success)>> callback;
186 EXPECT_CALL(*mock_image_fetcher_, 187 EXPECT_CALL(*mock_image_fetcher_,
187 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _, _)) 188 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _, _))
188 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( 189 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
189 CreateTestSkBitmap(64, 64, kTestColor)))); 190 CreateTestSkBitmap(64, 64, kTestColor))));
190 EXPECT_CALL(mock_favicon_service_, 191 EXPECT_CALL(mock_favicon_service_,
191 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl, 192 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl,
192 favicon_base::IconType::TOUCH_ICON, _, _)) 193 favicon_base::IconType::TOUCH_ICON, _, _))
193 .WillOnce(PostBoolReply(true)); 194 .WillOnce(PostBoolReply(true));
194 195
195 large_icon_service_ 196 large_icon_service_
196 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 197 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
197 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, 198 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42,
198 /*desired_size_in_pixel=*/61, callback.Get()); 199 /*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true,
200 callback.Get());
199 201
200 EXPECT_CALL(callback, Run(true)); 202 EXPECT_CALL(callback, Run(true));
201 base::RunLoop().RunUntilIdle(); 203 base::RunLoop().RunUntilIdle();
202 } 204 }
203 205
204 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) { 206 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) {
205 const GURL kExpectedServerUrl( 207 const GURL kExpectedServerUrl(
206 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 208 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
207 "&check_seen=true&size=61&min_size=42&max_size=122" 209 "&check_seen=true&size=61&min_size=42&max_size=122"
208 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/"); 210 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/");
209 const GURL kExpectedOriginalUrl("http://www.example.com/favicon.png"); 211 const GURL kExpectedOriginalUrl("http://www.example.com/favicon.png");
210 212
211 image_fetcher::RequestMetadata expected_metadata; 213 image_fetcher::RequestMetadata expected_metadata;
212 expected_metadata.content_location_header = kExpectedOriginalUrl.spec(); 214 expected_metadata.content_location_header = kExpectedOriginalUrl.spec();
213 EXPECT_CALL(*mock_image_fetcher_, 215 EXPECT_CALL(*mock_image_fetcher_,
214 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _, _)) 216 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _, _))
215 .WillOnce(PostFetchReplyWithMetadata( 217 .WillOnce(PostFetchReplyWithMetadata(
216 gfx::Image::CreateFrom1xBitmap( 218 gfx::Image::CreateFrom1xBitmap(
217 CreateTestSkBitmap(64, 64, kTestColor)), 219 CreateTestSkBitmap(64, 64, kTestColor)),
218 expected_metadata)); 220 expected_metadata));
219 EXPECT_CALL(mock_favicon_service_, 221 EXPECT_CALL(mock_favicon_service_,
220 SetLastResortFavicons(GURL(kDummyUrl), kExpectedOriginalUrl, 222 SetLastResortFavicons(GURL(kDummyUrl), kExpectedOriginalUrl,
221 favicon_base::IconType::TOUCH_ICON, _, _)) 223 favicon_base::IconType::TOUCH_ICON, _, _))
222 .WillOnce(PostBoolReply(true)); 224 .WillOnce(PostBoolReply(true));
223 225
224 base::MockCallback<base::Callback<void(bool success)>> callback; 226 base::MockCallback<base::Callback<void(bool success)>> callback;
225 large_icon_service_ 227 large_icon_service_
226 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 228 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
227 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, 229 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42,
228 /*desired_size_in_pixel=*/61, callback.Get()); 230 /*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true,
231 callback.Get());
229 232
230 EXPECT_CALL(callback, Run(true)); 233 EXPECT_CALL(callback, Run(true));
231 base::RunLoop().RunUntilIdle(); 234 base::RunLoop().RunUntilIdle();
232 } 235 }
233 236
234 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) { 237 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) {
235 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); 238 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1");
236 const GURL kExpectedServerUrl( 239 const GURL kExpectedServerUrl(
237 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 240 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
238 "&check_seen=true&size=61&min_size=42&max_size=122" 241 "&check_seen=true&size=61&min_size=42&max_size=122"
239 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/"); 242 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/");
240 243
241 EXPECT_CALL(*mock_image_fetcher_, 244 EXPECT_CALL(*mock_image_fetcher_,
242 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _, _)) 245 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _, _))
243 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( 246 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
244 CreateTestSkBitmap(64, 64, kTestColor)))); 247 CreateTestSkBitmap(64, 64, kTestColor))));
245 // Verify that the non-trimmed page URL is used when writing to the database. 248 // Verify that the non-trimmed page URL is used when writing to the database.
246 EXPECT_CALL(mock_favicon_service_, 249 EXPECT_CALL(mock_favicon_service_,
247 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _)); 250 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _));
248 251
249 large_icon_service_ 252 large_icon_service_
250 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 253 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
251 GURL(kDummyUrlWithQuery), /*min_source_size_in_pixel=*/42, 254 GURL(kDummyUrlWithQuery), /*min_source_size_in_pixel=*/42,
252 /*desired_size_in_pixel=*/61, base::Callback<void(bool success)>()); 255 /*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true,
256 base::Callback<void(bool success)>());
253 257
254 base::RunLoop().RunUntilIdle(); 258 base::RunLoop().RunUntilIdle();
255 } 259 }
260
261 TEST_F(LargeIconServiceTest, ShouldNotCheckOnPublicUrls) {
pkotwicz 2017/05/24 05:02:25 There is a lot of boiler plate code which is dupli
mastiz 2017/05/24 05:55:16 My two cents: I consider this last proposal an ant
jkrcal 2017/05/24 08:54:48 You are right, the tests can be made crisper. I st
262 const GURL kExpectedServerUrlWithoutCheck(
263 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
264 "&size=61&min_size=42&max_size=122"
265 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/");
266
267 EXPECT_CALL(
268 *mock_image_fetcher_,
269 StartOrQueueNetworkRequest(_, kExpectedServerUrlWithoutCheck, _, _))
270 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
271 CreateTestSkBitmap(64, 64, kTestColor))));
272 EXPECT_CALL(
273 mock_favicon_service_,
274 SetLastResortFavicons(_, kExpectedServerUrlWithoutCheck, _, _, _));
275
276 large_icon_service_
277 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
278 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42,
279 /*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/false,
280 base::Callback<void(bool success)>());
281
282 base::RunLoop().RunUntilIdle();
283 }
256 284
257 TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidScheme) { 285 TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidScheme) {
258 const GURL kDummyFtpUrl("ftp://www.example.com"); 286 const GURL kDummyFtpUrl("ftp://www.example.com");
259 287
260 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _, _)) 288 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _, _))
261 .Times(0); 289 .Times(0);
262 290
263 base::MockCallback<base::Callback<void(bool success)>> callback; 291 base::MockCallback<base::Callback<void(bool success)>> callback;
264 292
265 large_icon_service_ 293 large_icon_service_
266 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 294 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
267 GURL(kDummyFtpUrl), /*min_source_size_in_pixel=*/42, 295 GURL(kDummyFtpUrl), /*min_source_size_in_pixel=*/42,
268 /*desired_size_in_pixel=*/61, callback.Get()); 296 /*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true,
297 callback.Get());
269 298
270 EXPECT_CALL(callback, Run(false)); 299 EXPECT_CALL(callback, Run(false));
271 base::RunLoop().RunUntilIdle(); 300 base::RunLoop().RunUntilIdle();
272 EXPECT_THAT(histogram_tester_.GetAllSamples( 301 EXPECT_THAT(histogram_tester_.GetAllSamples(
273 "Favicons.LargeIconService.DownloadedSize"), 302 "Favicons.LargeIconService.DownloadedSize"),
274 IsEmpty()); 303 IsEmpty());
275 } 304 }
276 305
277 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) { 306 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) {
278 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1"); 307 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1");
279 const GURL kExpectedServerUrl( 308 const GURL kExpectedServerUrl(
280 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 309 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
281 "&check_seen=true&size=61&min_size=42&max_size=122" 310 "&check_seen=true&size=61&min_size=42&max_size=122"
282 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/"); 311 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/");
283 312
284 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) 313 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _))
285 .Times(0); 314 .Times(0);
286 315
287 base::MockCallback<base::Callback<void(bool success)>> callback; 316 base::MockCallback<base::Callback<void(bool success)>> callback;
288 EXPECT_CALL(*mock_image_fetcher_, 317 EXPECT_CALL(*mock_image_fetcher_,
289 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _, _)) 318 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _, _))
290 .WillOnce(PostFetchReply(gfx::Image())); 319 .WillOnce(PostFetchReply(gfx::Image()));
291 EXPECT_CALL(mock_favicon_service_, 320 EXPECT_CALL(mock_favicon_service_,
292 UnableToDownloadFavicon(kExpectedServerUrl)); 321 UnableToDownloadFavicon(kExpectedServerUrl));
293 322
294 large_icon_service_ 323 large_icon_service_
295 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 324 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
296 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42, 325 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42,
297 /*desired_size_in_pixel=*/61, callback.Get()); 326 /*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true,
327 callback.Get());
298 328
299 EXPECT_CALL(callback, Run(false)); 329 EXPECT_CALL(callback, Run(false));
300 base::RunLoop().RunUntilIdle(); 330 base::RunLoop().RunUntilIdle();
301 // Verify that download failure gets recorded. 331 // Verify that download failure gets recorded.
302 histogram_tester_.ExpectUniqueSample( 332 histogram_tester_.ExpectUniqueSample(
303 "Favicons.LargeIconService.DownloadedSize", 0, /*expected_count=*/1); 333 "Favicons.LargeIconService.DownloadedSize", 0, /*expected_count=*/1);
304 } 334 }
305 335
306 TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfUnavailable) { 336 TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfUnavailable) {
307 ON_CALL( 337 ON_CALL(
308 mock_favicon_service_, 338 mock_favicon_service_,
309 WasUnableToDownloadFavicon(GURL( 339 WasUnableToDownloadFavicon(GURL(
310 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 340 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
311 "&check_seen=true&size=61&min_size=42&max_size=122" 341 "&check_seen=true&size=61&min_size=42&max_size=122"
312 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/"))) 342 "&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/")))
313 .WillByDefault(Return(true)); 343 .WillByDefault(Return(true));
314 344
315 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); 345 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0);
316 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _, _)) 346 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _, _))
317 .Times(0); 347 .Times(0);
318 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) 348 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _))
319 .Times(0); 349 .Times(0);
320 350
321 base::MockCallback<base::Callback<void(bool success)>> callback; 351 base::MockCallback<base::Callback<void(bool success)>> callback;
322 large_icon_service_ 352 large_icon_service_
323 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 353 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
324 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, 354 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42,
325 /*desired_size_in_pixel=*/61, callback.Get()); 355 /*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true,
356 callback.Get());
326 357
327 EXPECT_CALL(callback, Run(false)); 358 EXPECT_CALL(callback, Run(false));
328 base::RunLoop().RunUntilIdle(); 359 base::RunLoop().RunUntilIdle();
329 EXPECT_THAT(histogram_tester_.GetAllSamples( 360 EXPECT_THAT(histogram_tester_.GetAllSamples(
330 "Favicons.LargeIconService.DownloadedSize"), 361 "Favicons.LargeIconService.DownloadedSize"),
331 IsEmpty()); 362 IsEmpty());
332 } 363 }
333 364
334 class LargeIconServiceGetterTest : public LargeIconServiceTest, 365 class LargeIconServiceGetterTest : public LargeIconServiceTest,
335 public ::testing::WithParamInterface<bool> { 366 public ::testing::WithParamInterface<bool> {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 515
485 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g. 516 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g.
486 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image. 517 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image.
487 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap. 518 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap.
488 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name. 519 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name.
489 LargeIconServiceGetterTest, 520 LargeIconServiceGetterTest,
490 ::testing::Values(false, true)); 521 ::testing::Values(false, true));
491 522
492 } // namespace 523 } // namespace
493 } // namespace favicon 524 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698