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

Side by Side Diff: chrome/browser/favicon_helper_unittest.cc

Issue 6883020: Make icon_messages use the IPC macros for defining the structs and the serialization code, and mo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/favicon_helper.cc ('k') | chrome/browser/prerender/prerender_contents.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/favicon_helper.h" 5 #include "chrome/browser/favicon_helper.h"
6 6
7 #include "content/browser/renderer_host/test_render_view_host.h" 7 #include "content/browser/renderer_host/test_render_view_host.h"
8 #include "content/browser/tab_contents/navigation_entry.h" 8 #include "content/browser/tab_contents/navigation_entry.h"
9 #include "content/browser/tab_contents/test_tab_contents.h" 9 #include "content/browser/tab_contents/test_tab_contents.h"
10 #include "ui/gfx/codec/png_codec.h" 10 #include "ui/gfx/codec/png_codec.h"
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 history_handler->favicon_data_.image_data = data; 300 history_handler->favicon_data_.image_data = data;
301 301
302 // Send history response. 302 // Send history response.
303 history_handler->InvokeCallback(); 303 history_handler->InvokeCallback();
304 // Verify FaviconHelper status 304 // Verify FaviconHelper status
305 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid()); 305 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid());
306 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url()); 306 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url());
307 307
308 // Simulates update favicon url. 308 // Simulates update favicon url.
309 std::vector<FaviconURL> urls; 309 std::vector<FaviconURL> urls;
310 urls.push_back(FaviconURL(icon_url, FAVICON)); 310 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON));
311 DownloadHandler::UpdateFaviconURL(&helper, urls); 311 DownloadHandler::UpdateFaviconURL(&helper, urls);
312 312
313 // Verify FaviconHelper status 313 // Verify FaviconHelper status
314 EXPECT_EQ(1U, helper.urls().size()); 314 EXPECT_EQ(1U, helper.urls().size());
315 ASSERT_TRUE(helper.current_candidate()); 315 ASSERT_TRUE(helper.current_candidate());
316 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 316 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
317 ASSERT_EQ(FAVICON, helper.current_candidate()->icon_type); 317 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type);
318 318
319 // Favicon shouldn't request to download icon. 319 // Favicon shouldn't request to download icon.
320 DownloadHandler* download_handler = helper.download_handler(); 320 DownloadHandler* download_handler = helper.download_handler();
321 ASSERT_FALSE(download_handler); 321 ASSERT_FALSE(download_handler);
322 } 322 }
323 323
324 TEST_F(FaviconHelperTest, DownloadFavicon) { 324 TEST_F(FaviconHelperTest, DownloadFavicon) {
325 const GURL page_url("http://www.google.com"); 325 const GURL page_url("http://www.google.com");
326 const GURL icon_url("http://www.google.com/favicon"); 326 const GURL icon_url("http://www.google.com/favicon");
327 327
(...skipping 13 matching lines...) Expand all
341 history_handler->favicon_data_.expired = true; 341 history_handler->favicon_data_.expired = true;
342 history_handler->favicon_data_.icon_url = icon_url; 342 history_handler->favicon_data_.icon_url = icon_url;
343 // Send history response. 343 // Send history response.
344 history_handler->InvokeCallback(); 344 history_handler->InvokeCallback();
345 // Verify FaviconHelper status 345 // Verify FaviconHelper status
346 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid()); 346 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid());
347 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url()); 347 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url());
348 348
349 // Simulates update favicon url. 349 // Simulates update favicon url.
350 std::vector<FaviconURL> urls; 350 std::vector<FaviconURL> urls;
351 urls.push_back(FaviconURL(icon_url, FAVICON)); 351 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON));
352 DownloadHandler::UpdateFaviconURL(&helper, urls); 352 DownloadHandler::UpdateFaviconURL(&helper, urls);
353 353
354 // Verify FaviconHelper status 354 // Verify FaviconHelper status
355 EXPECT_EQ(1U, helper.urls().size()); 355 EXPECT_EQ(1U, helper.urls().size());
356 ASSERT_TRUE(helper.current_candidate()); 356 ASSERT_TRUE(helper.current_candidate());
357 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 357 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
358 ASSERT_EQ(FAVICON, helper.current_candidate()->icon_type); 358 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type);
359 359
360 // Favicon should request to download icon now. 360 // Favicon should request to download icon now.
361 DownloadHandler* download_handler = helper.download_handler(); 361 DownloadHandler* download_handler = helper.download_handler();
362 ASSERT_TRUE(download_handler); 362 ASSERT_TRUE(download_handler);
363 // Verify the download request. 363 // Verify the download request.
364 EXPECT_EQ(icon_url, download_handler->image_url_); 364 EXPECT_EQ(icon_url, download_handler->image_url_);
365 EXPECT_EQ(kFaviconSize, download_handler->image_size_); 365 EXPECT_EQ(kFaviconSize, download_handler->image_size_);
366 366
367 // Reset the history_handler to verify whether favicon is set. 367 // Reset the history_handler to verify whether favicon is set.
368 helper.set_history_handler(NULL); 368 helper.set_history_handler(NULL);
369 369
370 // Smulates download done. 370 // Smulates download done.
371 download_handler->InvokeCallback(); 371 download_handler->InvokeCallback();
372 372
373 // New icon should be saved to history backend and navigation entry. 373 // New icon should be saved to history backend and navigation entry.
374 history_handler = helper.history_handler(); 374 history_handler = helper.history_handler();
375 ASSERT_TRUE(history_handler); 375 ASSERT_TRUE(history_handler);
376 EXPECT_EQ(icon_url, history_handler->icon_url_); 376 EXPECT_EQ(icon_url, history_handler->icon_url_);
377 EXPECT_EQ(FAVICON, history_handler->icon_type_); 377 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_);
378 EXPECT_LT(0U, history_handler->image_data_.size()); 378 EXPECT_LT(0U, history_handler->image_data_.size());
379 EXPECT_EQ(page_url, history_handler->page_url_); 379 EXPECT_EQ(page_url, history_handler->page_url_);
380 380
381 // Verify NavigationEntry. 381 // Verify NavigationEntry.
382 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url()); 382 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url());
383 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid()); 383 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid());
384 EXPECT_FALSE(helper.GetEntry()->favicon().bitmap().empty()); 384 EXPECT_FALSE(helper.GetEntry()->favicon().bitmap().empty());
385 } 385 }
386 386
387 TEST_F(FaviconHelperTest, UpdateAndDownloadFavicon) { 387 TEST_F(FaviconHelperTest, UpdateAndDownloadFavicon) {
(...skipping 25 matching lines...) Expand all
413 // Verify FaviconHelper status. 413 // Verify FaviconHelper status.
414 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid()); 414 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid());
415 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url()); 415 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url());
416 416
417 // Reset the history_handler to verify whether new icon is requested from 417 // Reset the history_handler to verify whether new icon is requested from
418 // history. 418 // history.
419 helper.set_history_handler(NULL); 419 helper.set_history_handler(NULL);
420 420
421 // Simulates update with the different favicon url. 421 // Simulates update with the different favicon url.
422 std::vector<FaviconURL> urls; 422 std::vector<FaviconURL> urls;
423 urls.push_back(FaviconURL(new_icon_url, FAVICON)); 423 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON));
424 DownloadHandler::UpdateFaviconURL(&helper, urls); 424 DownloadHandler::UpdateFaviconURL(&helper, urls);
425 425
426 // Verify FaviconHelper status. 426 // Verify FaviconHelper status.
427 EXPECT_EQ(1U, helper.urls().size()); 427 EXPECT_EQ(1U, helper.urls().size());
428 ASSERT_TRUE(helper.current_candidate()); 428 ASSERT_TRUE(helper.current_candidate());
429 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); 429 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url);
430 ASSERT_EQ(FAVICON, helper.current_candidate()->icon_type); 430 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type);
431 // The favicon status's url should be updated. 431 // The favicon status's url should be updated.
432 ASSERT_EQ(new_icon_url, helper.GetEntry()->favicon().url()); 432 ASSERT_EQ(new_icon_url, helper.GetEntry()->favicon().url());
433 433
434 // Favicon should be requested from history. 434 // Favicon should be requested from history.
435 history_handler = helper.history_handler(); 435 history_handler = helper.history_handler();
436 ASSERT_TRUE(history_handler); 436 ASSERT_TRUE(history_handler);
437 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 437 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
438 EXPECT_EQ(FAVICON, history_handler->icon_type_); 438 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_);
439 EXPECT_EQ(page_url, history_handler->page_url_); 439 EXPECT_EQ(page_url, history_handler->page_url_);
440 440
441 // Simulate not find icon. 441 // Simulate not find icon.
442 history_handler->favicon_data_.known_icon = false; 442 history_handler->favicon_data_.known_icon = false;
443 history_handler->InvokeCallback(); 443 history_handler->InvokeCallback();
444 444
445 // Favicon should request to download icon now. 445 // Favicon should request to download icon now.
446 DownloadHandler* download_handler = helper.download_handler(); 446 DownloadHandler* download_handler = helper.download_handler();
447 ASSERT_TRUE(download_handler); 447 ASSERT_TRUE(download_handler);
448 // Verify the download request. 448 // Verify the download request.
449 EXPECT_EQ(new_icon_url, download_handler->image_url_); 449 EXPECT_EQ(new_icon_url, download_handler->image_url_);
450 EXPECT_EQ(kFaviconSize, download_handler->image_size_); 450 EXPECT_EQ(kFaviconSize, download_handler->image_size_);
451 451
452 // Reset the history_handler to verify whether favicon is set. 452 // Reset the history_handler to verify whether favicon is set.
453 helper.set_history_handler(NULL); 453 helper.set_history_handler(NULL);
454 454
455 // Smulates download done. 455 // Smulates download done.
456 download_handler->InvokeCallback(); 456 download_handler->InvokeCallback();
457 457
458 // New icon should be saved to history backend and navigation entry. 458 // New icon should be saved to history backend and navigation entry.
459 history_handler = helper.history_handler(); 459 history_handler = helper.history_handler();
460 ASSERT_TRUE(history_handler); 460 ASSERT_TRUE(history_handler);
461 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 461 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
462 EXPECT_EQ(FAVICON, history_handler->icon_type_); 462 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_);
463 EXPECT_LT(0U, history_handler->image_data_.size()); 463 EXPECT_LT(0U, history_handler->image_data_.size());
464 EXPECT_EQ(page_url, history_handler->page_url_); 464 EXPECT_EQ(page_url, history_handler->page_url_);
465 465
466 // Verify NavigationEntry. 466 // Verify NavigationEntry.
467 EXPECT_EQ(new_icon_url, helper.GetEntry()->favicon().url()); 467 EXPECT_EQ(new_icon_url, helper.GetEntry()->favicon().url());
468 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid()); 468 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid());
469 EXPECT_FALSE(helper.GetEntry()->favicon().bitmap().empty()); 469 EXPECT_FALSE(helper.GetEntry()->favicon().bitmap().empty());
470 } 470 }
471 471
472 TEST_F(FaviconHelperTest, UpdateFavicon) { 472 TEST_F(FaviconHelperTest, UpdateFavicon) {
(...skipping 25 matching lines...) Expand all
498 // Verify FaviconHelper status. 498 // Verify FaviconHelper status.
499 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid()); 499 EXPECT_TRUE(helper.GetEntry()->favicon().is_valid());
500 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url()); 500 EXPECT_EQ(icon_url, helper.GetEntry()->favicon().url());
501 501
502 // Reset the history_handler to verify whether new icon is requested from 502 // Reset the history_handler to verify whether new icon is requested from
503 // history. 503 // history.
504 helper.set_history_handler(NULL); 504 helper.set_history_handler(NULL);
505 505
506 // Simulates update with the different favicon url. 506 // Simulates update with the different favicon url.
507 std::vector<FaviconURL> urls; 507 std::vector<FaviconURL> urls;
508 urls.push_back(FaviconURL(new_icon_url, FAVICON)); 508 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON));
509 DownloadHandler::UpdateFaviconURL(&helper, urls); 509 DownloadHandler::UpdateFaviconURL(&helper, urls);
510 510
511 // Verify FaviconHelper status. 511 // Verify FaviconHelper status.
512 EXPECT_EQ(1U, helper.urls().size()); 512 EXPECT_EQ(1U, helper.urls().size());
513 ASSERT_TRUE(helper.current_candidate()); 513 ASSERT_TRUE(helper.current_candidate());
514 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); 514 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url);
515 ASSERT_EQ(FAVICON, helper.current_candidate()->icon_type); 515 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type);
516 // The favicon status's url should be updated. 516 // The favicon status's url should be updated.
517 ASSERT_EQ(new_icon_url, helper.GetEntry()->favicon().url()); 517 ASSERT_EQ(new_icon_url, helper.GetEntry()->favicon().url());
518 518
519 // Favicon should be requested from history. 519 // Favicon should be requested from history.
520 history_handler = helper.history_handler(); 520 history_handler = helper.history_handler();
521 ASSERT_TRUE(history_handler); 521 ASSERT_TRUE(history_handler);
522 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 522 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
523 EXPECT_EQ(FAVICON, history_handler->icon_type_); 523 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_);
524 EXPECT_EQ(page_url, history_handler->page_url_); 524 EXPECT_EQ(page_url, history_handler->page_url_);
525 525
526 // Simulate find icon. 526 // Simulate find icon.
527 history_handler->favicon_data_.known_icon = true; 527 history_handler->favicon_data_.known_icon = true;
528 history_handler->favicon_data_.icon_type = history::FAVICON; 528 history_handler->favicon_data_.icon_type = history::FAVICON;
529 history_handler->favicon_data_.expired = false; 529 history_handler->favicon_data_.expired = false;
530 history_handler->favicon_data_.icon_url = new_icon_url; 530 history_handler->favicon_data_.icon_url = new_icon_url;
531 history_handler->favicon_data_.image_data = data; 531 history_handler->favicon_data_.image_data = data;
532 history_handler->InvokeCallback(); 532 history_handler->InvokeCallback();
533 533
(...skipping 29 matching lines...) Expand all
563 // Verify FaviconHelper status. 563 // Verify FaviconHelper status.
564 EXPECT_FALSE(helper.GetEntry()->favicon().is_valid()); 564 EXPECT_FALSE(helper.GetEntry()->favicon().is_valid());
565 EXPECT_EQ(GURL(), helper.GetEntry()->favicon().url()); 565 EXPECT_EQ(GURL(), helper.GetEntry()->favicon().url());
566 566
567 // Reset the history_handler to verify whether new icon is requested from 567 // Reset the history_handler to verify whether new icon is requested from
568 // history. 568 // history.
569 helper.set_history_handler(NULL); 569 helper.set_history_handler(NULL);
570 570
571 // Simulates update with the different favicon url. 571 // Simulates update with the different favicon url.
572 std::vector<FaviconURL> urls; 572 std::vector<FaviconURL> urls;
573 urls.push_back(FaviconURL(icon_url, TOUCH_PRECOMPOSED_ICON)); 573 urls.push_back(FaviconURL(icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON));
574 urls.push_back(FaviconURL(new_icon_url, TOUCH_ICON)); 574 urls.push_back(FaviconURL(new_icon_url, FaviconURL::TOUCH_ICON));
575 urls.push_back(FaviconURL(new_icon_url, FAVICON)); 575 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON));
576 576
577 DownloadHandler::UpdateFaviconURL(&helper, urls); 577 DownloadHandler::UpdateFaviconURL(&helper, urls);
578 578
579 // Verify FaviconHelper status. 579 // Verify FaviconHelper status.
580 EXPECT_EQ(2U, helper.urls().size()); 580 EXPECT_EQ(2U, helper.urls().size());
581 ASSERT_TRUE(helper.current_candidate()); 581 ASSERT_TRUE(helper.current_candidate());
582 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 582 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
583 ASSERT_EQ(TOUCH_PRECOMPOSED_ICON, helper.current_candidate()->icon_type); 583 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON,
584 helper.current_candidate()->icon_type);
584 585
585 // Favicon should be requested from history. 586 // Favicon should be requested from history.
586 history_handler = helper.history_handler(); 587 history_handler = helper.history_handler();
587 ASSERT_TRUE(history_handler); 588 ASSERT_TRUE(history_handler);
588 EXPECT_EQ(icon_url, history_handler->icon_url_); 589 EXPECT_EQ(icon_url, history_handler->icon_url_);
589 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); 590 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_);
590 EXPECT_EQ(page_url, history_handler->page_url_); 591 EXPECT_EQ(page_url, history_handler->page_url_);
591 592
592 // Simulate not find icon. 593 // Simulate not find icon.
593 history_handler->favicon_data_.known_icon = false; 594 history_handler->favicon_data_.known_icon = false;
594 history_handler->InvokeCallback(); 595 history_handler->InvokeCallback();
595 596
596 // Should request download favicon. 597 // Should request download favicon.
597 DownloadHandler* download_handler = helper.download_handler(); 598 DownloadHandler* download_handler = helper.download_handler();
598 EXPECT_TRUE(download_handler); 599 EXPECT_TRUE(download_handler);
599 // Verify the download request. 600 // Verify the download request.
600 EXPECT_EQ(icon_url, download_handler->image_url_); 601 EXPECT_EQ(icon_url, download_handler->image_url_);
601 EXPECT_EQ(0, download_handler->image_size_); 602 EXPECT_EQ(0, download_handler->image_size_);
602 603
603 // Reset the history_handler to verify whether favicon is request from 604 // Reset the history_handler to verify whether favicon is request from
604 // history. 605 // history.
605 helper.set_history_handler(NULL); 606 helper.set_history_handler(NULL);
606 // Smulates download failed. 607 // Smulates download failed.
607 download_handler->failed_ = true; 608 download_handler->failed_ = true;
608 download_handler->InvokeCallback(); 609 download_handler->InvokeCallback();
609 610
610 // Left 1 url. 611 // Left 1 url.
611 EXPECT_EQ(1U, helper.urls().size()); 612 EXPECT_EQ(1U, helper.urls().size());
612 ASSERT_TRUE(helper.current_candidate()); 613 ASSERT_TRUE(helper.current_candidate());
613 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url); 614 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url);
614 EXPECT_EQ(TOUCH_ICON, helper.current_candidate()->icon_type); 615 EXPECT_EQ(FaviconURL::TOUCH_ICON, helper.current_candidate()->icon_type);
615 616
616 // Favicon should be requested from history. 617 // Favicon should be requested from history.
617 history_handler = helper.history_handler(); 618 history_handler = helper.history_handler();
618 ASSERT_TRUE(history_handler); 619 ASSERT_TRUE(history_handler);
619 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 620 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
620 EXPECT_EQ(TOUCH_ICON, history_handler->icon_type_); 621 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_);
621 EXPECT_EQ(page_url, history_handler->page_url_); 622 EXPECT_EQ(page_url, history_handler->page_url_);
622 623
623 // Reset download handler 624 // Reset download handler
624 helper.set_download_handler(NULL); 625 helper.set_download_handler(NULL);
625 626
626 // Smulates getting a expired icon from history. 627 // Smulates getting a expired icon from history.
627 history_handler->favicon_data_.known_icon = true; 628 history_handler->favicon_data_.known_icon = true;
628 history_handler->favicon_data_.icon_type = history::TOUCH_ICON; 629 history_handler->favicon_data_.icon_type = history::TOUCH_ICON;
629 history_handler->favicon_data_.expired = true; 630 history_handler->favicon_data_.expired = true;
630 history_handler->favicon_data_.icon_url = new_icon_url; 631 history_handler->favicon_data_.icon_url = new_icon_url;
(...skipping 10 matching lines...) Expand all
641 642
642 helper.set_history_handler(NULL); 643 helper.set_history_handler(NULL);
643 644
644 // Simulates icon being downloaded. 645 // Simulates icon being downloaded.
645 download_handler->InvokeCallback(); 646 download_handler->InvokeCallback();
646 647
647 // New icon should be saved to history backend. 648 // New icon should be saved to history backend.
648 history_handler = helper.history_handler(); 649 history_handler = helper.history_handler();
649 ASSERT_TRUE(history_handler); 650 ASSERT_TRUE(history_handler);
650 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 651 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
651 EXPECT_EQ(TOUCH_ICON, history_handler->icon_type_); 652 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_);
652 EXPECT_LT(0U, history_handler->image_data_.size()); 653 EXPECT_LT(0U, history_handler->image_data_.size());
653 EXPECT_EQ(page_url, history_handler->page_url_); 654 EXPECT_EQ(page_url, history_handler->page_url_);
654 } 655 }
655 656
656 TEST_F(FaviconHelperTest, UpdateDuringDownloading) { 657 TEST_F(FaviconHelperTest, UpdateDuringDownloading) {
657 const GURL page_url("http://www.google.com"); 658 const GURL page_url("http://www.google.com");
658 const GURL icon_url("http://www.google.com/favicon"); 659 const GURL icon_url("http://www.google.com/favicon");
659 const GURL new_icon_url("http://www.google.com/new_favicon"); 660 const GURL new_icon_url("http://www.google.com/new_favicon");
660 661
661 TestFaviconHelper helper(page_url, contents(), FaviconHelper::TOUCH); 662 TestFaviconHelper helper(page_url, contents(), FaviconHelper::TOUCH);
(...skipping 14 matching lines...) Expand all
676 // Verify FaviconHelper status. 677 // Verify FaviconHelper status.
677 EXPECT_FALSE(helper.GetEntry()->favicon().is_valid()); 678 EXPECT_FALSE(helper.GetEntry()->favicon().is_valid());
678 EXPECT_EQ(GURL(), helper.GetEntry()->favicon().url()); 679 EXPECT_EQ(GURL(), helper.GetEntry()->favicon().url());
679 680
680 // Reset the history_handler to verify whether new icon is requested from 681 // Reset the history_handler to verify whether new icon is requested from
681 // history. 682 // history.
682 helper.set_history_handler(NULL); 683 helper.set_history_handler(NULL);
683 684
684 // Simulates update with the different favicon url. 685 // Simulates update with the different favicon url.
685 std::vector<FaviconURL> urls; 686 std::vector<FaviconURL> urls;
686 urls.push_back(FaviconURL(icon_url, TOUCH_PRECOMPOSED_ICON)); 687 urls.push_back(FaviconURL(icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON));
687 urls.push_back(FaviconURL(new_icon_url, TOUCH_ICON)); 688 urls.push_back(FaviconURL(new_icon_url, FaviconURL::TOUCH_ICON));
688 urls.push_back(FaviconURL(new_icon_url, FAVICON)); 689 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON));
689 690
690 DownloadHandler::UpdateFaviconURL(&helper, urls); 691 DownloadHandler::UpdateFaviconURL(&helper, urls);
691 692
692 // Verify FaviconHelper status. 693 // Verify FaviconHelper status.
693 EXPECT_EQ(2U, helper.urls().size()); 694 EXPECT_EQ(2U, helper.urls().size());
694 ASSERT_TRUE(helper.current_candidate()); 695 ASSERT_TRUE(helper.current_candidate());
695 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 696 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
696 ASSERT_EQ(TOUCH_PRECOMPOSED_ICON, helper.current_candidate()->icon_type); 697 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON,
698 helper.current_candidate()->icon_type);
697 699
698 // Favicon should be requested from history. 700 // Favicon should be requested from history.
699 history_handler = helper.history_handler(); 701 history_handler = helper.history_handler();
700 ASSERT_TRUE(history_handler); 702 ASSERT_TRUE(history_handler);
701 EXPECT_EQ(icon_url, history_handler->icon_url_); 703 EXPECT_EQ(icon_url, history_handler->icon_url_);
702 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); 704 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_);
703 EXPECT_EQ(page_url, history_handler->page_url_); 705 EXPECT_EQ(page_url, history_handler->page_url_);
704 706
705 // Simulate not find icon. 707 // Simulate not find icon.
706 history_handler->favicon_data_.known_icon = false; 708 history_handler->favicon_data_.known_icon = false;
707 history_handler->InvokeCallback(); 709 history_handler->InvokeCallback();
708 710
709 // Should request download favicon. 711 // Should request download favicon.
710 DownloadHandler* download_handler = helper.download_handler(); 712 DownloadHandler* download_handler = helper.download_handler();
711 EXPECT_TRUE(download_handler); 713 EXPECT_TRUE(download_handler);
712 // Verify the download request. 714 // Verify the download request.
713 EXPECT_EQ(icon_url, download_handler->image_url_); 715 EXPECT_EQ(icon_url, download_handler->image_url_);
714 EXPECT_EQ(0, download_handler->image_size_); 716 EXPECT_EQ(0, download_handler->image_size_);
715 717
716 // Reset the history_handler to verify whether favicon is request from 718 // Reset the history_handler to verify whether favicon is request from
717 // history. 719 // history.
718 helper.set_history_handler(NULL); 720 helper.set_history_handler(NULL);
719 const GURL latest_icon_url("http://www.google.com/latest_favicon"); 721 const GURL latest_icon_url("http://www.google.com/latest_favicon");
720 std::vector<FaviconURL> latest_urls; 722 std::vector<FaviconURL> latest_urls;
721 latest_urls.push_back(FaviconURL(latest_icon_url, TOUCH_ICON)); 723 latest_urls.push_back(FaviconURL(latest_icon_url, FaviconURL::TOUCH_ICON));
722 DownloadHandler::UpdateFaviconURL(&helper, latest_urls); 724 DownloadHandler::UpdateFaviconURL(&helper, latest_urls);
723 EXPECT_EQ(1U, helper.urls().size()); 725 EXPECT_EQ(1U, helper.urls().size());
724 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); 726 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url);
725 EXPECT_EQ(TOUCH_ICON, helper.current_candidate()->icon_type); 727 EXPECT_EQ(FaviconURL::TOUCH_ICON, helper.current_candidate()->icon_type);
726 728
727 // Whether new icon is requested from history 729 // Whether new icon is requested from history
728 history_handler = helper.history_handler(); 730 history_handler = helper.history_handler();
729 ASSERT_TRUE(history_handler); 731 ASSERT_TRUE(history_handler);
730 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); 732 EXPECT_EQ(latest_icon_url, history_handler->icon_url_);
731 EXPECT_EQ(TOUCH_ICON, history_handler->icon_type_); 733 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_);
732 EXPECT_EQ(page_url, history_handler->page_url_); 734 EXPECT_EQ(page_url, history_handler->page_url_);
733 735
734 // Reset the history_handler to verify whether favicon is request from 736 // Reset the history_handler to verify whether favicon is request from
735 // history. 737 // history.
736 // Save the callback for late use. 738 // Save the callback for late use.
737 FaviconService::FaviconDataCallback* callback = history_handler->callback_; 739 FaviconService::FaviconDataCallback* callback = history_handler->callback_;
738 // Prevent the callback from being released. 740 // Prevent the callback from being released.
739 history_handler->callback_ = NULL; 741 history_handler->callback_ = NULL;
740 helper.set_history_handler(NULL); 742 helper.set_history_handler(NULL);
741 743
(...skipping 16 matching lines...) Expand all
758 FillBitmap(kFaviconSize, kFaviconSize, &data->data); 760 FillBitmap(kFaviconSize, kFaviconSize, &data->data);
759 handler->favicon_data_.image_data = data; 761 handler->favicon_data_.image_data = data;
760 762
761 handler->InvokeCallback(); 763 handler->InvokeCallback();
762 764
763 // No download request. 765 // No download request.
764 EXPECT_FALSE(helper.download_handler()); 766 EXPECT_FALSE(helper.download_handler());
765 } 767 }
766 768
767 } // namespace. 769 } // namespace.
OLDNEW
« no previous file with comments | « chrome/browser/favicon_helper.cc ('k') | chrome/browser/prerender/prerender_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698