Index: chrome/browser/favicon/favicon_handler_unittest.cc |
diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc |
index 8f4fcf6f69ef5e794bf757f71b42329629b716f6..a080949b73d27d23903b0f1eeac6a0d82ef3bcc8 100644 |
--- a/chrome/browser/favicon/favicon_handler_unittest.cc |
+++ b/chrome/browser/favicon/favicon_handler_unittest.cc |
@@ -8,10 +8,6 @@ |
#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
-#include "content/public/browser/favicon_status.h" |
-#include "content/public/browser/invalidate_type.h" |
-#include "content/public/browser/navigation_entry.h" |
-#include "content/public/browser/web_contents.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
#include "ui/gfx/codec/png_codec.h" |
#include "ui/gfx/favicon_size.h" |
@@ -20,8 +16,6 @@ |
class TestFaviconHandler; |
using content::FaviconURL; |
-using content::NavigationEntry; |
-using content::WebContents; |
namespace { |
@@ -191,18 +185,31 @@ class TestFaviconClient : public FaviconClient { |
class TestFaviconDriver : public FaviconDriver { |
public: |
- TestFaviconDriver() { |
- } |
+ TestFaviconDriver() : favicon_validity_(false) {} |
virtual ~TestFaviconDriver() { |
} |
virtual bool IsOffTheRecord() OVERRIDE { return false; } |
- virtual NavigationEntry* GetActiveEntry() OVERRIDE { |
- ADD_FAILURE() << "TestFaviconDriver::GetActiveEntry() " |
- << "should never be called in tests."; |
- return NULL; |
+ virtual const gfx::Image GetActiveFaviconImage() OVERRIDE { return image_; } |
+ |
+ virtual const GURL GetActiveFaviconURL() OVERRIDE { return favicon_url_; } |
+ |
+ virtual bool GetActiveFaviconValidity() OVERRIDE { return favicon_validity_; } |
+ |
+ virtual const GURL GetActiveURL() OVERRIDE { return url_; } |
+ |
+ virtual void SetActiveFaviconImage(gfx::Image image) OVERRIDE { |
+ image_ = image; |
+ } |
+ |
+ virtual void SetActiveFaviconURL(GURL favicon_url) OVERRIDE { |
+ favicon_url_ = favicon_url; |
+ } |
+ |
+ virtual void SetActiveFaviconValidity(bool favicon_validity) OVERRIDE { |
+ favicon_validity_ = favicon_validity; |
} |
virtual int StartDownload(const GURL& url, |
@@ -217,7 +224,13 @@ class TestFaviconDriver : public FaviconDriver { |
<< "should never be called in tests."; |
} |
+ void SetActiveURL(GURL url) { url_ = url; } |
+ |
private: |
+ GURL favicon_url_; |
+ GURL url_; |
+ gfx::Image image_; |
+ bool favicon_validity_; |
DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); |
}; |
@@ -228,15 +241,13 @@ class TestFaviconHandler : public FaviconHandler { |
public: |
TestFaviconHandler(const GURL& page_url, |
FaviconClient* client, |
- FaviconDriver* driver, |
+ TestFaviconDriver* driver, |
Type type, |
bool download_largest_icon) |
- : FaviconHandler(client, driver, type, |
- download_largest_icon), |
- entry_(NavigationEntry::Create()), |
+ : FaviconHandler(client, driver, type, download_largest_icon), |
download_id_(0), |
num_favicon_updates_(0) { |
- entry_->SetURL(page_url); |
+ driver->SetActiveURL(page_url); |
download_handler_.reset(new DownloadHandler(this)); |
} |
@@ -265,10 +276,6 @@ class TestFaviconHandler : public FaviconHandler { |
} |
// Methods to access favicon internals. |
- virtual NavigationEntry* GetEntry() OVERRIDE { |
- return entry_.get(); |
- } |
- |
const std::vector<FaviconURL>& urls() { |
return image_urls_; |
} |
@@ -342,7 +349,6 @@ class TestFaviconHandler : public FaviconHandler { |
GURL page_url_; |
private: |
- scoped_ptr<NavigationEntry> entry_; |
// The unique id of a download request. It will be returned to a |
// FaviconHandler. |
@@ -491,8 +497,8 @@ TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
// Send history response. |
history_handler->InvokeCallback(); |
// Verify FaviconHandler status |
- EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
- EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
+ EXPECT_TRUE(driver.GetActiveFaviconValidity()); |
+ EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); |
// Simulates update favicon url. |
std::vector<FaviconURL> urls; |
@@ -535,8 +541,8 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) { |
// Send history response. |
history_handler->InvokeCallback(); |
// Verify FaviconHandler status |
- EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
- EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
+ EXPECT_TRUE(driver.GetActiveFaviconValidity()); |
+ EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); |
// Simulates update favicon url. |
std::vector<FaviconURL> urls; |
@@ -572,11 +578,10 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) { |
EXPECT_EQ(page_url, history_handler->page_url_); |
// Verify NavigationEntry. |
- content::FaviconStatus favicon_status = helper.GetEntry()->GetFavicon(); |
- EXPECT_EQ(icon_url, favicon_status.url); |
- EXPECT_TRUE(favicon_status.valid); |
- EXPECT_FALSE(favicon_status.image.IsEmpty()); |
- EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
+ EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); |
+ EXPECT_TRUE(driver.GetActiveFaviconValidity()); |
+ EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); |
+ EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); |
} |
TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
@@ -603,8 +608,8 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
// Send history response. |
history_handler->InvokeCallback(); |
// Verify FaviconHandler status. |
- EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
- EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
+ EXPECT_TRUE(driver.GetActiveFaviconValidity()); |
+ EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); |
// Reset the history_handler to verify whether new icon is requested from |
// history. |
@@ -655,11 +660,10 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
EXPECT_EQ(page_url, history_handler->page_url_); |
// Verify NavigationEntry. |
- content::FaviconStatus favicon_status = helper.GetEntry()->GetFavicon(); |
- EXPECT_EQ(new_icon_url, favicon_status.url); |
- EXPECT_TRUE(favicon_status.valid); |
- EXPECT_FALSE(favicon_status.image.IsEmpty()); |
- EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
+ EXPECT_EQ(new_icon_url, driver.GetActiveFaviconURL()); |
+ EXPECT_TRUE(driver.GetActiveFaviconValidity()); |
+ EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); |
+ EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); |
} |
TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
@@ -693,8 +697,8 @@ TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
// Send history response. |
history_handler->InvokeCallback(); |
// The NavigationEntry should not be set yet as the history data is invalid. |
- EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); |
- EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); |
+ EXPECT_FALSE(driver.GetActiveFaviconValidity()); |
+ EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); |
// Reset the history_handler to verify whether new icon is requested from |
// history. |
@@ -727,11 +731,10 @@ TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
EXPECT_EQ(page_url, history_handler->page_url_); |
// Verify NavigationEntry. |
- content::FaviconStatus favicon_status = helper.GetEntry()->GetFavicon(); |
- EXPECT_EQ(icon_url, favicon_status.url); |
- EXPECT_TRUE(favicon_status.valid); |
- EXPECT_FALSE(favicon_status.image.IsEmpty()); |
- EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
+ EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); |
+ EXPECT_TRUE(driver.GetActiveFaviconValidity()); |
+ EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); |
+ EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); |
} |
TEST_F(FaviconHandlerTest, UpdateFavicon) { |
@@ -757,8 +760,8 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) { |
// Send history response. |
history_handler->InvokeCallback(); |
// Verify FaviconHandler status. |
- EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
- EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
+ EXPECT_TRUE(driver.GetActiveFaviconValidity()); |
+ EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); |
// Reset the history_handler to verify whether new icon is requested from |
// history. |
@@ -791,9 +794,9 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) { |
EXPECT_FALSE(helper.download_handler()->HasDownload()); |
// Verify the favicon status. |
- EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
- EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
- EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
+ EXPECT_EQ(new_icon_url, driver.GetActiveFaviconURL()); |
+ EXPECT_TRUE(driver.GetActiveFaviconValidity()); |
+ EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); |
} |
TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
@@ -820,8 +823,8 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
// Send history response. |
history_handler->InvokeCallback(); |
// Verify FaviconHandler status. |
- EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); |
- EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); |
+ EXPECT_FALSE(driver.GetActiveFaviconValidity()); |
+ EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); |
// Reset the history_handler to verify whether new icon is requested from |
// history. |
@@ -934,8 +937,8 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
// Send history response. |
history_handler->InvokeCallback(); |
// Verify FaviconHandler status. |
- EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); |
- EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); |
+ EXPECT_FALSE(driver.GetActiveFaviconValidity()); |
+ EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); |
// Reset the history_handler to verify whether new icon is requested from |
// history. |
@@ -1067,16 +1070,15 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) { |
kSourceIconURLs + arraysize(kSizes1)); |
DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); |
- content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon()); |
EXPECT_EQ(0u, handler1.image_urls().size()); |
- EXPECT_TRUE(favicon_status1.valid); |
- EXPECT_FALSE(favicon_status1.image.IsEmpty()); |
- EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); |
+ EXPECT_TRUE(driver1.GetActiveFaviconValidity()); |
+ EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty()); |
+ EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width()); |
size_t expected_index = 2u; |
EXPECT_EQ(32, kSizes1[expected_index]); |
EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
- handler1.GetEntry()->GetFavicon().url); |
+ driver1.GetActiveFaviconURL()); |
// 2) Test that if there are several single resolution favicons to choose |
// from, the exact match is preferred even if it results in upsampling. |
@@ -1088,11 +1090,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) { |
std::vector<FaviconURL> urls2(kSourceIconURLs, |
kSourceIconURLs + arraysize(kSizes2)); |
DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); |
- EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); |
+ EXPECT_TRUE(driver2.GetActiveFaviconValidity()); |
expected_index = 0u; |
EXPECT_EQ(16, kSizes2[expected_index]); |
EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
- handler2.GetEntry()->GetFavicon().url); |
+ driver2.GetActiveFaviconURL()); |
// 3) Test that favicons which need to be upsampled a little or downsampled |
// a little are preferred over huge favicons. |
@@ -1104,11 +1106,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) { |
std::vector<FaviconURL> urls3(kSourceIconURLs, |
kSourceIconURLs + arraysize(kSizes3)); |
DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); |
- EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); |
+ EXPECT_TRUE(driver3.GetActiveFaviconValidity()); |
expected_index = 1u; |
EXPECT_EQ(48, kSizes3[expected_index]); |
EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
- handler3.GetEntry()->GetFavicon().url); |
+ driver3.GetActiveFaviconURL()); |
TestFaviconDriver driver4; |
TestFaviconHandler handler4( |
@@ -1118,11 +1120,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) { |
std::vector<FaviconURL> urls4(kSourceIconURLs, |
kSourceIconURLs + arraysize(kSizes4)); |
DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); |
- EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); |
+ EXPECT_TRUE(driver4.GetActiveFaviconValidity()); |
expected_index = 0u; |
EXPECT_EQ(17, kSizes4[expected_index]); |
EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
- handler4.GetEntry()->GetFavicon().url); |
+ driver4.GetActiveFaviconURL()); |
} |
#endif |