diff options
Diffstat (limited to 'chrome/browser/favicon/favicon_handler_unittest.cc')
| -rw-r--r-- | chrome/browser/favicon/favicon_handler_unittest.cc | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc index bdf05d8..3eba39a 100644 --- a/chrome/browser/favicon/favicon_handler_unittest.cc +++ b/chrome/browser/favicon/favicon_handler_unittest.cc @@ -86,7 +86,7 @@ class HistoryRequestHandler { HistoryRequestHandler(const GURL& page_url, const GURL& icon_url, int icon_type, - const FaviconService::FaviconDataCallback& callback) + FaviconService::FaviconDataCallback* callback) : page_url_(page_url), icon_url_(icon_url), icon_type_(icon_type), @@ -97,7 +97,7 @@ class HistoryRequestHandler { const GURL& icon_url, int icon_type, const std::vector<unsigned char>& image_data, - const FaviconService::FaviconDataCallback& callback) + FaviconService::FaviconDataCallback* callback) : page_url_(page_url), icon_url_(icon_url), icon_type_(icon_type), @@ -105,7 +105,9 @@ class HistoryRequestHandler { callback_(callback) { } - virtual ~HistoryRequestHandler() {} + virtual ~HistoryRequestHandler() { + delete callback_; + } void InvokeCallback(); const GURL page_url_; @@ -113,7 +115,7 @@ class HistoryRequestHandler { const int icon_type_; const std::vector<unsigned char> image_data_; history::FaviconData favicon_data_; - FaviconService::FaviconDataCallback callback_; + FaviconService::FaviconDataCallback* callback_; private: DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); @@ -217,7 +219,7 @@ class TestFaviconHandler : public FaviconHandler { const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - const FaviconService::FaviconDataCallback& callback) OVERRIDE { + FaviconService::FaviconDataCallback* callback) OVERRIDE { history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, icon_type, callback)); } @@ -226,7 +228,7 @@ class TestFaviconHandler : public FaviconHandler { const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - const FaviconService::FaviconDataCallback& callback) OVERRIDE { + FaviconService::FaviconDataCallback* callback) OVERRIDE { history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, icon_type, callback)); } @@ -235,7 +237,7 @@ class TestFaviconHandler : public FaviconHandler { const GURL& page_url, int icon_types, CancelableRequestConsumerBase* consumer, - const FaviconService::FaviconDataCallback& callback) OVERRIDE { + FaviconService::FaviconDataCallback* callback) OVERRIDE { history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), icon_types, callback)); } @@ -251,9 +253,8 @@ class TestFaviconHandler : public FaviconHandler { const GURL& icon_url, const std::vector<unsigned char>& image_data, history::IconType icon_type) OVERRIDE { - history_handler_.reset(new HistoryRequestHandler( - page_url, icon_url,icon_type, image_data, - FaviconService::FaviconDataCallback())); + history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, + icon_type, image_data, NULL)); } virtual FaviconService* GetFaviconService() OVERRIDE { @@ -301,7 +302,7 @@ void DownloadHandler::InvokeCallback() { } void HistoryRequestHandler::InvokeCallback() { - callback_.Run(0, favicon_data_); + callback_->Run(0, favicon_data_); } class FaviconHandlerTest : public ChromeRenderViewHostTestHarness { @@ -785,17 +786,19 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { // Reset the history_handler to verify whether favicon is request from // history. // Save the callback for late use. - FaviconService::FaviconDataCallback callback = history_handler->callback_; + FaviconService::FaviconDataCallback* callback = history_handler->callback_; + // Prevent the callback from being released. + history_handler->callback_ = NULL; helper.set_history_handler(NULL); - // Simulates download succeed. + // Smulates download succeed. download_handler->InvokeCallback(); - // The downloaded icon should be thrown away as there is favicon update. + // The downloaded icon should be thrown away as there is faviocn update. EXPECT_FALSE(helper.history_handler()); helper.set_download_handler(NULL); - // Simulates getting the icon from history. + // Smulates getting the icon from history. scoped_ptr<HistoryRequestHandler> handler; handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, history::TOUCH_ICON, callback)); |
