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 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 // Whether new icon is requested from history | 996 // Whether new icon is requested from history |
996 history_handler = helper.history_handler(); | 997 history_handler = helper.history_handler(); |
997 ASSERT_TRUE(history_handler); | 998 ASSERT_TRUE(history_handler); |
998 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); | 999 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); |
999 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 1000 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
1000 EXPECT_EQ(page_url, history_handler->page_url_); | 1001 EXPECT_EQ(page_url, history_handler->page_url_); |
1001 | 1002 |
1002 // Reset the history_handler to verify whether favicon is request from | 1003 // Reset the history_handler to verify whether favicon is request from |
1003 // history. | 1004 // history. |
1004 // Save the callback for late use. | 1005 // Save the callback for late use. |
1005 FaviconService::FaviconResultsCallback callback = history_handler->callback_; | 1006 favicon_base::FaviconResultsCallback callback = history_handler->callback_; |
1006 helper.set_history_handler(NULL); | 1007 helper.set_history_handler(NULL); |
1007 | 1008 |
1008 // Simulates download succeed. | 1009 // Simulates download succeed. |
1009 download_handler->InvokeCallback(); | 1010 download_handler->InvokeCallback(); |
1010 // The downloaded icon should be thrown away as there is favicon update. | 1011 // The downloaded icon should be thrown away as there is favicon update. |
1011 EXPECT_FALSE(helper.history_handler()); | 1012 EXPECT_FALSE(helper.history_handler()); |
1012 | 1013 |
1013 download_handler->Reset(); | 1014 download_handler->Reset(); |
1014 | 1015 |
1015 // Simulates getting the icon from history. | 1016 // Simulates getting the icon from history. |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1494 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
1494 EXPECT_NE(0, download_id); | 1495 EXPECT_NE(0, download_id); |
1495 // Report download success with HTTP 200 status. | 1496 // Report download success with HTTP 200 status. |
1496 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1497 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
1497 empty_icons, empty_icon_sizes); | 1498 empty_icons, empty_icon_sizes); |
1498 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1499 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
1499 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1500 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
1500 } | 1501 } |
1501 | 1502 |
1502 } // namespace. | 1503 } // namespace. |
OLD | NEW |