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

Side by Side Diff: chrome/browser/favicon/favicon_handler_unittest.cc

Issue 10832128: Convert FaviconStatus::bitmap from SkBitmap to gfx::Image. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tests? Created 8 years, 4 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
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/favicon/favicon_handler.h" 6 #include "chrome/browser/favicon/favicon_handler.h"
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
9 #include "content/public/browser/invalidate_type.h" 9 #include "content/public/browser/invalidate_type.h"
10 #include "content/public/browser/navigation_entry.h" 10 #include "content/public/browser/navigation_entry.h"
11 #include "content/public/browser/favicon_status.h" 11 #include "content/public/browser/favicon_status.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "ui/gfx/codec/png_codec.h" 13 #include "ui/gfx/codec/png_codec.h"
14 #include "ui/gfx/favicon_size.h" 14 #include "ui/gfx/favicon_size.h"
15 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
16 #include "third_party/skia/include/core/SkBitmap.h"
16 17
17 class TestFaviconHandler; 18 class TestFaviconHandler;
18 19
19 using content::NavigationEntry; 20 using content::NavigationEntry;
20 using content::WebContents; 21 using content::WebContents;
21 22
22 namespace { 23 namespace {
23 24
24 // Fill the given bmp with valid png data. 25 // Fill the given bmp with valid png data.
25 void FillDataToBitmap(int w, int h, SkBitmap* bmp) { 26 void FillDataToBitmap(int w, int h, SkBitmap* bmp) {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 history_handler = helper.history_handler(); 413 history_handler = helper.history_handler();
413 ASSERT_TRUE(history_handler); 414 ASSERT_TRUE(history_handler);
414 EXPECT_EQ(icon_url, history_handler->icon_url_); 415 EXPECT_EQ(icon_url, history_handler->icon_url_);
415 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); 416 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_);
416 EXPECT_LT(0U, history_handler->image_data_.size()); 417 EXPECT_LT(0U, history_handler->image_data_.size());
417 EXPECT_EQ(page_url, history_handler->page_url_); 418 EXPECT_EQ(page_url, history_handler->page_url_);
418 419
419 // Verify NavigationEntry. 420 // Verify NavigationEntry.
420 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); 421 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url);
421 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); 422 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
422 EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); 423 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
423 } 424 }
424 425
425 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { 426 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
426 const GURL page_url("http://www.google.com"); 427 const GURL page_url("http://www.google.com");
427 const GURL icon_url("http://www.google.com/favicon"); 428 const GURL icon_url("http://www.google.com/favicon");
428 const GURL new_icon_url("http://www.google.com/new_favicon"); 429 const GURL new_icon_url("http://www.google.com/new_favicon");
429 430
430 TestFaviconHandlerDelegate delegate(contents()); 431 TestFaviconHandlerDelegate delegate(contents());
431 Profile* profile = Profile::FromBrowserContext( 432 Profile* profile = Profile::FromBrowserContext(
432 contents()->GetBrowserContext()); 433 contents()->GetBrowserContext());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 history_handler = helper.history_handler(); 503 history_handler = helper.history_handler();
503 ASSERT_TRUE(history_handler); 504 ASSERT_TRUE(history_handler);
504 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 505 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
505 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); 506 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_);
506 EXPECT_LT(0U, history_handler->image_data_.size()); 507 EXPECT_LT(0U, history_handler->image_data_.size());
507 EXPECT_EQ(page_url, history_handler->page_url_); 508 EXPECT_EQ(page_url, history_handler->page_url_);
508 509
509 // Verify NavigationEntry. 510 // Verify NavigationEntry.
510 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); 511 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url);
511 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); 512 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
512 EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); 513 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
513 } 514 }
514 515
515 TEST_F(FaviconHandlerTest, UpdateFavicon) { 516 TEST_F(FaviconHandlerTest, UpdateFavicon) {
516 const GURL page_url("http://www.google.com"); 517 const GURL page_url("http://www.google.com");
517 const GURL icon_url("http://www.google.com/favicon"); 518 const GURL icon_url("http://www.google.com/favicon");
518 const GURL new_icon_url("http://www.google.com/new_favicon"); 519 const GURL new_icon_url("http://www.google.com/new_favicon");
519 520
520 TestFaviconHandlerDelegate delegate(contents()); 521 TestFaviconHandlerDelegate delegate(contents());
521 Profile* profile = Profile::FromBrowserContext( 522 Profile* profile = Profile::FromBrowserContext(
522 contents()->GetBrowserContext()); 523 contents()->GetBrowserContext());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 history_handler->favicon_data_.icon_url = new_icon_url; 578 history_handler->favicon_data_.icon_url = new_icon_url;
578 history_handler->favicon_data_.image_data = data; 579 history_handler->favicon_data_.image_data = data;
579 history_handler->InvokeCallback(); 580 history_handler->InvokeCallback();
580 581
581 // Shouldn't request download favicon 582 // Shouldn't request download favicon
582 EXPECT_FALSE(helper.download_handler()->HasDownload()); 583 EXPECT_FALSE(helper.download_handler()->HasDownload());
583 584
584 // Verify the favicon status. 585 // Verify the favicon status.
585 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); 586 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url);
586 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); 587 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
587 EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); 588 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
588 } 589 }
589 590
590 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { 591 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
591 const GURL page_url("http://www.google.com"); 592 const GURL page_url("http://www.google.com");
592 const GURL icon_url("http://www.google.com/favicon"); 593 const GURL icon_url("http://www.google.com/favicon");
593 const GURL new_icon_url("http://www.google.com/new_favicon"); 594 const GURL new_icon_url("http://www.google.com/new_favicon");
594 595
595 TestFaviconHandlerDelegate delegate(contents()); 596 TestFaviconHandlerDelegate delegate(contents());
596 Profile* profile = Profile::FromBrowserContext( 597 Profile* profile = Profile::FromBrowserContext(
597 contents()->GetBrowserContext()); 598 contents()->GetBrowserContext());
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 ASSERT_TRUE(download_handler->HasDownload()); 886 ASSERT_TRUE(download_handler->HasDownload());
886 EXPECT_EQ(icon_url_preferred1, download_handler->GetImageUrl()); 887 EXPECT_EQ(icon_url_preferred1, download_handler->GetImageUrl());
887 download_handler->SetImageSize(gfx::kFaviconSize); 888 download_handler->SetImageSize(gfx::kFaviconSize);
888 download_handler->InvokeCallback(); 889 download_handler->InvokeCallback();
889 // Verify that this was detected as an exact match and image_urls_ is cleared. 890 // Verify that this was detected as an exact match and image_urls_ is cleared.
890 EXPECT_EQ(0U, handler.image_urls().size()); 891 EXPECT_EQ(0U, handler.image_urls().size());
891 892
892 // Verify correct icon size chosen. 893 // Verify correct icon size chosen.
893 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); 894 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url);
894 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); 895 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid);
895 EXPECT_FALSE(handler.GetEntry()->GetFavicon().bitmap.empty()); 896 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty());
896 EXPECT_EQ(gfx::kFaviconSize, handler.GetEntry()->GetFavicon().bitmap.width()); 897 EXPECT_EQ(gfx::kFaviconSize,
898 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width());
897 } 899 }
898 900
899 TEST_F(FaviconHandlerTest, FirstFavicon) { 901 TEST_F(FaviconHandlerTest, FirstFavicon) {
900 const GURL page_url("http://www.google.com"); 902 const GURL page_url("http://www.google.com");
901 const GURL icon_url("http://www.google.com/favicon"); 903 const GURL icon_url("http://www.google.com/favicon");
902 const GURL icon_url_preferred1("http://www.google.com/favicon_preferred1"); 904 const GURL icon_url_preferred1("http://www.google.com/favicon_preferred1");
903 const GURL icon_url_large("http://www.google.com/favicon_large"); 905 const GURL icon_url_large("http://www.google.com/favicon_large");
904 906
905 TestFaviconHandlerDelegate delegate(contents()); 907 TestFaviconHandlerDelegate delegate(contents());
906 Profile* profile = Profile::FromBrowserContext( 908 Profile* profile = Profile::FromBrowserContext(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 ASSERT_TRUE(download_handler->HasDownload()); 942 ASSERT_TRUE(download_handler->HasDownload());
941 EXPECT_EQ(icon_url_preferred1, download_handler->GetImageUrl()); 943 EXPECT_EQ(icon_url_preferred1, download_handler->GetImageUrl());
942 download_handler->SetImageSize(gfx::kFaviconSize); 944 download_handler->SetImageSize(gfx::kFaviconSize);
943 download_handler->InvokeCallback(); 945 download_handler->InvokeCallback();
944 // Verify that this was detected as an exact match and image_urls_ is cleared. 946 // Verify that this was detected as an exact match and image_urls_ is cleared.
945 EXPECT_EQ(0U, handler.image_urls().size()); 947 EXPECT_EQ(0U, handler.image_urls().size());
946 948
947 // Verify correct icon size chosen. 949 // Verify correct icon size chosen.
948 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); 950 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url);
949 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); 951 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid);
950 EXPECT_FALSE(handler.GetEntry()->GetFavicon().bitmap.empty()); 952 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty());
951 EXPECT_EQ(gfx::kFaviconSize, handler.GetEntry()->GetFavicon().bitmap.width()); 953 EXPECT_EQ(gfx::kFaviconSize,
954 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width());
952 } 955 }
953 956
954 } // namespace. 957 } // namespace.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698