Chromium Code Reviews| 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/mock_callback.h" | 17 #include "base/test/mock_callback.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "components/favicon/core/favicon_client.h" | 19 #include "components/favicon/core/favicon_client.h" |
| 20 #include "components/favicon/core/test/mock_favicon_service.h" | 20 #include "components/favicon/core/test/mock_favicon_service.h" |
| 21 #include "components/favicon_base/fallback_icon_style.h" | 21 #include "components/favicon_base/fallback_icon_style.h" |
| 22 #include "components/favicon_base/favicon_types.h" | 22 #include "components/favicon_base/favicon_types.h" |
| 23 #include "components/image_fetcher/core/image_decoder.h" | |
| 23 #include "components/image_fetcher/core/image_fetcher.h" | 24 #include "components/image_fetcher/core/image_fetcher.h" |
| 24 #include "components/image_fetcher/core/request_metadata.h" | 25 #include "components/image_fetcher/core/request_metadata.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 #include "third_party/skia/include/core/SkColor.h" | 29 #include "third_party/skia/include/core/SkColor.h" |
| 29 #include "ui/gfx/codec/png_codec.h" | 30 #include "ui/gfx/codec/png_codec.h" |
| 30 #include "ui/gfx/geometry/size.h" | 31 #include "ui/gfx/geometry/size.h" |
| 31 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
| 33 #include "ui/gfx/image/image_skia.h" | |
| 32 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 33 | 35 |
| 34 namespace favicon { | 36 namespace favicon { |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 using testing::NiceMock; | 39 using testing::NiceMock; |
| 38 using testing::Return; | 40 using testing::Return; |
| 39 using testing::SaveArg; | 41 using testing::SaveArg; |
| 40 using testing::_; | 42 using testing::_; |
| 41 | 43 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 MOCK_METHOD1(SetImageDownloadLimit, | 92 MOCK_METHOD1(SetImageDownloadLimit, |
| 91 void(base::Optional<int64_t> max_download_bytes)); | 93 void(base::Optional<int64_t> max_download_bytes)); |
| 92 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size& size)); | 94 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size& size)); |
| 93 MOCK_METHOD3(StartOrQueueNetworkRequest, | 95 MOCK_METHOD3(StartOrQueueNetworkRequest, |
| 94 void(const std::string&, | 96 void(const std::string&, |
| 95 const GURL&, | 97 const GURL&, |
| 96 const ImageFetcherCallback&)); | 98 const ImageFetcherCallback&)); |
| 97 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); | 99 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); |
| 98 }; | 100 }; |
| 99 | 101 |
| 102 class FakeImageDecoder : public image_fetcher::ImageDecoder { | |
| 103 public: | |
| 104 void DecodeImage( | |
| 105 const std::string& image_data, | |
| 106 const gfx::Size& desired_image_frame_size, | |
| 107 const image_fetcher::ImageDecodedCallback& callback) override { | |
| 108 callback.Run(gfx::Image::CreateFrom1xPNGBytes( | |
| 109 reinterpret_cast<const unsigned char*>(image_data.data()), | |
| 110 image_data.size())); | |
| 111 } | |
| 112 }; | |
| 113 | |
| 100 class LargeIconServiceTest : public testing::Test { | 114 class LargeIconServiceTest : public testing::Test { |
| 101 public: | 115 public: |
| 102 LargeIconServiceTest() | 116 LargeIconServiceTest() |
| 103 : mock_image_fetcher_(new NiceMock<MockImageFetcher>()), | 117 : mock_image_fetcher_(new NiceMock<MockImageFetcher>()), |
| 104 large_icon_service_(&mock_favicon_service_, | 118 large_icon_service_(&mock_favicon_service_, |
| 105 base::ThreadTaskRunnerHandle::Get(), | 119 base::ThreadTaskRunnerHandle::Get(), |
| 106 base::WrapUnique(mock_image_fetcher_)), | 120 base::WrapUnique(mock_image_fetcher_)), |
| 107 is_callback_invoked_(false) {} | 121 is_callback_invoked_(false) { |
| 108 | 122 ON_CALL(*mock_image_fetcher_, GetImageDecoder()) |
| 109 ~LargeIconServiceTest() override { | 123 .WillByDefault(Return(&fake_image_decoder_)); |
| 110 } | 124 } |
| 111 | 125 |
| 112 void ResultCallback(const favicon_base::LargeIconResult& result) { | 126 ~LargeIconServiceTest() override {} |
| 127 | |
| 128 void RawBitmapResultCallback(const favicon_base::LargeIconResult& result) { | |
| 113 is_callback_invoked_ = true; | 129 is_callback_invoked_ = true; |
| 114 | 130 |
| 115 // Checking presence and absence of results. | 131 // Checking presence and absence of results. |
| 116 EXPECT_EQ(expected_bitmap_.is_valid(), result.bitmap.is_valid()); | 132 EXPECT_EQ(expected_bitmap_.is_valid(), result.bitmap.is_valid()); |
| 117 EXPECT_EQ(expected_fallback_icon_style_ != nullptr, | 133 EXPECT_EQ(expected_fallback_icon_style_ != nullptr, |
| 118 result.fallback_icon_style != nullptr); | 134 result.fallback_icon_style != nullptr); |
| 119 | 135 |
| 120 if (expected_bitmap_.is_valid()) { | 136 if (expected_bitmap_.is_valid()) { |
| 121 EXPECT_EQ(expected_bitmap_.pixel_size, result.bitmap.pixel_size); | 137 EXPECT_EQ(expected_bitmap_.pixel_size, result.bitmap.pixel_size); |
| 122 // Not actually checking bitmap content. | 138 // Not actually checking bitmap content. |
| 123 } | 139 } |
| 124 if (expected_fallback_icon_style_.get()) { | 140 if (expected_fallback_icon_style_.get()) { |
| 125 EXPECT_EQ(*expected_fallback_icon_style_, | 141 EXPECT_EQ(*expected_fallback_icon_style_, *result.fallback_icon_style); |
| 126 *result.fallback_icon_style); | |
| 127 } | 142 } |
| 128 } | 143 } |
| 129 | 144 |
| 145 void ImageResultCallback(const favicon_base::LargeIconImageResult& result) { | |
| 146 is_callback_invoked_ = true; | |
| 147 | |
| 148 // Checking presence and absence of results. | |
| 149 EXPECT_EQ(expected_bitmap_.is_valid(), !result.image.IsEmpty()); | |
| 150 EXPECT_EQ(expected_fallback_icon_style_ != nullptr, | |
| 151 result.fallback_icon_style != nullptr); | |
| 152 | |
| 153 if (expected_bitmap_.is_valid()) { | |
| 154 EXPECT_EQ(expected_bitmap_.pixel_size, | |
| 155 result.image.ToImageSkia()->size()); | |
| 156 // Not actually checking bitmap content. | |
| 157 } | |
| 158 if (expected_fallback_icon_style_.get()) { | |
| 159 EXPECT_EQ(*expected_fallback_icon_style_, *result.fallback_icon_style); | |
| 160 } | |
| 161 } | |
| 162 | |
| 130 void InjectMockResult( | 163 void InjectMockResult( |
| 131 const GURL& page_url, | 164 const GURL& page_url, |
| 132 const favicon_base::FaviconRawBitmapResult& mock_result) { | 165 const favicon_base::FaviconRawBitmapResult& mock_result) { |
| 133 EXPECT_CALL(mock_favicon_service_, | 166 EXPECT_CALL(mock_favicon_service_, |
| 134 GetLargestRawFaviconForPageURL(page_url, _, _, _, _)) | 167 GetLargestRawFaviconForPageURL(page_url, _, _, _, _)) |
| 135 .WillOnce(PostReply<5>(mock_result)); | 168 .WillOnce(PostReply<5>(mock_result)); |
| 136 } | 169 } |
| 137 | 170 |
| 138 protected: | 171 protected: |
| 139 base::MessageLoopForIO loop_; | 172 base::MessageLoopForIO loop_; |
| 140 | 173 |
| 141 NiceMock<MockImageFetcher>* mock_image_fetcher_; | 174 NiceMock<MockImageFetcher>* mock_image_fetcher_; |
| 175 FakeImageDecoder fake_image_decoder_; | |
| 142 testing::NiceMock<MockFaviconService> mock_favicon_service_; | 176 testing::NiceMock<MockFaviconService> mock_favicon_service_; |
| 143 LargeIconService large_icon_service_; | 177 LargeIconService large_icon_service_; |
| 144 base::CancelableTaskTracker cancelable_task_tracker_; | 178 base::CancelableTaskTracker cancelable_task_tracker_; |
| 145 | 179 |
| 146 favicon_base::FaviconRawBitmapResult expected_bitmap_; | 180 favicon_base::FaviconRawBitmapResult expected_bitmap_; |
| 147 std::unique_ptr<favicon_base::FallbackIconStyle> | 181 std::unique_ptr<favicon_base::FallbackIconStyle> |
| 148 expected_fallback_icon_style_; | 182 expected_fallback_icon_style_; |
| 149 | 183 |
| 150 bool is_callback_invoked_; | 184 bool is_callback_invoked_; |
| 151 | 185 |
| 152 private: | 186 private: |
| 153 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); | 187 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); |
| 154 }; | 188 }; |
| 155 | 189 |
| 156 TEST_F(LargeIconServiceTest, SameSize) { | 190 TEST_F(LargeIconServiceTest, RawBitmapSameSize) { |
|
jkrcal
2017/03/30 13:10:46
I am duplicating most of the tests. I was thinking
pkotwicz
2017/03/30 19:14:23
I don't think that duplicating the tests is worth
jkrcal
2017/03/31 12:31:11
In the current version, the new function is not a
| |
| 157 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); | 191 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); |
| 158 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); | 192 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 159 large_icon_service_.GetLargeIconOrFallbackStyle( | 193 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 160 GURL(kDummyUrl), | 194 GURL(kDummyUrl), |
| 161 24, // |min_source_size_in_pixel| | 195 24, // |min_source_size_in_pixel| |
| 162 24, // |desired_size_in_pixel| | 196 24, // |desired_size_in_pixel| |
| 163 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 197 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, |
| 164 &cancelable_task_tracker_); | 198 base::Unretained(this)), |
| 165 base::RunLoop().RunUntilIdle(); | 199 &cancelable_task_tracker_); |
| 166 EXPECT_TRUE(is_callback_invoked_); | 200 base::RunLoop().RunUntilIdle(); |
| 167 } | 201 EXPECT_TRUE(is_callback_invoked_); |
| 168 | 202 } |
| 169 TEST_F(LargeIconServiceTest, ScaleDown) { | 203 |
| 204 TEST_F(LargeIconServiceTest, ImageSameSize) { | |
| 205 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); | |
| 206 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); | |
| 207 large_icon_service_.GetLargeIconImageOrFallbackStyle( | |
| 208 GURL(kDummyUrl), | |
| 209 24, // |min_source_size_in_pixel| | |
| 210 24, // |desired_size_in_pixel| | |
| 211 base::Bind(&LargeIconServiceTest::ImageResultCallback, | |
| 212 base::Unretained(this)), | |
| 213 &cancelable_task_tracker_); | |
| 214 base::RunLoop().RunUntilIdle(); | |
| 215 EXPECT_TRUE(is_callback_invoked_); | |
| 216 } | |
| 217 | |
| 218 TEST_F(LargeIconServiceTest, RawBitmapScaleDown) { | |
| 170 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(32, 32, kTestColor)); | 219 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(32, 32, kTestColor)); |
| 171 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); | 220 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 172 large_icon_service_.GetLargeIconOrFallbackStyle( | 221 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 173 GURL(kDummyUrl), 24, 24, | 222 GURL(kDummyUrl), 24, 24, |
| 174 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 223 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, |
| 175 &cancelable_task_tracker_); | 224 base::Unretained(this)), |
| 176 base::RunLoop().RunUntilIdle(); | 225 &cancelable_task_tracker_); |
| 177 EXPECT_TRUE(is_callback_invoked_); | 226 base::RunLoop().RunUntilIdle(); |
| 178 } | 227 EXPECT_TRUE(is_callback_invoked_); |
| 179 | 228 } |
| 180 TEST_F(LargeIconServiceTest, ScaleUp) { | 229 |
| 230 TEST_F(LargeIconServiceTest, ImageScaleDown) { | |
| 231 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(32, 32, kTestColor)); | |
| 232 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); | |
| 233 large_icon_service_.GetLargeIconImageOrFallbackStyle( | |
| 234 GURL(kDummyUrl), 24, 24, | |
| 235 base::Bind(&LargeIconServiceTest::ImageResultCallback, | |
| 236 base::Unretained(this)), | |
| 237 &cancelable_task_tracker_); | |
| 238 base::RunLoop().RunUntilIdle(); | |
| 239 EXPECT_TRUE(is_callback_invoked_); | |
| 240 } | |
| 241 | |
| 242 TEST_F(LargeIconServiceTest, RawBitmapScaleUp) { | |
| 181 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(16, 16, kTestColor)); | 243 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(16, 16, kTestColor)); |
| 182 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); | 244 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 183 large_icon_service_.GetLargeIconOrFallbackStyle( | 245 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 184 GURL(kDummyUrl), | 246 GURL(kDummyUrl), |
| 185 14, // Lowered requirement so stored bitmap is admitted. | 247 14, // Lowered requirement so stored bitmap is admitted. |
| 186 24, | 248 24, |
| 187 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 249 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, |
| 250 base::Unretained(this)), | |
| 251 &cancelable_task_tracker_); | |
| 252 base::RunLoop().RunUntilIdle(); | |
| 253 EXPECT_TRUE(is_callback_invoked_); | |
| 254 } | |
| 255 | |
| 256 TEST_F(LargeIconServiceTest, ImageScaleUp) { | |
| 257 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(16, 16, kTestColor)); | |
| 258 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); | |
| 259 large_icon_service_.GetLargeIconImageOrFallbackStyle( | |
| 260 GURL(kDummyUrl), | |
| 261 14, // Lowered requirement so stored bitmap is admitted. | |
| 262 24, | |
| 263 base::Bind(&LargeIconServiceTest::ImageResultCallback, | |
| 264 base::Unretained(this)), | |
| 188 &cancelable_task_tracker_); | 265 &cancelable_task_tracker_); |
| 189 base::RunLoop().RunUntilIdle(); | 266 base::RunLoop().RunUntilIdle(); |
| 190 EXPECT_TRUE(is_callback_invoked_); | 267 EXPECT_TRUE(is_callback_invoked_); |
| 191 } | 268 } |
| 192 | 269 |
| 193 // |desired_size_in_pixel| == 0 means retrieve original image without scaling. | 270 // |desired_size_in_pixel| == 0 means retrieve original image without scaling. |
| 194 TEST_F(LargeIconServiceTest, NoScale) { | 271 TEST_F(LargeIconServiceTest, RawBitmapNoScale) { |
| 195 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); | 272 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); |
| 196 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); | 273 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 197 large_icon_service_.GetLargeIconOrFallbackStyle( | 274 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 198 GURL(kDummyUrl), 16, 0, | 275 GURL(kDummyUrl), 16, 0, |
| 199 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 276 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, |
| 200 &cancelable_task_tracker_); | 277 base::Unretained(this)), |
| 201 base::RunLoop().RunUntilIdle(); | 278 &cancelable_task_tracker_); |
| 202 EXPECT_TRUE(is_callback_invoked_); | 279 base::RunLoop().RunUntilIdle(); |
| 203 } | 280 EXPECT_TRUE(is_callback_invoked_); |
| 204 | 281 } |
| 205 TEST_F(LargeIconServiceTest, FallbackSinceIconTooSmall) { | 282 |
| 206 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(16, 16, kTestColor)); | 283 // |desired_size_in_pixel| == 0 means retrieve original image without scaling. |
| 207 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | 284 TEST_F(LargeIconServiceTest, ImageNoScale) { |
| 208 expected_fallback_icon_style_->background_color = kTestColor; | 285 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); |
| 209 expected_fallback_icon_style_->is_default_background_color = false; | 286 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 210 large_icon_service_.GetLargeIconOrFallbackStyle( | 287 large_icon_service_.GetLargeIconImageOrFallbackStyle( |
| 211 GURL(kDummyUrl), 24, 24, | 288 GURL(kDummyUrl), 16, 0, |
| 212 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 289 base::Bind(&LargeIconServiceTest::ImageResultCallback, |
| 213 &cancelable_task_tracker_); | 290 base::Unretained(this)), |
| 214 base::RunLoop().RunUntilIdle(); | 291 &cancelable_task_tracker_); |
| 215 EXPECT_TRUE(is_callback_invoked_); | 292 base::RunLoop().RunUntilIdle(); |
| 216 } | 293 EXPECT_TRUE(is_callback_invoked_); |
| 217 | 294 } |
| 218 TEST_F(LargeIconServiceTest, FallbackSinceIconNotSquare) { | 295 |
| 296 TEST_F(LargeIconServiceTest, RawBitmapFallbackSinceIconTooSmall) { | |
| 297 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(16, 16, kTestColor)); | |
| 298 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | |
| 299 expected_fallback_icon_style_->background_color = kTestColor; | |
| 300 expected_fallback_icon_style_->is_default_background_color = false; | |
| 301 large_icon_service_.GetLargeIconOrFallbackStyle( | |
| 302 GURL(kDummyUrl), 24, 24, | |
| 303 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, | |
| 304 base::Unretained(this)), | |
| 305 &cancelable_task_tracker_); | |
| 306 base::RunLoop().RunUntilIdle(); | |
| 307 EXPECT_TRUE(is_callback_invoked_); | |
| 308 } | |
| 309 | |
| 310 TEST_F(LargeIconServiceTest, ImageFallbackSinceIconTooSmall) { | |
| 311 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(16, 16, kTestColor)); | |
| 312 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | |
| 313 expected_fallback_icon_style_->background_color = kTestColor; | |
| 314 expected_fallback_icon_style_->is_default_background_color = false; | |
| 315 large_icon_service_.GetLargeIconImageOrFallbackStyle( | |
| 316 GURL(kDummyUrl), 24, 24, | |
| 317 base::Bind(&LargeIconServiceTest::ImageResultCallback, | |
| 318 base::Unretained(this)), | |
| 319 &cancelable_task_tracker_); | |
| 320 base::RunLoop().RunUntilIdle(); | |
| 321 EXPECT_TRUE(is_callback_invoked_); | |
| 322 } | |
| 323 | |
| 324 TEST_F(LargeIconServiceTest, RawBitmapFallbackSinceIconNotSquare) { | |
| 219 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 32, kTestColor)); | 325 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 32, kTestColor)); |
| 220 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | 326 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); |
| 221 expected_fallback_icon_style_->background_color = kTestColor; | 327 expected_fallback_icon_style_->background_color = kTestColor; |
| 222 expected_fallback_icon_style_->is_default_background_color = false; | 328 expected_fallback_icon_style_->is_default_background_color = false; |
| 223 large_icon_service_.GetLargeIconOrFallbackStyle( | 329 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 224 GURL(kDummyUrl), 24, 24, | 330 GURL(kDummyUrl), 24, 24, |
| 225 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 331 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, |
| 226 &cancelable_task_tracker_); | 332 base::Unretained(this)), |
| 227 base::RunLoop().RunUntilIdle(); | 333 &cancelable_task_tracker_); |
| 228 EXPECT_TRUE(is_callback_invoked_); | 334 base::RunLoop().RunUntilIdle(); |
| 229 } | 335 EXPECT_TRUE(is_callback_invoked_); |
| 230 | 336 } |
| 231 TEST_F(LargeIconServiceTest, FallbackSinceIconMissing) { | 337 |
| 232 InjectMockResult(GURL(kDummyUrl), favicon_base::FaviconRawBitmapResult()); | 338 TEST_F(LargeIconServiceTest, ImageFallbackSinceIconNotSquare) { |
| 233 // Expect default fallback style, including background. | 339 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 32, kTestColor)); |
| 234 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | 340 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); |
| 235 large_icon_service_.GetLargeIconOrFallbackStyle( | 341 expected_fallback_icon_style_->background_color = kTestColor; |
| 236 GURL(kDummyUrl), 24, 24, | 342 expected_fallback_icon_style_->is_default_background_color = false; |
| 237 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 343 large_icon_service_.GetLargeIconImageOrFallbackStyle( |
| 238 &cancelable_task_tracker_); | 344 GURL(kDummyUrl), 24, 24, |
| 239 base::RunLoop().RunUntilIdle(); | 345 base::Bind(&LargeIconServiceTest::ImageResultCallback, |
| 240 EXPECT_TRUE(is_callback_invoked_); | 346 base::Unretained(this)), |
| 241 } | 347 &cancelable_task_tracker_); |
| 242 | 348 base::RunLoop().RunUntilIdle(); |
| 243 TEST_F(LargeIconServiceTest, FallbackSinceIconMissingNoScale) { | 349 EXPECT_TRUE(is_callback_invoked_); |
| 350 } | |
| 351 | |
| 352 TEST_F(LargeIconServiceTest, RawBitmapFallbackSinceIconMissing) { | |
| 353 InjectMockResult(GURL(kDummyUrl), favicon_base::FaviconRawBitmapResult()); | |
| 354 // Expect default fallback style, including background. | |
| 355 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | |
| 356 large_icon_service_.GetLargeIconOrFallbackStyle( | |
| 357 GURL(kDummyUrl), 24, 24, | |
| 358 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, | |
| 359 base::Unretained(this)), | |
| 360 &cancelable_task_tracker_); | |
| 361 base::RunLoop().RunUntilIdle(); | |
| 362 EXPECT_TRUE(is_callback_invoked_); | |
| 363 } | |
| 364 | |
| 365 TEST_F(LargeIconServiceTest, ImageFallbackSinceIconMissing) { | |
| 366 InjectMockResult(GURL(kDummyUrl), favicon_base::FaviconRawBitmapResult()); | |
| 367 // Expect default fallback style, including background. | |
| 368 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | |
| 369 large_icon_service_.GetLargeIconImageOrFallbackStyle( | |
| 370 GURL(kDummyUrl), 24, 24, | |
| 371 base::Bind(&LargeIconServiceTest::ImageResultCallback, | |
| 372 base::Unretained(this)), | |
| 373 &cancelable_task_tracker_); | |
| 374 base::RunLoop().RunUntilIdle(); | |
| 375 EXPECT_TRUE(is_callback_invoked_); | |
| 376 } | |
| 377 | |
| 378 TEST_F(LargeIconServiceTest, RawBitmapFallbackSinceIconMissingNoScale) { | |
| 244 InjectMockResult(GURL(kDummyUrl), favicon_base::FaviconRawBitmapResult()); | 379 InjectMockResult(GURL(kDummyUrl), favicon_base::FaviconRawBitmapResult()); |
| 245 // Expect default fallback style, including background. | 380 // Expect default fallback style, including background. |
| 246 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | 381 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); |
| 247 large_icon_service_.GetLargeIconOrFallbackStyle( | 382 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 248 GURL(kDummyUrl), 24, 0, | 383 GURL(kDummyUrl), 24, 0, |
| 249 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 384 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, |
| 250 &cancelable_task_tracker_); | 385 base::Unretained(this)), |
| 251 base::RunLoop().RunUntilIdle(); | 386 &cancelable_task_tracker_); |
| 252 EXPECT_TRUE(is_callback_invoked_); | 387 base::RunLoop().RunUntilIdle(); |
| 388 EXPECT_TRUE(is_callback_invoked_); | |
| 389 } | |
| 390 | |
| 391 TEST_F(LargeIconServiceTest, ImageFallbackSinceIconMissingNoScale) { | |
| 392 InjectMockResult(GURL(kDummyUrl), favicon_base::FaviconRawBitmapResult()); | |
| 393 // Expect default fallback style, including background. | |
| 394 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | |
| 395 large_icon_service_.GetLargeIconImageOrFallbackStyle( | |
| 396 GURL(kDummyUrl), 24, 0, | |
| 397 base::Bind(&LargeIconServiceTest::ImageResultCallback, | |
| 398 base::Unretained(this)), | |
| 399 &cancelable_task_tracker_); | |
| 400 base::RunLoop().RunUntilIdle(); | |
| 401 EXPECT_TRUE(is_callback_invoked_); | |
| 253 } | 402 } |
| 254 | 403 |
| 255 // Oddball case where we demand a high resolution icon to scale down. Generates | 404 // Oddball case where we demand a high resolution icon to scale down. Generates |
| 256 // fallback even though an icon with the final size is available. | 405 // fallback even though an icon with the final size is available. |
| 257 TEST_F(LargeIconServiceTest, FallbackSinceTooPicky) { | 406 TEST_F(LargeIconServiceTest, RawBitmapFallbackSinceTooPicky) { |
| 258 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); | 407 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); |
| 259 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | 408 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); |
| 260 expected_fallback_icon_style_->background_color = kTestColor; | 409 expected_fallback_icon_style_->background_color = kTestColor; |
| 261 expected_fallback_icon_style_->is_default_background_color = false; | 410 expected_fallback_icon_style_->is_default_background_color = false; |
| 262 large_icon_service_.GetLargeIconOrFallbackStyle( | 411 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 263 GURL(kDummyUrl), 32, 24, | 412 GURL(kDummyUrl), 32, 24, |
| 264 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 413 base::Bind(&LargeIconServiceTest::RawBitmapResultCallback, |
| 414 base::Unretained(this)), | |
| 265 &cancelable_task_tracker_); | 415 &cancelable_task_tracker_); |
| 266 base::RunLoop().RunUntilIdle(); | 416 base::RunLoop().RunUntilIdle(); |
| 267 EXPECT_TRUE(is_callback_invoked_); | 417 EXPECT_TRUE(is_callback_invoked_); |
| 418 } | |
| 419 | |
| 420 TEST_F(LargeIconServiceTest, ImageFallbackSinceTooPicky) { | |
| 421 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); | |
| 422 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | |
| 423 expected_fallback_icon_style_->background_color = kTestColor; | |
| 424 expected_fallback_icon_style_->is_default_background_color = false; | |
| 425 large_icon_service_.GetLargeIconImageOrFallbackStyle( | |
| 426 GURL(kDummyUrl), 32, 24, | |
| 427 base::Bind(&LargeIconServiceTest::ImageResultCallback, | |
| 428 base::Unretained(this)), | |
| 429 &cancelable_task_tracker_); | |
| 430 base::RunLoop().RunUntilIdle(); | |
| 431 EXPECT_TRUE(is_callback_invoked_); | |
| 268 } | 432 } |
| 269 | 433 |
| 270 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { | 434 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { |
| 271 const GURL kExpectedServerUrl( | 435 const GURL kExpectedServerUrl( |
| 272 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" | 436 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" |
| 273 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE" | 437 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE" |
| 274 "&url=http://www.example.com/"); | 438 "&url=http://www.example.com/"); |
| 275 | 439 |
| 276 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); | 440 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); |
| 277 | 441 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 large_icon_service_ | 539 large_icon_service_ |
| 376 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 540 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 377 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | 541 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); |
| 378 | 542 |
| 379 EXPECT_CALL(callback, Run(false)); | 543 EXPECT_CALL(callback, Run(false)); |
| 380 base::RunLoop().RunUntilIdle(); | 544 base::RunLoop().RunUntilIdle(); |
| 381 } | 545 } |
| 382 | 546 |
| 383 } // namespace | 547 } // namespace |
| 384 } // namespace favicon | 548 } // namespace favicon |
| OLD | NEW |