| OLD | NEW |
| 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/favicon/favicon_service.h" |
| 7 #include "chrome/browser/favicon/favicon_service_factory.h" | 8 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 8 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "ui/gfx/codec/png_codec.h" | 13 #include "ui/gfx/codec/png_codec.h" |
| 13 #include "ui/gfx/favicon_size.h" | 14 #include "ui/gfx/favicon_size.h" |
| 14 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 15 | 16 |
| 16 class TestFaviconHandler; | 17 class TestFaviconHandler; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); | 129 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 // This class is used to save the history request for verifying with test case. | 132 // This class is used to save the history request for verifying with test case. |
| 132 // It also will be used to simulate the history response. | 133 // It also will be used to simulate the history response. |
| 133 class HistoryRequestHandler { | 134 class HistoryRequestHandler { |
| 134 public: | 135 public: |
| 135 HistoryRequestHandler(const GURL& page_url, | 136 HistoryRequestHandler(const GURL& page_url, |
| 136 const GURL& icon_url, | 137 const GURL& icon_url, |
| 137 int icon_type, | 138 int icon_type, |
| 138 const FaviconService::FaviconResultsCallback& callback) | 139 const favicon_base::FaviconResultsCallback& callback) |
| 139 : page_url_(page_url), | 140 : page_url_(page_url), |
| 140 icon_url_(icon_url), | 141 icon_url_(icon_url), |
| 141 icon_type_(icon_type), | 142 icon_type_(icon_type), |
| 142 callback_(callback) { | 143 callback_(callback) { |
| 143 } | 144 } |
| 144 | 145 |
| 145 HistoryRequestHandler(const GURL& page_url, | 146 HistoryRequestHandler(const GURL& page_url, |
| 146 const GURL& icon_url, | 147 const GURL& icon_url, |
| 147 int icon_type, | 148 int icon_type, |
| 148 const std::vector<unsigned char>& bitmap_data, | 149 const std::vector<unsigned char>& bitmap_data, |
| 149 const gfx::Size& size) | 150 const gfx::Size& size) |
| 150 : page_url_(page_url), | 151 : page_url_(page_url), |
| 151 icon_url_(icon_url), | 152 icon_url_(icon_url), |
| 152 icon_type_(icon_type), | 153 icon_type_(icon_type), |
| 153 bitmap_data_(bitmap_data), | 154 bitmap_data_(bitmap_data), |
| 154 size_(size) { | 155 size_(size) { |
| 155 } | 156 } |
| 156 | 157 |
| 157 virtual ~HistoryRequestHandler() {} | 158 virtual ~HistoryRequestHandler() {} |
| 158 void InvokeCallback(); | 159 void InvokeCallback(); |
| 159 | 160 |
| 160 const GURL page_url_; | 161 const GURL page_url_; |
| 161 const GURL icon_url_; | 162 const GURL icon_url_; |
| 162 const int icon_type_; | 163 const int icon_type_; |
| 163 const std::vector<unsigned char> bitmap_data_; | 164 const std::vector<unsigned char> bitmap_data_; |
| 164 const gfx::Size size_; | 165 const gfx::Size size_; |
| 165 std::vector<favicon_base::FaviconBitmapResult> history_results_; | 166 std::vector<favicon_base::FaviconBitmapResult> history_results_; |
| 166 FaviconService::FaviconResultsCallback callback_; | 167 favicon_base::FaviconResultsCallback callback_; |
| 167 | 168 |
| 168 private: | 169 private: |
| 169 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 170 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 } // namespace | 173 } // namespace |
| 173 | 174 |
| 174 class TestFaviconClient : public FaviconClient { | 175 class TestFaviconClient : public FaviconClient { |
| 175 public: | 176 public: |
| 176 virtual ~TestFaviconClient() {}; | 177 virtual ~TestFaviconClient() {}; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 287 |
| 287 const FaviconCandidate& best_favicon_candidate() { | 288 const FaviconCandidate& best_favicon_candidate() { |
| 288 return best_favicon_candidate_; | 289 return best_favicon_candidate_; |
| 289 } | 290 } |
| 290 | 291 |
| 291 protected: | 292 protected: |
| 292 virtual void UpdateFaviconMappingAndFetch( | 293 virtual void UpdateFaviconMappingAndFetch( |
| 293 const GURL& page_url, | 294 const GURL& page_url, |
| 294 const GURL& icon_url, | 295 const GURL& icon_url, |
| 295 favicon_base::IconType icon_type, | 296 favicon_base::IconType icon_type, |
| 296 const FaviconService::FaviconResultsCallback& callback, | 297 const favicon_base::FaviconResultsCallback& callback, |
| 297 base::CancelableTaskTracker* tracker) OVERRIDE { | 298 base::CancelableTaskTracker* tracker) OVERRIDE { |
| 298 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, | 299 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, |
| 299 icon_type, callback)); | 300 icon_type, callback)); |
| 300 } | 301 } |
| 301 | 302 |
| 302 virtual void GetFaviconFromFaviconService( | 303 virtual void GetFaviconFromFaviconService( |
| 303 const GURL& icon_url, | 304 const GURL& icon_url, |
| 304 favicon_base::IconType icon_type, | 305 favicon_base::IconType icon_type, |
| 305 const FaviconService::FaviconResultsCallback& callback, | 306 const favicon_base::FaviconResultsCallback& callback, |
| 306 base::CancelableTaskTracker* tracker) OVERRIDE { | 307 base::CancelableTaskTracker* tracker) OVERRIDE { |
| 307 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, | 308 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, |
| 308 icon_type, callback)); | 309 icon_type, callback)); |
| 309 } | 310 } |
| 310 | 311 |
| 311 virtual void GetFaviconForURLFromFaviconService( | 312 virtual void GetFaviconForURLFromFaviconService( |
| 312 const GURL& page_url, | 313 const GURL& page_url, |
| 313 int icon_types, | 314 int icon_types, |
| 314 const FaviconService::FaviconResultsCallback& callback, | 315 const favicon_base::FaviconResultsCallback& callback, |
| 315 base::CancelableTaskTracker* tracker) OVERRIDE { | 316 base::CancelableTaskTracker* tracker) OVERRIDE { |
| 316 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), | 317 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), |
| 317 icon_types, callback)); | 318 icon_types, callback)); |
| 318 } | 319 } |
| 319 | 320 |
| 320 virtual int DownloadFavicon(const GURL& image_url, | 321 virtual int DownloadFavicon(const GURL& image_url, |
| 321 int max_bitmap_size) OVERRIDE { | 322 int max_bitmap_size) OVERRIDE { |
| 322 download_id_++; | 323 download_id_++; |
| 323 std::vector<int> sizes; | 324 std::vector<int> sizes; |
| 324 sizes.push_back(0); | 325 sizes.push_back(0); |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 // Whether new icon is requested from history | 998 // Whether new icon is requested from history |
| 998 history_handler = helper.history_handler(); | 999 history_handler = helper.history_handler(); |
| 999 ASSERT_TRUE(history_handler); | 1000 ASSERT_TRUE(history_handler); |
| 1000 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); | 1001 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); |
| 1001 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); | 1002 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); |
| 1002 EXPECT_EQ(page_url, history_handler->page_url_); | 1003 EXPECT_EQ(page_url, history_handler->page_url_); |
| 1003 | 1004 |
| 1004 // Reset the history_handler to verify whether favicon is request from | 1005 // Reset the history_handler to verify whether favicon is request from |
| 1005 // history. | 1006 // history. |
| 1006 // Save the callback for late use. | 1007 // Save the callback for late use. |
| 1007 FaviconService::FaviconResultsCallback callback = history_handler->callback_; | 1008 favicon_base::FaviconResultsCallback callback = history_handler->callback_; |
| 1008 helper.set_history_handler(NULL); | 1009 helper.set_history_handler(NULL); |
| 1009 | 1010 |
| 1010 // Simulates download succeed. | 1011 // Simulates download succeed. |
| 1011 download_handler->InvokeCallback(); | 1012 download_handler->InvokeCallback(); |
| 1012 // The downloaded icon should be thrown away as there is favicon update. | 1013 // The downloaded icon should be thrown away as there is favicon update. |
| 1013 EXPECT_FALSE(helper.history_handler()); | 1014 EXPECT_FALSE(helper.history_handler()); |
| 1014 | 1015 |
| 1015 download_handler->Reset(); | 1016 download_handler->Reset(); |
| 1016 | 1017 |
| 1017 // Simulates getting the icon from history. | 1018 // Simulates getting the icon from history. |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1480 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1481 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
| 1481 EXPECT_NE(0, download_id); | 1482 EXPECT_NE(0, download_id); |
| 1482 // Report download success with HTTP 200 status. | 1483 // Report download success with HTTP 200 status. |
| 1483 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1484 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
| 1484 empty_icons, empty_icon_sizes); | 1485 empty_icons, empty_icon_sizes); |
| 1485 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1486 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
| 1486 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1487 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
| 1487 } | 1488 } |
| 1488 | 1489 |
| 1489 } // namespace. | 1490 } // namespace. |
| OLD | NEW |