OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "components/favicon/core/favicon_driver.h" | 14 #include "components/favicon/core/favicon_driver.h" |
15 #include "components/favicon/core/test/mock_favicon_service.h" | |
16 #include "testing/gmock/include/gmock/gmock.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
17 #include "ui/base/layout.h" | 19 #include "ui/base/layout.h" |
18 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
19 #include "ui/gfx/favicon_size.h" | 21 #include "ui/gfx/favicon_size.h" |
20 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
21 | 23 |
22 namespace favicon { | 24 namespace favicon { |
23 namespace { | 25 namespace { |
24 | 26 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 void SetFaviconRawBitmapResult( | 66 void SetFaviconRawBitmapResult( |
65 const GURL& icon_url, | 67 const GURL& icon_url, |
66 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { | 68 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { |
67 SetFaviconRawBitmapResult(icon_url, | 69 SetFaviconRawBitmapResult(icon_url, |
68 favicon_base::FAVICON, | 70 favicon_base::FAVICON, |
69 false /* expired */, | 71 false /* expired */, |
70 favicon_bitmap_results); | 72 favicon_bitmap_results); |
71 } | 73 } |
72 | 74 |
73 // This class is used to save the download request for verifying with test case. | 75 // This class is used to save the download request for verifying with test case. |
74 // It also will be used to invoke the onDidDownload callback. | |
75 class DownloadHandler { | 76 class DownloadHandler { |
76 public: | 77 public: |
77 explicit DownloadHandler(FaviconHandler* favicon_handler) | 78 DownloadHandler() : callback_invoked_(false) {} |
78 : favicon_handler_(favicon_handler), callback_invoked_(false) {} | |
79 | |
80 ~DownloadHandler() {} | 79 ~DownloadHandler() {} |
81 | 80 |
82 void Reset() { | 81 void Reset() { |
83 download_.reset(); | 82 download_.reset(); |
84 callback_invoked_ = false; | 83 callback_invoked_ = false; |
85 // Does not affect |should_fail_download_icon_urls_| and | 84 // Does not affect |should_fail_download_icon_urls_| and |
86 // |failed_download_icon_urls_|. | 85 // |failed_download_icon_urls_|. |
87 } | 86 } |
88 | 87 |
89 // Make downloads for any of |icon_urls| fail. | 88 // Make downloads for any of |icon_urls| fail. |
90 void FailDownloadForIconURLs(const std::set<GURL>& icon_urls) { | 89 void FailDownloadForIconURLs(const std::set<GURL>& icon_urls) { |
91 should_fail_download_icon_urls_ = icon_urls; | 90 should_fail_download_icon_urls_ = icon_urls; |
92 } | 91 } |
93 | 92 |
94 // Returns whether a download for |icon_url| did fail. | 93 // Returns whether a download for |icon_url| did fail. |
95 bool DidFailDownloadForIconURL(const GURL& icon_url) const { | 94 bool DidFailDownloadForIconURL(const GURL& icon_url) const { |
96 return failed_download_icon_urls_.count(icon_url); | 95 return failed_download_icon_urls_.count(icon_url); |
97 } | 96 } |
98 | 97 |
99 void AddDownload( | 98 void AddDownload(int download_id, |
100 int download_id, | 99 const GURL& image_url, |
101 const GURL& image_url, | 100 const std::vector<int>& image_sizes, |
102 const std::vector<int>& image_sizes, | 101 int max_image_size, |
103 int max_image_size) { | 102 FaviconHandler::Delegate::ImageDownloadCallback callback) { |
104 download_.reset(new Download( | 103 download_.reset(new Download(download_id, image_url, image_sizes, |
105 download_id, image_url, image_sizes, max_image_size)); | 104 max_image_size, callback)); |
106 } | 105 } |
107 | 106 |
108 void InvokeCallback(); | 107 void InvokeCallback(); |
109 | 108 |
110 bool HasDownload() const { return download_.get(); } | 109 bool HasDownload() const { return download_.get(); } |
111 const GURL& GetImageUrl() const { return download_->image_url; } | 110 const GURL& GetImageUrl() const { return download_->image_url; } |
112 void SetImageSizes(const std::vector<int>& sizes) { | 111 void SetImageSizes(const std::vector<int>& sizes) { |
113 download_->image_sizes = sizes; } | 112 download_->image_sizes = sizes; } |
114 | 113 |
115 private: | 114 private: |
116 struct Download { | 115 struct Download { |
117 Download(int id, | 116 Download(int id, |
118 GURL url, | 117 GURL url, |
119 const std::vector<int>& sizes, | 118 const std::vector<int>& sizes, |
120 int max_size) | 119 int max_size, |
120 FaviconHandler::Delegate::ImageDownloadCallback callback) | |
121 : download_id(id), | 121 : download_id(id), |
122 image_url(url), | 122 image_url(url), |
123 image_sizes(sizes), | 123 image_sizes(sizes), |
124 max_image_size(max_size) {} | 124 max_image_size(max_size), |
125 callback(callback) {} | |
125 ~Download() {} | 126 ~Download() {} |
126 int download_id; | 127 int download_id; |
127 GURL image_url; | 128 GURL image_url; |
128 std::vector<int> image_sizes; | 129 std::vector<int> image_sizes; |
129 int max_image_size; | 130 int max_image_size; |
131 FaviconHandler::Delegate::ImageDownloadCallback callback; | |
130 }; | 132 }; |
131 | 133 |
132 FaviconHandler* favicon_handler_; | |
133 std::unique_ptr<Download> download_; | 134 std::unique_ptr<Download> download_; |
134 bool callback_invoked_; | 135 bool callback_invoked_; |
135 | 136 |
136 // The icon URLs for which the download should fail. | 137 // The icon URLs for which the download should fail. |
137 std::set<GURL> should_fail_download_icon_urls_; | 138 std::set<GURL> should_fail_download_icon_urls_; |
138 | 139 |
139 // The icon URLs for which the download did fail. This should be a subset of | 140 // The icon URLs for which the download did fail. This should be a subset of |
140 // |should_fail_download_icon_urls_|. | 141 // |should_fail_download_icon_urls_|. |
141 std::set<GURL> failed_download_icon_urls_; | 142 std::set<GURL> failed_download_icon_urls_; |
142 | 143 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 const int icon_type_; | 178 const int icon_type_; |
178 const std::vector<unsigned char> bitmap_data_; | 179 const std::vector<unsigned char> bitmap_data_; |
179 const gfx::Size size_; | 180 const gfx::Size size_; |
180 std::vector<favicon_base::FaviconRawBitmapResult> history_results_; | 181 std::vector<favicon_base::FaviconRawBitmapResult> history_results_; |
181 favicon_base::FaviconResultsCallback callback_; | 182 favicon_base::FaviconResultsCallback callback_; |
182 | 183 |
183 private: | 184 private: |
184 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 185 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
185 }; | 186 }; |
186 | 187 |
187 } // namespace | 188 class TestDelegate : public FaviconHandler::Delegate { |
189 public: | |
190 TestDelegate() : num_notifications_(0), download_id_(0) {} | |
188 | 191 |
189 class TestFaviconDriver : public FaviconDriver { | 192 int DownloadImage(const GURL& image_url, |
190 public: | 193 int max_bitmap_size, |
191 TestFaviconDriver() | 194 ImageDownloadCallback callback) override { |
192 : num_notifications_(0u) {} | 195 // Do not do a download if downloading |image_url| failed previously. This |
196 // emulates the behavior of FaviconDriver::StartDownload() | |
pkotwicz
2017/02/22 02:37:54
Nit: Please update comment. FaviconDriver::StartDo
mastiz
2017/02/23 21:55:54
Done.
| |
197 if (download_handler_.DidFailDownloadForIconURL(image_url)) { | |
198 download_handler_.AddDownload(download_id_, image_url, std::vector<int>(), | |
199 0, callback); | |
200 return 0; | |
201 } | |
193 | 202 |
194 ~TestFaviconDriver() override {} | 203 download_id_++; |
195 | 204 std::vector<int> sizes; |
196 // FaviconDriver implementation. | 205 sizes.push_back(0); |
197 void FetchFavicon(const GURL& url) override { | 206 download_handler_.AddDownload(download_id_, image_url, sizes, |
198 ADD_FAILURE() << "TestFaviconDriver::FetchFavicon() " | 207 max_bitmap_size, callback); |
199 << "should never be called in tests."; | 208 return download_id_; |
200 } | |
201 | |
202 gfx::Image GetFavicon() const override { | |
203 ADD_FAILURE() << "TestFaviconDriver::GetFavicon() " | |
204 << "should never be called in tests."; | |
205 return gfx::Image(); | |
206 } | |
207 | |
208 bool FaviconIsValid() const override { | |
209 ADD_FAILURE() << "TestFaviconDriver::FaviconIsValid() " | |
210 << "should never be called in tests."; | |
211 return false; | |
212 } | |
213 | |
214 bool HasPendingTasksForTest() override { | |
215 ADD_FAILURE() << "TestFaviconDriver::HasPendingTasksForTest() " | |
216 << "should never be called in tests."; | |
217 return false; | |
218 } | |
219 | |
220 int StartDownload(const GURL& url, int max_bitmap_size) override { | |
221 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " | |
222 << "should never be called in tests."; | |
223 return -1; | |
224 } | 209 } |
225 | 210 |
226 bool IsOffTheRecord() override { return false; } | 211 bool IsOffTheRecord() override { return false; } |
227 | 212 |
228 bool IsBookmarked(const GURL& url) override { return false; } | 213 bool IsBookmarked(const GURL& url) override { return false; } |
229 | 214 |
230 GURL GetActiveURL() override { | |
231 ADD_FAILURE() << "TestFaviconDriver::GetActiveURL() " | |
232 << "should never be called in tests."; | |
233 return GURL(); | |
234 } | |
235 | |
236 void OnFaviconUpdated( | 215 void OnFaviconUpdated( |
237 const GURL& page_url, | 216 const GURL& page_url, |
238 FaviconDriverObserver::NotificationIconType notification_icon_type, | 217 FaviconDriverObserver::NotificationIconType notification_icon_type, |
239 const GURL& icon_url, | 218 const GURL& icon_url, |
240 bool icon_url_changed, | 219 bool icon_url_changed, |
241 const gfx::Image& image) override { | 220 const gfx::Image& image) override { |
242 ++num_notifications_; | 221 ++num_notifications_; |
243 icon_url_ = icon_url; | 222 icon_url_ = icon_url; |
244 image_ = image; | 223 image_ = image; |
245 } | 224 } |
246 | 225 |
226 DownloadHandler* download_handler() { return &download_handler_; } | |
247 const GURL& icon_url() const { return icon_url_; } | 227 const GURL& icon_url() const { return icon_url_; } |
248 | |
249 const gfx::Image& image() const { return image_; } | 228 const gfx::Image& image() const { return image_; } |
250 | |
251 size_t num_notifications() const { return num_notifications_; } | 229 size_t num_notifications() const { return num_notifications_; } |
252 void ResetNumNotifications() { num_notifications_ = 0; } | 230 void ResetNumNotifications() { num_notifications_ = 0; } |
253 | 231 |
254 private: | 232 private: |
255 GURL icon_url_; | 233 GURL icon_url_; |
256 gfx::Image image_; | 234 gfx::Image image_; |
257 size_t num_notifications_; | 235 size_t num_notifications_; |
258 | 236 |
259 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); | 237 // The unique id of a download request. It will be returned to a |
238 // FaviconHandler. | |
239 int download_id_; | |
240 DownloadHandler download_handler_; | |
241 | |
242 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | |
260 }; | 243 }; |
261 | 244 |
245 } // namespace | |
246 | |
262 // This class is used to catch the FaviconHandler's download and history | 247 // This class is used to catch the FaviconHandler's download and history |
263 // request, and also provide the methods to access the FaviconHandler | 248 // request, and also provide the methods to access the FaviconHandler |
264 // internals. | 249 // internals. |
265 class TestFaviconHandler : public FaviconHandler { | 250 class TestFaviconHandler : public FaviconHandler { |
266 public: | 251 public: |
267 static int GetMaximalIconSize(favicon_base::IconType icon_type) { | 252 static int GetMaximalIconSize(favicon_base::IconType icon_type) { |
268 return FaviconHandler::GetMaximalIconSize(icon_type); | 253 return FaviconHandler::GetMaximalIconSize(icon_type); |
269 } | 254 } |
270 | 255 |
271 TestFaviconHandler(TestFaviconDriver* driver, | 256 TestFaviconHandler(FaviconService* service, |
257 FaviconHandler::Delegate* delegate, | |
272 FaviconDriverObserver::NotificationIconType handler_type) | 258 FaviconDriverObserver::NotificationIconType handler_type) |
273 : FaviconHandler(nullptr, driver, handler_type), | 259 : FaviconHandler(service, delegate, handler_type) {} |
pkotwicz
2017/02/22 02:37:54
Why not keep first parameter as nullptr?
mastiz
2017/02/23 21:55:54
Reverted, this was a leftover after attempting to
| |
274 download_id_(0) { | |
275 download_handler_.reset(new DownloadHandler(this)); | |
276 } | |
277 | 260 |
278 ~TestFaviconHandler() override {} | 261 ~TestFaviconHandler() override {} |
279 | 262 |
280 HistoryRequestHandler* history_handler() { | 263 HistoryRequestHandler* history_handler() { |
281 return history_handler_.get(); | 264 return history_handler_.get(); |
282 } | 265 } |
283 | 266 |
284 // This method will take the ownership of the given handler. | 267 // This method will take the ownership of the given handler. |
285 void set_history_handler(HistoryRequestHandler* handler) { | 268 void set_history_handler(HistoryRequestHandler* handler) { |
286 history_handler_.reset(handler); | 269 history_handler_.reset(handler); |
287 } | 270 } |
288 | 271 |
289 DownloadHandler* download_handler() { | |
290 return download_handler_.get(); | |
291 } | |
292 | |
293 FaviconURL* current_candidate() { | 272 FaviconURL* current_candidate() { |
294 return FaviconHandler::current_candidate(); | 273 return FaviconHandler::current_candidate(); |
295 } | 274 } |
296 | 275 |
297 size_t current_candidate_index() const { | 276 size_t current_candidate_index() const { |
298 return current_candidate_index_; | 277 return current_candidate_index_; |
299 } | 278 } |
300 | 279 |
301 const FaviconCandidate& best_favicon_candidate() { | 280 const FaviconCandidate& best_favicon_candidate() { |
302 return best_favicon_candidate_; | 281 return best_favicon_candidate_; |
(...skipping 21 matching lines...) Expand all Loading... | |
324 | 303 |
325 void GetFaviconForURLFromFaviconService( | 304 void GetFaviconForURLFromFaviconService( |
326 const GURL& page_url, | 305 const GURL& page_url, |
327 int icon_types, | 306 int icon_types, |
328 const favicon_base::FaviconResultsCallback& callback, | 307 const favicon_base::FaviconResultsCallback& callback, |
329 base::CancelableTaskTracker* tracker) override { | 308 base::CancelableTaskTracker* tracker) override { |
330 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), | 309 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), |
331 icon_types, callback)); | 310 icon_types, callback)); |
332 } | 311 } |
333 | 312 |
334 int DownloadFavicon(const GURL& image_url, int max_bitmap_size) override { | |
335 // Do not do a download if downloading |image_url| failed previously. This | |
336 // emulates the behavior of FaviconDriver::StartDownload() | |
337 if (download_handler_->DidFailDownloadForIconURL(image_url)) { | |
338 download_handler_->AddDownload(download_id_, image_url, | |
339 std::vector<int>(), 0); | |
340 return 0; | |
341 } | |
342 | |
343 download_id_++; | |
344 std::vector<int> sizes; | |
345 sizes.push_back(0); | |
346 download_handler_->AddDownload( | |
347 download_id_, image_url, sizes, max_bitmap_size); | |
348 return download_id_; | |
349 } | |
350 | |
351 void SetHistoryFavicons(const GURL& page_url, | 313 void SetHistoryFavicons(const GURL& page_url, |
352 const GURL& icon_url, | 314 const GURL& icon_url, |
353 favicon_base::IconType icon_type, | 315 favicon_base::IconType icon_type, |
354 const gfx::Image& image) override { | 316 const gfx::Image& image) override { |
355 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); | 317 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); |
356 std::vector<unsigned char> bitmap_data(bytes->front(), | 318 std::vector<unsigned char> bitmap_data(bytes->front(), |
357 bytes->front() + bytes->size()); | 319 bytes->front() + bytes->size()); |
358 history_handler_.reset(new HistoryRequestHandler( | 320 history_handler_.reset(new HistoryRequestHandler( |
359 page_url, icon_url, icon_type, bitmap_data, image.Size())); | 321 page_url, icon_url, icon_type, bitmap_data, image.Size())); |
360 } | 322 } |
361 | 323 |
362 bool ShouldSaveFavicon() override { return true; } | 324 bool ShouldSaveFavicon() override { return true; } |
363 | 325 |
364 GURL page_url_; | 326 GURL page_url_; |
365 | 327 |
366 private: | 328 private: |
367 | |
368 // The unique id of a download request. It will be returned to a | |
369 // FaviconHandler. | |
370 int download_id_; | |
371 | |
372 std::unique_ptr<DownloadHandler> download_handler_; | |
373 std::unique_ptr<HistoryRequestHandler> history_handler_; | 329 std::unique_ptr<HistoryRequestHandler> history_handler_; |
374 | 330 |
375 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | 331 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); |
376 }; | 332 }; |
377 | 333 |
378 namespace { | 334 namespace { |
379 | 335 |
380 void HistoryRequestHandler::InvokeCallback() { | 336 void HistoryRequestHandler::InvokeCallback() { |
381 if (!callback_.is_null()) { | 337 if (!callback_.is_null()) { |
382 callback_.Run(history_results_); | 338 callback_.Run(history_results_); |
(...skipping 16 matching lines...) Expand all Loading... | |
399 if (download_->max_image_size != 0 && | 355 if (download_->max_image_size != 0 && |
400 downloaded_size > download_->max_image_size) { | 356 downloaded_size > download_->max_image_size) { |
401 downloaded_size = download_->max_image_size; | 357 downloaded_size = download_->max_image_size; |
402 } | 358 } |
403 SkBitmap bitmap; | 359 SkBitmap bitmap; |
404 FillDataToBitmap(downloaded_size, downloaded_size, &bitmap); | 360 FillDataToBitmap(downloaded_size, downloaded_size, &bitmap); |
405 bitmaps.push_back(bitmap); | 361 bitmaps.push_back(bitmap); |
406 original_bitmap_sizes.push_back(gfx::Size(original_size, original_size)); | 362 original_bitmap_sizes.push_back(gfx::Size(original_size, original_size)); |
407 } | 363 } |
408 } | 364 } |
409 favicon_handler_->OnDidDownloadFavicon(download_->download_id, | 365 download_->callback.Run(download_->download_id, |
410 download_->image_url, bitmaps, | 366 /*=status_code=*/200, download_->image_url, bitmaps, |
411 original_bitmap_sizes); | 367 original_bitmap_sizes); |
412 callback_invoked_ = true; | 368 callback_invoked_ = true; |
413 } | 369 } |
414 | 370 |
415 class FaviconHandlerTest : public testing::Test { | 371 class FaviconHandlerTest : public testing::Test { |
416 public: | 372 protected: |
417 FaviconHandlerTest() { | 373 FaviconHandlerTest() { |
418 } | 374 } |
419 | 375 |
420 ~FaviconHandlerTest() override {} | 376 ~FaviconHandlerTest() override {} |
421 | 377 |
422 // Simulates requesting a favicon for |page_url| given: | 378 // Simulates requesting a favicon for |page_url| given: |
423 // - We have not previously cached anything in history for |page_url| or for | 379 // - We have not previously cached anything in history for |page_url| or for |
424 // any of |candidates|. | 380 // any of |candidates|. |
425 // - The page provides favicons at |candidate_icons|. | 381 // - The page provides favicons at |candidate_icons|. |
426 // - The favicons at |candidate_icons| have edge pixel sizes of | 382 // - The favicons at |candidate_icons| have edge pixel sizes of |
427 // |candidate_icon_sizes|. | 383 // |candidate_icon_sizes|. |
428 void DownloadTillDoneIgnoringHistory( | 384 void DownloadTillDoneIgnoringHistory( |
429 TestFaviconDriver* favicon_driver, | 385 TestDelegate* delegate, |
430 TestFaviconHandler* favicon_handler, | 386 TestFaviconHandler* favicon_handler, |
431 const GURL& page_url, | 387 const GURL& page_url, |
432 const std::vector<FaviconURL>& candidate_icons, | 388 const std::vector<FaviconURL>& candidate_icons, |
433 const int* candidate_icon_sizes) { | 389 const int* candidate_icon_sizes) { |
434 size_t old_num_notifications = favicon_driver->num_notifications(); | 390 size_t old_num_notifications = delegate->num_notifications(); |
435 | 391 |
436 UpdateFaviconURL( | 392 UpdateFaviconURL(delegate, favicon_handler, page_url, candidate_icons); |
437 favicon_driver, favicon_handler, page_url, candidate_icons); | |
438 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); | 393 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); |
439 | 394 |
440 DownloadHandler* download_handler = favicon_handler->download_handler(); | 395 DownloadHandler* download_handler = delegate->download_handler(); |
441 for (size_t i = 0; i < candidate_icons.size(); ++i) { | 396 for (size_t i = 0; i < candidate_icons.size(); ++i) { |
442 favicon_handler->history_handler()->history_results_.clear(); | 397 favicon_handler->history_handler()->history_results_.clear(); |
443 favicon_handler->history_handler()->InvokeCallback(); | 398 favicon_handler->history_handler()->InvokeCallback(); |
444 ASSERT_TRUE(download_handler->HasDownload()); | 399 ASSERT_TRUE(download_handler->HasDownload()); |
445 EXPECT_EQ(download_handler->GetImageUrl(), | 400 EXPECT_EQ(download_handler->GetImageUrl(), |
446 candidate_icons[i].icon_url); | 401 candidate_icons[i].icon_url); |
447 std::vector<int> sizes; | 402 std::vector<int> sizes; |
448 sizes.push_back(candidate_icon_sizes[i]); | 403 sizes.push_back(candidate_icon_sizes[i]); |
449 download_handler->SetImageSizes(sizes); | 404 download_handler->SetImageSizes(sizes); |
450 download_handler->InvokeCallback(); | 405 download_handler->InvokeCallback(); |
451 | 406 |
452 download_handler->Reset(); | 407 download_handler->Reset(); |
453 | 408 |
454 if (favicon_driver->num_notifications() > old_num_notifications) | 409 if (delegate->num_notifications() > old_num_notifications) |
455 return; | 410 return; |
456 } | 411 } |
457 } | 412 } |
458 | 413 |
459 void UpdateFaviconURL(TestFaviconDriver* favicon_driver, | 414 void UpdateFaviconURL(TestDelegate* delegate, |
460 TestFaviconHandler* favicon_handler, | 415 TestFaviconHandler* favicon_handler, |
461 const GURL& page_url, | 416 const GURL& page_url, |
462 const std::vector<FaviconURL>& candidate_icons) { | 417 const std::vector<FaviconURL>& candidate_icons) { |
463 favicon_driver->ResetNumNotifications(); | 418 delegate->ResetNumNotifications(); |
464 | 419 |
465 favicon_handler->FetchFavicon(page_url); | 420 favicon_handler->FetchFavicon(page_url); |
466 favicon_handler->history_handler()->InvokeCallback(); | 421 favicon_handler->history_handler()->InvokeCallback(); |
467 | 422 |
468 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); | 423 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); |
469 } | 424 } |
470 | 425 |
471 void SetUp() override { | 426 void SetUp() override { |
472 // The score computed by SelectFaviconFrames() is dependent on the supported | 427 // The score computed by SelectFaviconFrames() is dependent on the supported |
473 // scale factors of the platform. It is used for determining the goodness of | 428 // scale factors of the platform. It is used for determining the goodness of |
474 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 429 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
475 // Force the values of the scale factors so that the tests produce the same | 430 // Force the values of the scale factors so that the tests produce the same |
476 // results on all platforms. | 431 // results on all platforms. |
477 std::vector<ui::ScaleFactor> scale_factors; | 432 std::vector<ui::ScaleFactor> scale_factors; |
478 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 433 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
479 scoped_set_supported_scale_factors_.reset( | 434 scoped_set_supported_scale_factors_.reset( |
480 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); | 435 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); |
481 testing::Test::SetUp(); | 436 testing::Test::SetUp(); |
482 } | 437 } |
483 | 438 |
484 private: | |
485 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 439 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
486 scoped_set_supported_scale_factors_; | 440 scoped_set_supported_scale_factors_; |
487 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 441 testing::StrictMock<MockFaviconService> favicon_service_; |
488 }; | 442 }; |
489 | 443 |
490 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 444 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
491 const GURL page_url("http://www.google.com"); | 445 const GURL page_url("http://www.google.com"); |
492 const GURL icon_url("http://www.google.com/favicon"); | 446 const GURL icon_url("http://www.google.com/favicon"); |
493 | 447 |
494 TestFaviconDriver driver; | 448 TestDelegate delegate; |
495 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 449 TestFaviconHandler helper(&favicon_service_, &delegate, |
450 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
496 | 451 |
497 helper.FetchFavicon(page_url); | 452 helper.FetchFavicon(page_url); |
498 HistoryRequestHandler* history_handler = helper.history_handler(); | 453 HistoryRequestHandler* history_handler = helper.history_handler(); |
499 // Ensure the data given to history is correct. | 454 // Ensure the data given to history is correct. |
500 ASSERT_TRUE(history_handler); | 455 ASSERT_TRUE(history_handler); |
501 EXPECT_EQ(page_url, history_handler->page_url_); | 456 EXPECT_EQ(page_url, history_handler->page_url_); |
502 EXPECT_EQ(GURL(), history_handler->icon_url_); | 457 EXPECT_EQ(GURL(), history_handler->icon_url_); |
503 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 458 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
504 | 459 |
505 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 460 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
506 | 461 |
507 // Send history response. | 462 // Send history response. |
508 history_handler->InvokeCallback(); | 463 history_handler->InvokeCallback(); |
509 // Verify FaviconHandler status | 464 // Verify FaviconHandler status |
510 EXPECT_EQ(1u, driver.num_notifications()); | 465 EXPECT_EQ(1u, delegate.num_notifications()); |
511 EXPECT_EQ(icon_url, driver.icon_url()); | 466 EXPECT_EQ(icon_url, delegate.icon_url()); |
512 | 467 |
513 // Simulates update favicon url. | 468 // Simulates update favicon url. |
514 std::vector<FaviconURL> urls; | 469 std::vector<FaviconURL> urls; |
515 urls.push_back( | 470 urls.push_back( |
516 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 471 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
517 helper.OnUpdateFaviconURL(page_url, urls); | 472 helper.OnUpdateFaviconURL(page_url, urls); |
518 | 473 |
519 // Verify FaviconHandler status | 474 // Verify FaviconHandler status |
520 EXPECT_EQ(1u, helper.image_urls().size()); | 475 EXPECT_EQ(1u, helper.image_urls().size()); |
521 ASSERT_TRUE(helper.current_candidate()); | 476 ASSERT_TRUE(helper.current_candidate()); |
522 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 477 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
523 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 478 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
524 | 479 |
525 // Favicon shouldn't request to download icon. | 480 // Favicon shouldn't request to download icon. |
526 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 481 EXPECT_FALSE(delegate.download_handler()->HasDownload()); |
527 } | 482 } |
528 | 483 |
529 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 484 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
530 const GURL page_url("http://www.google.com"); | 485 const GURL page_url("http://www.google.com"); |
531 const GURL icon_url("http://www.google.com/favicon"); | 486 const GURL icon_url("http://www.google.com/favicon"); |
532 | 487 |
533 TestFaviconDriver driver; | 488 TestDelegate delegate; |
534 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 489 TestFaviconHandler helper(&favicon_service_, &delegate, |
490 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
535 | 491 |
536 helper.FetchFavicon(page_url); | 492 helper.FetchFavicon(page_url); |
537 HistoryRequestHandler* history_handler = helper.history_handler(); | 493 HistoryRequestHandler* history_handler = helper.history_handler(); |
538 // Ensure the data given to history is correct. | 494 // Ensure the data given to history is correct. |
539 ASSERT_TRUE(history_handler); | 495 ASSERT_TRUE(history_handler); |
540 EXPECT_EQ(page_url, history_handler->page_url_); | 496 EXPECT_EQ(page_url, history_handler->page_url_); |
541 EXPECT_EQ(GURL(), history_handler->icon_url_); | 497 EXPECT_EQ(GURL(), history_handler->icon_url_); |
542 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 498 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
543 | 499 |
544 // Set icon data expired | 500 // Set icon data expired |
545 SetFaviconRawBitmapResult(icon_url, | 501 SetFaviconRawBitmapResult(icon_url, |
546 favicon_base::FAVICON, | 502 favicon_base::FAVICON, |
547 true /* expired */, | 503 true /* expired */, |
548 &history_handler->history_results_); | 504 &history_handler->history_results_); |
549 // Send history response. | 505 // Send history response. |
550 history_handler->InvokeCallback(); | 506 history_handler->InvokeCallback(); |
551 // Verify FaviconHandler status | 507 // Verify FaviconHandler status |
552 EXPECT_EQ(1u, driver.num_notifications()); | 508 EXPECT_EQ(1u, delegate.num_notifications()); |
553 EXPECT_EQ(icon_url, driver.icon_url()); | 509 EXPECT_EQ(icon_url, delegate.icon_url()); |
554 | 510 |
555 // Simulates update favicon url. | 511 // Simulates update favicon url. |
556 std::vector<FaviconURL> urls; | 512 std::vector<FaviconURL> urls; |
557 urls.push_back( | 513 urls.push_back( |
558 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 514 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
559 helper.OnUpdateFaviconURL(page_url, urls); | 515 helper.OnUpdateFaviconURL(page_url, urls); |
560 | 516 |
561 // Verify FaviconHandler status | 517 // Verify FaviconHandler status |
562 EXPECT_EQ(1u, helper.image_urls().size()); | 518 EXPECT_EQ(1u, helper.image_urls().size()); |
563 ASSERT_TRUE(helper.current_candidate()); | 519 ASSERT_TRUE(helper.current_candidate()); |
564 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 520 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
565 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 521 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
566 | 522 |
567 // Favicon should request to download icon now. | 523 // Favicon should request to download icon now. |
568 DownloadHandler* download_handler = helper.download_handler(); | 524 DownloadHandler* download_handler = delegate.download_handler(); |
569 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 525 EXPECT_TRUE(download_handler->HasDownload()); |
570 | 526 |
571 // Verify the download request. | 527 // Verify the download request. |
572 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 528 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
573 | 529 |
574 // Reset the history_handler to verify whether favicon is set. | 530 // Reset the history_handler to verify whether favicon is set. |
575 helper.set_history_handler(nullptr); | 531 helper.set_history_handler(nullptr); |
576 | 532 |
577 // Smulates download done. | 533 // Smulates download done. |
578 download_handler->InvokeCallback(); | 534 download_handler->InvokeCallback(); |
579 | 535 |
580 // New icon should be saved to history backend and navigation entry. | 536 // New icon should be saved to history backend and navigation entry. |
581 history_handler = helper.history_handler(); | 537 history_handler = helper.history_handler(); |
582 ASSERT_TRUE(history_handler); | 538 ASSERT_TRUE(history_handler); |
583 EXPECT_EQ(icon_url, history_handler->icon_url_); | 539 EXPECT_EQ(icon_url, history_handler->icon_url_); |
584 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 540 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
585 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 541 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
586 EXPECT_EQ(page_url, history_handler->page_url_); | 542 EXPECT_EQ(page_url, history_handler->page_url_); |
587 | 543 |
588 // Verify NavigationEntry. | 544 // Verify NavigationEntry. |
589 EXPECT_EQ(2u, driver.num_notifications()); | 545 EXPECT_EQ(2u, delegate.num_notifications()); |
590 EXPECT_EQ(icon_url, driver.icon_url()); | 546 EXPECT_EQ(icon_url, delegate.icon_url()); |
591 EXPECT_FALSE(driver.image().IsEmpty()); | 547 EXPECT_FALSE(delegate.image().IsEmpty()); |
592 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 548 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); |
593 } | 549 } |
594 | 550 |
595 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 551 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
596 const GURL page_url("http://www.google.com"); | 552 const GURL page_url("http://www.google.com"); |
597 const GURL icon_url("http://www.google.com/favicon"); | 553 const GURL icon_url("http://www.google.com/favicon"); |
598 const GURL new_icon_url("http://www.google.com/new_favicon"); | 554 const GURL new_icon_url("http://www.google.com/new_favicon"); |
599 | 555 |
600 TestFaviconDriver driver; | 556 TestDelegate delegate; |
601 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 557 TestFaviconHandler helper(&favicon_service_, &delegate, |
558 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
602 | 559 |
603 helper.FetchFavicon(page_url); | 560 helper.FetchFavicon(page_url); |
604 HistoryRequestHandler* history_handler = helper.history_handler(); | 561 HistoryRequestHandler* history_handler = helper.history_handler(); |
605 // Ensure the data given to history is correct. | 562 // Ensure the data given to history is correct. |
606 ASSERT_TRUE(history_handler); | 563 ASSERT_TRUE(history_handler); |
607 EXPECT_EQ(page_url, history_handler->page_url_); | 564 EXPECT_EQ(page_url, history_handler->page_url_); |
608 EXPECT_EQ(GURL(), history_handler->icon_url_); | 565 EXPECT_EQ(GURL(), history_handler->icon_url_); |
609 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 566 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
610 | 567 |
611 // Set valid icon data. | 568 // Set valid icon data. |
612 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 569 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
613 | 570 |
614 // Send history response. | 571 // Send history response. |
615 history_handler->InvokeCallback(); | 572 history_handler->InvokeCallback(); |
616 // Verify FaviconHandler status. | 573 // Verify FaviconHandler status. |
617 EXPECT_EQ(1u, driver.num_notifications()); | 574 EXPECT_EQ(1u, delegate.num_notifications()); |
618 EXPECT_EQ(icon_url, driver.icon_url()); | 575 EXPECT_EQ(icon_url, delegate.icon_url()); |
619 | 576 |
620 // Reset the history_handler to verify whether new icon is requested from | 577 // Reset the history_handler to verify whether new icon is requested from |
621 // history. | 578 // history. |
622 helper.set_history_handler(nullptr); | 579 helper.set_history_handler(nullptr); |
623 | 580 |
624 // Simulates update with the different favicon url. | 581 // Simulates update with the different favicon url. |
625 std::vector<FaviconURL> urls; | 582 std::vector<FaviconURL> urls; |
626 urls.push_back(FaviconURL( | 583 urls.push_back(FaviconURL( |
627 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 584 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
628 helper.OnUpdateFaviconURL(page_url, urls); | 585 helper.OnUpdateFaviconURL(page_url, urls); |
629 | 586 |
630 // Verify FaviconHandler status. | 587 // Verify FaviconHandler status. |
631 EXPECT_EQ(1u, helper.image_urls().size()); | 588 EXPECT_EQ(1u, helper.image_urls().size()); |
632 ASSERT_TRUE(helper.current_candidate()); | 589 ASSERT_TRUE(helper.current_candidate()); |
633 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 590 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
634 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 591 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
635 | 592 |
636 // Favicon should be requested from history. | 593 // Favicon should be requested from history. |
637 history_handler = helper.history_handler(); | 594 history_handler = helper.history_handler(); |
638 ASSERT_TRUE(history_handler); | 595 ASSERT_TRUE(history_handler); |
639 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 596 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
640 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 597 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
641 EXPECT_EQ(page_url, history_handler->page_url_); | 598 EXPECT_EQ(page_url, history_handler->page_url_); |
642 | 599 |
643 // Simulate not find icon. | 600 // Simulate not find icon. |
644 history_handler->history_results_.clear(); | 601 history_handler->history_results_.clear(); |
645 history_handler->InvokeCallback(); | 602 history_handler->InvokeCallback(); |
646 | 603 |
647 // Favicon should request to download icon now. | 604 // Favicon should request to download icon now. |
648 DownloadHandler* download_handler = helper.download_handler(); | 605 DownloadHandler* download_handler = delegate.download_handler(); |
649 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 606 EXPECT_TRUE(download_handler->HasDownload()); |
650 | 607 |
651 // Verify the download request. | 608 // Verify the download request. |
652 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 609 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
653 | 610 |
654 // Reset the history_handler to verify whether favicon is set. | 611 // Reset the history_handler to verify whether favicon is set. |
655 helper.set_history_handler(nullptr); | 612 helper.set_history_handler(nullptr); |
656 | 613 |
657 // Smulates download done. | 614 // Smulates download done. |
658 download_handler->InvokeCallback(); | 615 download_handler->InvokeCallback(); |
659 | 616 |
660 // New icon should be saved to history backend and navigation entry. | 617 // New icon should be saved to history backend and navigation entry. |
661 history_handler = helper.history_handler(); | 618 history_handler = helper.history_handler(); |
662 ASSERT_TRUE(history_handler); | 619 ASSERT_TRUE(history_handler); |
663 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 620 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
664 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 621 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
665 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 622 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
666 EXPECT_EQ(page_url, history_handler->page_url_); | 623 EXPECT_EQ(page_url, history_handler->page_url_); |
667 | 624 |
668 // Verify NavigationEntry. | 625 // Verify NavigationEntry. |
669 EXPECT_EQ(2u, driver.num_notifications()); | 626 EXPECT_EQ(2u, delegate.num_notifications()); |
670 EXPECT_EQ(new_icon_url, driver.icon_url()); | 627 EXPECT_EQ(new_icon_url, delegate.icon_url()); |
671 EXPECT_FALSE(driver.image().IsEmpty()); | 628 EXPECT_FALSE(delegate.image().IsEmpty()); |
672 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 629 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); |
673 } | 630 } |
674 | 631 |
675 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 632 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
676 const GURL page_url("http://www.google.com"); | 633 const GURL page_url("http://www.google.com"); |
677 const GURL icon_url("http://www.google.com/favicon"); | 634 const GURL icon_url("http://www.google.com/favicon"); |
678 | 635 |
679 TestFaviconDriver driver; | 636 TestDelegate delegate; |
680 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 637 TestFaviconHandler helper(&favicon_service_, &delegate, |
638 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
681 | 639 |
682 helper.FetchFavicon(page_url); | 640 helper.FetchFavicon(page_url); |
683 HistoryRequestHandler* history_handler = helper.history_handler(); | 641 HistoryRequestHandler* history_handler = helper.history_handler(); |
684 // Ensure the data given to history is correct. | 642 // Ensure the data given to history is correct. |
685 ASSERT_TRUE(history_handler); | 643 ASSERT_TRUE(history_handler); |
686 EXPECT_EQ(page_url, history_handler->page_url_); | 644 EXPECT_EQ(page_url, history_handler->page_url_); |
687 EXPECT_EQ(GURL(), history_handler->icon_url_); | 645 EXPECT_EQ(GURL(), history_handler->icon_url_); |
688 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 646 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
689 | 647 |
690 // Set non empty but invalid data. | 648 // Set non empty but invalid data. |
691 favicon_base::FaviconRawBitmapResult bitmap_result; | 649 favicon_base::FaviconRawBitmapResult bitmap_result; |
692 bitmap_result.expired = false; | 650 bitmap_result.expired = false; |
693 // Empty bitmap data is invalid. | 651 // Empty bitmap data is invalid. |
694 bitmap_result.bitmap_data = new base::RefCountedBytes(); | 652 bitmap_result.bitmap_data = new base::RefCountedBytes(); |
695 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); | 653 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
696 bitmap_result.icon_type = favicon_base::FAVICON; | 654 bitmap_result.icon_type = favicon_base::FAVICON; |
697 bitmap_result.icon_url = icon_url; | 655 bitmap_result.icon_url = icon_url; |
698 history_handler->history_results_.clear(); | 656 history_handler->history_results_.clear(); |
699 history_handler->history_results_.push_back(bitmap_result); | 657 history_handler->history_results_.push_back(bitmap_result); |
700 | 658 |
701 // Send history response. | 659 // Send history response. |
702 history_handler->InvokeCallback(); | 660 history_handler->InvokeCallback(); |
703 // The NavigationEntry should not be set yet as the history data is invalid. | 661 // The NavigationEntry should not be set yet as the history data is invalid. |
704 EXPECT_EQ(0u, driver.num_notifications()); | 662 EXPECT_EQ(0u, delegate.num_notifications()); |
705 EXPECT_EQ(GURL(), driver.icon_url()); | 663 EXPECT_EQ(GURL(), delegate.icon_url()); |
706 | 664 |
707 // Reset the history_handler to verify whether new icon is requested from | 665 // Reset the history_handler to verify whether new icon is requested from |
708 // history. | 666 // history. |
709 helper.set_history_handler(nullptr); | 667 helper.set_history_handler(nullptr); |
710 | 668 |
711 // Simulates update with matching favicon URL. | 669 // Simulates update with matching favicon URL. |
712 std::vector<FaviconURL> urls; | 670 std::vector<FaviconURL> urls; |
713 urls.push_back( | 671 urls.push_back( |
714 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 672 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
715 helper.OnUpdateFaviconURL(page_url, urls); | 673 helper.OnUpdateFaviconURL(page_url, urls); |
716 | 674 |
717 // A download for the favicon should be requested, and we should not do | 675 // A download for the favicon should be requested, and we should not do |
718 // another history request. | 676 // another history request. |
719 DownloadHandler* download_handler = helper.download_handler(); | 677 DownloadHandler* download_handler = delegate.download_handler(); |
720 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 678 EXPECT_TRUE(download_handler->HasDownload()); |
721 EXPECT_EQ(nullptr, helper.history_handler()); | 679 EXPECT_EQ(nullptr, helper.history_handler()); |
722 | 680 |
723 // Verify the download request. | 681 // Verify the download request. |
724 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 682 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
725 | 683 |
726 // Simulates download done. | 684 // Simulates download done. |
727 download_handler->InvokeCallback(); | 685 download_handler->InvokeCallback(); |
728 | 686 |
729 // New icon should be saved to history backend and navigation entry. | 687 // New icon should be saved to history backend and navigation entry. |
730 history_handler = helper.history_handler(); | 688 history_handler = helper.history_handler(); |
731 ASSERT_TRUE(history_handler); | 689 ASSERT_TRUE(history_handler); |
732 EXPECT_EQ(icon_url, history_handler->icon_url_); | 690 EXPECT_EQ(icon_url, history_handler->icon_url_); |
733 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 691 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
734 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 692 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
735 EXPECT_EQ(page_url, history_handler->page_url_); | 693 EXPECT_EQ(page_url, history_handler->page_url_); |
736 | 694 |
737 // Verify NavigationEntry. | 695 // Verify NavigationEntry. |
738 EXPECT_EQ(1u, driver.num_notifications()); | 696 EXPECT_EQ(1u, delegate.num_notifications()); |
739 EXPECT_EQ(icon_url, driver.icon_url()); | 697 EXPECT_EQ(icon_url, delegate.icon_url()); |
740 EXPECT_FALSE(driver.image().IsEmpty()); | 698 EXPECT_FALSE(delegate.image().IsEmpty()); |
741 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 699 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); |
742 } | 700 } |
743 | 701 |
744 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 702 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
745 const GURL page_url("http://www.google.com"); | 703 const GURL page_url("http://www.google.com"); |
746 const GURL icon_url("http://www.google.com/favicon"); | 704 const GURL icon_url("http://www.google.com/favicon"); |
747 const GURL new_icon_url("http://www.google.com/new_favicon"); | 705 const GURL new_icon_url("http://www.google.com/new_favicon"); |
748 | 706 |
749 TestFaviconDriver driver; | 707 TestDelegate delegate; |
750 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 708 TestFaviconHandler helper(&favicon_service_, &delegate, |
709 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
751 | 710 |
752 helper.FetchFavicon(page_url); | 711 helper.FetchFavicon(page_url); |
753 HistoryRequestHandler* history_handler = helper.history_handler(); | 712 HistoryRequestHandler* history_handler = helper.history_handler(); |
754 // Ensure the data given to history is correct. | 713 // Ensure the data given to history is correct. |
755 ASSERT_TRUE(history_handler); | 714 ASSERT_TRUE(history_handler); |
756 EXPECT_EQ(page_url, history_handler->page_url_); | 715 EXPECT_EQ(page_url, history_handler->page_url_); |
757 EXPECT_EQ(GURL(), history_handler->icon_url_); | 716 EXPECT_EQ(GURL(), history_handler->icon_url_); |
758 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 717 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
759 | 718 |
760 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 719 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
761 | 720 |
762 // Send history response. | 721 // Send history response. |
763 history_handler->InvokeCallback(); | 722 history_handler->InvokeCallback(); |
764 // Verify FaviconHandler status. | 723 // Verify FaviconHandler status. |
765 EXPECT_EQ(1u, driver.num_notifications()); | 724 EXPECT_EQ(1u, delegate.num_notifications()); |
766 EXPECT_EQ(icon_url, driver.icon_url()); | 725 EXPECT_EQ(icon_url, delegate.icon_url()); |
767 | 726 |
768 // Reset the history_handler to verify whether new icon is requested from | 727 // Reset the history_handler to verify whether new icon is requested from |
769 // history. | 728 // history. |
770 helper.set_history_handler(nullptr); | 729 helper.set_history_handler(nullptr); |
771 | 730 |
772 // Simulates update with the different favicon url. | 731 // Simulates update with the different favicon url. |
773 std::vector<FaviconURL> urls; | 732 std::vector<FaviconURL> urls; |
774 urls.push_back(FaviconURL( | 733 urls.push_back(FaviconURL( |
775 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 734 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
776 helper.OnUpdateFaviconURL(page_url, urls); | 735 helper.OnUpdateFaviconURL(page_url, urls); |
777 | 736 |
778 // Verify FaviconHandler status. | 737 // Verify FaviconHandler status. |
779 EXPECT_EQ(1u, helper.image_urls().size()); | 738 EXPECT_EQ(1u, helper.image_urls().size()); |
780 ASSERT_TRUE(helper.current_candidate()); | 739 ASSERT_TRUE(helper.current_candidate()); |
781 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 740 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
782 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 741 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
783 | 742 |
784 // Favicon should be requested from history. | 743 // Favicon should be requested from history. |
785 history_handler = helper.history_handler(); | 744 history_handler = helper.history_handler(); |
786 ASSERT_TRUE(history_handler); | 745 ASSERT_TRUE(history_handler); |
787 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 746 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
788 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 747 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
789 EXPECT_EQ(page_url, history_handler->page_url_); | 748 EXPECT_EQ(page_url, history_handler->page_url_); |
790 | 749 |
791 // Simulate find icon. | 750 // Simulate find icon. |
792 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); | 751 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); |
793 history_handler->InvokeCallback(); | 752 history_handler->InvokeCallback(); |
794 | 753 |
795 // Shouldn't request download favicon | 754 // Shouldn't request download favicon |
796 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 755 EXPECT_FALSE(delegate.download_handler()->HasDownload()); |
797 | 756 |
798 // Verify the favicon status. | 757 // Verify the favicon status. |
799 EXPECT_EQ(2u, driver.num_notifications()); | 758 EXPECT_EQ(2u, delegate.num_notifications()); |
800 EXPECT_EQ(new_icon_url, driver.icon_url()); | 759 EXPECT_EQ(new_icon_url, delegate.icon_url()); |
801 EXPECT_FALSE(driver.image().IsEmpty()); | 760 EXPECT_FALSE(delegate.image().IsEmpty()); |
802 } | 761 } |
803 | 762 |
804 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 763 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
805 const GURL page_url("http://www.google.com"); | 764 const GURL page_url("http://www.google.com"); |
806 const GURL icon_url("http://www.google.com/favicon"); | 765 const GURL icon_url("http://www.google.com/favicon"); |
807 const GURL new_icon_url("http://www.google.com/new_favicon"); | 766 const GURL new_icon_url("http://www.google.com/new_favicon"); |
808 | 767 |
809 TestFaviconDriver driver; | 768 TestDelegate delegate; |
810 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); | 769 TestFaviconHandler helper(&favicon_service_, &delegate, |
770 FaviconDriverObserver::TOUCH_LARGEST); | |
811 std::set<GURL> fail_downloads; | 771 std::set<GURL> fail_downloads; |
812 fail_downloads.insert(icon_url); | 772 fail_downloads.insert(icon_url); |
813 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); | 773 delegate.download_handler()->FailDownloadForIconURLs(fail_downloads); |
814 | 774 |
815 helper.FetchFavicon(page_url); | 775 helper.FetchFavicon(page_url); |
816 HistoryRequestHandler* history_handler = helper.history_handler(); | 776 HistoryRequestHandler* history_handler = helper.history_handler(); |
817 // Ensure the data given to history is correct. | 777 // Ensure the data given to history is correct. |
818 ASSERT_TRUE(history_handler); | 778 ASSERT_TRUE(history_handler); |
819 EXPECT_EQ(page_url, history_handler->page_url_); | 779 EXPECT_EQ(page_url, history_handler->page_url_); |
820 EXPECT_EQ(GURL(), history_handler->icon_url_); | 780 EXPECT_EQ(GURL(), history_handler->icon_url_); |
821 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 781 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
822 history_handler->icon_type_); | 782 history_handler->icon_type_); |
823 | 783 |
824 // Icon not found. | 784 // Icon not found. |
825 history_handler->history_results_.clear(); | 785 history_handler->history_results_.clear(); |
826 // Send history response. | 786 // Send history response. |
827 history_handler->InvokeCallback(); | 787 history_handler->InvokeCallback(); |
828 // Verify FaviconHandler status. | 788 // Verify FaviconHandler status. |
829 EXPECT_EQ(0u, driver.num_notifications()); | 789 EXPECT_EQ(0u, delegate.num_notifications()); |
830 EXPECT_EQ(GURL(), driver.icon_url()); | 790 EXPECT_EQ(GURL(), delegate.icon_url()); |
831 | 791 |
832 // Reset the history_handler to verify whether new icon is requested from | 792 // Reset the history_handler to verify whether new icon is requested from |
833 // history. | 793 // history. |
834 helper.set_history_handler(nullptr); | 794 helper.set_history_handler(nullptr); |
835 | 795 |
836 // Simulates update with the different favicon url. | 796 // Simulates update with the different favicon url. |
837 std::vector<FaviconURL> urls; | 797 std::vector<FaviconURL> urls; |
838 urls.push_back(FaviconURL(icon_url, | 798 urls.push_back(FaviconURL(icon_url, |
839 favicon_base::TOUCH_PRECOMPOSED_ICON, | 799 favicon_base::TOUCH_PRECOMPOSED_ICON, |
840 std::vector<gfx::Size>())); | 800 std::vector<gfx::Size>())); |
(...skipping 16 matching lines...) Expand all Loading... | |
857 ASSERT_TRUE(history_handler); | 817 ASSERT_TRUE(history_handler); |
858 EXPECT_EQ(icon_url, history_handler->icon_url_); | 818 EXPECT_EQ(icon_url, history_handler->icon_url_); |
859 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 819 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
860 EXPECT_EQ(page_url, history_handler->page_url_); | 820 EXPECT_EQ(page_url, history_handler->page_url_); |
861 | 821 |
862 // Simulate not find icon. | 822 // Simulate not find icon. |
863 history_handler->history_results_.clear(); | 823 history_handler->history_results_.clear(); |
864 history_handler->InvokeCallback(); | 824 history_handler->InvokeCallback(); |
865 | 825 |
866 // Should request download favicon. | 826 // Should request download favicon. |
867 DownloadHandler* download_handler = helper.download_handler(); | 827 DownloadHandler* download_handler = delegate.download_handler(); |
868 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 828 EXPECT_TRUE(download_handler->HasDownload()); |
869 | 829 |
870 // Verify the download request. | 830 // Verify the download request. |
871 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 831 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
872 | 832 |
873 // Reset the history_handler to verify whether favicon is request from | 833 // Reset the history_handler to verify whether favicon is request from |
874 // history. | 834 // history. |
875 helper.set_history_handler(nullptr); | 835 helper.set_history_handler(nullptr); |
876 download_handler->InvokeCallback(); | 836 download_handler->InvokeCallback(); |
877 | 837 |
878 // Left 1 url. | 838 // Left 1 url. |
(...skipping 13 matching lines...) Expand all Loading... | |
892 download_handler->Reset(); | 852 download_handler->Reset(); |
893 | 853 |
894 // Simulates getting a expired icon from history. | 854 // Simulates getting a expired icon from history. |
895 SetFaviconRawBitmapResult(new_icon_url, | 855 SetFaviconRawBitmapResult(new_icon_url, |
896 favicon_base::TOUCH_ICON, | 856 favicon_base::TOUCH_ICON, |
897 true /* expired */, | 857 true /* expired */, |
898 &history_handler->history_results_); | 858 &history_handler->history_results_); |
899 history_handler->InvokeCallback(); | 859 history_handler->InvokeCallback(); |
900 | 860 |
901 // Verify the download request. | 861 // Verify the download request. |
902 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 862 EXPECT_TRUE(delegate.download_handler()->HasDownload()); |
903 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 863 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
904 | 864 |
905 helper.set_history_handler(nullptr); | 865 helper.set_history_handler(nullptr); |
906 | 866 |
907 // Simulates icon being downloaded. | 867 // Simulates icon being downloaded. |
908 download_handler->InvokeCallback(); | 868 download_handler->InvokeCallback(); |
909 | 869 |
910 // New icon should be saved to history backend. | 870 // New icon should be saved to history backend. |
911 history_handler = helper.history_handler(); | 871 history_handler = helper.history_handler(); |
912 ASSERT_TRUE(history_handler); | 872 ASSERT_TRUE(history_handler); |
913 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 873 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
914 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); | 874 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); |
915 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 875 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
916 EXPECT_EQ(page_url, history_handler->page_url_); | 876 EXPECT_EQ(page_url, history_handler->page_url_); |
917 } | 877 } |
918 | 878 |
919 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 879 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
920 const GURL page_url("http://www.google.com"); | 880 const GURL page_url("http://www.google.com"); |
921 const GURL icon_url("http://www.google.com/favicon"); | 881 const GURL icon_url("http://www.google.com/favicon"); |
922 const GURL new_icon_url("http://www.google.com/new_favicon"); | 882 const GURL new_icon_url("http://www.google.com/new_favicon"); |
923 | 883 |
924 TestFaviconDriver driver; | 884 TestDelegate delegate; |
925 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); | 885 TestFaviconHandler helper(&favicon_service_, &delegate, |
886 FaviconDriverObserver::TOUCH_LARGEST); | |
926 | 887 |
927 helper.FetchFavicon(page_url); | 888 helper.FetchFavicon(page_url); |
928 HistoryRequestHandler* history_handler = helper.history_handler(); | 889 HistoryRequestHandler* history_handler = helper.history_handler(); |
929 // Ensure the data given to history is correct. | 890 // Ensure the data given to history is correct. |
930 ASSERT_TRUE(history_handler); | 891 ASSERT_TRUE(history_handler); |
931 EXPECT_EQ(page_url, history_handler->page_url_); | 892 EXPECT_EQ(page_url, history_handler->page_url_); |
932 EXPECT_EQ(GURL(), history_handler->icon_url_); | 893 EXPECT_EQ(GURL(), history_handler->icon_url_); |
933 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 894 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
934 history_handler->icon_type_); | 895 history_handler->icon_type_); |
935 | 896 |
936 // Icon not found. | 897 // Icon not found. |
937 history_handler->history_results_.clear(); | 898 history_handler->history_results_.clear(); |
938 // Send history response. | 899 // Send history response. |
939 history_handler->InvokeCallback(); | 900 history_handler->InvokeCallback(); |
940 // Verify FaviconHandler status. | 901 // Verify FaviconHandler status. |
941 EXPECT_EQ(0u, driver.num_notifications()); | 902 EXPECT_EQ(0u, delegate.num_notifications()); |
942 EXPECT_EQ(GURL(), driver.icon_url()); | 903 EXPECT_EQ(GURL(), delegate.icon_url()); |
943 | 904 |
944 // Reset the history_handler to verify whether new icon is requested from | 905 // Reset the history_handler to verify whether new icon is requested from |
945 // history. | 906 // history. |
946 helper.set_history_handler(nullptr); | 907 helper.set_history_handler(nullptr); |
947 | 908 |
948 // Simulates update with the different favicon url. | 909 // Simulates update with the different favicon url. |
949 std::vector<FaviconURL> urls; | 910 std::vector<FaviconURL> urls; |
950 urls.push_back(FaviconURL(icon_url, | 911 urls.push_back(FaviconURL(icon_url, |
951 favicon_base::TOUCH_PRECOMPOSED_ICON, | 912 favicon_base::TOUCH_PRECOMPOSED_ICON, |
952 std::vector<gfx::Size>())); | 913 std::vector<gfx::Size>())); |
(...skipping 15 matching lines...) Expand all Loading... | |
968 ASSERT_TRUE(history_handler); | 929 ASSERT_TRUE(history_handler); |
969 EXPECT_EQ(icon_url, history_handler->icon_url_); | 930 EXPECT_EQ(icon_url, history_handler->icon_url_); |
970 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 931 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
971 EXPECT_EQ(page_url, history_handler->page_url_); | 932 EXPECT_EQ(page_url, history_handler->page_url_); |
972 | 933 |
973 // Simulate not find icon. | 934 // Simulate not find icon. |
974 history_handler->history_results_.clear(); | 935 history_handler->history_results_.clear(); |
975 history_handler->InvokeCallback(); | 936 history_handler->InvokeCallback(); |
976 | 937 |
977 // Should request download favicon. | 938 // Should request download favicon. |
978 DownloadHandler* download_handler = helper.download_handler(); | 939 DownloadHandler* download_handler = delegate.download_handler(); |
979 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 940 EXPECT_TRUE(download_handler->HasDownload()); |
980 | 941 |
981 // Verify the download request. | 942 // Verify the download request. |
982 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 943 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
983 | 944 |
984 // Reset the history_handler to verify whether favicon is request from | 945 // Reset the history_handler to verify whether favicon is request from |
985 // history. | 946 // history. |
986 helper.set_history_handler(nullptr); | 947 helper.set_history_handler(nullptr); |
987 const GURL latest_icon_url("http://www.google.com/latest_favicon"); | 948 const GURL latest_icon_url("http://www.google.com/latest_favicon"); |
988 std::vector<FaviconURL> latest_urls; | 949 std::vector<FaviconURL> latest_urls; |
989 latest_urls.push_back(FaviconURL( | 950 latest_urls.push_back(FaviconURL( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1036 const GURL icon_url1("http://www.google.com/favicon1"); | 997 const GURL icon_url1("http://www.google.com/favicon1"); |
1037 const GURL icon_url2("http://www.google.com/favicon2"); | 998 const GURL icon_url2("http://www.google.com/favicon2"); |
1038 std::vector<FaviconURL> favicon_urls; | 999 std::vector<FaviconURL> favicon_urls; |
1039 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), | 1000 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), |
1040 favicon_base::FAVICON, | 1001 favicon_base::FAVICON, |
1041 std::vector<gfx::Size>())); | 1002 std::vector<gfx::Size>())); |
1042 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), | 1003 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), |
1043 favicon_base::FAVICON, | 1004 favicon_base::FAVICON, |
1044 std::vector<gfx::Size>())); | 1005 std::vector<gfx::Size>())); |
1045 | 1006 |
1046 TestFaviconDriver driver; | 1007 TestDelegate delegate; |
1047 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1008 TestFaviconHandler helper(&favicon_service_, &delegate, |
1009 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
1048 | 1010 |
1049 // Initiate a request for favicon data for |page_url|. History does not know | 1011 // Initiate a request for favicon data for |page_url|. History does not know |
1050 // about the page URL or the icon URLs. | 1012 // about the page URL or the icon URLs. |
1051 helper.FetchFavicon(page_url); | 1013 helper.FetchFavicon(page_url); |
1052 helper.history_handler()->InvokeCallback(); | 1014 helper.history_handler()->InvokeCallback(); |
1053 helper.set_history_handler(nullptr); | 1015 helper.set_history_handler(nullptr); |
1054 | 1016 |
1055 // Got icon URLs. | 1017 // Got icon URLs. |
1056 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1018 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
1057 | 1019 |
1058 // There should be an ongoing history request for |icon_url1|. | 1020 // There should be an ongoing history request for |icon_url1|. |
1059 ASSERT_EQ(2u, helper.image_urls().size()); | 1021 ASSERT_EQ(2u, helper.image_urls().size()); |
1060 ASSERT_EQ(0u, helper.current_candidate_index()); | 1022 ASSERT_EQ(0u, helper.current_candidate_index()); |
1061 HistoryRequestHandler* history_handler = helper.history_handler(); | 1023 HistoryRequestHandler* history_handler = helper.history_handler(); |
1062 ASSERT_TRUE(history_handler); | 1024 ASSERT_TRUE(history_handler); |
1063 | 1025 |
1064 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. | 1026 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. |
1065 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1027 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
1066 EXPECT_EQ(history_handler, helper.history_handler()); | 1028 EXPECT_EQ(history_handler, helper.history_handler()); |
1067 | 1029 |
1068 // Complete history request for |icon_url1| and do download. | 1030 // Complete history request for |icon_url1| and do download. |
1069 helper.history_handler()->InvokeCallback(); | 1031 helper.history_handler()->InvokeCallback(); |
1070 helper.set_history_handler(nullptr); | 1032 helper.set_history_handler(nullptr); |
1071 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); | 1033 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); |
1072 helper.download_handler()->InvokeCallback(); | 1034 delegate.download_handler()->InvokeCallback(); |
1073 helper.download_handler()->Reset(); | 1035 delegate.download_handler()->Reset(); |
1074 | 1036 |
1075 // There should now be an ongoing history request for |icon_url2|. | 1037 // There should now be an ongoing history request for |icon_url2|. |
1076 ASSERT_EQ(1u, helper.current_candidate_index()); | 1038 ASSERT_EQ(1u, helper.current_candidate_index()); |
1077 history_handler = helper.history_handler(); | 1039 history_handler = helper.history_handler(); |
1078 ASSERT_TRUE(history_handler); | 1040 ASSERT_TRUE(history_handler); |
1079 | 1041 |
1080 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. | 1042 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. |
1081 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1043 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
1082 EXPECT_EQ(history_handler, helper.history_handler()); | 1044 EXPECT_EQ(history_handler, helper.history_handler()); |
1083 } | 1045 } |
1084 | 1046 |
1085 // Fixes crbug.com/544560 | 1047 // Fixes crbug.com/544560 |
1086 TEST_F(FaviconHandlerTest, | 1048 TEST_F(FaviconHandlerTest, |
1087 OnFaviconAvailableNotificationSentAfterIconURLChange) { | 1049 OnFaviconAvailableNotificationSentAfterIconURLChange) { |
1088 const GURL kPageURL("http://www.page_which_animates_favicon.com"); | 1050 const GURL kPageURL("http://www.page_which_animates_favicon.com"); |
1089 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png") ; | 1051 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png") ; |
1090 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png") ; | 1052 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png") ; |
1091 | 1053 |
1092 TestFaviconDriver driver; | 1054 TestDelegate delegate; |
1093 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1055 TestFaviconHandler helper(&favicon_service_, &delegate, |
1056 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
1094 | 1057 |
1095 // Initial state: | 1058 // Initial state: |
1096 // - The database does not know about |kPageURL|. | 1059 // - The database does not know about |kPageURL|. |
1097 // - The page uses |kIconURL1| and |kIconURL2|. | 1060 // - The page uses |kIconURL1| and |kIconURL2|. |
1098 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons | 1061 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons |
1099 // are expired in the database. | 1062 // are expired in the database. |
1100 helper.FetchFavicon(kPageURL); | 1063 helper.FetchFavicon(kPageURL); |
1101 ASSERT_TRUE(helper.history_handler()); | 1064 ASSERT_TRUE(helper.history_handler()); |
1102 helper.history_handler()->InvokeCallback(); | 1065 helper.history_handler()->InvokeCallback(); |
1103 { | 1066 { |
1104 std::vector<FaviconURL> icon_urls; | 1067 std::vector<FaviconURL> icon_urls; |
1105 icon_urls.push_back( | 1068 icon_urls.push_back( |
1106 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>())); | 1069 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>())); |
1107 icon_urls.push_back( | 1070 icon_urls.push_back( |
1108 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>())); | 1071 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>())); |
1109 helper.OnUpdateFaviconURL(kPageURL, icon_urls); | 1072 helper.OnUpdateFaviconURL(kPageURL, icon_urls); |
1110 } | 1073 } |
1111 | 1074 |
1112 // FaviconHandler should request from history and download |kIconURL1| and | 1075 // FaviconHandler should request from history and download |kIconURL1| and |
1113 // |kIconURL2|. |kIconURL1| is the better match. A | 1076 // |kIconURL2|. |kIconURL1| is the better match. A |
1114 // FaviconDriver::OnFaviconUpdated() notification should be sent for | 1077 // FaviconDriver::OnFaviconUpdated() notification should be sent for |
1115 // |kIconURL1|. | 1078 // |kIconURL1|. |
1116 ASSERT_EQ(0u, driver.num_notifications()); | 1079 ASSERT_EQ(0u, delegate.num_notifications()); |
1117 ASSERT_TRUE(helper.history_handler()); | 1080 ASSERT_TRUE(helper.history_handler()); |
1118 SetFaviconRawBitmapResult(kIconURL1, | 1081 SetFaviconRawBitmapResult(kIconURL1, |
1119 favicon_base::FAVICON, | 1082 favicon_base::FAVICON, |
1120 true /* expired */, | 1083 true /* expired */, |
1121 &helper.history_handler()->history_results_); | 1084 &helper.history_handler()->history_results_); |
1122 helper.history_handler()->InvokeCallback(); | 1085 helper.history_handler()->InvokeCallback(); |
1123 helper.set_history_handler(nullptr); | 1086 helper.set_history_handler(nullptr); |
1124 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1087 ASSERT_TRUE(delegate.download_handler()->HasDownload()); |
1125 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); | 1088 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); |
1126 helper.download_handler()->InvokeCallback(); | 1089 delegate.download_handler()->InvokeCallback(); |
1127 helper.download_handler()->Reset(); | 1090 delegate.download_handler()->Reset(); |
1128 | 1091 |
1129 ASSERT_TRUE(helper.history_handler()); | 1092 ASSERT_TRUE(helper.history_handler()); |
1130 helper.history_handler()->InvokeCallback(); | 1093 helper.history_handler()->InvokeCallback(); |
1131 SetFaviconRawBitmapResult(kIconURL2, | 1094 SetFaviconRawBitmapResult(kIconURL2, |
1132 favicon_base::FAVICON, | 1095 favicon_base::FAVICON, |
1133 true /* expired */, | 1096 true /* expired */, |
1134 &helper.history_handler()->history_results_); | 1097 &helper.history_handler()->history_results_); |
1135 helper.history_handler()->InvokeCallback(); | 1098 helper.history_handler()->InvokeCallback(); |
1136 helper.set_history_handler(nullptr); | 1099 helper.set_history_handler(nullptr); |
1137 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1100 ASSERT_TRUE(delegate.download_handler()->HasDownload()); |
1138 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); | 1101 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); |
1139 helper.download_handler()->InvokeCallback(); | 1102 delegate.download_handler()->InvokeCallback(); |
1140 helper.download_handler()->Reset(); | 1103 delegate.download_handler()->Reset(); |
1141 | 1104 |
1142 ASSERT_LT(0u, driver.num_notifications()); | 1105 ASSERT_LT(0u, delegate.num_notifications()); |
1143 ASSERT_EQ(kIconURL1, driver.icon_url()); | 1106 ASSERT_EQ(kIconURL1, delegate.icon_url()); |
1144 | 1107 |
1145 // Clear the history handler because SetHistoryFavicons() sets it. | 1108 // Clear the history handler because SetHistoryFavicons() sets it. |
1146 helper.set_history_handler(nullptr); | 1109 helper.set_history_handler(nullptr); |
1147 | 1110 |
1148 // Simulate the page changing it's icon URL to just |kIconURL2| via | 1111 // Simulate the page changing it's icon URL to just |kIconURL2| via |
1149 // Javascript. | 1112 // Javascript. |
1150 helper.OnUpdateFaviconURL( | 1113 helper.OnUpdateFaviconURL( |
1151 kPageURL, | 1114 kPageURL, |
1152 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON, | 1115 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON, |
1153 std::vector<gfx::Size>()))); | 1116 std::vector<gfx::Size>()))); |
1154 | 1117 |
1155 // FaviconHandler should request from history and download |kIconURL2|. A | 1118 // FaviconHandler should request from history and download |kIconURL2|. A |
1156 // FaviconDriver::OnFaviconUpdated() notification should be sent for | 1119 // FaviconDriver::OnFaviconUpdated() notification should be sent for |
1157 // |kIconURL2|. | 1120 // |kIconURL2|. |
1158 driver.ResetNumNotifications(); | 1121 delegate.ResetNumNotifications(); |
1159 ASSERT_TRUE(helper.history_handler()); | 1122 ASSERT_TRUE(helper.history_handler()); |
1160 SetFaviconRawBitmapResult(kIconURL2, | 1123 SetFaviconRawBitmapResult(kIconURL2, |
1161 favicon_base::FAVICON, | 1124 favicon_base::FAVICON, |
1162 true /* expired */, | 1125 true /* expired */, |
1163 &helper.history_handler()->history_results_); | 1126 &helper.history_handler()->history_results_); |
1164 helper.history_handler()->InvokeCallback(); | 1127 helper.history_handler()->InvokeCallback(); |
1165 helper.set_history_handler(nullptr); | 1128 helper.set_history_handler(nullptr); |
1166 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1129 ASSERT_TRUE(delegate.download_handler()->HasDownload()); |
1167 helper.download_handler()->InvokeCallback(); | 1130 delegate.download_handler()->InvokeCallback(); |
1168 helper.download_handler()->Reset(); | 1131 delegate.download_handler()->Reset(); |
1169 ASSERT_LT(0u, driver.num_notifications()); | 1132 ASSERT_LT(0u, delegate.num_notifications()); |
1170 EXPECT_EQ(kIconURL2, driver.icon_url()); | 1133 EXPECT_EQ(kIconURL2, delegate.icon_url()); |
1171 } | 1134 } |
1172 | 1135 |
1173 // Test the favicon which is selected when the web page provides several | 1136 // Test the favicon which is selected when the web page provides several |
1174 // favicons and none of the favicons are cached in history. | 1137 // favicons and none of the favicons are cached in history. |
1175 // The goal of this test is to be more of an integration test than | 1138 // The goal of this test is to be more of an integration test than |
1176 // SelectFaviconFramesTest.*. | 1139 // SelectFaviconFramesTest.*. |
1177 TEST_F(FaviconHandlerTest, MultipleFavicons) { | 1140 TEST_F(FaviconHandlerTest, MultipleFavicons) { |
1178 const GURL kPageURL("http://www.google.com"); | 1141 const GURL kPageURL("http://www.google.com"); |
1179 const FaviconURL kSourceIconURLs[] = { | 1142 const FaviconURL kSourceIconURLs[] = { |
1180 FaviconURL(GURL("http://www.google.com/a"), | 1143 FaviconURL(GURL("http://www.google.com/a"), |
(...skipping 14 matching lines...) Expand all Loading... | |
1195 | 1158 |
1196 // Set the supported scale factors to 1x and 2x. This affects the behavior of | 1159 // Set the supported scale factors to 1x and 2x. This affects the behavior of |
1197 // SelectFaviconFrames(). | 1160 // SelectFaviconFrames(). |
1198 std::vector<ui::ScaleFactor> scale_factors; | 1161 std::vector<ui::ScaleFactor> scale_factors; |
1199 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1162 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
1200 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1163 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
1201 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1164 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
1202 | 1165 |
1203 // 1) Test that if there are several single resolution favicons to choose from | 1166 // 1) Test that if there are several single resolution favicons to choose from |
1204 // that the largest exact match is chosen. | 1167 // that the largest exact match is chosen. |
1205 TestFaviconDriver driver1; | 1168 TestDelegate delegate1; |
1206 TestFaviconHandler handler1(&driver1, | 1169 TestFaviconHandler handler1(&favicon_service_, &delegate1, |
1207 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1170 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1208 | 1171 |
1209 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1172 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
1210 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1173 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1211 kSourceIconURLs + arraysize(kSizes1)); | 1174 kSourceIconURLs + arraysize(kSizes1)); |
1212 DownloadTillDoneIgnoringHistory( | 1175 DownloadTillDoneIgnoringHistory(&delegate1, &handler1, kPageURL, urls1, |
1213 &driver1, &handler1, kPageURL, urls1, kSizes1); | 1176 kSizes1); |
1214 | 1177 |
1215 EXPECT_EQ(nullptr, handler1.current_candidate()); | 1178 EXPECT_EQ(nullptr, handler1.current_candidate()); |
1216 EXPECT_EQ(1u, driver1.num_notifications()); | 1179 EXPECT_EQ(1u, delegate1.num_notifications()); |
1217 EXPECT_FALSE(driver1.image().IsEmpty()); | 1180 EXPECT_FALSE(delegate1.image().IsEmpty()); |
1218 EXPECT_EQ(gfx::kFaviconSize, driver1.image().Width()); | 1181 EXPECT_EQ(gfx::kFaviconSize, delegate1.image().Width()); |
1219 | 1182 |
1220 size_t expected_index = 2u; | 1183 size_t expected_index = 2u; |
1221 EXPECT_EQ(32, kSizes1[expected_index]); | 1184 EXPECT_EQ(32, kSizes1[expected_index]); |
1222 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver1.icon_url()); | 1185 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate1.icon_url()); |
1223 | 1186 |
1224 // 2) Test that if there are several single resolution favicons to choose | 1187 // 2) Test that if there are several single resolution favicons to choose |
1225 // from, the exact match is preferred even if it results in upsampling. | 1188 // from, the exact match is preferred even if it results in upsampling. |
1226 TestFaviconDriver driver2; | 1189 TestDelegate delegate2; |
1227 TestFaviconHandler handler2(&driver2, | 1190 TestFaviconHandler handler2(&favicon_service_, &delegate2, |
1228 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1191 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1229 | 1192 |
1230 const int kSizes2[] = { 16, 24, 48, 256 }; | 1193 const int kSizes2[] = { 16, 24, 48, 256 }; |
1231 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1194 std::vector<FaviconURL> urls2(kSourceIconURLs, |
1232 kSourceIconURLs + arraysize(kSizes2)); | 1195 kSourceIconURLs + arraysize(kSizes2)); |
1233 DownloadTillDoneIgnoringHistory( | 1196 DownloadTillDoneIgnoringHistory(&delegate2, &handler2, kPageURL, urls2, |
1234 &driver2, &handler2, kPageURL, urls2, kSizes2); | 1197 kSizes2); |
1235 EXPECT_EQ(1u, driver2.num_notifications()); | 1198 EXPECT_EQ(1u, delegate2.num_notifications()); |
1236 expected_index = 0u; | 1199 expected_index = 0u; |
1237 EXPECT_EQ(16, kSizes2[expected_index]); | 1200 EXPECT_EQ(16, kSizes2[expected_index]); |
1238 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver2.icon_url()); | 1201 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate2.icon_url()); |
1239 | 1202 |
1240 // 3) Test that favicons which need to be upsampled a little or downsampled | 1203 // 3) Test that favicons which need to be upsampled a little or downsampled |
1241 // a little are preferred over huge favicons. | 1204 // a little are preferred over huge favicons. |
1242 TestFaviconDriver driver3; | 1205 TestDelegate delegate3; |
1243 TestFaviconHandler handler3(&driver3, | 1206 TestFaviconHandler handler3(&favicon_service_, &delegate3, |
1244 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1207 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1245 | 1208 |
1246 const int kSizes3[] = { 256, 48 }; | 1209 const int kSizes3[] = { 256, 48 }; |
1247 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1210 std::vector<FaviconURL> urls3(kSourceIconURLs, |
1248 kSourceIconURLs + arraysize(kSizes3)); | 1211 kSourceIconURLs + arraysize(kSizes3)); |
1249 DownloadTillDoneIgnoringHistory( | 1212 DownloadTillDoneIgnoringHistory(&delegate3, &handler3, kPageURL, urls3, |
1250 &driver3, &handler3, kPageURL, urls3, kSizes3); | 1213 kSizes3); |
1251 EXPECT_EQ(1u, driver3.num_notifications()); | 1214 EXPECT_EQ(1u, delegate3.num_notifications()); |
1252 expected_index = 1u; | 1215 expected_index = 1u; |
1253 EXPECT_EQ(48, kSizes3[expected_index]); | 1216 EXPECT_EQ(48, kSizes3[expected_index]); |
1254 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url()); | 1217 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate3.icon_url()); |
1255 | 1218 |
1256 TestFaviconDriver driver4; | 1219 TestDelegate delegate4; |
1257 TestFaviconHandler handler4(&driver4, | 1220 TestFaviconHandler handler4(&favicon_service_, &delegate4, |
1258 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1221 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1259 | 1222 |
1260 const int kSizes4[] = { 17, 256 }; | 1223 const int kSizes4[] = { 17, 256 }; |
1261 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1224 std::vector<FaviconURL> urls4(kSourceIconURLs, |
1262 kSourceIconURLs + arraysize(kSizes4)); | 1225 kSourceIconURLs + arraysize(kSizes4)); |
1263 DownloadTillDoneIgnoringHistory( | 1226 DownloadTillDoneIgnoringHistory(&delegate4, &handler4, kPageURL, urls4, |
1264 &driver4, &handler4, kPageURL, urls4, kSizes4); | 1227 kSizes4); |
1265 EXPECT_EQ(1u, driver4.num_notifications()); | 1228 EXPECT_EQ(1u, delegate4.num_notifications()); |
1266 expected_index = 0u; | 1229 expected_index = 0u; |
1267 EXPECT_EQ(17, kSizes4[expected_index]); | 1230 EXPECT_EQ(17, kSizes4[expected_index]); |
1268 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver4.icon_url()); | 1231 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate4.icon_url()); |
1269 } | 1232 } |
1270 | 1233 |
1271 // Test that the best favicon is selected when: | 1234 // Test that the best favicon is selected when: |
1272 // - The page provides several favicons. | 1235 // - The page provides several favicons. |
1273 // - Downloading one of the page's icon URLs previously returned a 404. | 1236 // - Downloading one of the page's icon URLs previously returned a 404. |
1274 // - None of the favicons are cached in the Favicons database. | 1237 // - None of the favicons are cached in the Favicons database. |
1275 TEST_F(FaviconHandlerTest, MultipleFavicons404) { | 1238 TEST_F(FaviconHandlerTest, MultipleFavicons404) { |
1276 const GURL kPageURL("http://www.google.com"); | 1239 const GURL kPageURL("http://www.google.com"); |
1277 const GURL k404IconURL("http://www.google.com/404.png"); | 1240 const GURL k404IconURL("http://www.google.com/404.png"); |
1278 const FaviconURL k404FaviconURL( | 1241 const FaviconURL k404FaviconURL( |
1279 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>()); | 1242 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>()); |
1280 const FaviconURL kFaviconURLs[] = { | 1243 const FaviconURL kFaviconURLs[] = { |
1281 FaviconURL(GURL("http://www.google.com/a"), | 1244 FaviconURL(GURL("http://www.google.com/a"), |
1282 favicon_base::FAVICON, | 1245 favicon_base::FAVICON, |
1283 std::vector<gfx::Size>()), | 1246 std::vector<gfx::Size>()), |
1284 k404FaviconURL, | 1247 k404FaviconURL, |
1285 FaviconURL(GURL("http://www.google.com/c"), | 1248 FaviconURL(GURL("http://www.google.com/c"), |
1286 favicon_base::FAVICON, | 1249 favicon_base::FAVICON, |
1287 std::vector<gfx::Size>()), | 1250 std::vector<gfx::Size>()), |
1288 }; | 1251 }; |
1289 | 1252 |
1290 TestFaviconDriver driver; | 1253 TestDelegate delegate; |
1291 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1254 TestFaviconHandler handler(&favicon_service_, &delegate, |
1292 DownloadHandler* download_handler = handler.download_handler(); | 1255 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1256 DownloadHandler* download_handler = delegate.download_handler(); | |
1293 | 1257 |
1294 std::set<GURL> k404URLs; | 1258 std::set<GURL> k404URLs; |
1295 k404URLs.insert(k404IconURL); | 1259 k404URLs.insert(k404IconURL); |
1296 download_handler->FailDownloadForIconURLs(k404URLs); | 1260 download_handler->FailDownloadForIconURLs(k404URLs); |
1297 | 1261 |
1298 // Make the initial download for |k404IconURL| fail. | 1262 // Make the initial download for |k404IconURL| fail. |
1299 const int kSizes1[] = { 0 }; | 1263 const int kSizes1[] = { 0 }; |
1300 std::vector<FaviconURL> urls1(1u, k404FaviconURL); | 1264 std::vector<FaviconURL> urls1(1u, k404FaviconURL); |
1301 DownloadTillDoneIgnoringHistory( | 1265 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls1, |
1302 &driver, &handler, kPageURL, urls1, kSizes1); | 1266 kSizes1); |
1303 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); | 1267 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); |
1304 | 1268 |
1305 // Do a fetch now that the initial download for |k404IconURL| has failed. The | 1269 // Do a fetch now that the initial download for |k404IconURL| has failed. The |
1306 // behavior is different because OnDidDownloadFavicon() is invoked | 1270 // behavior is different because OnDidDownloadFavicon() is invoked |
1307 // synchronously from DownloadFavicon(). | 1271 // synchronously from DownloadFavicon(). |
1308 const int kSizes2[] = { 10, 0, 16 }; | 1272 const int kSizes2[] = { 10, 0, 16 }; |
1309 std::vector<FaviconURL> urls2(kFaviconURLs, | 1273 std::vector<FaviconURL> urls2(kFaviconURLs, |
1310 kFaviconURLs + arraysize(kFaviconURLs)); | 1274 kFaviconURLs + arraysize(kFaviconURLs)); |
1311 DownloadTillDoneIgnoringHistory( | 1275 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls2, |
1312 &driver, &handler, kPageURL, urls2, kSizes2); | 1276 kSizes2); |
1313 | 1277 |
1314 EXPECT_EQ(nullptr, handler.current_candidate()); | 1278 EXPECT_EQ(nullptr, handler.current_candidate()); |
1315 EXPECT_EQ(1u, driver.num_notifications()); | 1279 EXPECT_EQ(1u, delegate.num_notifications()); |
1316 EXPECT_FALSE(driver.image().IsEmpty()); | 1280 EXPECT_FALSE(delegate.image().IsEmpty()); |
1317 int expected_index = 2u; | 1281 int expected_index = 2u; |
1318 EXPECT_EQ(16, kSizes2[expected_index]); | 1282 EXPECT_EQ(16, kSizes2[expected_index]); |
1319 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, driver.icon_url()); | 1283 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, delegate.icon_url()); |
1320 } | 1284 } |
1321 | 1285 |
1322 // Test that no favicon is selected when: | 1286 // Test that no favicon is selected when: |
1323 // - The page provides several favicons. | 1287 // - The page provides several favicons. |
1324 // - Downloading the page's icons has previously returned a 404. | 1288 // - Downloading the page's icons has previously returned a 404. |
1325 // - None of the favicons are cached in the Favicons database. | 1289 // - None of the favicons are cached in the Favicons database. |
1326 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { | 1290 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { |
1327 const GURL kPageURL("http://www.google.com"); | 1291 const GURL kPageURL("http://www.google.com"); |
1328 const GURL k404IconURL1("http://www.google.com/4041.png"); | 1292 const GURL k404IconURL1("http://www.google.com/4041.png"); |
1329 const GURL k404IconURL2("http://www.google.com/4042.png"); | 1293 const GURL k404IconURL2("http://www.google.com/4042.png"); |
1330 const FaviconURL kFaviconURLs[] = { | 1294 const FaviconURL kFaviconURLs[] = { |
1331 FaviconURL(k404IconURL1, | 1295 FaviconURL(k404IconURL1, |
1332 favicon_base::FAVICON, | 1296 favicon_base::FAVICON, |
1333 std::vector<gfx::Size>()), | 1297 std::vector<gfx::Size>()), |
1334 FaviconURL(k404IconURL2, | 1298 FaviconURL(k404IconURL2, |
1335 favicon_base::FAVICON, | 1299 favicon_base::FAVICON, |
1336 std::vector<gfx::Size>()), | 1300 std::vector<gfx::Size>()), |
1337 }; | 1301 }; |
1338 | 1302 |
1339 TestFaviconDriver driver; | 1303 TestDelegate delegate; |
1340 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1304 TestFaviconHandler handler(&favicon_service_, &delegate, |
1341 DownloadHandler* download_handler = handler.download_handler(); | 1305 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1306 DownloadHandler* download_handler = delegate.download_handler(); | |
1342 | 1307 |
1343 std::set<GURL> k404URLs; | 1308 std::set<GURL> k404URLs; |
1344 k404URLs.insert(k404IconURL1); | 1309 k404URLs.insert(k404IconURL1); |
1345 k404URLs.insert(k404IconURL2); | 1310 k404URLs.insert(k404IconURL2); |
1346 download_handler->FailDownloadForIconURLs(k404URLs); | 1311 download_handler->FailDownloadForIconURLs(k404URLs); |
1347 | 1312 |
1348 // Make the initial downloads for |kFaviconURLs| fail. | 1313 // Make the initial downloads for |kFaviconURLs| fail. |
1349 for (const FaviconURL& favicon_url : kFaviconURLs) { | 1314 for (const FaviconURL& favicon_url : kFaviconURLs) { |
1350 const int kSizes[] = { 0 }; | 1315 const int kSizes[] = { 0 }; |
1351 std::vector<FaviconURL> urls(1u, favicon_url); | 1316 std::vector<FaviconURL> urls(1u, favicon_url); |
1352 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); | 1317 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls, |
1318 kSizes); | |
1353 } | 1319 } |
1354 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); | 1320 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); |
1355 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); | 1321 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); |
1356 | 1322 |
1357 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. | 1323 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. |
1358 // The behavior is different because OnDidDownloadFavicon() is invoked | 1324 // The behavior is different because OnDidDownloadFavicon() is invoked |
1359 // synchronously from DownloadFavicon(). | 1325 // synchronously from DownloadFavicon(). |
1360 const int kSizes[] = { 0, 0 }; | 1326 const int kSizes[] = { 0, 0 }; |
1361 std::vector<FaviconURL> urls(kFaviconURLs, | 1327 std::vector<FaviconURL> urls(kFaviconURLs, |
1362 kFaviconURLs + arraysize(kFaviconURLs)); | 1328 kFaviconURLs + arraysize(kFaviconURLs)); |
1363 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); | 1329 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls, kSizes); |
1364 | 1330 |
1365 EXPECT_EQ(nullptr, handler.current_candidate()); | 1331 EXPECT_EQ(nullptr, handler.current_candidate()); |
1366 EXPECT_EQ(0u, driver.num_notifications()); | 1332 EXPECT_EQ(0u, delegate.num_notifications()); |
1367 EXPECT_TRUE(driver.image().IsEmpty()); | 1333 EXPECT_TRUE(delegate.image().IsEmpty()); |
1368 } | 1334 } |
1369 | 1335 |
1370 // Test that no favicon is selected when the page's only icon uses an invalid | 1336 // Test that no favicon is selected when the page's only icon uses an invalid |
1371 // URL syntax. | 1337 // URL syntax. |
1372 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { | 1338 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { |
1373 const GURL kPageURL("http://www.google.com"); | 1339 const GURL kPageURL("http://www.google.com"); |
1374 const GURL kInvalidFormatURL("invalid"); | 1340 const GURL kInvalidFormatURL("invalid"); |
1375 ASSERT_TRUE(kInvalidFormatURL.is_empty()); | 1341 ASSERT_TRUE(kInvalidFormatURL.is_empty()); |
1376 | 1342 |
1377 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, | 1343 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, |
1378 std::vector<gfx::Size>()); | 1344 std::vector<gfx::Size>()); |
1379 | 1345 |
1380 TestFaviconDriver driver; | 1346 TestDelegate delegate; |
1381 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1347 TestFaviconHandler handler(&favicon_service_, &delegate, |
1382 UpdateFaviconURL(&driver, &handler, kPageURL, | 1348 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1349 UpdateFaviconURL(&delegate, &handler, kPageURL, | |
1383 std::vector<FaviconURL>(1u, favicon_url)); | 1350 std::vector<FaviconURL>(1u, favicon_url)); |
1384 EXPECT_EQ(0u, handler.image_urls().size()); | 1351 EXPECT_EQ(0u, handler.image_urls().size()); |
1385 } | 1352 } |
1386 | 1353 |
1387 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 1354 TEST_F(FaviconHandlerTest, TestSortFavicon) { |
1388 const GURL kPageURL("http://www.google.com"); | 1355 const GURL kPageURL("http://www.google.com"); |
1389 std::vector<gfx::Size> icon1; | 1356 std::vector<gfx::Size> icon1; |
1390 icon1.push_back(gfx::Size(1024, 1024)); | 1357 icon1.push_back(gfx::Size(1024, 1024)); |
1391 icon1.push_back(gfx::Size(512, 512)); | 1358 icon1.push_back(gfx::Size(512, 512)); |
1392 | 1359 |
1393 std::vector<gfx::Size> icon2; | 1360 std::vector<gfx::Size> icon2; |
1394 icon2.push_back(gfx::Size(15, 15)); | 1361 icon2.push_back(gfx::Size(15, 15)); |
1395 icon2.push_back(gfx::Size(16, 16)); | 1362 icon2.push_back(gfx::Size(16, 16)); |
1396 | 1363 |
1397 std::vector<gfx::Size> icon3; | 1364 std::vector<gfx::Size> icon3; |
1398 icon3.push_back(gfx::Size(16, 16)); | 1365 icon3.push_back(gfx::Size(16, 16)); |
1399 icon3.push_back(gfx::Size(14, 14)); | 1366 icon3.push_back(gfx::Size(14, 14)); |
1400 | 1367 |
1401 const FaviconURL kSourceIconURLs[] = { | 1368 const FaviconURL kSourceIconURLs[] = { |
1402 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, icon1), | 1369 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, icon1), |
1403 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), | 1370 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
1404 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1371 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
1405 FaviconURL(GURL("http://www.google.com/d"), | 1372 FaviconURL(GURL("http://www.google.com/d"), |
1406 favicon_base::FAVICON, | 1373 favicon_base::FAVICON, |
1407 std::vector<gfx::Size>()), | 1374 std::vector<gfx::Size>()), |
1408 FaviconURL(GURL("http://www.google.com/e"), | 1375 FaviconURL(GURL("http://www.google.com/e"), |
1409 favicon_base::FAVICON, | 1376 favicon_base::FAVICON, |
1410 std::vector<gfx::Size>())}; | 1377 std::vector<gfx::Size>())}; |
1411 | 1378 |
1412 TestFaviconDriver driver1; | 1379 TestDelegate delegate1; |
1413 TestFaviconHandler handler1(&driver1, | 1380 TestFaviconHandler handler1(&favicon_service_, &delegate1, |
1414 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1381 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1415 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1382 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1416 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1383 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1417 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1384 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
1418 | 1385 |
1419 struct ExpectedResult { | 1386 struct ExpectedResult { |
1420 // The favicon's index in kSourceIconURLs. | 1387 // The favicon's index in kSourceIconURLs. |
1421 size_t favicon_index; | 1388 size_t favicon_index; |
1422 // Width of largest bitmap. | 1389 // Width of largest bitmap. |
1423 int width; | 1390 int width; |
1424 } results[] = { | 1391 } results[] = { |
1425 // First is icon1, though its size larger than maximal. | 1392 // First is icon1, though its size larger than maximal. |
1426 {0, 1024}, | 1393 {0, 1024}, |
1427 // Second is icon2 | 1394 // Second is icon2 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1465 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), | 1432 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
1466 FaviconURL( | 1433 FaviconURL( |
1467 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1434 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
1468 FaviconURL(GURL("http://www.google.com/d"), | 1435 FaviconURL(GURL("http://www.google.com/d"), |
1469 favicon_base::FAVICON, | 1436 favicon_base::FAVICON, |
1470 std::vector<gfx::Size>()), | 1437 std::vector<gfx::Size>()), |
1471 FaviconURL(GURL("http://www.google.com/e"), | 1438 FaviconURL(GURL("http://www.google.com/e"), |
1472 favicon_base::FAVICON, | 1439 favicon_base::FAVICON, |
1473 std::vector<gfx::Size>())}; | 1440 std::vector<gfx::Size>())}; |
1474 | 1441 |
1475 TestFaviconDriver driver1; | 1442 TestDelegate delegate1; |
1476 TestFaviconHandler handler1(&driver1, | 1443 TestFaviconHandler handler1(&favicon_service_, &delegate1, |
1477 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1444 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1478 | 1445 |
1479 std::set<GURL> fail_icon_urls; | 1446 std::set<GURL> fail_icon_urls; |
1480 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { | 1447 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { |
1481 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); | 1448 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); |
1482 } | 1449 } |
1483 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); | 1450 delegate1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); |
1484 | 1451 |
1485 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1452 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1486 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1453 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1487 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1454 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
1488 | 1455 |
1489 // Simulate the download failed, to check whether the icons were requested | 1456 // Simulate the download failed, to check whether the icons were requested |
1490 // to download according their size. | 1457 // to download according their size. |
1491 struct ExpectedResult { | 1458 struct ExpectedResult { |
1492 // The favicon's index in kSourceIconURLs. | 1459 // The favicon's index in kSourceIconURLs. |
1493 size_t favicon_index; | 1460 size_t favicon_index; |
1494 // Width of largest bitmap. | 1461 // Width of largest bitmap. |
1495 int width; | 1462 int width; |
1496 } results[] = { | 1463 } results[] = { |
1497 {0, 1024}, | 1464 {0, 1024}, |
(...skipping 10 matching lines...) Expand all Loading... | |
1508 if (results[i].width != -1) { | 1475 if (results[i].width != -1) { |
1509 EXPECT_EQ(results[i].width, handler1.current_candidate()-> | 1476 EXPECT_EQ(results[i].width, handler1.current_candidate()-> |
1510 icon_sizes[0].width()); | 1477 icon_sizes[0].width()); |
1511 } | 1478 } |
1512 | 1479 |
1513 // Simulate no favicon from history. | 1480 // Simulate no favicon from history. |
1514 handler1.history_handler()->history_results_.clear(); | 1481 handler1.history_handler()->history_results_.clear(); |
1515 handler1.history_handler()->InvokeCallback(); | 1482 handler1.history_handler()->InvokeCallback(); |
1516 | 1483 |
1517 // Verify download request | 1484 // Verify download request |
1518 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1485 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
1519 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, | 1486 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, |
1520 handler1.download_handler()->GetImageUrl()); | 1487 delegate1.download_handler()->GetImageUrl()); |
1521 | 1488 |
1522 handler1.download_handler()->InvokeCallback(); | 1489 delegate1.download_handler()->InvokeCallback(); |
1523 handler1.download_handler()->Reset(); | 1490 delegate1.download_handler()->Reset(); |
1524 } | 1491 } |
1525 } | 1492 } |
1526 | 1493 |
1527 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { | 1494 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { |
1528 const GURL kPageURL("http://www.google.com"); | 1495 const GURL kPageURL("http://www.google.com"); |
1529 | 1496 |
1530 std::vector<gfx::Size> one_icon; | 1497 std::vector<gfx::Size> one_icon; |
1531 one_icon.push_back(gfx::Size(15, 15)); | 1498 one_icon.push_back(gfx::Size(15, 15)); |
1532 | 1499 |
1533 std::vector<gfx::Size> two_icons; | 1500 std::vector<gfx::Size> two_icons; |
1534 two_icons.push_back(gfx::Size(14, 14)); | 1501 two_icons.push_back(gfx::Size(14, 14)); |
1535 two_icons.push_back(gfx::Size(16, 16)); | 1502 two_icons.push_back(gfx::Size(16, 16)); |
1536 | 1503 |
1537 const FaviconURL kSourceIconURLs[] = { | 1504 const FaviconURL kSourceIconURLs[] = { |
1538 FaviconURL( | 1505 FaviconURL( |
1539 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), | 1506 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), |
1540 FaviconURL( | 1507 FaviconURL( |
1541 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; | 1508 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; |
1542 | 1509 |
1543 TestFaviconDriver driver1; | 1510 TestDelegate delegate1; |
1544 TestFaviconHandler handler1(&driver1, | 1511 TestFaviconHandler handler1(&favicon_service_, &delegate1, |
1545 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1512 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1546 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1513 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1547 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1514 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1548 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1515 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
1549 | 1516 |
1550 ASSERT_EQ(2u, handler1.image_urls().size()); | 1517 ASSERT_EQ(2u, handler1.image_urls().size()); |
1551 | 1518 |
1552 // Index of largest favicon in kSourceIconURLs. | 1519 // Index of largest favicon in kSourceIconURLs. |
1553 size_t i = 1; | 1520 size_t i = 1; |
1554 // The largest bitmap's index in Favicon . | 1521 // The largest bitmap's index in Favicon . |
1555 int b = 1; | 1522 int b = 1; |
1556 | 1523 |
1557 // Verify the icon_bitmaps_ was initialized correctly. | 1524 // Verify the icon_bitmaps_ was initialized correctly. |
1558 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1525 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
1559 handler1.current_candidate()->icon_url); | 1526 handler1.current_candidate()->icon_url); |
1560 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1527 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1561 handler1.current_candidate()->icon_sizes[0]); | 1528 handler1.current_candidate()->icon_sizes[0]); |
1562 | 1529 |
1563 // Simulate no favicon from history. | 1530 // Simulate no favicon from history. |
1564 handler1.history_handler()->history_results_.clear(); | 1531 handler1.history_handler()->history_results_.clear(); |
1565 handler1.history_handler()->InvokeCallback(); | 1532 handler1.history_handler()->InvokeCallback(); |
1566 | 1533 |
1567 // Verify download request | 1534 // Verify download request |
1568 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1535 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
1569 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1536 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
1570 handler1.download_handler()->GetImageUrl()); | 1537 delegate1.download_handler()->GetImageUrl()); |
1571 | 1538 |
1572 // Give the correct download result. | 1539 // Give the correct download result. |
1573 std::vector<int> sizes; | 1540 std::vector<int> sizes; |
1574 for (std::vector<gfx::Size>::const_iterator j = | 1541 for (std::vector<gfx::Size>::const_iterator j = |
1575 kSourceIconURLs[i].icon_sizes.begin(); | 1542 kSourceIconURLs[i].icon_sizes.begin(); |
1576 j != kSourceIconURLs[i].icon_sizes.end(); ++j) | 1543 j != kSourceIconURLs[i].icon_sizes.end(); ++j) |
1577 sizes.push_back(j->width()); | 1544 sizes.push_back(j->width()); |
1578 | 1545 |
1579 handler1.download_handler()->SetImageSizes(sizes); | 1546 delegate1.download_handler()->SetImageSizes(sizes); |
1580 handler1.download_handler()->InvokeCallback(); | 1547 delegate1.download_handler()->InvokeCallback(); |
1581 | 1548 |
1582 // Verify the largest bitmap has been saved into history. | 1549 // Verify the largest bitmap has been saved into history. |
1583 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1550 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
1584 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1551 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1585 handler1.history_handler()->size_); | 1552 handler1.history_handler()->size_); |
1586 // Verify NotifyFaviconAvailable(). | 1553 // Verify NotifyFaviconAvailable(). |
1587 EXPECT_EQ(1u, driver1.num_notifications()); | 1554 EXPECT_EQ(1u, delegate1.num_notifications()); |
1588 EXPECT_EQ(kSourceIconURLs[i].icon_url, driver1.icon_url()); | 1555 EXPECT_EQ(kSourceIconURLs[i].icon_url, delegate1.icon_url()); |
1589 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], driver1.image().Size()); | 1556 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], delegate1.image().Size()); |
1590 } | 1557 } |
1591 | 1558 |
1592 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1559 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
1593 const GURL kPageURL("http://www.google.com"); | 1560 const GURL kPageURL("http://www.google.com"); |
1594 const int kMaximalSize = | 1561 const int kMaximalSize = |
1595 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); | 1562 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); |
1596 | 1563 |
1597 std::vector<gfx::Size> icon1; | 1564 std::vector<gfx::Size> icon1; |
1598 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); | 1565 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); |
1599 | 1566 |
1600 std::vector<gfx::Size> icon2; | 1567 std::vector<gfx::Size> icon2; |
1601 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); | 1568 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); |
1602 | 1569 |
1603 const FaviconURL kSourceIconURLs[] = { | 1570 const FaviconURL kSourceIconURLs[] = { |
1604 FaviconURL( | 1571 FaviconURL( |
1605 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1572 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
1606 FaviconURL( | 1573 FaviconURL( |
1607 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; | 1574 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; |
1608 | 1575 |
1609 TestFaviconDriver driver1; | 1576 TestDelegate delegate1; |
1610 TestFaviconHandler handler1(&driver1, | 1577 TestFaviconHandler handler1(&favicon_service_, &delegate1, |
1611 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1578 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1612 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1579 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1613 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1580 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1614 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1581 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
1615 | 1582 |
1616 ASSERT_EQ(2u, handler1.image_urls().size()); | 1583 ASSERT_EQ(2u, handler1.image_urls().size()); |
1617 | 1584 |
1618 // Index of largest favicon in kSourceIconURLs. | 1585 // Index of largest favicon in kSourceIconURLs. |
1619 size_t i = 1; | 1586 size_t i = 1; |
1620 // The largest bitmap's index in Favicon . | 1587 // The largest bitmap's index in Favicon . |
1621 int b = 0; | 1588 int b = 0; |
1622 | 1589 |
1623 // Verify the icon_bitmaps_ was initialized correctly. | 1590 // Verify the icon_bitmaps_ was initialized correctly. |
1624 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1591 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
1625 handler1.current_candidate()->icon_url); | 1592 handler1.current_candidate()->icon_url); |
1626 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1593 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1627 handler1.current_candidate()->icon_sizes[0]); | 1594 handler1.current_candidate()->icon_sizes[0]); |
1628 | 1595 |
1629 // Simulate no favicon from history. | 1596 // Simulate no favicon from history. |
1630 handler1.history_handler()->history_results_.clear(); | 1597 handler1.history_handler()->history_results_.clear(); |
1631 handler1.history_handler()->InvokeCallback(); | 1598 handler1.history_handler()->InvokeCallback(); |
1632 | 1599 |
1633 // Verify download request | 1600 // Verify download request |
1634 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1601 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
1635 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1602 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
1636 handler1.download_handler()->GetImageUrl()); | 1603 delegate1.download_handler()->GetImageUrl()); |
1637 | 1604 |
1638 // Give the scaled download bitmap. | 1605 // Give the scaled download bitmap. |
1639 std::vector<int> sizes; | 1606 std::vector<int> sizes; |
1640 sizes.push_back(kMaximalSize); | 1607 sizes.push_back(kMaximalSize); |
1641 | 1608 |
1642 handler1.download_handler()->SetImageSizes(sizes); | 1609 delegate1.download_handler()->SetImageSizes(sizes); |
1643 handler1.download_handler()->InvokeCallback(); | 1610 delegate1.download_handler()->InvokeCallback(); |
1644 | 1611 |
1645 // Verify the largest bitmap has been saved into history though it was | 1612 // Verify the largest bitmap has been saved into history though it was |
1646 // scaled down to maximal size and smaller than icon1 now. | 1613 // scaled down to maximal size and smaller than icon1 now. |
1647 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1614 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
1648 EXPECT_EQ(gfx::Size(kMaximalSize, kMaximalSize), | 1615 EXPECT_EQ(gfx::Size(kMaximalSize, kMaximalSize), |
1649 handler1.history_handler()->size_); | 1616 handler1.history_handler()->size_); |
1650 } | 1617 } |
1651 | 1618 |
1652 TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) { | 1619 TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) { |
1653 const GURL kPageURL("http://www.google.com"); | 1620 const GURL kPageURL("http://www.google.com"); |
1654 | 1621 |
1655 std::vector<gfx::Size> icon1; | 1622 std::vector<gfx::Size> icon1; |
1656 icon1.push_back(gfx::Size(16, 16)); | 1623 icon1.push_back(gfx::Size(16, 16)); |
1657 const int actual_size1 = 10; | 1624 const int actual_size1 = 10; |
1658 | 1625 |
1659 std::vector<gfx::Size> icon2; | 1626 std::vector<gfx::Size> icon2; |
1660 icon2.push_back(gfx::Size(15, 15)); | 1627 icon2.push_back(gfx::Size(15, 15)); |
1661 const int actual_size2 = 12; | 1628 const int actual_size2 = 12; |
1662 | 1629 |
1663 const FaviconURL kSourceIconURLs[] = { | 1630 const FaviconURL kSourceIconURLs[] = { |
1664 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1631 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
1665 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), | 1632 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), |
1666 FaviconURL(GURL("http://www.google.com/d"), | 1633 FaviconURL(GURL("http://www.google.com/d"), |
1667 favicon_base::FAVICON, | 1634 favicon_base::FAVICON, |
1668 std::vector<gfx::Size>())}; | 1635 std::vector<gfx::Size>())}; |
1669 | 1636 |
1670 TestFaviconDriver driver1; | 1637 TestDelegate delegate1; |
1671 TestFaviconHandler handler1(&driver1, | 1638 TestFaviconHandler handler1(&favicon_service_, &delegate1, |
1672 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1639 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1673 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1640 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1674 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1641 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1675 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1642 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
1676 ASSERT_EQ(3u, handler1.image_urls().size()); | 1643 ASSERT_EQ(3u, handler1.image_urls().size()); |
1677 | 1644 |
1678 // Simulate no favicon from history. | 1645 // Simulate no favicon from history. |
1679 handler1.history_handler()->history_results_.clear(); | 1646 handler1.history_handler()->history_results_.clear(); |
1680 handler1.history_handler()->InvokeCallback(); | 1647 handler1.history_handler()->InvokeCallback(); |
1681 | 1648 |
1682 // Verify the first icon was request to download | 1649 // Verify the first icon was request to download |
1683 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1650 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
1684 EXPECT_EQ(kSourceIconURLs[0].icon_url, | 1651 EXPECT_EQ(kSourceIconURLs[0].icon_url, |
1685 handler1.download_handler()->GetImageUrl()); | 1652 delegate1.download_handler()->GetImageUrl()); |
1686 | 1653 |
1687 // Give the incorrect size. | 1654 // Give the incorrect size. |
1688 std::vector<int> sizes; | 1655 std::vector<int> sizes; |
1689 sizes.push_back(actual_size1); | 1656 sizes.push_back(actual_size1); |
1690 handler1.download_handler()->SetImageSizes(sizes); | 1657 delegate1.download_handler()->SetImageSizes(sizes); |
1691 handler1.download_handler()->InvokeCallback(); | 1658 delegate1.download_handler()->InvokeCallback(); |
1692 handler1.download_handler()->Reset(); | 1659 delegate1.download_handler()->Reset(); |
1693 | 1660 |
1694 // Simulate no favicon from history. | 1661 // Simulate no favicon from history. |
1695 handler1.history_handler()->history_results_.clear(); | 1662 handler1.history_handler()->history_results_.clear(); |
1696 handler1.history_handler()->InvokeCallback(); | 1663 handler1.history_handler()->InvokeCallback(); |
1697 | 1664 |
1698 // Verify the 2nd icon was request to download | 1665 // Verify the 2nd icon was request to download |
1699 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1666 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
1700 EXPECT_EQ(kSourceIconURLs[1].icon_url, | 1667 EXPECT_EQ(kSourceIconURLs[1].icon_url, |
1701 handler1.download_handler()->GetImageUrl()); | 1668 delegate1.download_handler()->GetImageUrl()); |
1702 | 1669 |
1703 // Very the best candidate is icon1 | 1670 // Very the best candidate is icon1 |
1704 EXPECT_EQ(kSourceIconURLs[0].icon_url, | 1671 EXPECT_EQ(kSourceIconURLs[0].icon_url, |
1705 handler1.best_favicon_candidate().image_url); | 1672 handler1.best_favicon_candidate().image_url); |
1706 EXPECT_EQ(gfx::Size(actual_size1, actual_size1), | 1673 EXPECT_EQ(gfx::Size(actual_size1, actual_size1), |
1707 handler1.best_favicon_candidate().image.Size()); | 1674 handler1.best_favicon_candidate().image.Size()); |
1708 | 1675 |
1709 // Give the incorrect size. | 1676 // Give the incorrect size. |
1710 sizes.clear(); | 1677 sizes.clear(); |
1711 sizes.push_back(actual_size2); | 1678 sizes.push_back(actual_size2); |
1712 handler1.download_handler()->SetImageSizes(sizes); | 1679 delegate1.download_handler()->SetImageSizes(sizes); |
1713 handler1.download_handler()->InvokeCallback(); | 1680 delegate1.download_handler()->InvokeCallback(); |
1714 handler1.download_handler()->Reset(); | 1681 delegate1.download_handler()->Reset(); |
1715 | 1682 |
1716 // Verify icon2 has been saved into history. | 1683 // Verify icon2 has been saved into history. |
1717 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); | 1684 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); |
1718 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), | 1685 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), |
1719 handler1.history_handler()->size_); | 1686 handler1.history_handler()->size_); |
1720 } | 1687 } |
1721 | 1688 |
1722 } // namespace | 1689 } // namespace |
1723 } // namespace favicon | 1690 } // namespace favicon |
OLD | NEW |