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