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