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/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 Loading... |
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 } |
| 195 |
167 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) { | 196 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) { |
168 const GURL kExpectedServerUrl( | 197 const GURL kExpectedServerUrl( |
169 "https://t0.gstatic.com/faviconV2?client=chrome&drop_404_icon=true" | 198 "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" | 199 "&size=32&min_size=42&max_size=64&fallback_opts=TYPE,SIZE,URL" |
171 "&url=http://www.example.com/"); | 200 "&url=http://www.example.com/"); |
172 const GURL kExpectedOriginalUrl("http://www.example.com/favicon.png"); | 201 const GURL kExpectedOriginalUrl("http://www.example.com/favicon.png"); |
173 | 202 |
174 image_fetcher::RequestMetadata expected_metadata; | 203 image_fetcher::RequestMetadata expected_metadata; |
175 expected_metadata.content_location_header = kExpectedOriginalUrl.spec(); | 204 expected_metadata.content_location_header = kExpectedOriginalUrl.spec(); |
176 EXPECT_CALL(*mock_image_fetcher_, | 205 EXPECT_CALL(*mock_image_fetcher_, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 472 |
444 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g. | 473 // Every test will appear with suffix /0 (param false) and /1 (param true), e.g. |
445 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image. | 474 // LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image. |
446 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap. | 475 // LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap. |
447 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name. | 476 INSTANTIATE_TEST_CASE_P(, // Empty instatiation name. |
448 LargeIconServiceGetterTest, | 477 LargeIconServiceGetterTest, |
449 ::testing::Values(false, true)); | 478 ::testing::Values(false, true)); |
450 | 479 |
451 } // namespace | 480 } // namespace |
452 } // namespace favicon | 481 } // namespace favicon |
OLD | NEW |