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

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

Issue 1407353012: Refactor FaviconDriver::OnFaviconAvailable() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@initial_simplify
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (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<set> 7 #include<set>
8 #include<vector> 8 #include<vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 private: 180 private:
181 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); 181 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler);
182 }; 182 };
183 183
184 } // namespace 184 } // namespace
185 185
186 class TestFaviconDriver : public FaviconDriver { 186 class TestFaviconDriver : public FaviconDriver {
187 public: 187 public:
188 TestFaviconDriver() 188 TestFaviconDriver()
189 : favicon_validity_(false), 189 : num_notifications_(0u) {}
190 num_active_favicon_(0),
191 num_favicon_available_(0),
192 update_active_favicon_(false) {}
193 190
194 ~TestFaviconDriver() override {} 191 ~TestFaviconDriver() override {}
195 192
196 // FaviconDriver implementation. 193 // FaviconDriver implementation.
197 void FetchFavicon(const GURL& url) override { 194 void FetchFavicon(const GURL& url) override {
198 ADD_FAILURE() << "TestFaviconDriver::FetchFavicon() " 195 ADD_FAILURE() << "TestFaviconDriver::FetchFavicon() "
199 << "should never be called in tests."; 196 << "should never be called in tests.";
200 } 197 }
201 198
202 gfx::Image GetFavicon() const override { 199 gfx::Image GetFavicon() const override {
203 ADD_FAILURE() << "TestFaviconDriver::GetFavicon() " 200 ADD_FAILURE() << "TestFaviconDriver::GetFavicon() "
204 << "should never be called in tests."; 201 << "should never be called in tests.";
205 return gfx::Image(); 202 return gfx::Image();
206 } 203 }
207 204
205 GURL GetFaviconURL() const override {
206 ADD_FAILURE() << "TestFaviconDriver::GetFaviconURL() "
207 << "should never be called in tests.";
208 return GURL();
209 }
210
208 bool FaviconIsValid() const override { 211 bool FaviconIsValid() const override {
209 ADD_FAILURE() << "TestFaviconDriver::FaviconIsValid() " 212 ADD_FAILURE() << "TestFaviconDriver::FaviconIsValid() "
210 << "should never be called in tests."; 213 << "should never be called in tests.";
211 return false; 214 return false;
212 } 215 }
213 216
214 bool HasPendingTasksForTest() override { 217 bool HasPendingTasksForTest() override {
215 ADD_FAILURE() << "TestFaviconDriver::HasPendingTasksForTest() " 218 ADD_FAILURE() << "TestFaviconDriver::HasPendingTasksForTest() "
216 << "should never be called in tests."; 219 << "should never be called in tests.";
217 return false; 220 return false;
218 } 221 }
219 222
220 int StartDownload(const GURL& url, int max_bitmap_size) override { 223 int StartDownload(const GURL& url, int max_bitmap_size) override {
221 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " 224 ADD_FAILURE() << "TestFaviconDriver::StartDownload() "
222 << "should never be called in tests."; 225 << "should never be called in tests.";
223 return -1; 226 return -1;
224 } 227 }
225 228
226 bool IsOffTheRecord() override { return false; } 229 bool IsOffTheRecord() override { return false; }
227 230
228 bool IsBookmarked(const GURL& url) override { return false; } 231 bool IsBookmarked(const GURL& url) override { return false; }
229 232
230 GURL GetActiveURL() override { return url_; } 233 GURL GetActiveURL() override {
231 234 ADD_FAILURE() << "TestFaviconDriver::GetActiveURL() "
232 bool GetActiveFaviconValidity() { return favicon_validity_; } 235 << "should never be called in tests.";
233 236 return GURL();
234 void SetActiveFaviconValidity(bool favicon_validity) override {
235 favicon_validity_ = favicon_validity;
236 } 237 }
237 238
238 GURL GetActiveFaviconURL() override { return favicon_url_; } 239 void OnFaviconUpdated(
239 240 const GURL& page_url,
240 void SetActiveFaviconURL(const GURL& favicon_url) override { 241 FaviconDriverObserver::NotificationIconType notification_icon_type,
241 favicon_url_ = favicon_url; 242 const GURL& icon_url,
242 } 243 bool icon_url_changed,
243 244 const gfx::Image& image) override {
244 gfx::Image GetActiveFaviconImage() { return image_; } 245 ++num_notifications_;
245 246 icon_url_ = icon_url;
246 void SetActiveFaviconImage(const gfx::Image& image) override {
247 image_ = image; 247 image_ = image;
248 } 248 }
249 249
250 void OnFaviconAvailable(const GURL& page_url, 250 const GURL& icon_url() const { return icon_url_; }
251 const GURL& icon_url,
252 const gfx::Image& image,
253 bool update_active_favicon) override {
254 ++num_favicon_available_;
255 available_image_ = image;
256 available_icon_url_ = icon_url;
257 update_active_favicon_ = update_active_favicon;
258 if (!update_active_favicon)
259 return;
260 251
261 ++num_active_favicon_; 252 const gfx::Image& image() const { return image_; }
262 SetActiveFaviconURL(icon_url);
263 SetActiveFaviconValidity(true);
264 SetActiveFaviconImage(image);
265 }
266 253
267 size_t num_active_favicon() const { return num_active_favicon_; } 254 size_t num_notifications() const { return num_notifications_; }
268 size_t num_favicon_available() const { return num_favicon_available_; } 255 void ResetNumNotifications() { num_notifications_ = 0; }
269 void ResetNumActiveFavicon() { num_active_favicon_ = 0; }
270 void ResetNumFaviconAvailable() { num_favicon_available_ = 0; }
271
272 void SetActiveURL(GURL url) { url_ = url; }
273
274 const gfx::Image& available_favicon() { return available_image_; }
275
276 const GURL& available_icon_url() { return available_icon_url_; }
277
278 bool update_active_favicon() { return update_active_favicon_; }
279 256
280 private: 257 private:
281 GURL favicon_url_; 258 GURL icon_url_;
282 GURL url_;
283 gfx::Image image_; 259 gfx::Image image_;
284 bool favicon_validity_; 260 size_t num_notifications_;
285
286 // The number of times that NotifyFaviconAvailable() has been called with
287 // |is_active_favicon| is true.
288 size_t num_active_favicon_;
289 // The number of times that NotifyFaviconAvailable() has been called.
290 size_t num_favicon_available_;
291 gfx::Image available_image_;
292 GURL available_icon_url_;
293 bool update_active_favicon_;
294 261
295 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); 262 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver);
296 }; 263 };
297 264
298 // This class is used to catch the FaviconHandler's download and history 265 // This class is used to catch the FaviconHandler's download and history
299 // request, and also provide the methods to access the FaviconHandler 266 // request, and also provide the methods to access the FaviconHandler
300 // internals. 267 // internals.
301 class TestFaviconHandler : public FaviconHandler { 268 class TestFaviconHandler : public FaviconHandler {
302 public: 269 public:
303 static int GetMaximalIconSize(favicon_base::IconType icon_type) { 270 static int GetMaximalIconSize(favicon_base::IconType icon_type) {
304 return FaviconHandler::GetMaximalIconSize(icon_type); 271 return FaviconHandler::GetMaximalIconSize(icon_type);
305 } 272 }
306 273
307 TestFaviconHandler(const GURL& page_url, 274 TestFaviconHandler(TestFaviconDriver* driver,
308 TestFaviconDriver* driver, 275 FaviconDriverObserver::NotificationIconType handler_type)
309 Type type) 276 : FaviconHandler(nullptr, driver, handler_type),
310 : FaviconHandler(nullptr, driver, type),
311 download_id_(0) { 277 download_id_(0) {
312 driver->SetActiveURL(page_url);
313 download_handler_.reset(new DownloadHandler(this)); 278 download_handler_.reset(new DownloadHandler(this));
314 } 279 }
315 280
316 ~TestFaviconHandler() override {} 281 ~TestFaviconHandler() override {}
317 282
318 HistoryRequestHandler* history_handler() { 283 HistoryRequestHandler* history_handler() {
319 return history_handler_.get(); 284 return history_handler_.get();
320 } 285 }
321 286
322 // This method will take the ownership of the given handler. 287 // This method will take the ownership of the given handler.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // any of |candidates|. 427 // any of |candidates|.
463 // - The page provides favicons at |candidate_icons|. 428 // - The page provides favicons at |candidate_icons|.
464 // - The favicons at |candidate_icons| have edge pixel sizes of 429 // - The favicons at |candidate_icons| have edge pixel sizes of
465 // |candidate_icon_sizes|. 430 // |candidate_icon_sizes|.
466 void DownloadTillDoneIgnoringHistory( 431 void DownloadTillDoneIgnoringHistory(
467 TestFaviconDriver* favicon_driver, 432 TestFaviconDriver* favicon_driver,
468 TestFaviconHandler* favicon_handler, 433 TestFaviconHandler* favicon_handler,
469 const GURL& page_url, 434 const GURL& page_url,
470 const std::vector<FaviconURL>& candidate_icons, 435 const std::vector<FaviconURL>& candidate_icons,
471 const int* candidate_icon_sizes) { 436 const int* candidate_icon_sizes) {
437 size_t old_num_notifications = favicon_driver->num_notifications();
438
472 UpdateFaviconURL( 439 UpdateFaviconURL(
473 favicon_driver, favicon_handler, page_url, candidate_icons); 440 favicon_driver, favicon_handler, page_url, candidate_icons);
474 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); 441 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size());
475 442
476 DownloadHandler* download_handler = favicon_handler->download_handler(); 443 DownloadHandler* download_handler = favicon_handler->download_handler();
477 for (size_t i = 0; i < candidate_icons.size(); ++i) { 444 for (size_t i = 0; i < candidate_icons.size(); ++i) {
478 favicon_handler->history_handler()->history_results_.clear(); 445 favicon_handler->history_handler()->history_results_.clear();
479 favicon_handler->history_handler()->InvokeCallback(); 446 favicon_handler->history_handler()->InvokeCallback();
480 ASSERT_TRUE(download_handler->HasDownload()); 447 ASSERT_TRUE(download_handler->HasDownload());
481 EXPECT_EQ(download_handler->GetImageUrl(), 448 EXPECT_EQ(download_handler->GetImageUrl(),
482 candidate_icons[i].icon_url); 449 candidate_icons[i].icon_url);
483 std::vector<int> sizes; 450 std::vector<int> sizes;
484 sizes.push_back(candidate_icon_sizes[i]); 451 sizes.push_back(candidate_icon_sizes[i]);
485 download_handler->SetImageSizes(sizes); 452 download_handler->SetImageSizes(sizes);
486 download_handler->InvokeCallback(); 453 download_handler->InvokeCallback();
487 454
488 download_handler->Reset(); 455 download_handler->Reset();
489 456
490 if (favicon_driver->num_active_favicon()) 457 if (favicon_driver->num_notifications() > old_num_notifications)
491 return; 458 return;
492 } 459 }
493 } 460 }
494 461
495 void UpdateFaviconURL(TestFaviconDriver* favicon_driver, 462 void UpdateFaviconURL(TestFaviconDriver* favicon_driver,
496 TestFaviconHandler* favicon_handler, 463 TestFaviconHandler* favicon_handler,
497 const GURL& page_url, 464 const GURL& page_url,
498 const std::vector<FaviconURL>& candidate_icons) { 465 const std::vector<FaviconURL>& candidate_icons) {
499 favicon_driver->ResetNumActiveFavicon(); 466 favicon_driver->ResetNumNotifications();
500 467
501 favicon_handler->FetchFavicon(page_url); 468 favicon_handler->FetchFavicon(page_url);
502 favicon_handler->history_handler()->InvokeCallback(); 469 favicon_handler->history_handler()->InvokeCallback();
503 470
504 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); 471 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons);
505 } 472 }
506 473
507 void SetUp() override { 474 void SetUp() override {
508 // The score computed by SelectFaviconFrames() is dependent on the supported 475 // The score computed by SelectFaviconFrames() is dependent on the supported
509 // scale factors of the platform. It is used for determining the goodness of 476 // scale factors of the platform. It is used for determining the goodness of
(...skipping 11 matching lines...) Expand all
521 scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> 488 scoped_ptr<ui::test::ScopedSetSupportedScaleFactors>
522 scoped_set_supported_scale_factors_; 489 scoped_set_supported_scale_factors_;
523 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); 490 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest);
524 }; 491 };
525 492
526 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { 493 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) {
527 const GURL page_url("http://www.google.com"); 494 const GURL page_url("http://www.google.com");
528 const GURL icon_url("http://www.google.com/favicon"); 495 const GURL icon_url("http://www.google.com/favicon");
529 496
530 TestFaviconDriver driver; 497 TestFaviconDriver driver;
531 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); 498 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
532 499
533 helper.FetchFavicon(page_url); 500 helper.FetchFavicon(page_url);
534 HistoryRequestHandler* history_handler = helper.history_handler(); 501 HistoryRequestHandler* history_handler = helper.history_handler();
535 // Ensure the data given to history is correct. 502 // Ensure the data given to history is correct.
536 ASSERT_TRUE(history_handler); 503 ASSERT_TRUE(history_handler);
537 EXPECT_EQ(page_url, history_handler->page_url_); 504 EXPECT_EQ(page_url, history_handler->page_url_);
538 EXPECT_EQ(GURL(), history_handler->icon_url_); 505 EXPECT_EQ(GURL(), history_handler->icon_url_);
539 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 506 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
540 507
541 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); 508 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_);
542 509
543 // Send history response. 510 // Send history response.
544 history_handler->InvokeCallback(); 511 history_handler->InvokeCallback();
545 // Verify FaviconHandler status 512 // Verify FaviconHandler status
546 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 513 EXPECT_EQ(1u, driver.num_notifications());
547 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 514 EXPECT_EQ(icon_url, driver.icon_url());
548 515
549 // Simulates update favicon url. 516 // Simulates update favicon url.
550 std::vector<FaviconURL> urls; 517 std::vector<FaviconURL> urls;
551 urls.push_back( 518 urls.push_back(
552 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 519 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
553 helper.OnUpdateFaviconURL(page_url, urls); 520 helper.OnUpdateFaviconURL(page_url, urls);
554 521
555 // Verify FaviconHandler status 522 // Verify FaviconHandler status
556 EXPECT_EQ(1u, helper.image_urls().size()); 523 EXPECT_EQ(1u, helper.image_urls().size());
557 ASSERT_TRUE(helper.current_candidate()); 524 ASSERT_TRUE(helper.current_candidate());
558 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 525 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
559 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 526 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
560 527
561 // Favicon shouldn't request to download icon. 528 // Favicon shouldn't request to download icon.
562 EXPECT_FALSE(helper.download_handler()->HasDownload()); 529 EXPECT_FALSE(helper.download_handler()->HasDownload());
563 } 530 }
564 531
565 TEST_F(FaviconHandlerTest, DownloadFavicon) { 532 TEST_F(FaviconHandlerTest, DownloadFavicon) {
566 const GURL page_url("http://www.google.com"); 533 const GURL page_url("http://www.google.com");
567 const GURL icon_url("http://www.google.com/favicon"); 534 const GURL icon_url("http://www.google.com/favicon");
568 535
569 TestFaviconDriver driver; 536 TestFaviconDriver driver;
570 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); 537 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
571 538
572 helper.FetchFavicon(page_url); 539 helper.FetchFavicon(page_url);
573 HistoryRequestHandler* history_handler = helper.history_handler(); 540 HistoryRequestHandler* history_handler = helper.history_handler();
574 // Ensure the data given to history is correct. 541 // Ensure the data given to history is correct.
575 ASSERT_TRUE(history_handler); 542 ASSERT_TRUE(history_handler);
576 EXPECT_EQ(page_url, history_handler->page_url_); 543 EXPECT_EQ(page_url, history_handler->page_url_);
577 EXPECT_EQ(GURL(), history_handler->icon_url_); 544 EXPECT_EQ(GURL(), history_handler->icon_url_);
578 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 545 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
579 546
580 // Set icon data expired 547 // Set icon data expired
581 SetFaviconRawBitmapResult(icon_url, 548 SetFaviconRawBitmapResult(icon_url,
582 favicon_base::FAVICON, 549 favicon_base::FAVICON,
583 true /* expired */, 550 true /* expired */,
584 &history_handler->history_results_); 551 &history_handler->history_results_);
585 // Send history response. 552 // Send history response.
586 history_handler->InvokeCallback(); 553 history_handler->InvokeCallback();
587 // Verify FaviconHandler status 554 // Verify FaviconHandler status
588 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 555 EXPECT_EQ(1u, driver.num_notifications());
589 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 556 EXPECT_EQ(icon_url, driver.icon_url());
590 557
591 // Simulates update favicon url. 558 // Simulates update favicon url.
592 std::vector<FaviconURL> urls; 559 std::vector<FaviconURL> urls;
593 urls.push_back( 560 urls.push_back(
594 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 561 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
595 helper.OnUpdateFaviconURL(page_url, urls); 562 helper.OnUpdateFaviconURL(page_url, urls);
596 563
597 // Verify FaviconHandler status 564 // Verify FaviconHandler status
598 EXPECT_EQ(1u, helper.image_urls().size()); 565 EXPECT_EQ(1u, helper.image_urls().size());
599 ASSERT_TRUE(helper.current_candidate()); 566 ASSERT_TRUE(helper.current_candidate());
(...skipping 15 matching lines...) Expand all
615 582
616 // New icon should be saved to history backend and navigation entry. 583 // New icon should be saved to history backend and navigation entry.
617 history_handler = helper.history_handler(); 584 history_handler = helper.history_handler();
618 ASSERT_TRUE(history_handler); 585 ASSERT_TRUE(history_handler);
619 EXPECT_EQ(icon_url, history_handler->icon_url_); 586 EXPECT_EQ(icon_url, history_handler->icon_url_);
620 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 587 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
621 EXPECT_LT(0U, history_handler->bitmap_data_.size()); 588 EXPECT_LT(0U, history_handler->bitmap_data_.size());
622 EXPECT_EQ(page_url, history_handler->page_url_); 589 EXPECT_EQ(page_url, history_handler->page_url_);
623 590
624 // Verify NavigationEntry. 591 // Verify NavigationEntry.
625 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 592 EXPECT_EQ(2u, driver.num_notifications());
626 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 593 EXPECT_EQ(icon_url, driver.icon_url());
627 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); 594 EXPECT_FALSE(driver.image().IsEmpty());
628 EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); 595 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width());
629 } 596 }
630 597
631 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { 598 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
632 const GURL page_url("http://www.google.com"); 599 const GURL page_url("http://www.google.com");
633 const GURL icon_url("http://www.google.com/favicon"); 600 const GURL icon_url("http://www.google.com/favicon");
634 const GURL new_icon_url("http://www.google.com/new_favicon"); 601 const GURL new_icon_url("http://www.google.com/new_favicon");
635 602
636 TestFaviconDriver driver; 603 TestFaviconDriver driver;
637 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); 604 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
638 605
639 helper.FetchFavicon(page_url); 606 helper.FetchFavicon(page_url);
640 HistoryRequestHandler* history_handler = helper.history_handler(); 607 HistoryRequestHandler* history_handler = helper.history_handler();
641 // Ensure the data given to history is correct. 608 // Ensure the data given to history is correct.
642 ASSERT_TRUE(history_handler); 609 ASSERT_TRUE(history_handler);
643 EXPECT_EQ(page_url, history_handler->page_url_); 610 EXPECT_EQ(page_url, history_handler->page_url_);
644 EXPECT_EQ(GURL(), history_handler->icon_url_); 611 EXPECT_EQ(GURL(), history_handler->icon_url_);
645 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 612 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
646 613
647 // Set valid icon data. 614 // Set valid icon data.
648 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); 615 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_);
649 616
650 // Send history response. 617 // Send history response.
651 history_handler->InvokeCallback(); 618 history_handler->InvokeCallback();
652 // Verify FaviconHandler status. 619 // Verify FaviconHandler status.
653 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 620 EXPECT_EQ(1u, driver.num_notifications());
654 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 621 EXPECT_EQ(icon_url, driver.icon_url());
655 622
656 // Reset the history_handler to verify whether new icon is requested from 623 // Reset the history_handler to verify whether new icon is requested from
657 // history. 624 // history.
658 helper.set_history_handler(nullptr); 625 helper.set_history_handler(nullptr);
659 626
660 // Simulates update with the different favicon url. 627 // Simulates update with the different favicon url.
661 std::vector<FaviconURL> urls; 628 std::vector<FaviconURL> urls;
662 urls.push_back(FaviconURL( 629 urls.push_back(FaviconURL(
663 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 630 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
664 helper.OnUpdateFaviconURL(page_url, urls); 631 helper.OnUpdateFaviconURL(page_url, urls);
(...skipping 30 matching lines...) Expand all
695 662
696 // New icon should be saved to history backend and navigation entry. 663 // New icon should be saved to history backend and navigation entry.
697 history_handler = helper.history_handler(); 664 history_handler = helper.history_handler();
698 ASSERT_TRUE(history_handler); 665 ASSERT_TRUE(history_handler);
699 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 666 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
700 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 667 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
701 EXPECT_LT(0U, history_handler->bitmap_data_.size()); 668 EXPECT_LT(0U, history_handler->bitmap_data_.size());
702 EXPECT_EQ(page_url, history_handler->page_url_); 669 EXPECT_EQ(page_url, history_handler->page_url_);
703 670
704 // Verify NavigationEntry. 671 // Verify NavigationEntry.
705 EXPECT_EQ(new_icon_url, driver.GetActiveFaviconURL()); 672 EXPECT_EQ(2u, driver.num_notifications());
706 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 673 EXPECT_EQ(new_icon_url, driver.icon_url());
707 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); 674 EXPECT_FALSE(driver.image().IsEmpty());
708 EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); 675 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width());
709 } 676 }
710 677
711 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { 678 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) {
712 const GURL page_url("http://www.google.com"); 679 const GURL page_url("http://www.google.com");
713 const GURL icon_url("http://www.google.com/favicon"); 680 const GURL icon_url("http://www.google.com/favicon");
714 681
715 TestFaviconDriver driver; 682 TestFaviconDriver driver;
716 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); 683 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
717 684
718 helper.FetchFavicon(page_url); 685 helper.FetchFavicon(page_url);
719 HistoryRequestHandler* history_handler = helper.history_handler(); 686 HistoryRequestHandler* history_handler = helper.history_handler();
720 // Ensure the data given to history is correct. 687 // Ensure the data given to history is correct.
721 ASSERT_TRUE(history_handler); 688 ASSERT_TRUE(history_handler);
722 EXPECT_EQ(page_url, history_handler->page_url_); 689 EXPECT_EQ(page_url, history_handler->page_url_);
723 EXPECT_EQ(GURL(), history_handler->icon_url_); 690 EXPECT_EQ(GURL(), history_handler->icon_url_);
724 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 691 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
725 692
726 // Set non empty but invalid data. 693 // Set non empty but invalid data.
727 favicon_base::FaviconRawBitmapResult bitmap_result; 694 favicon_base::FaviconRawBitmapResult bitmap_result;
728 bitmap_result.expired = false; 695 bitmap_result.expired = false;
729 // Empty bitmap data is invalid. 696 // Empty bitmap data is invalid.
730 bitmap_result.bitmap_data = new base::RefCountedBytes(); 697 bitmap_result.bitmap_data = new base::RefCountedBytes();
731 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); 698 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize);
732 bitmap_result.icon_type = favicon_base::FAVICON; 699 bitmap_result.icon_type = favicon_base::FAVICON;
733 bitmap_result.icon_url = icon_url; 700 bitmap_result.icon_url = icon_url;
734 history_handler->history_results_.clear(); 701 history_handler->history_results_.clear();
735 history_handler->history_results_.push_back(bitmap_result); 702 history_handler->history_results_.push_back(bitmap_result);
736 703
737 // Send history response. 704 // Send history response.
738 history_handler->InvokeCallback(); 705 history_handler->InvokeCallback();
739 // The NavigationEntry should not be set yet as the history data is invalid. 706 // The NavigationEntry should not be set yet as the history data is invalid.
740 EXPECT_FALSE(driver.GetActiveFaviconValidity()); 707 EXPECT_EQ(0u, driver.num_notifications());
741 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); 708 EXPECT_EQ(GURL(), driver.icon_url());
742 709
743 // Reset the history_handler to verify whether new icon is requested from 710 // Reset the history_handler to verify whether new icon is requested from
744 // history. 711 // history.
745 helper.set_history_handler(nullptr); 712 helper.set_history_handler(nullptr);
746 713
747 // Simulates update with matching favicon URL. 714 // Simulates update with matching favicon URL.
748 std::vector<FaviconURL> urls; 715 std::vector<FaviconURL> urls;
749 urls.push_back( 716 urls.push_back(
750 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 717 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
751 helper.OnUpdateFaviconURL(page_url, urls); 718 helper.OnUpdateFaviconURL(page_url, urls);
(...skipping 12 matching lines...) Expand all
764 731
765 // New icon should be saved to history backend and navigation entry. 732 // New icon should be saved to history backend and navigation entry.
766 history_handler = helper.history_handler(); 733 history_handler = helper.history_handler();
767 ASSERT_TRUE(history_handler); 734 ASSERT_TRUE(history_handler);
768 EXPECT_EQ(icon_url, history_handler->icon_url_); 735 EXPECT_EQ(icon_url, history_handler->icon_url_);
769 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 736 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
770 EXPECT_LT(0U, history_handler->bitmap_data_.size()); 737 EXPECT_LT(0U, history_handler->bitmap_data_.size());
771 EXPECT_EQ(page_url, history_handler->page_url_); 738 EXPECT_EQ(page_url, history_handler->page_url_);
772 739
773 // Verify NavigationEntry. 740 // Verify NavigationEntry.
774 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 741 EXPECT_EQ(1u, driver.num_notifications());
775 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 742 EXPECT_EQ(icon_url, driver.icon_url());
776 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); 743 EXPECT_FALSE(driver.image().IsEmpty());
777 EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); 744 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width());
778 } 745 }
779 746
780 TEST_F(FaviconHandlerTest, UpdateFavicon) { 747 TEST_F(FaviconHandlerTest, UpdateFavicon) {
781 const GURL page_url("http://www.google.com"); 748 const GURL page_url("http://www.google.com");
782 const GURL icon_url("http://www.google.com/favicon"); 749 const GURL icon_url("http://www.google.com/favicon");
783 const GURL new_icon_url("http://www.google.com/new_favicon"); 750 const GURL new_icon_url("http://www.google.com/new_favicon");
784 751
785 TestFaviconDriver driver; 752 TestFaviconDriver driver;
786 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); 753 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
787 754
788 helper.FetchFavicon(page_url); 755 helper.FetchFavicon(page_url);
789 HistoryRequestHandler* history_handler = helper.history_handler(); 756 HistoryRequestHandler* history_handler = helper.history_handler();
790 // Ensure the data given to history is correct. 757 // Ensure the data given to history is correct.
791 ASSERT_TRUE(history_handler); 758 ASSERT_TRUE(history_handler);
792 EXPECT_EQ(page_url, history_handler->page_url_); 759 EXPECT_EQ(page_url, history_handler->page_url_);
793 EXPECT_EQ(GURL(), history_handler->icon_url_); 760 EXPECT_EQ(GURL(), history_handler->icon_url_);
794 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 761 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
795 762
796 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); 763 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_);
797 764
798 // Send history response. 765 // Send history response.
799 history_handler->InvokeCallback(); 766 history_handler->InvokeCallback();
800 // Verify FaviconHandler status. 767 // Verify FaviconHandler status.
801 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 768 EXPECT_EQ(1u, driver.num_notifications());
802 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 769 EXPECT_EQ(icon_url, driver.icon_url());
803 770
804 // Reset the history_handler to verify whether new icon is requested from 771 // Reset the history_handler to verify whether new icon is requested from
805 // history. 772 // history.
806 helper.set_history_handler(nullptr); 773 helper.set_history_handler(nullptr);
807 774
808 // Simulates update with the different favicon url. 775 // Simulates update with the different favicon url.
809 std::vector<FaviconURL> urls; 776 std::vector<FaviconURL> urls;
810 urls.push_back(FaviconURL( 777 urls.push_back(FaviconURL(
811 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 778 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
812 helper.OnUpdateFaviconURL(page_url, urls); 779 helper.OnUpdateFaviconURL(page_url, urls);
(...skipping 12 matching lines...) Expand all
825 EXPECT_EQ(page_url, history_handler->page_url_); 792 EXPECT_EQ(page_url, history_handler->page_url_);
826 793
827 // Simulate find icon. 794 // Simulate find icon.
828 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); 795 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_);
829 history_handler->InvokeCallback(); 796 history_handler->InvokeCallback();
830 797
831 // Shouldn't request download favicon 798 // Shouldn't request download favicon
832 EXPECT_FALSE(helper.download_handler()->HasDownload()); 799 EXPECT_FALSE(helper.download_handler()->HasDownload());
833 800
834 // Verify the favicon status. 801 // Verify the favicon status.
835 EXPECT_EQ(new_icon_url, driver.GetActiveFaviconURL()); 802 EXPECT_EQ(2u, driver.num_notifications());
836 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 803 EXPECT_EQ(new_icon_url, driver.icon_url());
837 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); 804 EXPECT_FALSE(driver.image().IsEmpty());
838 } 805 }
839 806
840 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { 807 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
841 const GURL page_url("http://www.google.com"); 808 const GURL page_url("http://www.google.com");
842 const GURL icon_url("http://www.google.com/favicon"); 809 const GURL icon_url("http://www.google.com/favicon");
843 const GURL new_icon_url("http://www.google.com/new_favicon"); 810 const GURL new_icon_url("http://www.google.com/new_favicon");
844 811
845 TestFaviconDriver driver; 812 TestFaviconDriver driver;
846 TestFaviconHandler helper(page_url, &driver, FaviconHandler::LARGEST_TOUCH); 813 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST);
847 std::set<GURL> fail_downloads; 814 std::set<GURL> fail_downloads;
848 fail_downloads.insert(icon_url); 815 fail_downloads.insert(icon_url);
849 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); 816 helper.download_handler()->FailDownloadForIconURLs(fail_downloads);
850 817
851 helper.FetchFavicon(page_url); 818 helper.FetchFavicon(page_url);
852 HistoryRequestHandler* history_handler = helper.history_handler(); 819 HistoryRequestHandler* history_handler = helper.history_handler();
853 // Ensure the data given to history is correct. 820 // Ensure the data given to history is correct.
854 ASSERT_TRUE(history_handler); 821 ASSERT_TRUE(history_handler);
855 EXPECT_EQ(page_url, history_handler->page_url_); 822 EXPECT_EQ(page_url, history_handler->page_url_);
856 EXPECT_EQ(GURL(), history_handler->icon_url_); 823 EXPECT_EQ(GURL(), history_handler->icon_url_);
857 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, 824 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON,
858 history_handler->icon_type_); 825 history_handler->icon_type_);
859 826
860 // Icon not found. 827 // Icon not found.
861 history_handler->history_results_.clear(); 828 history_handler->history_results_.clear();
862 // Send history response. 829 // Send history response.
863 history_handler->InvokeCallback(); 830 history_handler->InvokeCallback();
864 // Verify FaviconHandler status. 831 // Verify FaviconHandler status.
865 EXPECT_FALSE(driver.GetActiveFaviconValidity()); 832 EXPECT_EQ(0u, driver.num_notifications());
866 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); 833 EXPECT_EQ(GURL(), driver.icon_url());
867 834
868 // Reset the history_handler to verify whether new icon is requested from 835 // Reset the history_handler to verify whether new icon is requested from
869 // history. 836 // history.
870 helper.set_history_handler(nullptr); 837 helper.set_history_handler(nullptr);
871 838
872 // Simulates update with the different favicon url. 839 // Simulates update with the different favicon url.
873 std::vector<FaviconURL> urls; 840 std::vector<FaviconURL> urls;
874 urls.push_back(FaviconURL(icon_url, 841 urls.push_back(FaviconURL(icon_url,
875 favicon_base::TOUCH_PRECOMPOSED_ICON, 842 favicon_base::TOUCH_PRECOMPOSED_ICON,
876 std::vector<gfx::Size>())); 843 std::vector<gfx::Size>()));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 EXPECT_LT(0U, history_handler->bitmap_data_.size()); 918 EXPECT_LT(0U, history_handler->bitmap_data_.size());
952 EXPECT_EQ(page_url, history_handler->page_url_); 919 EXPECT_EQ(page_url, history_handler->page_url_);
953 } 920 }
954 921
955 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { 922 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) {
956 const GURL page_url("http://www.google.com"); 923 const GURL page_url("http://www.google.com");
957 const GURL icon_url("http://www.google.com/favicon"); 924 const GURL icon_url("http://www.google.com/favicon");
958 const GURL new_icon_url("http://www.google.com/new_favicon"); 925 const GURL new_icon_url("http://www.google.com/new_favicon");
959 926
960 TestFaviconDriver driver; 927 TestFaviconDriver driver;
961 TestFaviconHandler helper(page_url, &driver, FaviconHandler::LARGEST_TOUCH); 928 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST);
962 929
963 helper.FetchFavicon(page_url); 930 helper.FetchFavicon(page_url);
964 HistoryRequestHandler* history_handler = helper.history_handler(); 931 HistoryRequestHandler* history_handler = helper.history_handler();
965 // Ensure the data given to history is correct. 932 // Ensure the data given to history is correct.
966 ASSERT_TRUE(history_handler); 933 ASSERT_TRUE(history_handler);
967 EXPECT_EQ(page_url, history_handler->page_url_); 934 EXPECT_EQ(page_url, history_handler->page_url_);
968 EXPECT_EQ(GURL(), history_handler->icon_url_); 935 EXPECT_EQ(GURL(), history_handler->icon_url_);
969 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, 936 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON,
970 history_handler->icon_type_); 937 history_handler->icon_type_);
971 938
972 // Icon not found. 939 // Icon not found.
973 history_handler->history_results_.clear(); 940 history_handler->history_results_.clear();
974 // Send history response. 941 // Send history response.
975 history_handler->InvokeCallback(); 942 history_handler->InvokeCallback();
976 // Verify FaviconHandler status. 943 // Verify FaviconHandler status.
977 EXPECT_FALSE(driver.GetActiveFaviconValidity()); 944 EXPECT_EQ(0u, driver.num_notifications());
978 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); 945 EXPECT_EQ(GURL(), driver.icon_url());
979 946
980 // Reset the history_handler to verify whether new icon is requested from 947 // Reset the history_handler to verify whether new icon is requested from
981 // history. 948 // history.
982 helper.set_history_handler(nullptr); 949 helper.set_history_handler(nullptr);
983 950
984 // Simulates update with the different favicon url. 951 // Simulates update with the different favicon url.
985 std::vector<FaviconURL> urls; 952 std::vector<FaviconURL> urls;
986 urls.push_back(FaviconURL(icon_url, 953 urls.push_back(FaviconURL(icon_url,
987 favicon_base::TOUCH_PRECOMPOSED_ICON, 954 favicon_base::TOUCH_PRECOMPOSED_ICON,
988 std::vector<gfx::Size>())); 955 std::vector<gfx::Size>()));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 const GURL icon_url2("http://www.google.com/favicon2"); 1040 const GURL icon_url2("http://www.google.com/favicon2");
1074 std::vector<FaviconURL> favicon_urls; 1041 std::vector<FaviconURL> favicon_urls;
1075 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), 1042 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"),
1076 favicon_base::FAVICON, 1043 favicon_base::FAVICON,
1077 std::vector<gfx::Size>())); 1044 std::vector<gfx::Size>()));
1078 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), 1045 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"),
1079 favicon_base::FAVICON, 1046 favicon_base::FAVICON,
1080 std::vector<gfx::Size>())); 1047 std::vector<gfx::Size>()));
1081 1048
1082 TestFaviconDriver driver; 1049 TestFaviconDriver driver;
1083 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); 1050 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
1084 1051
1085 // Initiate a request for favicon data for |page_url|. History does not know 1052 // Initiate a request for favicon data for |page_url|. History does not know
1086 // about the page URL or the icon URLs. 1053 // about the page URL or the icon URLs.
1087 helper.FetchFavicon(page_url); 1054 helper.FetchFavicon(page_url);
1088 helper.history_handler()->InvokeCallback(); 1055 helper.history_handler()->InvokeCallback();
1089 helper.set_history_handler(nullptr); 1056 helper.set_history_handler(nullptr);
1090 1057
1091 // Got icon URLs. 1058 // Got icon URLs.
1092 helper.OnUpdateFaviconURL(page_url, favicon_urls); 1059 helper.OnUpdateFaviconURL(page_url, favicon_urls);
1093 1060
(...skipping 25 matching lines...) Expand all
1119 } 1086 }
1120 1087
1121 // Fixes crbug.com/544560 1088 // Fixes crbug.com/544560
1122 TEST_F(FaviconHandlerTest, 1089 TEST_F(FaviconHandlerTest,
1123 OnFaviconAvailableNotificationSentAfterIconURLChange) { 1090 OnFaviconAvailableNotificationSentAfterIconURLChange) {
1124 const GURL kPageURL("http://www.page_which_animates_favicon.com"); 1091 const GURL kPageURL("http://www.page_which_animates_favicon.com");
1125 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png") ; 1092 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png") ;
1126 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png") ; 1093 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png") ;
1127 1094
1128 TestFaviconDriver driver; 1095 TestFaviconDriver driver;
1129 TestFaviconHandler helper(kPageURL, &driver, FaviconHandler::FAVICON); 1096 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
1130 1097
1131 // Initial state: 1098 // Initial state:
1132 // - The database does not know about |kPageURL|. 1099 // - The database does not know about |kPageURL|.
1133 // - The page uses |kIconURL1| and |kIconURL2|. 1100 // - The page uses |kIconURL1| and |kIconURL2|.
1134 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons 1101 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons
1135 // are expired in the database. 1102 // are expired in the database.
1136 helper.FetchFavicon(kPageURL); 1103 helper.FetchFavicon(kPageURL);
1137 ASSERT_TRUE(helper.history_handler()); 1104 ASSERT_TRUE(helper.history_handler());
1138 helper.history_handler()->InvokeCallback(); 1105 helper.history_handler()->InvokeCallback();
1139 { 1106 {
1140 std::vector<FaviconURL> icon_urls; 1107 std::vector<FaviconURL> icon_urls;
1141 icon_urls.push_back( 1108 icon_urls.push_back(
1142 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>())); 1109 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>()));
1143 icon_urls.push_back( 1110 icon_urls.push_back(
1144 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>())); 1111 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>()));
1145 helper.OnUpdateFaviconURL(kPageURL, icon_urls); 1112 helper.OnUpdateFaviconURL(kPageURL, icon_urls);
1146 } 1113 }
1147 1114
1148 // FaviconHandler should request from history and download |kIconURL1| and 1115 // FaviconHandler should request from history and download |kIconURL1| and
1149 // |kIconURL2|. |kIconURL1| is the better match. A 1116 // |kIconURL2|. |kIconURL1| is the better match. A
1150 // FaviconDriver::OnFaviconAvailable() notification should be sent for 1117 // FaviconDriver::OnFaviconUpdated() notification should be sent for
1151 // |kIconURL1|. 1118 // |kIconURL1|.
1152 1119 ASSERT_EQ(0u, driver.num_notifications());
1153 // Clear the favicon validity so that we can use it to detect whether
1154 // OnFaviconAvailable() is invoked.
1155 driver.SetActiveFaviconValidity(false);
1156
1157 ASSERT_TRUE(helper.history_handler()); 1120 ASSERT_TRUE(helper.history_handler());
1158 SetFaviconRawBitmapResult(kIconURL1, 1121 SetFaviconRawBitmapResult(kIconURL1,
1159 favicon_base::FAVICON, 1122 favicon_base::FAVICON,
1160 true /* expired */, 1123 true /* expired */,
1161 &helper.history_handler()->history_results_); 1124 &helper.history_handler()->history_results_);
1162 helper.history_handler()->InvokeCallback(); 1125 helper.history_handler()->InvokeCallback();
1163 helper.set_history_handler(nullptr); 1126 helper.set_history_handler(nullptr);
1164 ASSERT_TRUE(helper.download_handler()->HasDownload()); 1127 ASSERT_TRUE(helper.download_handler()->HasDownload());
1165 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); 1128 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 15));
1166 helper.download_handler()->InvokeCallback(); 1129 helper.download_handler()->InvokeCallback();
1167 helper.download_handler()->Reset(); 1130 helper.download_handler()->Reset();
1168 1131
1169 ASSERT_TRUE(helper.history_handler()); 1132 ASSERT_TRUE(helper.history_handler());
1170 helper.history_handler()->InvokeCallback(); 1133 helper.history_handler()->InvokeCallback();
1171 SetFaviconRawBitmapResult(kIconURL2, 1134 SetFaviconRawBitmapResult(kIconURL2,
1172 favicon_base::FAVICON, 1135 favicon_base::FAVICON,
1173 true /* expired */, 1136 true /* expired */,
1174 &helper.history_handler()->history_results_); 1137 &helper.history_handler()->history_results_);
1175 helper.history_handler()->InvokeCallback(); 1138 helper.history_handler()->InvokeCallback();
1176 helper.set_history_handler(nullptr); 1139 helper.set_history_handler(nullptr);
1177 ASSERT_TRUE(helper.download_handler()->HasDownload()); 1140 ASSERT_TRUE(helper.download_handler()->HasDownload());
1178 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); 1141 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10));
1179 helper.download_handler()->InvokeCallback(); 1142 helper.download_handler()->InvokeCallback();
1180 helper.download_handler()->Reset(); 1143 helper.download_handler()->Reset();
1181 1144
1182 ASSERT_TRUE(driver.GetActiveFaviconValidity()); 1145 ASSERT_LT(0u, driver.num_notifications());
1183 ASSERT_EQ(kIconURL1, driver.GetActiveFaviconURL()); 1146 ASSERT_EQ(kIconURL1, driver.icon_url());
1184 1147
1185 // Clear the history handler because SetHistoryFavicons() sets it. 1148 // Clear the history handler because SetHistoryFavicons() sets it.
1186 helper.set_history_handler(nullptr); 1149 helper.set_history_handler(nullptr);
1187 1150
1188 // Simulate the page changing it's icon URL to just |kIconURL2| via 1151 // Simulate the page changing it's icon URL to just |kIconURL2| via
1189 // Javascript. 1152 // Javascript.
1190 helper.OnUpdateFaviconURL( 1153 helper.OnUpdateFaviconURL(
1191 kPageURL, 1154 kPageURL,
1192 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON, 1155 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON,
1193 std::vector<gfx::Size>()))); 1156 std::vector<gfx::Size>())));
1194 1157
1195 // FaviconHandler should request from history and download |kIconURL2|. A 1158 // FaviconHandler should request from history and download |kIconURL2|. A
1196 // FaviconDriver::OnFaviconAvailable() notification should be sent for 1159 // FaviconDriver::OnFaviconUpdated() notification should be sent for
1197 // |kIconURL2|. 1160 // |kIconURL2|.
1198 driver.SetActiveFaviconValidity(false); 1161 driver.ResetNumNotifications();
1199
1200 ASSERT_TRUE(helper.history_handler()); 1162 ASSERT_TRUE(helper.history_handler());
1201 SetFaviconRawBitmapResult(kIconURL2, 1163 SetFaviconRawBitmapResult(kIconURL2,
1202 favicon_base::FAVICON, 1164 favicon_base::FAVICON,
1203 true /* expired */, 1165 true /* expired */,
1204 &helper.history_handler()->history_results_); 1166 &helper.history_handler()->history_results_);
1205 helper.history_handler()->InvokeCallback(); 1167 helper.history_handler()->InvokeCallback();
1206 helper.set_history_handler(nullptr); 1168 helper.set_history_handler(nullptr);
1207 ASSERT_TRUE(helper.download_handler()->HasDownload()); 1169 ASSERT_TRUE(helper.download_handler()->HasDownload());
1208 helper.download_handler()->InvokeCallback(); 1170 helper.download_handler()->InvokeCallback();
1209 helper.download_handler()->Reset(); 1171 helper.download_handler()->Reset();
1210 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 1172 ASSERT_LT(0u, driver.num_notifications());
1211 EXPECT_EQ(kIconURL2, driver.GetActiveFaviconURL()); 1173 EXPECT_EQ(kIconURL2, driver.icon_url());
1212 } 1174 }
1213 1175
1214 // Test the favicon which is selected when the web page provides several 1176 // Test the favicon which is selected when the web page provides several
1215 // favicons and none of the favicons are cached in history. 1177 // favicons and none of the favicons are cached in history.
1216 // The goal of this test is to be more of an integration test than 1178 // The goal of this test is to be more of an integration test than
1217 // SelectFaviconFramesTest.*. 1179 // SelectFaviconFramesTest.*.
1218 TEST_F(FaviconHandlerTest, MultipleFavicons) { 1180 TEST_F(FaviconHandlerTest, MultipleFavicons) {
1219 const GURL kPageURL("http://www.google.com"); 1181 const GURL kPageURL("http://www.google.com");
1220 const FaviconURL kSourceIconURLs[] = { 1182 const FaviconURL kSourceIconURLs[] = {
1221 FaviconURL(GURL("http://www.google.com/a"), 1183 FaviconURL(GURL("http://www.google.com/a"),
(...skipping 15 matching lines...) Expand all
1237 // Set the supported scale factors to 1x and 2x. This affects the behavior of 1199 // Set the supported scale factors to 1x and 2x. This affects the behavior of
1238 // SelectFaviconFrames(). 1200 // SelectFaviconFrames().
1239 std::vector<ui::ScaleFactor> scale_factors; 1201 std::vector<ui::ScaleFactor> scale_factors;
1240 scale_factors.push_back(ui::SCALE_FACTOR_100P); 1202 scale_factors.push_back(ui::SCALE_FACTOR_100P);
1241 scale_factors.push_back(ui::SCALE_FACTOR_200P); 1203 scale_factors.push_back(ui::SCALE_FACTOR_200P);
1242 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); 1204 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors);
1243 1205
1244 // 1) Test that if there are several single resolution favicons to choose from 1206 // 1) Test that if there are several single resolution favicons to choose from
1245 // that the largest exact match is chosen. 1207 // that the largest exact match is chosen.
1246 TestFaviconDriver driver1; 1208 TestFaviconDriver driver1;
1247 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON); 1209 TestFaviconHandler handler1(&driver1,
1210 FaviconDriverObserver::NON_TOUCH_16_DIP);
1248 1211
1249 const int kSizes1[] = { 16, 24, 32, 48, 256 }; 1212 const int kSizes1[] = { 16, 24, 32, 48, 256 };
1250 std::vector<FaviconURL> urls1(kSourceIconURLs, 1213 std::vector<FaviconURL> urls1(kSourceIconURLs,
1251 kSourceIconURLs + arraysize(kSizes1)); 1214 kSourceIconURLs + arraysize(kSizes1));
1252 DownloadTillDoneIgnoringHistory( 1215 DownloadTillDoneIgnoringHistory(
1253 &driver1, &handler1, kPageURL, urls1, kSizes1); 1216 &driver1, &handler1, kPageURL, urls1, kSizes1);
1254 1217
1255 EXPECT_EQ(nullptr, handler1.current_candidate()); 1218 EXPECT_EQ(nullptr, handler1.current_candidate());
1256 EXPECT_TRUE(driver1.GetActiveFaviconValidity()); 1219 EXPECT_EQ(1u, driver1.num_notifications());
1257 EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty()); 1220 EXPECT_FALSE(driver1.image().IsEmpty());
1258 EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width()); 1221 EXPECT_EQ(gfx::kFaviconSize, driver1.image().Width());
1259 1222
1260 size_t expected_index = 2u; 1223 size_t expected_index = 2u;
1261 EXPECT_EQ(32, kSizes1[expected_index]); 1224 EXPECT_EQ(32, kSizes1[expected_index]);
1262 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1225 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver1.icon_url());
1263 driver1.GetActiveFaviconURL());
1264 1226
1265 // 2) Test that if there are several single resolution favicons to choose 1227 // 2) Test that if there are several single resolution favicons to choose
1266 // from, the exact match is preferred even if it results in upsampling. 1228 // from, the exact match is preferred even if it results in upsampling.
1267 TestFaviconDriver driver2; 1229 TestFaviconDriver driver2;
1268 TestFaviconHandler handler2(kPageURL, &driver2, FaviconHandler::FAVICON); 1230 TestFaviconHandler handler2(&driver2,
1231 FaviconDriverObserver::NON_TOUCH_16_DIP);
1269 1232
1270 const int kSizes2[] = { 16, 24, 48, 256 }; 1233 const int kSizes2[] = { 16, 24, 48, 256 };
1271 std::vector<FaviconURL> urls2(kSourceIconURLs, 1234 std::vector<FaviconURL> urls2(kSourceIconURLs,
1272 kSourceIconURLs + arraysize(kSizes2)); 1235 kSourceIconURLs + arraysize(kSizes2));
1273 DownloadTillDoneIgnoringHistory( 1236 DownloadTillDoneIgnoringHistory(
1274 &driver2, &handler2, kPageURL, urls2, kSizes2); 1237 &driver2, &handler2, kPageURL, urls2, kSizes2);
1275 EXPECT_TRUE(driver2.GetActiveFaviconValidity()); 1238 EXPECT_EQ(1u, driver2.num_notifications());
1276 expected_index = 0u; 1239 expected_index = 0u;
1277 EXPECT_EQ(16, kSizes2[expected_index]); 1240 EXPECT_EQ(16, kSizes2[expected_index]);
1278 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1241 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver2.icon_url());
1279 driver2.GetActiveFaviconURL());
1280 1242
1281 // 3) Test that favicons which need to be upsampled a little or downsampled 1243 // 3) Test that favicons which need to be upsampled a little or downsampled
1282 // a little are preferred over huge favicons. 1244 // a little are preferred over huge favicons.
1283 TestFaviconDriver driver3; 1245 TestFaviconDriver driver3;
1284 TestFaviconHandler handler3(kPageURL, &driver3, FaviconHandler::FAVICON); 1246 TestFaviconHandler handler3(&driver3,
1247 FaviconDriverObserver::NON_TOUCH_16_DIP);
1285 1248
1286 const int kSizes3[] = { 256, 48 }; 1249 const int kSizes3[] = { 256, 48 };
1287 std::vector<FaviconURL> urls3(kSourceIconURLs, 1250 std::vector<FaviconURL> urls3(kSourceIconURLs,
1288 kSourceIconURLs + arraysize(kSizes3)); 1251 kSourceIconURLs + arraysize(kSizes3));
1289 DownloadTillDoneIgnoringHistory( 1252 DownloadTillDoneIgnoringHistory(
1290 &driver3, &handler3, kPageURL, urls3, kSizes3); 1253 &driver3, &handler3, kPageURL, urls3, kSizes3);
1291 EXPECT_TRUE(driver3.GetActiveFaviconValidity()); 1254 EXPECT_EQ(1u, driver3.num_notifications());
1292 expected_index = 1u; 1255 expected_index = 1u;
1293 EXPECT_EQ(48, kSizes3[expected_index]); 1256 EXPECT_EQ(48, kSizes3[expected_index]);
1294 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1257 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url());
1295 driver3.GetActiveFaviconURL());
1296 1258
1297 TestFaviconDriver driver4; 1259 TestFaviconDriver driver4;
1298 TestFaviconHandler handler4(kPageURL, &driver4, FaviconHandler::FAVICON); 1260 TestFaviconHandler handler4(&driver4,
1261 FaviconDriverObserver::NON_TOUCH_16_DIP);
1299 1262
1300 const int kSizes4[] = { 17, 256 }; 1263 const int kSizes4[] = { 17, 256 };
1301 std::vector<FaviconURL> urls4(kSourceIconURLs, 1264 std::vector<FaviconURL> urls4(kSourceIconURLs,
1302 kSourceIconURLs + arraysize(kSizes4)); 1265 kSourceIconURLs + arraysize(kSizes4));
1303 DownloadTillDoneIgnoringHistory( 1266 DownloadTillDoneIgnoringHistory(
1304 &driver4, &handler4, kPageURL, urls4, kSizes4); 1267 &driver4, &handler4, kPageURL, urls4, kSizes4);
1305 EXPECT_TRUE(driver4.GetActiveFaviconValidity()); 1268 EXPECT_EQ(1u, driver4.num_notifications());
1306 expected_index = 0u; 1269 expected_index = 0u;
1307 EXPECT_EQ(17, kSizes4[expected_index]); 1270 EXPECT_EQ(17, kSizes4[expected_index]);
1308 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1271 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver4.icon_url());
1309 driver4.GetActiveFaviconURL());
1310 } 1272 }
1311 1273
1312 // Test that the best favicon is selected when: 1274 // Test that the best favicon is selected when:
1313 // - The page provides several favicons. 1275 // - The page provides several favicons.
1314 // - Downloading one of the page's icon URLs previously returned a 404. 1276 // - Downloading one of the page's icon URLs previously returned a 404.
1315 // - None of the favicons are cached in the Favicons database. 1277 // - None of the favicons are cached in the Favicons database.
1316 TEST_F(FaviconHandlerTest, MultipleFavicons404) { 1278 TEST_F(FaviconHandlerTest, MultipleFavicons404) {
1317 const GURL kPageURL("http://www.google.com"); 1279 const GURL kPageURL("http://www.google.com");
1318 const GURL k404IconURL("http://www.google.com/404.png"); 1280 const GURL k404IconURL("http://www.google.com/404.png");
1319 const FaviconURL k404FaviconURL( 1281 const FaviconURL k404FaviconURL(
1320 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>()); 1282 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>());
1321 const FaviconURL kFaviconURLs[] = { 1283 const FaviconURL kFaviconURLs[] = {
1322 FaviconURL(GURL("http://www.google.com/a"), 1284 FaviconURL(GURL("http://www.google.com/a"),
1323 favicon_base::FAVICON, 1285 favicon_base::FAVICON,
1324 std::vector<gfx::Size>()), 1286 std::vector<gfx::Size>()),
1325 k404FaviconURL, 1287 k404FaviconURL,
1326 FaviconURL(GURL("http://www.google.com/c"), 1288 FaviconURL(GURL("http://www.google.com/c"),
1327 favicon_base::FAVICON, 1289 favicon_base::FAVICON,
1328 std::vector<gfx::Size>()), 1290 std::vector<gfx::Size>()),
1329 }; 1291 };
1330 1292
1331 TestFaviconDriver driver; 1293 TestFaviconDriver driver;
1332 TestFaviconHandler handler(kPageURL, &driver, FaviconHandler::FAVICON); 1294 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
1333 DownloadHandler* download_handler = handler.download_handler(); 1295 DownloadHandler* download_handler = handler.download_handler();
1334 1296
1335 std::set<GURL> k404URLs; 1297 std::set<GURL> k404URLs;
1336 k404URLs.insert(k404IconURL); 1298 k404URLs.insert(k404IconURL);
1337 download_handler->FailDownloadForIconURLs(k404URLs); 1299 download_handler->FailDownloadForIconURLs(k404URLs);
1338 1300
1339 // Make the initial download for |k404IconURL| fail. 1301 // Make the initial download for |k404IconURL| fail.
1340 const int kSizes1[] = { 0 }; 1302 const int kSizes1[] = { 0 };
1341 std::vector<FaviconURL> urls1(1u, k404FaviconURL); 1303 std::vector<FaviconURL> urls1(1u, k404FaviconURL);
1342 DownloadTillDoneIgnoringHistory( 1304 DownloadTillDoneIgnoringHistory(
1343 &driver, &handler, kPageURL, urls1, kSizes1); 1305 &driver, &handler, kPageURL, urls1, kSizes1);
1344 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); 1306 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL));
1345 1307
1346 // Do a fetch now that the initial download for |k404IconURL| has failed. The 1308 // Do a fetch now that the initial download for |k404IconURL| has failed. The
1347 // behavior is different because OnDidDownloadFavicon() is invoked 1309 // behavior is different because OnDidDownloadFavicon() is invoked
1348 // synchronously from DownloadFavicon(). 1310 // synchronously from DownloadFavicon().
1349 const int kSizes2[] = { 10, 0, 16 }; 1311 const int kSizes2[] = { 10, 0, 16 };
1350 std::vector<FaviconURL> urls2(kFaviconURLs, 1312 std::vector<FaviconURL> urls2(kFaviconURLs,
1351 kFaviconURLs + arraysize(kFaviconURLs)); 1313 kFaviconURLs + arraysize(kFaviconURLs));
1352 DownloadTillDoneIgnoringHistory( 1314 DownloadTillDoneIgnoringHistory(
1353 &driver, &handler, kPageURL, urls2, kSizes2); 1315 &driver, &handler, kPageURL, urls2, kSizes2);
1354 1316
1355 EXPECT_EQ(nullptr, handler.current_candidate()); 1317 EXPECT_EQ(nullptr, handler.current_candidate());
1356 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 1318 EXPECT_EQ(1u, driver.num_notifications());
1357 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); 1319 EXPECT_FALSE(driver.image().IsEmpty());
1358 int expected_index = 2u; 1320 int expected_index = 2u;
1359 EXPECT_EQ(16, kSizes2[expected_index]); 1321 EXPECT_EQ(16, kSizes2[expected_index]);
1360 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, 1322 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, driver.icon_url());
1361 driver.GetActiveFaviconURL());
1362 } 1323 }
1363 1324
1364 // Test that no favicon is selected when: 1325 // Test that no favicon is selected when:
1365 // - The page provides several favicons. 1326 // - The page provides several favicons.
1366 // - Downloading the page's icons has previously returned a 404. 1327 // - Downloading the page's icons has previously returned a 404.
1367 // - None of the favicons are cached in the Favicons database. 1328 // - None of the favicons are cached in the Favicons database.
1368 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { 1329 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) {
1369 const GURL kPageURL("http://www.google.com"); 1330 const GURL kPageURL("http://www.google.com");
1370 const GURL k404IconURL1("http://www.google.com/4041.png"); 1331 const GURL k404IconURL1("http://www.google.com/4041.png");
1371 const GURL k404IconURL2("http://www.google.com/4042.png"); 1332 const GURL k404IconURL2("http://www.google.com/4042.png");
1372 const FaviconURL kFaviconURLs[] = { 1333 const FaviconURL kFaviconURLs[] = {
1373 FaviconURL(k404IconURL1, 1334 FaviconURL(k404IconURL1,
1374 favicon_base::FAVICON, 1335 favicon_base::FAVICON,
1375 std::vector<gfx::Size>()), 1336 std::vector<gfx::Size>()),
1376 FaviconURL(k404IconURL2, 1337 FaviconURL(k404IconURL2,
1377 favicon_base::FAVICON, 1338 favicon_base::FAVICON,
1378 std::vector<gfx::Size>()), 1339 std::vector<gfx::Size>()),
1379 }; 1340 };
1380 1341
1381 TestFaviconDriver driver; 1342 TestFaviconDriver driver;
1382 TestFaviconHandler handler(kPageURL, &driver, FaviconHandler::FAVICON); 1343 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
1383 DownloadHandler* download_handler = handler.download_handler(); 1344 DownloadHandler* download_handler = handler.download_handler();
1384 1345
1385 std::set<GURL> k404URLs; 1346 std::set<GURL> k404URLs;
1386 k404URLs.insert(k404IconURL1); 1347 k404URLs.insert(k404IconURL1);
1387 k404URLs.insert(k404IconURL2); 1348 k404URLs.insert(k404IconURL2);
1388 download_handler->FailDownloadForIconURLs(k404URLs); 1349 download_handler->FailDownloadForIconURLs(k404URLs);
1389 1350
1390 // Make the initial downloads for |kFaviconURLs| fail. 1351 // Make the initial downloads for |kFaviconURLs| fail.
1391 for (const FaviconURL& favicon_url : kFaviconURLs) { 1352 for (const FaviconURL& favicon_url : kFaviconURLs) {
1392 const int kSizes[] = { 0 }; 1353 const int kSizes[] = { 0 };
1393 std::vector<FaviconURL> urls(1u, favicon_url); 1354 std::vector<FaviconURL> urls(1u, favicon_url);
1394 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); 1355 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes);
1395 } 1356 }
1396 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); 1357 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1));
1397 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); 1358 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2));
1398 1359
1399 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. 1360 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed.
1400 // The behavior is different because OnDidDownloadFavicon() is invoked 1361 // The behavior is different because OnDidDownloadFavicon() is invoked
1401 // synchronously from DownloadFavicon(). 1362 // synchronously from DownloadFavicon().
1402 const int kSizes[] = { 0, 0 }; 1363 const int kSizes[] = { 0, 0 };
1403 std::vector<FaviconURL> urls(kFaviconURLs, 1364 std::vector<FaviconURL> urls(kFaviconURLs,
1404 kFaviconURLs + arraysize(kFaviconURLs)); 1365 kFaviconURLs + arraysize(kFaviconURLs));
1405 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); 1366 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes);
1406 1367
1407 EXPECT_EQ(nullptr, handler.current_candidate()); 1368 EXPECT_EQ(nullptr, handler.current_candidate());
1408 EXPECT_FALSE(driver.GetActiveFaviconValidity()); 1369 EXPECT_EQ(0u, driver.num_notifications());
1409 EXPECT_TRUE(driver.GetActiveFaviconImage().IsEmpty()); 1370 EXPECT_TRUE(driver.image().IsEmpty());
1410 } 1371 }
1411 1372
1412 // Test that no favicon is selected when the page's only icon uses an invalid 1373 // Test that no favicon is selected when the page's only icon uses an invalid
1413 // URL syntax. 1374 // URL syntax.
1414 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { 1375 TEST_F(FaviconHandlerTest, FaviconInvalidURL) {
1415 const GURL kPageURL("http://www.google.com"); 1376 const GURL kPageURL("http://www.google.com");
1416 const GURL kInvalidFormatURL("invalid"); 1377 const GURL kInvalidFormatURL("invalid");
1417 ASSERT_TRUE(kInvalidFormatURL.is_empty()); 1378 ASSERT_TRUE(kInvalidFormatURL.is_empty());
1418 1379
1419 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, 1380 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON,
1420 std::vector<gfx::Size>()); 1381 std::vector<gfx::Size>());
1421 1382
1422 TestFaviconDriver driver; 1383 TestFaviconDriver driver;
1423 TestFaviconHandler handler(kPageURL, &driver, FaviconHandler::FAVICON); 1384 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
1424 UpdateFaviconURL(&driver, &handler, kPageURL, 1385 UpdateFaviconURL(&driver, &handler, kPageURL,
1425 std::vector<FaviconURL>(1u, favicon_url)); 1386 std::vector<FaviconURL>(1u, favicon_url));
1426 EXPECT_EQ(0u, handler.image_urls().size()); 1387 EXPECT_EQ(0u, handler.image_urls().size());
1427 } 1388 }
1428 1389
1429 TEST_F(FaviconHandlerTest, TestSortFavicon) { 1390 TEST_F(FaviconHandlerTest, TestSortFavicon) {
1430 const GURL kPageURL("http://www.google.com"); 1391 const GURL kPageURL("http://www.google.com");
1431 std::vector<gfx::Size> icon1; 1392 std::vector<gfx::Size> icon1;
1432 icon1.push_back(gfx::Size(1024, 1024)); 1393 icon1.push_back(gfx::Size(1024, 1024));
1433 icon1.push_back(gfx::Size(512, 512)); 1394 icon1.push_back(gfx::Size(512, 512));
(...skipping 11 matching lines...) Expand all
1445 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), 1406 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2),
1446 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), 1407 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3),
1447 FaviconURL(GURL("http://www.google.com/d"), 1408 FaviconURL(GURL("http://www.google.com/d"),
1448 favicon_base::FAVICON, 1409 favicon_base::FAVICON,
1449 std::vector<gfx::Size>()), 1410 std::vector<gfx::Size>()),
1450 FaviconURL(GURL("http://www.google.com/e"), 1411 FaviconURL(GURL("http://www.google.com/e"),
1451 favicon_base::FAVICON, 1412 favicon_base::FAVICON,
1452 std::vector<gfx::Size>())}; 1413 std::vector<gfx::Size>())};
1453 1414
1454 TestFaviconDriver driver1; 1415 TestFaviconDriver driver1;
1455 TestFaviconHandler handler1(kPageURL, &driver1, 1416 TestFaviconHandler handler1(&driver1,
1456 FaviconHandler::LARGEST_FAVICON); 1417 FaviconDriverObserver::NON_TOUCH_LARGEST);
1457 std::vector<FaviconURL> urls1(kSourceIconURLs, 1418 std::vector<FaviconURL> urls1(kSourceIconURLs,
1458 kSourceIconURLs + arraysize(kSourceIconURLs)); 1419 kSourceIconURLs + arraysize(kSourceIconURLs));
1459 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1420 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
1460 1421
1461 struct ExpectedResult { 1422 struct ExpectedResult {
1462 // The favicon's index in kSourceIconURLs. 1423 // The favicon's index in kSourceIconURLs.
1463 size_t favicon_index; 1424 size_t favicon_index;
1464 // Width of largest bitmap. 1425 // Width of largest bitmap.
1465 int width; 1426 int width;
1466 } results[] = { 1427 } results[] = {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 FaviconURL( 1469 FaviconURL(
1509 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), 1470 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3),
1510 FaviconURL(GURL("http://www.google.com/d"), 1471 FaviconURL(GURL("http://www.google.com/d"),
1511 favicon_base::FAVICON, 1472 favicon_base::FAVICON,
1512 std::vector<gfx::Size>()), 1473 std::vector<gfx::Size>()),
1513 FaviconURL(GURL("http://www.google.com/e"), 1474 FaviconURL(GURL("http://www.google.com/e"),
1514 favicon_base::FAVICON, 1475 favicon_base::FAVICON,
1515 std::vector<gfx::Size>())}; 1476 std::vector<gfx::Size>())};
1516 1477
1517 TestFaviconDriver driver1; 1478 TestFaviconDriver driver1;
1518 TestFaviconHandler handler1(kPageURL, &driver1, 1479 TestFaviconHandler handler1(&driver1,
1519 FaviconHandler::LARGEST_FAVICON); 1480 FaviconDriverObserver::NON_TOUCH_LARGEST);
1520 1481
1521 std::set<GURL> fail_icon_urls; 1482 std::set<GURL> fail_icon_urls;
1522 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { 1483 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) {
1523 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); 1484 fail_icon_urls.insert(kSourceIconURLs[i].icon_url);
1524 } 1485 }
1525 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); 1486 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls);
1526 1487
1527 std::vector<FaviconURL> urls1(kSourceIconURLs, 1488 std::vector<FaviconURL> urls1(kSourceIconURLs,
1528 kSourceIconURLs + arraysize(kSourceIconURLs)); 1489 kSourceIconURLs + arraysize(kSourceIconURLs));
1529 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1490 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 two_icons.push_back(gfx::Size(14, 14)); 1537 two_icons.push_back(gfx::Size(14, 14));
1577 two_icons.push_back(gfx::Size(16, 16)); 1538 two_icons.push_back(gfx::Size(16, 16));
1578 1539
1579 const FaviconURL kSourceIconURLs[] = { 1540 const FaviconURL kSourceIconURLs[] = {
1580 FaviconURL( 1541 FaviconURL(
1581 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), 1542 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon),
1582 FaviconURL( 1543 FaviconURL(
1583 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; 1544 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)};
1584 1545
1585 TestFaviconDriver driver1; 1546 TestFaviconDriver driver1;
1586 TestFaviconHandler handler1(kPageURL, &driver1, 1547 TestFaviconHandler handler1(&driver1,
1587 FaviconHandler::LARGEST_FAVICON); 1548 FaviconDriverObserver::NON_TOUCH_LARGEST);
1588 std::vector<FaviconURL> urls1(kSourceIconURLs, 1549 std::vector<FaviconURL> urls1(kSourceIconURLs,
1589 kSourceIconURLs + arraysize(kSourceIconURLs)); 1550 kSourceIconURLs + arraysize(kSourceIconURLs));
1590 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1551 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
1591 1552
1592 ASSERT_EQ(2u, handler1.image_urls().size()); 1553 ASSERT_EQ(2u, handler1.image_urls().size());
1593 1554
1594 // Index of largest favicon in kSourceIconURLs. 1555 // Index of largest favicon in kSourceIconURLs.
1595 size_t i = 1; 1556 size_t i = 1;
1596 // The largest bitmap's index in Favicon . 1557 // The largest bitmap's index in Favicon .
1597 int b = 1; 1558 int b = 1;
(...skipping 21 matching lines...) Expand all
1619 sizes.push_back(j->width()); 1580 sizes.push_back(j->width());
1620 1581
1621 handler1.download_handler()->SetImageSizes(sizes); 1582 handler1.download_handler()->SetImageSizes(sizes);
1622 handler1.download_handler()->InvokeCallback(); 1583 handler1.download_handler()->InvokeCallback();
1623 1584
1624 // Verify the largest bitmap has been saved into history. 1585 // Verify the largest bitmap has been saved into history.
1625 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); 1586 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_);
1626 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], 1587 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b],
1627 handler1.history_handler()->size_); 1588 handler1.history_handler()->size_);
1628 // Verify NotifyFaviconAvailable(). 1589 // Verify NotifyFaviconAvailable().
1629 EXPECT_FALSE(driver1.update_active_favicon()); 1590 EXPECT_EQ(1u, driver1.num_notifications());
1630 EXPECT_EQ(kSourceIconURLs[i].icon_url, driver1.available_icon_url()); 1591 EXPECT_EQ(kSourceIconURLs[i].icon_url, driver1.icon_url());
1631 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], 1592 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], driver1.image().Size());
1632 driver1.available_favicon().Size());
1633 } 1593 }
1634 1594
1635 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { 1595 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) {
1636 const GURL kPageURL("http://www.google.com"); 1596 const GURL kPageURL("http://www.google.com");
1637 const int kMaximalSize = 1597 const int kMaximalSize =
1638 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); 1598 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON);
1639 1599
1640 std::vector<gfx::Size> icon1; 1600 std::vector<gfx::Size> icon1;
1641 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); 1601 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1));
1642 1602
1643 std::vector<gfx::Size> icon2; 1603 std::vector<gfx::Size> icon2;
1644 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); 1604 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2));
1645 1605
1646 const FaviconURL kSourceIconURLs[] = { 1606 const FaviconURL kSourceIconURLs[] = {
1647 FaviconURL( 1607 FaviconURL(
1648 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), 1608 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1),
1649 FaviconURL( 1609 FaviconURL(
1650 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; 1610 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)};
1651 1611
1652 TestFaviconDriver driver1; 1612 TestFaviconDriver driver1;
1653 TestFaviconHandler handler1(kPageURL, &driver1, 1613 TestFaviconHandler handler1(&driver1,
1654 FaviconHandler::LARGEST_FAVICON); 1614 FaviconDriverObserver::NON_TOUCH_LARGEST);
1655 std::vector<FaviconURL> urls1(kSourceIconURLs, 1615 std::vector<FaviconURL> urls1(kSourceIconURLs,
1656 kSourceIconURLs + arraysize(kSourceIconURLs)); 1616 kSourceIconURLs + arraysize(kSourceIconURLs));
1657 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1617 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
1658 1618
1659 ASSERT_EQ(2u, handler1.image_urls().size()); 1619 ASSERT_EQ(2u, handler1.image_urls().size());
1660 1620
1661 // Index of largest favicon in kSourceIconURLs. 1621 // Index of largest favicon in kSourceIconURLs.
1662 size_t i = 1; 1622 size_t i = 1;
1663 // The largest bitmap's index in Favicon . 1623 // The largest bitmap's index in Favicon .
1664 int b = 0; 1624 int b = 0;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 const int actual_size2 = 12; 1664 const int actual_size2 = 12;
1705 1665
1706 const FaviconURL kSourceIconURLs[] = { 1666 const FaviconURL kSourceIconURLs[] = {
1707 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), 1667 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1),
1708 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), 1668 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2),
1709 FaviconURL(GURL("http://www.google.com/d"), 1669 FaviconURL(GURL("http://www.google.com/d"),
1710 favicon_base::FAVICON, 1670 favicon_base::FAVICON,
1711 std::vector<gfx::Size>())}; 1671 std::vector<gfx::Size>())};
1712 1672
1713 TestFaviconDriver driver1; 1673 TestFaviconDriver driver1;
1714 TestFaviconHandler handler1(kPageURL, &driver1, 1674 TestFaviconHandler handler1(&driver1,
1715 FaviconHandler::LARGEST_FAVICON); 1675 FaviconDriverObserver::NON_TOUCH_LARGEST);
1716 std::vector<FaviconURL> urls1(kSourceIconURLs, 1676 std::vector<FaviconURL> urls1(kSourceIconURLs,
1717 kSourceIconURLs + arraysize(kSourceIconURLs)); 1677 kSourceIconURLs + arraysize(kSourceIconURLs));
1718 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1678 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
1719 ASSERT_EQ(3u, handler1.image_urls().size()); 1679 ASSERT_EQ(3u, handler1.image_urls().size());
1720 1680
1721 // Simulate no favicon from history. 1681 // Simulate no favicon from history.
1722 handler1.history_handler()->history_results_.clear(); 1682 handler1.history_handler()->history_results_.clear();
1723 handler1.history_handler()->InvokeCallback(); 1683 handler1.history_handler()->InvokeCallback();
1724 1684
1725 // Verify the first icon was request to download 1685 // Verify the first icon was request to download
(...skipping 29 matching lines...) Expand all
1755 handler1.download_handler()->SetImageSizes(sizes); 1715 handler1.download_handler()->SetImageSizes(sizes);
1756 handler1.download_handler()->InvokeCallback(); 1716 handler1.download_handler()->InvokeCallback();
1757 handler1.download_handler()->Reset(); 1717 handler1.download_handler()->Reset();
1758 1718
1759 // Verify icon2 has been saved into history. 1719 // Verify icon2 has been saved into history.
1760 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); 1720 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_);
1761 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), 1721 EXPECT_EQ(gfx::Size(actual_size2, actual_size2),
1762 handler1.history_handler()->size_); 1722 handler1.history_handler()->size_);
1763 } 1723 }
1764 1724
1765 class FaviconHandlerActiveFaviconValidityParamTest :
1766 public FaviconHandlerTest,
1767 public ::testing::WithParamInterface<bool> {
1768 public:
1769 FaviconHandlerActiveFaviconValidityParamTest() {}
1770
1771 ~FaviconHandlerActiveFaviconValidityParamTest() override {}
1772
1773 bool GetActiveFaviconValiditySetting() {
1774 return GetParam();
1775 }
1776
1777 private:
1778 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerActiveFaviconValidityParamTest);
1779 };
1780
1781 TEST_P(FaviconHandlerActiveFaviconValidityParamTest,
1782 TestDownloadLargestIconDoesNotImpactActiveFaviconValidity) {
1783 const GURL page_url("http://www.google.com");
1784
1785 std::vector<gfx::Size> one_icon;
1786 one_icon.push_back(gfx::Size(15, 15));
1787
1788 const GURL old_favicon_url("http://www.google.com/old");
1789 const GURL new_favicon_url("http://www.google.com/b");
1790 const FaviconURL source_icon_urls[] = {
1791 FaviconURL(new_favicon_url, favicon_base::FAVICON, one_icon)};
1792 TestFaviconDriver driver1;
1793 TestFaviconHandler handler1(page_url, &driver1,
1794 FaviconHandler::LARGEST_FAVICON);
1795 std::vector<FaviconURL> urls1(source_icon_urls,
1796 source_icon_urls + arraysize(source_icon_urls));
1797 UpdateFaviconURL(&driver1, &handler1, page_url, urls1);
1798
1799 HistoryRequestHandler* history_handler = handler1.history_handler();
1800
1801 // Simulate the active favicon is updated, this shouldn't happen in real
1802 // use case, but we want to verify the behavior below is not impacted by
1803 // accident.
1804 driver1.SetActiveFaviconValidity(GetActiveFaviconValiditySetting());
1805 // Simulate the get favicon from history, but favicon URL didn't match.
1806 SetFaviconRawBitmapResult(old_favicon_url,
1807 &history_handler->history_results_);
1808 history_handler->InvokeCallback();
1809 // Since we downloaded largest icon, and don't want to set active favicon
1810 // NotifyFaviconAvaliable() should be called with is_active_favicon as false.
1811 EXPECT_EQ(old_favicon_url, driver1.available_icon_url());
1812 EXPECT_FALSE(driver1.update_active_favicon());
1813 EXPECT_EQ(1u, driver1.num_favicon_available());
1814
1815 // We are trying to get favicon from history again.
1816 history_handler = handler1.history_handler();
1817 EXPECT_EQ(new_favicon_url, history_handler->icon_url_);
1818 // Simulate the get expired favicon from history.
1819 history_handler->history_results_.clear();
1820 SetFaviconRawBitmapResult(new_favicon_url, favicon_base::FAVICON, true,
1821 &history_handler->history_results_);
1822 history_handler->InvokeCallback();
1823 // Since we downloaded largest icon, and don't want to set active favicon
1824 // NotifyFaviconAvaliable() should be called with is_active_favicon as false.
1825 EXPECT_EQ(new_favicon_url, driver1.available_icon_url());
1826 EXPECT_FALSE(driver1.update_active_favicon());
1827 EXPECT_EQ(2u, driver1.num_favicon_available());
1828
1829 // We are trying to download favicon.
1830 DownloadHandler* download_handler = handler1.download_handler();
1831 EXPECT_TRUE(download_handler->HasDownload());
1832 EXPECT_EQ(new_favicon_url, download_handler->GetImageUrl());
1833 // Simulate the download succeed.
1834 download_handler->InvokeCallback();
1835 // Since we downloaded largest icon, and don't want to set active favicon
1836 // NotifyFaviconAvaliable() should be called with is_active_favicon as false.
1837 EXPECT_EQ(new_favicon_url, driver1.available_icon_url());
1838 EXPECT_FALSE(driver1.update_active_favicon());
1839 EXPECT_EQ(3u, driver1.num_favicon_available());
1840 }
1841
1842 INSTANTIATE_TEST_CASE_P(FaviconHandlerTestActiveFaviconValidityTrueOrFalse,
1843 FaviconHandlerActiveFaviconValidityParamTest,
1844 ::testing::Bool());
1845
1846 } // namespace 1725 } // namespace
1847 } // namespace favicon 1726 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698