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/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/task/cancelable_task_tracker.h" | 16 #include "base/task/cancelable_task_tracker.h" |
| 17 #include "base/test/mock_callback.h" | |
| 16 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "components/favicon/core/favicon_client.h" | 19 #include "components/favicon/core/favicon_client.h" |
| 18 #include "components/favicon/core/test/mock_favicon_service.h" | 20 #include "components/favicon/core/test/mock_favicon_service.h" |
| 19 #include "components/favicon_base/fallback_icon_style.h" | 21 #include "components/favicon_base/fallback_icon_style.h" |
| 20 #include "components/favicon_base/favicon_types.h" | 22 #include "components/favicon_base/favicon_types.h" |
| 23 #include "components/image_fetcher/image_fetcher.h" | |
| 24 #include "components/image_fetcher/request_metadata.h" | |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
| 25 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
| 26 #include "ui/gfx/geometry/size.h" | 30 #include "ui/gfx/geometry/size.h" |
| 27 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
| 28 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 29 | 33 |
| 30 namespace favicon { | 34 namespace favicon { |
| 31 namespace { | 35 namespace { |
| 32 | 36 |
| 37 using testing::NiceMock; | |
| 38 using testing::Return; | |
| 39 using testing::SaveArg; | |
| 33 using testing::_; | 40 using testing::_; |
| 34 | 41 |
| 35 const char kDummyUrl[] = "http://www.example.com"; | 42 const char kDummyUrl[] = "http://www.example.com"; |
| 36 const char kDummyIconUrl[] = "http://www.example.com/touch_icon.png"; | 43 const char kDummyIconUrl[] = "http://www.example.com/touch_icon.png"; |
| 37 const SkColor kTestColor = SK_ColorRED; | 44 const SkColor kTestColor = SK_ColorRED; |
| 38 | 45 |
| 39 favicon_base::FaviconRawBitmapResult CreateTestBitmap( | 46 ACTION_P(PostFetchReply, p0) { |
| 40 int w, int h, SkColor color) { | 47 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 48 FROM_HERE, base::Bind(arg2, arg0, p0, image_fetcher::RequestMetadata())); | |
| 49 } | |
| 50 | |
| 51 ACTION_P(PostBoolReply, p0) { | |
| 52 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | |
| 53 base::Bind(arg4, p0)); | |
| 54 } | |
| 55 | |
| 56 SkBitmap CreateTestSkBitmap(int w, int h, SkColor color) { | |
| 57 SkBitmap bitmap; | |
| 58 bitmap.allocN32Pixels(w, h); | |
| 59 bitmap.eraseColor(color); | |
| 60 return bitmap; | |
| 61 } | |
| 62 | |
| 63 favicon_base::FaviconRawBitmapResult CreateTestBitmapResult(int w, | |
| 64 int h, | |
| 65 SkColor color) { | |
| 41 favicon_base::FaviconRawBitmapResult result; | 66 favicon_base::FaviconRawBitmapResult result; |
| 42 result.expired = false; | 67 result.expired = false; |
| 43 | 68 |
| 44 // Create bitmap and fill with |color|. | 69 // Create bitmap and fill with |color|. |
| 45 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); | 70 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
| 46 SkBitmap bitmap; | 71 SkBitmap bitmap; |
| 47 bitmap.allocN32Pixels(w, h); | 72 bitmap.allocN32Pixels(w, h); |
| 48 bitmap.eraseColor(color); | 73 bitmap.eraseColor(color); |
| 49 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &data->data()); | 74 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &data->data()); |
| 50 result.bitmap_data = data; | 75 result.bitmap_data = data; |
| 51 | 76 |
| 52 result.pixel_size = gfx::Size(w, h); | 77 result.pixel_size = gfx::Size(w, h); |
| 53 result.icon_url = GURL(kDummyIconUrl); | 78 result.icon_url = GURL(kDummyIconUrl); |
| 54 result.icon_type = favicon_base::TOUCH_ICON; | 79 result.icon_type = favicon_base::TOUCH_ICON; |
| 55 CHECK(result.is_valid()); | 80 CHECK(result.is_valid()); |
| 56 return result; | 81 return result; |
| 57 } | 82 } |
| 58 | 83 |
| 84 class MockImageFetcher : public image_fetcher::ImageFetcher { | |
| 85 public: | |
| 86 MOCK_METHOD1(SetImageFetcherDelegate, | |
| 87 void(image_fetcher::ImageFetcherDelegate* delegate)); | |
| 88 MOCK_METHOD1(SetDataUseServiceName, | |
| 89 void(image_fetcher::ImageFetcher::DataUseServiceName name)); | |
| 90 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size& size)); | |
| 91 MOCK_METHOD3(StartOrQueueNetworkRequest, | |
| 92 void(const std::string&, | |
| 93 const GURL&, | |
| 94 const ImageFetcherCallback&)); | |
| 95 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); | |
| 96 }; | |
| 97 | |
| 59 class LargeIconServiceTest : public testing::Test { | 98 class LargeIconServiceTest : public testing::Test { |
| 60 public: | 99 public: |
| 61 LargeIconServiceTest() | 100 LargeIconServiceTest() |
| 62 : large_icon_service_(&mock_favicon_service_, | 101 : mock_image_fetcher_(new NiceMock<MockImageFetcher>()), |
| 63 base::ThreadTaskRunnerHandle::Get()), | 102 large_icon_service_(&mock_favicon_service_, |
| 103 base::ThreadTaskRunnerHandle::Get(), | |
| 104 base::WrapUnique(mock_image_fetcher_)), | |
| 64 is_callback_invoked_(false) {} | 105 is_callback_invoked_(false) {} |
| 65 | 106 |
| 66 ~LargeIconServiceTest() override { | 107 ~LargeIconServiceTest() override { |
| 67 } | 108 } |
| 68 | 109 |
| 69 void ResultCallback(const favicon_base::LargeIconResult& result) { | 110 void ResultCallback(const favicon_base::LargeIconResult& result) { |
| 70 is_callback_invoked_ = true; | 111 is_callback_invoked_ = true; |
| 71 | 112 |
| 72 // Checking presence and absence of results. | 113 // Checking presence and absence of results. |
| 73 EXPECT_EQ(expected_bitmap_.is_valid(), result.bitmap.is_valid()); | 114 EXPECT_EQ(expected_bitmap_.is_valid(), result.bitmap.is_valid()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 88 const GURL& page_url, | 129 const GURL& page_url, |
| 89 const favicon_base::FaviconRawBitmapResult& mock_result) { | 130 const favicon_base::FaviconRawBitmapResult& mock_result) { |
| 90 EXPECT_CALL(mock_favicon_service_, | 131 EXPECT_CALL(mock_favicon_service_, |
| 91 GetLargestRawFaviconForPageURL(page_url, _, _, _, _)) | 132 GetLargestRawFaviconForPageURL(page_url, _, _, _, _)) |
| 92 .WillOnce(PostReply<5>(mock_result)); | 133 .WillOnce(PostReply<5>(mock_result)); |
| 93 } | 134 } |
| 94 | 135 |
| 95 protected: | 136 protected: |
| 96 base::MessageLoopForIO loop_; | 137 base::MessageLoopForIO loop_; |
| 97 | 138 |
| 98 testing::StrictMock<MockFaviconService> mock_favicon_service_; | 139 NiceMock<MockImageFetcher>* mock_image_fetcher_; |
| 140 testing::NiceMock<MockFaviconService> mock_favicon_service_; | |
| 99 LargeIconService large_icon_service_; | 141 LargeIconService large_icon_service_; |
| 100 base::CancelableTaskTracker cancelable_task_tracker_; | 142 base::CancelableTaskTracker cancelable_task_tracker_; |
| 101 | 143 |
| 102 favicon_base::FaviconRawBitmapResult expected_bitmap_; | 144 favicon_base::FaviconRawBitmapResult expected_bitmap_; |
| 103 std::unique_ptr<favicon_base::FallbackIconStyle> | 145 std::unique_ptr<favicon_base::FallbackIconStyle> |
| 104 expected_fallback_icon_style_; | 146 expected_fallback_icon_style_; |
| 105 | 147 |
| 106 bool is_callback_invoked_; | 148 bool is_callback_invoked_; |
| 107 | 149 |
| 108 private: | 150 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); | 151 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); |
| 110 }; | 152 }; |
| 111 | 153 |
| 112 TEST_F(LargeIconServiceTest, SameSize) { | 154 TEST_F(LargeIconServiceTest, SameSize) { |
| 113 InjectMockResult(GURL(kDummyUrl), CreateTestBitmap(24, 24, kTestColor)); | 155 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); |
| 114 expected_bitmap_ = CreateTestBitmap(24, 24, kTestColor); | 156 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 115 large_icon_service_.GetLargeIconOrFallbackStyle( | 157 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 116 GURL(kDummyUrl), | 158 GURL(kDummyUrl), |
| 117 24, // |min_source_size_in_pixel| | 159 24, // |min_source_size_in_pixel| |
| 118 24, // |desired_size_in_pixel| | 160 24, // |desired_size_in_pixel| |
| 119 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 161 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 120 &cancelable_task_tracker_); | 162 &cancelable_task_tracker_); |
| 121 base::RunLoop().RunUntilIdle(); | 163 base::RunLoop().RunUntilIdle(); |
| 122 EXPECT_TRUE(is_callback_invoked_); | 164 EXPECT_TRUE(is_callback_invoked_); |
| 123 } | 165 } |
| 124 | 166 |
| 125 TEST_F(LargeIconServiceTest, ScaleDown) { | 167 TEST_F(LargeIconServiceTest, ScaleDown) { |
| 126 InjectMockResult(GURL(kDummyUrl), CreateTestBitmap(32, 32, kTestColor)); | 168 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(32, 32, kTestColor)); |
| 127 expected_bitmap_ = CreateTestBitmap(24, 24, kTestColor); | 169 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 128 large_icon_service_.GetLargeIconOrFallbackStyle( | 170 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 129 GURL(kDummyUrl), 24, 24, | 171 GURL(kDummyUrl), 24, 24, |
| 130 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 172 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 131 &cancelable_task_tracker_); | 173 &cancelable_task_tracker_); |
| 132 base::RunLoop().RunUntilIdle(); | 174 base::RunLoop().RunUntilIdle(); |
| 133 EXPECT_TRUE(is_callback_invoked_); | 175 EXPECT_TRUE(is_callback_invoked_); |
| 134 } | 176 } |
| 135 | 177 |
| 136 TEST_F(LargeIconServiceTest, ScaleUp) { | 178 TEST_F(LargeIconServiceTest, ScaleUp) { |
| 137 InjectMockResult(GURL(kDummyUrl), CreateTestBitmap(16, 16, kTestColor)); | 179 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(16, 16, kTestColor)); |
| 138 expected_bitmap_ = CreateTestBitmap(24, 24, kTestColor); | 180 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 139 large_icon_service_.GetLargeIconOrFallbackStyle( | 181 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 140 GURL(kDummyUrl), | 182 GURL(kDummyUrl), |
| 141 14, // Lowered requirement so stored bitmap is admitted. | 183 14, // Lowered requirement so stored bitmap is admitted. |
| 142 24, | 184 24, |
| 143 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 185 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 144 &cancelable_task_tracker_); | 186 &cancelable_task_tracker_); |
| 145 base::RunLoop().RunUntilIdle(); | 187 base::RunLoop().RunUntilIdle(); |
| 146 EXPECT_TRUE(is_callback_invoked_); | 188 EXPECT_TRUE(is_callback_invoked_); |
| 147 } | 189 } |
| 148 | 190 |
| 149 // |desired_size_in_pixel| == 0 means retrieve original image without scaling. | 191 // |desired_size_in_pixel| == 0 means retrieve original image without scaling. |
| 150 TEST_F(LargeIconServiceTest, NoScale) { | 192 TEST_F(LargeIconServiceTest, NoScale) { |
| 151 InjectMockResult(GURL(kDummyUrl), CreateTestBitmap(24, 24, kTestColor)); | 193 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); |
| 152 expected_bitmap_ = CreateTestBitmap(24, 24, kTestColor); | 194 expected_bitmap_ = CreateTestBitmapResult(24, 24, kTestColor); |
| 153 large_icon_service_.GetLargeIconOrFallbackStyle( | 195 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 154 GURL(kDummyUrl), 16, 0, | 196 GURL(kDummyUrl), 16, 0, |
| 155 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 197 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 156 &cancelable_task_tracker_); | 198 &cancelable_task_tracker_); |
| 157 base::RunLoop().RunUntilIdle(); | 199 base::RunLoop().RunUntilIdle(); |
| 158 EXPECT_TRUE(is_callback_invoked_); | 200 EXPECT_TRUE(is_callback_invoked_); |
| 159 } | 201 } |
| 160 | 202 |
| 161 TEST_F(LargeIconServiceTest, FallbackSinceIconTooSmall) { | 203 TEST_F(LargeIconServiceTest, FallbackSinceIconTooSmall) { |
| 162 InjectMockResult(GURL(kDummyUrl), CreateTestBitmap(16, 16, kTestColor)); | 204 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(16, 16, kTestColor)); |
| 163 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | 205 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); |
| 164 expected_fallback_icon_style_->background_color = kTestColor; | 206 expected_fallback_icon_style_->background_color = kTestColor; |
| 165 expected_fallback_icon_style_->is_default_background_color = false; | 207 expected_fallback_icon_style_->is_default_background_color = false; |
| 166 large_icon_service_.GetLargeIconOrFallbackStyle( | 208 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 167 GURL(kDummyUrl), 24, 24, | 209 GURL(kDummyUrl), 24, 24, |
| 168 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 210 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 169 &cancelable_task_tracker_); | 211 &cancelable_task_tracker_); |
| 170 base::RunLoop().RunUntilIdle(); | 212 base::RunLoop().RunUntilIdle(); |
| 171 EXPECT_TRUE(is_callback_invoked_); | 213 EXPECT_TRUE(is_callback_invoked_); |
| 172 } | 214 } |
| 173 | 215 |
| 174 TEST_F(LargeIconServiceTest, FallbackSinceIconNotSquare) { | 216 TEST_F(LargeIconServiceTest, FallbackSinceIconNotSquare) { |
| 175 InjectMockResult(GURL(kDummyUrl), CreateTestBitmap(24, 32, kTestColor)); | 217 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 32, kTestColor)); |
| 176 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | 218 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); |
| 177 expected_fallback_icon_style_->background_color = kTestColor; | 219 expected_fallback_icon_style_->background_color = kTestColor; |
| 178 expected_fallback_icon_style_->is_default_background_color = false; | 220 expected_fallback_icon_style_->is_default_background_color = false; |
| 179 large_icon_service_.GetLargeIconOrFallbackStyle( | 221 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 180 GURL(kDummyUrl), 24, 24, | 222 GURL(kDummyUrl), 24, 24, |
| 181 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 223 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 182 &cancelable_task_tracker_); | 224 &cancelable_task_tracker_); |
| 183 base::RunLoop().RunUntilIdle(); | 225 base::RunLoop().RunUntilIdle(); |
| 184 EXPECT_TRUE(is_callback_invoked_); | 226 EXPECT_TRUE(is_callback_invoked_); |
| 185 } | 227 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 204 GURL(kDummyUrl), 24, 0, | 246 GURL(kDummyUrl), 24, 0, |
| 205 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 247 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 206 &cancelable_task_tracker_); | 248 &cancelable_task_tracker_); |
| 207 base::RunLoop().RunUntilIdle(); | 249 base::RunLoop().RunUntilIdle(); |
| 208 EXPECT_TRUE(is_callback_invoked_); | 250 EXPECT_TRUE(is_callback_invoked_); |
| 209 } | 251 } |
| 210 | 252 |
| 211 // Oddball case where we demand a high resolution icon to scale down. Generates | 253 // Oddball case where we demand a high resolution icon to scale down. Generates |
| 212 // fallback even though an icon with the final size is available. | 254 // fallback even though an icon with the final size is available. |
| 213 TEST_F(LargeIconServiceTest, FallbackSinceTooPicky) { | 255 TEST_F(LargeIconServiceTest, FallbackSinceTooPicky) { |
| 214 InjectMockResult(GURL(kDummyUrl), CreateTestBitmap(24, 24, kTestColor)); | 256 InjectMockResult(GURL(kDummyUrl), CreateTestBitmapResult(24, 24, kTestColor)); |
| 215 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); | 257 expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle); |
| 216 expected_fallback_icon_style_->background_color = kTestColor; | 258 expected_fallback_icon_style_->background_color = kTestColor; |
| 217 expected_fallback_icon_style_->is_default_background_color = false; | 259 expected_fallback_icon_style_->is_default_background_color = false; |
| 218 large_icon_service_.GetLargeIconOrFallbackStyle( | 260 large_icon_service_.GetLargeIconOrFallbackStyle( |
| 219 GURL(kDummyUrl), 32, 24, | 261 GURL(kDummyUrl), 32, 24, |
| 220 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 262 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 221 &cancelable_task_tracker_); | 263 &cancelable_task_tracker_); |
| 222 base::RunLoop().RunUntilIdle(); | 264 base::RunLoop().RunUntilIdle(); |
| 223 EXPECT_TRUE(is_callback_invoked_); | 265 EXPECT_TRUE(is_callback_invoked_); |
| 224 } | 266 } |
| 225 | 267 |
| 268 TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { | |
| 269 const std::string expected_server_url = | |
| 270 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" | |
| 271 "&url=http://www.example.com/&size=192&min_size=42&max_size=256"; | |
| 272 | |
| 273 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
| 274 | |
| 275 base::MockCallback<base::Callback<void(bool success)>> callback; | |
| 276 EXPECT_CALL(*mock_image_fetcher_, | |
| 277 StartOrQueueNetworkRequest(expected_server_url, | |
|
pkotwicz
2017/03/21 18:20:30
I don't think that it is worth testing the id para
mastiz
2017/03/22 09:46:53
Done.
| |
| 278 GURL(expected_server_url), _)) | |
| 279 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap( | |
| 280 CreateTestSkBitmap(64, 64, kTestColor)))); | |
| 281 EXPECT_CALL(mock_favicon_service_, | |
| 282 SetLastResortFavicons(GURL(kDummyUrl), GURL(expected_server_url), | |
| 283 favicon_base::IconType::TOUCH_ICON, _, _)) | |
| 284 .WillOnce(PostBoolReply(true)); | |
| 285 EXPECT_CALL(callback, Run(true)); | |
| 286 | |
| 287 large_icon_service_ | |
| 288 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | |
| 289 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | |
| 290 | |
| 291 base::RunLoop().RunUntilIdle(); | |
| 292 } | |
| 293 | |
| 294 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) { | |
| 295 const std::string expected_server_url = | |
| 296 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" | |
| 297 "&url=http://www.example.com/&size=192&min_size=42&max_size=256"; | |
| 298 | |
| 299 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) | |
| 300 .Times(0); | |
| 301 | |
| 302 base::MockCallback<base::Callback<void(bool success)>> callback; | |
| 303 EXPECT_CALL(*mock_image_fetcher_, | |
| 304 StartOrQueueNetworkRequest(expected_server_url, | |
| 305 GURL(expected_server_url), _)) | |
| 306 .WillOnce(PostFetchReply(gfx::Image())); | |
| 307 EXPECT_CALL(mock_favicon_service_, | |
| 308 UnableToDownloadFavicon(GURL(expected_server_url))); | |
| 309 EXPECT_CALL(callback, Run(false)); | |
| 310 | |
| 311 large_icon_service_ | |
| 312 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | |
| 313 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | |
| 314 | |
| 315 base::RunLoop().RunUntilIdle(); | |
| 316 } | |
| 317 | |
| 318 TEST_F(LargeIconServiceTest, ShoutNotGetFromGoogleServerIfUnavailable) { | |
| 319 ON_CALL(mock_favicon_service_, | |
| 320 WasUnableToDownloadFavicon(GURL( | |
| 321 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true" | |
| 322 "&url=http://www.example.com/&size=192&min_size=42" | |
| 323 "&max_size=256"))) | |
|
pkotwicz
2017/03/21 18:20:30
Can you make WasUnableToDownloadFavicon() return t
mastiz
2017/03/22 09:46:53
Leaving unmodified because that would cause tests
| |
| 324 .WillByDefault(Return(true)); | |
| 325 | |
| 326 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
| 327 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _)) | |
| 328 .Times(0); | |
| 329 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _)) | |
| 330 .Times(0); | |
| 331 | |
| 332 base::MockCallback<base::Callback<void(bool success)>> callback; | |
| 333 large_icon_service_ | |
| 334 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | |
| 335 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get()); | |
| 336 | |
| 337 EXPECT_CALL(callback, Run(false)); | |
| 338 base::RunLoop().RunUntilIdle(); | |
| 339 } | |
| 340 | |
| 226 } // namespace | 341 } // namespace |
| 227 } // namespace favicon | 342 } // namespace favicon |
| OLD | NEW |