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

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

Issue 2852383002: [LargeIconService] Add a unit-test for overriding request URL (Closed)
Patch Set: 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
« no previous file with comments | « components/favicon/core/DEPS ('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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/task/cancelable_task_tracker.h" 16 #include "base/task/cancelable_task_tracker.h"
17 #include "base/test/histogram_tester.h" 17 #include "base/test/histogram_tester.h"
18 #include "base/test/mock_callback.h" 18 #include "base/test/mock_callback.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "components/favicon/core/favicon_client.h" 20 #include "components/favicon/core/favicon_client.h"
21 #include "components/favicon/core/test/mock_favicon_service.h" 21 #include "components/favicon/core/test/mock_favicon_service.h"
22 #include "components/favicon_base/fallback_icon_style.h" 22 #include "components/favicon_base/fallback_icon_style.h"
23 #include "components/favicon_base/favicon_types.h" 23 #include "components/favicon_base/favicon_types.h"
24 #include "components/image_fetcher/core/image_fetcher.h" 24 #include "components/image_fetcher/core/image_fetcher.h"
25 #include "components/image_fetcher/core/request_metadata.h" 25 #include "components/image_fetcher/core/request_metadata.h"
26 #include "components/variations/variations_params_manager.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 29 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "third_party/skia/include/core/SkColor.h" 30 #include "third_party/skia/include/core/SkColor.h"
30 #include "ui/gfx/codec/png_codec.h" 31 #include "ui/gfx/codec/png_codec.h"
31 #include "ui/gfx/geometry/size.h" 32 #include "ui/gfx/geometry/size.h"
32 #include "ui/gfx/image/image.h" 33 #include "ui/gfx/image/image.h"
33 #include "ui/gfx/image/image_skia.h" 34 #include "ui/gfx/image/image_skia.h"
34 #include "url/gurl.h" 35 #include "url/gurl.h"
35 36
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 large_icon_service_ 158 large_icon_service_
158 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 159 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
159 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); 160 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get());
160 161
161 EXPECT_CALL(callback, Run(true)); 162 EXPECT_CALL(callback, Run(true));
162 base::RunLoop().RunUntilIdle(); 163 base::RunLoop().RunUntilIdle();
163 histogram_tester_.ExpectUniqueSample( 164 histogram_tester_.ExpectUniqueSample(
164 "Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1); 165 "Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1);
165 } 166 }
166 167
168 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithCustomUrl) {
169 variations::testing::VariationParamsManager variation_params(
170 "LargeIconServiceFetching",
171 {{"request_format", "https://t0.gstatic.com/faviconV2?size=%d&url=%s"}},
172 {"LargeIconServiceFetching"});
173 const GURL kExpectedServerUrl(
174 "https://t0.gstatic.com/faviconV2?size=42&url=http://www.example.com/");
175
176 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0);
177
178 base::MockCallback<base::Callback<void(bool success)>> callback;
179 EXPECT_CALL(*mock_image_fetcher_,
180 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _))
181 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
182 CreateTestSkBitmap(64, 64, kTestColor))));
183 EXPECT_CALL(mock_favicon_service_,
184 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl,
185 favicon_base::IconType::TOUCH_ICON, _, _))
186 .WillOnce(PostBoolReply(true));
187
188 large_icon_service_
189 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
190 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get());
191
192 EXPECT_CALL(callback, Run(true));
193 base::RunLoop().RunUntilIdle();
194 histogram_tester_.ExpectUniqueSample(
195 "Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1);
pkotwicz 2017/05/03 17:35:20 Checking the histogram is unrelated to the main go
jkrcal 2017/05/04 15:37:39 Correct, removed.
196 }
197
167 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) { 198 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) {
168 const GURL kExpectedServerUrl( 199 const GURL kExpectedServerUrl(
169 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" 200 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true"
170 "&size=32&min_size=42&max_size=64&fallback_opts=TYPE,SIZE,URL" 201 "&size=32&min_size=42&max_size=64&fallback_opts=TYPE,SIZE,URL"
171 "&url=http://www.example.com/"); 202 "&url=http://www.example.com/");
172 const GURL kExpectedOriginalUrl("http://www.example.com/favicon.png"); 203 const GURL kExpectedOriginalUrl("http://www.example.com/favicon.png");
173 204
174 image_fetcher::RequestMetadata expected_metadata; 205 image_fetcher::RequestMetadata expected_metadata;
175 expected_metadata.content_location_header = kExpectedOriginalUrl.spec(); 206 expected_metadata.content_location_header = kExpectedOriginalUrl.spec();
176 EXPECT_CALL(*mock_image_fetcher_, 207 EXPECT_CALL(*mock_image_fetcher_,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 474
444 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g. 475 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g.
445 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image. 476 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image.
446 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap. 477 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap.
447 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name. 478 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name.
448 LargeIconServiceGetterTest, 479 LargeIconServiceGetterTest,
449 ::testing::Values(false, true)); 480 ::testing::Values(false, true));
450 481
451 } // namespace 482 } // namespace
452 } // namespace favicon 483 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698