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

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

Issue 2721363002: Extend LargeIconService to fetch missing favicons from a Google server (Closed)
Patch Set: Add fallback_opts=TYPE Created 3 years, 9 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
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/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/core/image_fetcher.h"
24 #include "components/image_fetcher/core/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
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
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 GURL kExpectedServerUrl(
270 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true"
271 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE"
272 "&url=http://www.example.com/");
273
274 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0);
275
276 base::MockCallback<base::Callback<void(bool success)>> callback;
277 EXPECT_CALL(*mock_image_fetcher_,
278 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _))
279 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
280 CreateTestSkBitmap(64, 64, kTestColor))));
281 EXPECT_CALL(mock_favicon_service_,
282 SetLastResortFavicons(GURL(kDummyUrl), kExpectedServerUrl,
283 favicon_base::IconType::TOUCH_ICON, _, _))
284 .WillOnce(PostBoolReply(true));
285
286 large_icon_service_
287 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
288 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get());
289
290 EXPECT_CALL(callback, Run(true));
291 base::RunLoop().RunUntilIdle();
292 }
293
294 TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) {
295 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1");
296 const GURL kExpectedServerUrl(
297 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true"
298 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE"
299 "&url=http://www.example.com/");
300
301 EXPECT_CALL(*mock_image_fetcher_,
302 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _))
303 .WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
304 CreateTestSkBitmap(64, 64, kTestColor))));
305 // Verify that the non-trimmed page URL is used when writing to the database.
306 EXPECT_CALL(mock_favicon_service_,
307 SetLastResortFavicons(_, kExpectedServerUrl, _, _, _));
308
309 large_icon_service_
310 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
311 GURL(kDummyUrlWithQuery), /*min_source_size_in_pixel=*/42,
312 base::Callback<void(bool success)>());
313
314 base::RunLoop().RunUntilIdle();
315 }
316
317 TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidScheme) {
318 const GURL kDummyFtpUrl("ftp://www.example.com");
319
320 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _))
321 .Times(0);
322
323 base::MockCallback<base::Callback<void(bool success)>> callback;
324
325 large_icon_service_
326 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
327 GURL(kDummyFtpUrl), /*min_source_size_in_pixel=*/42, callback.Get());
328
329 EXPECT_CALL(callback, Run(false));
330 base::RunLoop().RunUntilIdle();
331 }
332
333 TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) {
334 const GURL kDummyUrlWithQuery("http://www.example.com?foo=1");
335 const GURL kExpectedServerUrl(
336 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true"
337 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE"
338 "&url=http://www.example.com/");
339
340 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _))
341 .Times(0);
342
343 base::MockCallback<base::Callback<void(bool success)>> callback;
344 EXPECT_CALL(*mock_image_fetcher_,
345 StartOrQueueNetworkRequest(_, kExpectedServerUrl, _))
346 .WillOnce(PostFetchReply(gfx::Image()));
347 EXPECT_CALL(mock_favicon_service_,
348 UnableToDownloadFavicon(kExpectedServerUrl));
349
350 large_icon_service_
351 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
352 kDummyUrlWithQuery, /*min_source_size_in_pixel=*/42, callback.Get());
353
354 EXPECT_CALL(callback, Run(false));
355 base::RunLoop().RunUntilIdle();
356 }
357
358 TEST_F(LargeIconServiceTest, ShoutNotGetFromGoogleServerIfUnavailable) {
359 ON_CALL(mock_favicon_service_,
360 WasUnableToDownloadFavicon(GURL(
361 "https://t0.gstatic.com/faviconV2?user=chrome&drop_404_icon=true"
362 "&size=192&min_size=42&max_size=256&fallback_opts=TYPE"
363 "&url=http://www.example.com/")))
364 .WillByDefault(Return(true));
365
366 EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0);
367 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _))
368 .Times(0);
369 EXPECT_CALL(mock_favicon_service_, SetLastResortFavicons(_, _, _, _, _))
370 .Times(0);
371
372 base::MockCallback<base::Callback<void(bool success)>> callback;
373 large_icon_service_
374 .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
375 GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, callback.Get());
376
377 EXPECT_CALL(callback, Run(false));
378 base::RunLoop().RunUntilIdle();
379 }
380
226 } // namespace 381 } // namespace
227 } // namespace favicon 382 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/large_icon_service.cc ('k') | components/favicon/core/test/mock_favicon_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698