| 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 "components/favicon/core/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 void SetFaviconRawBitmapResult( | 64 void SetFaviconRawBitmapResult( |
| 65 const GURL& icon_url, | 65 const GURL& icon_url, |
| 66 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { | 66 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { |
| 67 SetFaviconRawBitmapResult(icon_url, | 67 SetFaviconRawBitmapResult(icon_url, |
| 68 favicon_base::FAVICON, | 68 favicon_base::FAVICON, |
| 69 false /* expired */, | 69 false /* expired */, |
| 70 favicon_bitmap_results); | 70 favicon_bitmap_results); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // This class is used to save the download request for verifying with test case. | 73 // This class is used to save the download request for verifying with test case. |
| 74 // It also will be used to invoke the onDidDownload callback. | |
| 75 class DownloadHandler { | 74 class DownloadHandler { |
| 76 public: | 75 public: |
| 77 explicit DownloadHandler(FaviconHandler* favicon_handler) | 76 DownloadHandler() : callback_invoked_(false) {} |
| 78 : favicon_handler_(favicon_handler), callback_invoked_(false) {} | |
| 79 | |
| 80 ~DownloadHandler() {} | 77 ~DownloadHandler() {} |
| 81 | 78 |
| 82 void Reset() { | 79 void Reset() { |
| 83 download_.reset(); | 80 download_.reset(); |
| 84 callback_invoked_ = false; | 81 callback_invoked_ = false; |
| 85 // Does not affect |should_fail_download_icon_urls_| and | 82 // Does not affect |should_fail_download_icon_urls_| and |
| 86 // |failed_download_icon_urls_|. | 83 // |failed_download_icon_urls_|. |
| 87 } | 84 } |
| 88 | 85 |
| 89 // Make downloads for any of |icon_urls| fail. | 86 // Make downloads for any of |icon_urls| fail. |
| 90 void FailDownloadForIconURLs(const std::set<GURL>& icon_urls) { | 87 void FailDownloadForIconURLs(const std::set<GURL>& icon_urls) { |
| 91 should_fail_download_icon_urls_ = icon_urls; | 88 should_fail_download_icon_urls_ = icon_urls; |
| 92 } | 89 } |
| 93 | 90 |
| 94 // Returns whether a download for |icon_url| did fail. | 91 // Returns whether a download for |icon_url| did fail. |
| 95 bool DidFailDownloadForIconURL(const GURL& icon_url) const { | 92 bool DidFailDownloadForIconURL(const GURL& icon_url) const { |
| 96 return failed_download_icon_urls_.count(icon_url); | 93 return failed_download_icon_urls_.count(icon_url); |
| 97 } | 94 } |
| 98 | 95 |
| 99 void AddDownload( | 96 void AddDownload(int download_id, |
| 100 int download_id, | 97 const GURL& image_url, |
| 101 const GURL& image_url, | 98 const std::vector<int>& image_sizes, |
| 102 const std::vector<int>& image_sizes, | 99 int max_image_size, |
| 103 int max_image_size) { | 100 FaviconHandler::Delegate::ImageDownloadCallback callback) { |
| 104 download_.reset(new Download( | 101 download_.reset(new Download(download_id, image_url, image_sizes, |
| 105 download_id, image_url, image_sizes, max_image_size)); | 102 max_image_size, callback)); |
| 106 } | 103 } |
| 107 | 104 |
| 108 void InvokeCallback(); | 105 void InvokeCallback(); |
| 109 | 106 |
| 110 bool HasDownload() const { return download_.get(); } | 107 bool HasDownload() const { return download_.get(); } |
| 111 const GURL& GetImageUrl() const { return download_->image_url; } | 108 const GURL& GetImageUrl() const { return download_->image_url; } |
| 112 void SetImageSizes(const std::vector<int>& sizes) { | 109 void SetImageSizes(const std::vector<int>& sizes) { |
| 113 download_->image_sizes = sizes; } | 110 download_->image_sizes = sizes; } |
| 114 | 111 |
| 115 private: | 112 private: |
| 116 struct Download { | 113 struct Download { |
| 117 Download(int id, | 114 Download(int id, |
| 118 GURL url, | 115 GURL url, |
| 119 const std::vector<int>& sizes, | 116 const std::vector<int>& sizes, |
| 120 int max_size) | 117 int max_size, |
| 118 FaviconHandler::Delegate::ImageDownloadCallback callback) |
| 121 : download_id(id), | 119 : download_id(id), |
| 122 image_url(url), | 120 image_url(url), |
| 123 image_sizes(sizes), | 121 image_sizes(sizes), |
| 124 max_image_size(max_size) {} | 122 max_image_size(max_size), |
| 123 callback(callback) {} |
| 125 ~Download() {} | 124 ~Download() {} |
| 126 int download_id; | 125 int download_id; |
| 127 GURL image_url; | 126 GURL image_url; |
| 128 std::vector<int> image_sizes; | 127 std::vector<int> image_sizes; |
| 129 int max_image_size; | 128 int max_image_size; |
| 129 FaviconHandler::Delegate::ImageDownloadCallback callback; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 FaviconHandler* favicon_handler_; | |
| 133 std::unique_ptr<Download> download_; | 132 std::unique_ptr<Download> download_; |
| 134 bool callback_invoked_; | 133 bool callback_invoked_; |
| 135 | 134 |
| 136 // The icon URLs for which the download should fail. | 135 // The icon URLs for which the download should fail. |
| 137 std::set<GURL> should_fail_download_icon_urls_; | 136 std::set<GURL> should_fail_download_icon_urls_; |
| 138 | 137 |
| 139 // The icon URLs for which the download did fail. This should be a subset of | 138 // The icon URLs for which the download did fail. This should be a subset of |
| 140 // |should_fail_download_icon_urls_|. | 139 // |should_fail_download_icon_urls_|. |
| 141 std::set<GURL> failed_download_icon_urls_; | 140 std::set<GURL> failed_download_icon_urls_; |
| 142 | 141 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 const int icon_type_; | 176 const int icon_type_; |
| 178 const std::vector<unsigned char> bitmap_data_; | 177 const std::vector<unsigned char> bitmap_data_; |
| 179 const gfx::Size size_; | 178 const gfx::Size size_; |
| 180 std::vector<favicon_base::FaviconRawBitmapResult> history_results_; | 179 std::vector<favicon_base::FaviconRawBitmapResult> history_results_; |
| 181 favicon_base::FaviconResultsCallback callback_; | 180 favicon_base::FaviconResultsCallback callback_; |
| 182 | 181 |
| 183 private: | 182 private: |
| 184 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 183 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
| 185 }; | 184 }; |
| 186 | 185 |
| 187 } // namespace | 186 class TestDelegate : public FaviconHandler::Delegate { |
| 187 public: |
| 188 TestDelegate() : num_notifications_(0), download_id_(0) {} |
| 188 | 189 |
| 189 class TestFaviconDriver : public FaviconDriver { | 190 int DownloadImage(const GURL& image_url, |
| 190 public: | 191 int max_bitmap_size, |
| 191 TestFaviconDriver() | 192 ImageDownloadCallback callback) override { |
| 192 : num_notifications_(0u) {} | 193 // Do not do a download if downloading |image_url| failed previously. This |
| 194 // emulates the behavior of FaviconDriver::StartDownload() |
| 195 if (download_handler_.DidFailDownloadForIconURL(image_url)) { |
| 196 download_handler_.AddDownload(download_id_, image_url, std::vector<int>(), |
| 197 0, callback); |
| 198 return 0; |
| 199 } |
| 193 | 200 |
| 194 ~TestFaviconDriver() override {} | 201 download_id_++; |
| 195 | 202 std::vector<int> sizes; |
| 196 // FaviconDriver implementation. | 203 sizes.push_back(0); |
| 197 void FetchFavicon(const GURL& url) override { | 204 download_handler_.AddDownload(download_id_, image_url, sizes, |
| 198 ADD_FAILURE() << "TestFaviconDriver::FetchFavicon() " | 205 max_bitmap_size, callback); |
| 199 << "should never be called in tests."; | 206 return download_id_; |
| 200 } | |
| 201 | |
| 202 gfx::Image GetFavicon() const override { | |
| 203 ADD_FAILURE() << "TestFaviconDriver::GetFavicon() " | |
| 204 << "should never be called in tests."; | |
| 205 return gfx::Image(); | |
| 206 } | |
| 207 | |
| 208 bool FaviconIsValid() const override { | |
| 209 ADD_FAILURE() << "TestFaviconDriver::FaviconIsValid() " | |
| 210 << "should never be called in tests."; | |
| 211 return false; | |
| 212 } | |
| 213 | |
| 214 bool HasPendingTasksForTest() override { | |
| 215 ADD_FAILURE() << "TestFaviconDriver::HasPendingTasksForTest() " | |
| 216 << "should never be called in tests."; | |
| 217 return false; | |
| 218 } | |
| 219 | |
| 220 int StartDownload(const GURL& url, int max_bitmap_size) override { | |
| 221 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " | |
| 222 << "should never be called in tests."; | |
| 223 return -1; | |
| 224 } | 207 } |
| 225 | 208 |
| 226 bool IsOffTheRecord() override { return false; } | 209 bool IsOffTheRecord() override { return false; } |
| 227 | 210 |
| 228 bool IsBookmarked(const GURL& url) override { return false; } | |
| 229 | |
| 230 GURL GetActiveURL() override { | |
| 231 ADD_FAILURE() << "TestFaviconDriver::GetActiveURL() " | |
| 232 << "should never be called in tests."; | |
| 233 return GURL(); | |
| 234 } | |
| 235 | |
| 236 void OnFaviconUpdated( | 211 void OnFaviconUpdated( |
| 237 const GURL& page_url, | 212 const GURL& page_url, |
| 238 FaviconDriverObserver::NotificationIconType notification_icon_type, | 213 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 239 const GURL& icon_url, | 214 const GURL& icon_url, |
| 240 bool icon_url_changed, | 215 bool icon_url_changed, |
| 241 const gfx::Image& image) override { | 216 const gfx::Image& image) override { |
| 242 ++num_notifications_; | 217 ++num_notifications_; |
| 243 icon_url_ = icon_url; | 218 icon_url_ = icon_url; |
| 244 image_ = image; | 219 image_ = image; |
| 245 } | 220 } |
| 246 | 221 |
| 222 DownloadHandler* download_handler() { return &download_handler_; } |
| 247 const GURL& icon_url() const { return icon_url_; } | 223 const GURL& icon_url() const { return icon_url_; } |
| 248 | |
| 249 const gfx::Image& image() const { return image_; } | 224 const gfx::Image& image() const { return image_; } |
| 250 | |
| 251 size_t num_notifications() const { return num_notifications_; } | 225 size_t num_notifications() const { return num_notifications_; } |
| 252 void ResetNumNotifications() { num_notifications_ = 0; } | 226 void ResetNumNotifications() { num_notifications_ = 0; } |
| 253 | 227 |
| 254 private: | 228 private: |
| 255 GURL icon_url_; | 229 GURL icon_url_; |
| 256 gfx::Image image_; | 230 gfx::Image image_; |
| 257 size_t num_notifications_; | 231 size_t num_notifications_; |
| 258 | 232 |
| 259 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); | 233 // The unique id of a download request. It will be returned to a |
| 234 // FaviconHandler. |
| 235 int download_id_; |
| 236 DownloadHandler download_handler_; |
| 237 |
| 238 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 260 }; | 239 }; |
| 261 | 240 |
| 241 } // namespace |
| 242 |
| 262 // This class is used to catch the FaviconHandler's download and history | 243 // This class is used to catch the FaviconHandler's download and history |
| 263 // request, and also provide the methods to access the FaviconHandler | 244 // request, and also provide the methods to access the FaviconHandler |
| 264 // internals. | 245 // internals. |
| 265 class TestFaviconHandler : public FaviconHandler { | 246 class TestFaviconHandler : public FaviconHandler { |
| 266 public: | 247 public: |
| 267 static int GetMaximalIconSize(favicon_base::IconType icon_type) { | 248 static int GetMaximalIconSize(favicon_base::IconType icon_type) { |
| 268 return FaviconHandler::GetMaximalIconSize(icon_type); | 249 return FaviconHandler::GetMaximalIconSize(icon_type); |
| 269 } | 250 } |
| 270 | 251 |
| 271 TestFaviconHandler(TestFaviconDriver* driver, | 252 TestFaviconHandler(FaviconHandler::Delegate* delegate, |
| 272 FaviconDriverObserver::NotificationIconType handler_type) | 253 FaviconDriverObserver::NotificationIconType handler_type) |
| 273 : FaviconHandler(nullptr, driver, handler_type), | 254 : FaviconHandler(nullptr, delegate, handler_type) {} |
| 274 download_id_(0) { | |
| 275 download_handler_.reset(new DownloadHandler(this)); | |
| 276 } | |
| 277 | 255 |
| 278 ~TestFaviconHandler() override {} | 256 ~TestFaviconHandler() override {} |
| 279 | 257 |
| 280 HistoryRequestHandler* history_handler() { | 258 HistoryRequestHandler* history_handler() { |
| 281 return history_handler_.get(); | 259 return history_handler_.get(); |
| 282 } | 260 } |
| 283 | 261 |
| 284 // This method will take the ownership of the given handler. | 262 // This method will take the ownership of the given handler. |
| 285 void set_history_handler(HistoryRequestHandler* handler) { | 263 void set_history_handler(HistoryRequestHandler* handler) { |
| 286 history_handler_.reset(handler); | 264 history_handler_.reset(handler); |
| 287 } | 265 } |
| 288 | 266 |
| 289 DownloadHandler* download_handler() { | |
| 290 return download_handler_.get(); | |
| 291 } | |
| 292 | |
| 293 FaviconURL* current_candidate() { | 267 FaviconURL* current_candidate() { |
| 294 return FaviconHandler::current_candidate(); | 268 return FaviconHandler::current_candidate(); |
| 295 } | 269 } |
| 296 | 270 |
| 297 size_t current_candidate_index() const { | 271 size_t current_candidate_index() const { |
| 298 return current_candidate_index_; | 272 return current_candidate_index_; |
| 299 } | 273 } |
| 300 | 274 |
| 301 const FaviconCandidate& best_favicon_candidate() { | 275 const FaviconCandidate& best_favicon_candidate() { |
| 302 return best_favicon_candidate_; | 276 return best_favicon_candidate_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 324 | 298 |
| 325 void GetFaviconForURLFromFaviconService( | 299 void GetFaviconForURLFromFaviconService( |
| 326 const GURL& page_url, | 300 const GURL& page_url, |
| 327 int icon_types, | 301 int icon_types, |
| 328 const favicon_base::FaviconResultsCallback& callback, | 302 const favicon_base::FaviconResultsCallback& callback, |
| 329 base::CancelableTaskTracker* tracker) override { | 303 base::CancelableTaskTracker* tracker) override { |
| 330 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), | 304 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), |
| 331 icon_types, callback)); | 305 icon_types, callback)); |
| 332 } | 306 } |
| 333 | 307 |
| 334 int DownloadFavicon(const GURL& image_url, int max_bitmap_size) override { | |
| 335 // Do not do a download if downloading |image_url| failed previously. This | |
| 336 // emulates the behavior of FaviconDriver::StartDownload() | |
| 337 if (download_handler_->DidFailDownloadForIconURL(image_url)) { | |
| 338 download_handler_->AddDownload(download_id_, image_url, | |
| 339 std::vector<int>(), 0); | |
| 340 return 0; | |
| 341 } | |
| 342 | |
| 343 download_id_++; | |
| 344 std::vector<int> sizes; | |
| 345 sizes.push_back(0); | |
| 346 download_handler_->AddDownload( | |
| 347 download_id_, image_url, sizes, max_bitmap_size); | |
| 348 return download_id_; | |
| 349 } | |
| 350 | |
| 351 void SetHistoryFavicons(const GURL& page_url, | 308 void SetHistoryFavicons(const GURL& page_url, |
| 352 const GURL& icon_url, | 309 const GURL& icon_url, |
| 353 favicon_base::IconType icon_type, | 310 favicon_base::IconType icon_type, |
| 354 const gfx::Image& image) override { | 311 const gfx::Image& image) override { |
| 355 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); | 312 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); |
| 356 std::vector<unsigned char> bitmap_data(bytes->front(), | 313 std::vector<unsigned char> bitmap_data(bytes->front(), |
| 357 bytes->front() + bytes->size()); | 314 bytes->front() + bytes->size()); |
| 358 history_handler_.reset(new HistoryRequestHandler( | 315 history_handler_.reset(new HistoryRequestHandler( |
| 359 page_url, icon_url, icon_type, bitmap_data, image.Size())); | 316 page_url, icon_url, icon_type, bitmap_data, image.Size())); |
| 360 } | 317 } |
| 361 | 318 |
| 362 bool ShouldSaveFavicon() override { return true; } | 319 bool ShouldSaveFavicon() override { return true; } |
| 363 | 320 |
| 364 GURL page_url_; | 321 GURL page_url_; |
| 365 | 322 |
| 366 private: | 323 private: |
| 367 | 324 |
| 368 // The unique id of a download request. It will be returned to a | |
| 369 // FaviconHandler. | |
| 370 int download_id_; | |
| 371 | |
| 372 std::unique_ptr<DownloadHandler> download_handler_; | |
| 373 std::unique_ptr<HistoryRequestHandler> history_handler_; | 325 std::unique_ptr<HistoryRequestHandler> history_handler_; |
| 374 | 326 |
| 375 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | 327 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); |
| 376 }; | 328 }; |
| 377 | 329 |
| 378 namespace { | 330 namespace { |
| 379 | 331 |
| 380 void HistoryRequestHandler::InvokeCallback() { | 332 void HistoryRequestHandler::InvokeCallback() { |
| 381 if (!callback_.is_null()) { | 333 if (!callback_.is_null()) { |
| 382 callback_.Run(history_results_); | 334 callback_.Run(history_results_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 399 if (download_->max_image_size != 0 && | 351 if (download_->max_image_size != 0 && |
| 400 downloaded_size > download_->max_image_size) { | 352 downloaded_size > download_->max_image_size) { |
| 401 downloaded_size = download_->max_image_size; | 353 downloaded_size = download_->max_image_size; |
| 402 } | 354 } |
| 403 SkBitmap bitmap; | 355 SkBitmap bitmap; |
| 404 FillDataToBitmap(downloaded_size, downloaded_size, &bitmap); | 356 FillDataToBitmap(downloaded_size, downloaded_size, &bitmap); |
| 405 bitmaps.push_back(bitmap); | 357 bitmaps.push_back(bitmap); |
| 406 original_bitmap_sizes.push_back(gfx::Size(original_size, original_size)); | 358 original_bitmap_sizes.push_back(gfx::Size(original_size, original_size)); |
| 407 } | 359 } |
| 408 } | 360 } |
| 409 favicon_handler_->OnDidDownloadFavicon(download_->download_id, | 361 download_->callback.Run(download_->download_id, |
| 410 download_->image_url, bitmaps, | 362 /*=status_code=*/200, download_->image_url, bitmaps, |
| 411 original_bitmap_sizes); | 363 original_bitmap_sizes); |
| 412 callback_invoked_ = true; | 364 callback_invoked_ = true; |
| 413 } | 365 } |
| 414 | 366 |
| 415 class FaviconHandlerTest : public testing::Test { | 367 class FaviconHandlerTest : public testing::Test { |
| 416 public: | 368 public: |
| 417 FaviconHandlerTest() { | 369 FaviconHandlerTest() { |
| 418 } | 370 } |
| 419 | 371 |
| 420 ~FaviconHandlerTest() override {} | 372 ~FaviconHandlerTest() override {} |
| 421 | 373 |
| 422 // Simulates requesting a favicon for |page_url| given: | 374 // Simulates requesting a favicon for |page_url| given: |
| 423 // - We have not previously cached anything in history for |page_url| or for | 375 // - We have not previously cached anything in history for |page_url| or for |
| 424 // any of |candidates|. | 376 // any of |candidates|. |
| 425 // - The page provides favicons at |candidate_icons|. | 377 // - The page provides favicons at |candidate_icons|. |
| 426 // - The favicons at |candidate_icons| have edge pixel sizes of | 378 // - The favicons at |candidate_icons| have edge pixel sizes of |
| 427 // |candidate_icon_sizes|. | 379 // |candidate_icon_sizes|. |
| 428 void DownloadTillDoneIgnoringHistory( | 380 void DownloadTillDoneIgnoringHistory( |
| 429 TestFaviconDriver* favicon_driver, | 381 TestDelegate* delegate, |
| 430 TestFaviconHandler* favicon_handler, | 382 TestFaviconHandler* favicon_handler, |
| 431 const GURL& page_url, | 383 const GURL& page_url, |
| 432 const std::vector<FaviconURL>& candidate_icons, | 384 const std::vector<FaviconURL>& candidate_icons, |
| 433 const int* candidate_icon_sizes) { | 385 const int* candidate_icon_sizes) { |
| 434 size_t old_num_notifications = favicon_driver->num_notifications(); | 386 size_t old_num_notifications = delegate->num_notifications(); |
| 435 | 387 |
| 436 UpdateFaviconURL( | 388 UpdateFaviconURL(delegate, favicon_handler, page_url, candidate_icons); |
| 437 favicon_driver, favicon_handler, page_url, candidate_icons); | |
| 438 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); | 389 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); |
| 439 | 390 |
| 440 DownloadHandler* download_handler = favicon_handler->download_handler(); | 391 DownloadHandler* download_handler = delegate->download_handler(); |
| 441 for (size_t i = 0; i < candidate_icons.size(); ++i) { | 392 for (size_t i = 0; i < candidate_icons.size(); ++i) { |
| 442 favicon_handler->history_handler()->history_results_.clear(); | 393 favicon_handler->history_handler()->history_results_.clear(); |
| 443 favicon_handler->history_handler()->InvokeCallback(); | 394 favicon_handler->history_handler()->InvokeCallback(); |
| 444 ASSERT_TRUE(download_handler->HasDownload()); | 395 ASSERT_TRUE(download_handler->HasDownload()); |
| 445 EXPECT_EQ(download_handler->GetImageUrl(), | 396 EXPECT_EQ(download_handler->GetImageUrl(), |
| 446 candidate_icons[i].icon_url); | 397 candidate_icons[i].icon_url); |
| 447 std::vector<int> sizes; | 398 std::vector<int> sizes; |
| 448 sizes.push_back(candidate_icon_sizes[i]); | 399 sizes.push_back(candidate_icon_sizes[i]); |
| 449 download_handler->SetImageSizes(sizes); | 400 download_handler->SetImageSizes(sizes); |
| 450 download_handler->InvokeCallback(); | 401 download_handler->InvokeCallback(); |
| 451 | 402 |
| 452 download_handler->Reset(); | 403 download_handler->Reset(); |
| 453 | 404 |
| 454 if (favicon_driver->num_notifications() > old_num_notifications) | 405 if (delegate->num_notifications() > old_num_notifications) |
| 455 return; | 406 return; |
| 456 } | 407 } |
| 457 } | 408 } |
| 458 | 409 |
| 459 void UpdateFaviconURL(TestFaviconDriver* favicon_driver, | 410 void UpdateFaviconURL(TestDelegate* delegate, |
| 460 TestFaviconHandler* favicon_handler, | 411 TestFaviconHandler* favicon_handler, |
| 461 const GURL& page_url, | 412 const GURL& page_url, |
| 462 const std::vector<FaviconURL>& candidate_icons) { | 413 const std::vector<FaviconURL>& candidate_icons) { |
| 463 favicon_driver->ResetNumNotifications(); | 414 delegate->ResetNumNotifications(); |
| 464 | 415 |
| 465 favicon_handler->FetchFavicon(page_url); | 416 favicon_handler->FetchFavicon(page_url); |
| 466 favicon_handler->history_handler()->InvokeCallback(); | 417 favicon_handler->history_handler()->InvokeCallback(); |
| 467 | 418 |
| 468 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); | 419 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); |
| 469 } | 420 } |
| 470 | 421 |
| 471 void SetUp() override { | 422 void SetUp() override { |
| 472 // The score computed by SelectFaviconFrames() is dependent on the supported | 423 // The score computed by SelectFaviconFrames() is dependent on the supported |
| 473 // scale factors of the platform. It is used for determining the goodness of | 424 // scale factors of the platform. It is used for determining the goodness of |
| (...skipping 10 matching lines...) Expand all Loading... |
| 484 private: | 435 private: |
| 485 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 436 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 486 scoped_set_supported_scale_factors_; | 437 scoped_set_supported_scale_factors_; |
| 487 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 438 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); |
| 488 }; | 439 }; |
| 489 | 440 |
| 490 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 441 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 491 const GURL page_url("http://www.google.com"); | 442 const GURL page_url("http://www.google.com"); |
| 492 const GURL icon_url("http://www.google.com/favicon"); | 443 const GURL icon_url("http://www.google.com/favicon"); |
| 493 | 444 |
| 494 TestFaviconDriver driver; | 445 TestDelegate delegate; |
| 495 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 446 TestFaviconHandler helper(&delegate, FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 496 | 447 |
| 497 helper.FetchFavicon(page_url); | 448 helper.FetchFavicon(page_url); |
| 498 HistoryRequestHandler* history_handler = helper.history_handler(); | 449 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 499 // Ensure the data given to history is correct. | 450 // Ensure the data given to history is correct. |
| 500 ASSERT_TRUE(history_handler); | 451 ASSERT_TRUE(history_handler); |
| 501 EXPECT_EQ(page_url, history_handler->page_url_); | 452 EXPECT_EQ(page_url, history_handler->page_url_); |
| 502 EXPECT_EQ(GURL(), history_handler->icon_url_); | 453 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 503 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 454 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 504 | 455 |
| 505 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 456 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
| 506 | 457 |
| 507 // Send history response. | 458 // Send history response. |
| 508 history_handler->InvokeCallback(); | 459 history_handler->InvokeCallback(); |
| 509 // Verify FaviconHandler status | 460 // Verify FaviconHandler status |
| 510 EXPECT_EQ(1u, driver.num_notifications()); | 461 EXPECT_EQ(1u, delegate.num_notifications()); |
| 511 EXPECT_EQ(icon_url, driver.icon_url()); | 462 EXPECT_EQ(icon_url, delegate.icon_url()); |
| 512 | 463 |
| 513 // Simulates update favicon url. | 464 // Simulates update favicon url. |
| 514 std::vector<FaviconURL> urls; | 465 std::vector<FaviconURL> urls; |
| 515 urls.push_back( | 466 urls.push_back( |
| 516 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 467 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
| 517 helper.OnUpdateFaviconURL(page_url, urls); | 468 helper.OnUpdateFaviconURL(page_url, urls); |
| 518 | 469 |
| 519 // Verify FaviconHandler status | 470 // Verify FaviconHandler status |
| 520 EXPECT_EQ(1u, helper.image_urls().size()); | 471 EXPECT_EQ(1u, helper.image_urls().size()); |
| 521 ASSERT_TRUE(helper.current_candidate()); | 472 ASSERT_TRUE(helper.current_candidate()); |
| 522 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 473 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
| 523 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 474 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
| 524 | 475 |
| 525 // Favicon shouldn't request to download icon. | 476 // Favicon shouldn't request to download icon. |
| 526 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 477 EXPECT_FALSE(delegate.download_handler()->HasDownload()); |
| 527 } | 478 } |
| 528 | 479 |
| 529 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 480 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
| 530 const GURL page_url("http://www.google.com"); | 481 const GURL page_url("http://www.google.com"); |
| 531 const GURL icon_url("http://www.google.com/favicon"); | 482 const GURL icon_url("http://www.google.com/favicon"); |
| 532 | 483 |
| 533 TestFaviconDriver driver; | 484 TestDelegate delegate; |
| 534 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 485 TestFaviconHandler helper(&delegate, FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 535 | 486 |
| 536 helper.FetchFavicon(page_url); | 487 helper.FetchFavicon(page_url); |
| 537 HistoryRequestHandler* history_handler = helper.history_handler(); | 488 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 538 // Ensure the data given to history is correct. | 489 // Ensure the data given to history is correct. |
| 539 ASSERT_TRUE(history_handler); | 490 ASSERT_TRUE(history_handler); |
| 540 EXPECT_EQ(page_url, history_handler->page_url_); | 491 EXPECT_EQ(page_url, history_handler->page_url_); |
| 541 EXPECT_EQ(GURL(), history_handler->icon_url_); | 492 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 542 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 493 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 543 | 494 |
| 544 // Set icon data expired | 495 // Set icon data expired |
| 545 SetFaviconRawBitmapResult(icon_url, | 496 SetFaviconRawBitmapResult(icon_url, |
| 546 favicon_base::FAVICON, | 497 favicon_base::FAVICON, |
| 547 true /* expired */, | 498 true /* expired */, |
| 548 &history_handler->history_results_); | 499 &history_handler->history_results_); |
| 549 // Send history response. | 500 // Send history response. |
| 550 history_handler->InvokeCallback(); | 501 history_handler->InvokeCallback(); |
| 551 // Verify FaviconHandler status | 502 // Verify FaviconHandler status |
| 552 EXPECT_EQ(1u, driver.num_notifications()); | 503 EXPECT_EQ(1u, delegate.num_notifications()); |
| 553 EXPECT_EQ(icon_url, driver.icon_url()); | 504 EXPECT_EQ(icon_url, delegate.icon_url()); |
| 554 | 505 |
| 555 // Simulates update favicon url. | 506 // Simulates update favicon url. |
| 556 std::vector<FaviconURL> urls; | 507 std::vector<FaviconURL> urls; |
| 557 urls.push_back( | 508 urls.push_back( |
| 558 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 509 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
| 559 helper.OnUpdateFaviconURL(page_url, urls); | 510 helper.OnUpdateFaviconURL(page_url, urls); |
| 560 | 511 |
| 561 // Verify FaviconHandler status | 512 // Verify FaviconHandler status |
| 562 EXPECT_EQ(1u, helper.image_urls().size()); | 513 EXPECT_EQ(1u, helper.image_urls().size()); |
| 563 ASSERT_TRUE(helper.current_candidate()); | 514 ASSERT_TRUE(helper.current_candidate()); |
| 564 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 515 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
| 565 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 516 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
| 566 | 517 |
| 567 // Favicon should request to download icon now. | 518 // Favicon should request to download icon now. |
| 568 DownloadHandler* download_handler = helper.download_handler(); | 519 DownloadHandler* download_handler = delegate.download_handler(); |
| 569 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 520 EXPECT_TRUE(delegate.download_handler()->HasDownload()); |
| 570 | 521 |
| 571 // Verify the download request. | 522 // Verify the download request. |
| 572 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 523 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
| 573 | 524 |
| 574 // Reset the history_handler to verify whether favicon is set. | 525 // Reset the history_handler to verify whether favicon is set. |
| 575 helper.set_history_handler(nullptr); | 526 helper.set_history_handler(nullptr); |
| 576 | 527 |
| 577 // Smulates download done. | 528 // Smulates download done. |
| 578 download_handler->InvokeCallback(); | 529 download_handler->InvokeCallback(); |
| 579 | 530 |
| 580 // New icon should be saved to history backend and navigation entry. | 531 // New icon should be saved to history backend and navigation entry. |
| 581 history_handler = helper.history_handler(); | 532 history_handler = helper.history_handler(); |
| 582 ASSERT_TRUE(history_handler); | 533 ASSERT_TRUE(history_handler); |
| 583 EXPECT_EQ(icon_url, history_handler->icon_url_); | 534 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 584 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 535 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 585 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 536 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 586 EXPECT_EQ(page_url, history_handler->page_url_); | 537 EXPECT_EQ(page_url, history_handler->page_url_); |
| 587 | 538 |
| 588 // Verify NavigationEntry. | 539 // Verify NavigationEntry. |
| 589 EXPECT_EQ(2u, driver.num_notifications()); | 540 EXPECT_EQ(2u, delegate.num_notifications()); |
| 590 EXPECT_EQ(icon_url, driver.icon_url()); | 541 EXPECT_EQ(icon_url, delegate.icon_url()); |
| 591 EXPECT_FALSE(driver.image().IsEmpty()); | 542 EXPECT_FALSE(delegate.image().IsEmpty()); |
| 592 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 543 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); |
| 593 } | 544 } |
| 594 | 545 |
| 595 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 546 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
| 596 const GURL page_url("http://www.google.com"); | 547 const GURL page_url("http://www.google.com"); |
| 597 const GURL icon_url("http://www.google.com/favicon"); | 548 const GURL icon_url("http://www.google.com/favicon"); |
| 598 const GURL new_icon_url("http://www.google.com/new_favicon"); | 549 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 599 | 550 |
| 600 TestFaviconDriver driver; | 551 TestDelegate delegate; |
| 601 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 552 TestFaviconHandler helper(&delegate, FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 602 | 553 |
| 603 helper.FetchFavicon(page_url); | 554 helper.FetchFavicon(page_url); |
| 604 HistoryRequestHandler* history_handler = helper.history_handler(); | 555 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 605 // Ensure the data given to history is correct. | 556 // Ensure the data given to history is correct. |
| 606 ASSERT_TRUE(history_handler); | 557 ASSERT_TRUE(history_handler); |
| 607 EXPECT_EQ(page_url, history_handler->page_url_); | 558 EXPECT_EQ(page_url, history_handler->page_url_); |
| 608 EXPECT_EQ(GURL(), history_handler->icon_url_); | 559 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 609 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 560 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 610 | 561 |
| 611 // Set valid icon data. | 562 // Set valid icon data. |
| 612 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 563 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
| 613 | 564 |
| 614 // Send history response. | 565 // Send history response. |
| 615 history_handler->InvokeCallback(); | 566 history_handler->InvokeCallback(); |
| 616 // Verify FaviconHandler status. | 567 // Verify FaviconHandler status. |
| 617 EXPECT_EQ(1u, driver.num_notifications()); | 568 EXPECT_EQ(1u, delegate.num_notifications()); |
| 618 EXPECT_EQ(icon_url, driver.icon_url()); | 569 EXPECT_EQ(icon_url, delegate.icon_url()); |
| 619 | 570 |
| 620 // Reset the history_handler to verify whether new icon is requested from | 571 // Reset the history_handler to verify whether new icon is requested from |
| 621 // history. | 572 // history. |
| 622 helper.set_history_handler(nullptr); | 573 helper.set_history_handler(nullptr); |
| 623 | 574 |
| 624 // Simulates update with the different favicon url. | 575 // Simulates update with the different favicon url. |
| 625 std::vector<FaviconURL> urls; | 576 std::vector<FaviconURL> urls; |
| 626 urls.push_back(FaviconURL( | 577 urls.push_back(FaviconURL( |
| 627 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 578 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
| 628 helper.OnUpdateFaviconURL(page_url, urls); | 579 helper.OnUpdateFaviconURL(page_url, urls); |
| 629 | 580 |
| 630 // Verify FaviconHandler status. | 581 // Verify FaviconHandler status. |
| 631 EXPECT_EQ(1u, helper.image_urls().size()); | 582 EXPECT_EQ(1u, helper.image_urls().size()); |
| 632 ASSERT_TRUE(helper.current_candidate()); | 583 ASSERT_TRUE(helper.current_candidate()); |
| 633 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 584 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
| 634 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 585 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
| 635 | 586 |
| 636 // Favicon should be requested from history. | 587 // Favicon should be requested from history. |
| 637 history_handler = helper.history_handler(); | 588 history_handler = helper.history_handler(); |
| 638 ASSERT_TRUE(history_handler); | 589 ASSERT_TRUE(history_handler); |
| 639 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 590 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 640 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 591 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 641 EXPECT_EQ(page_url, history_handler->page_url_); | 592 EXPECT_EQ(page_url, history_handler->page_url_); |
| 642 | 593 |
| 643 // Simulate not find icon. | 594 // Simulate not find icon. |
| 644 history_handler->history_results_.clear(); | 595 history_handler->history_results_.clear(); |
| 645 history_handler->InvokeCallback(); | 596 history_handler->InvokeCallback(); |
| 646 | 597 |
| 647 // Favicon should request to download icon now. | 598 // Favicon should request to download icon now. |
| 648 DownloadHandler* download_handler = helper.download_handler(); | 599 DownloadHandler* download_handler = delegate.download_handler(); |
| 649 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 600 EXPECT_TRUE(delegate.download_handler()->HasDownload()); |
| 650 | 601 |
| 651 // Verify the download request. | 602 // Verify the download request. |
| 652 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 603 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
| 653 | 604 |
| 654 // Reset the history_handler to verify whether favicon is set. | 605 // Reset the history_handler to verify whether favicon is set. |
| 655 helper.set_history_handler(nullptr); | 606 helper.set_history_handler(nullptr); |
| 656 | 607 |
| 657 // Smulates download done. | 608 // Smulates download done. |
| 658 download_handler->InvokeCallback(); | 609 download_handler->InvokeCallback(); |
| 659 | 610 |
| 660 // New icon should be saved to history backend and navigation entry. | 611 // New icon should be saved to history backend and navigation entry. |
| 661 history_handler = helper.history_handler(); | 612 history_handler = helper.history_handler(); |
| 662 ASSERT_TRUE(history_handler); | 613 ASSERT_TRUE(history_handler); |
| 663 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 614 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 664 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 615 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 665 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 616 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 666 EXPECT_EQ(page_url, history_handler->page_url_); | 617 EXPECT_EQ(page_url, history_handler->page_url_); |
| 667 | 618 |
| 668 // Verify NavigationEntry. | 619 // Verify NavigationEntry. |
| 669 EXPECT_EQ(2u, driver.num_notifications()); | 620 EXPECT_EQ(2u, delegate.num_notifications()); |
| 670 EXPECT_EQ(new_icon_url, driver.icon_url()); | 621 EXPECT_EQ(new_icon_url, delegate.icon_url()); |
| 671 EXPECT_FALSE(driver.image().IsEmpty()); | 622 EXPECT_FALSE(delegate.image().IsEmpty()); |
| 672 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 623 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); |
| 673 } | 624 } |
| 674 | 625 |
| 675 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 626 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
| 676 const GURL page_url("http://www.google.com"); | 627 const GURL page_url("http://www.google.com"); |
| 677 const GURL icon_url("http://www.google.com/favicon"); | 628 const GURL icon_url("http://www.google.com/favicon"); |
| 678 | 629 |
| 679 TestFaviconDriver driver; | 630 TestDelegate delegate; |
| 680 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 631 TestFaviconHandler helper(&delegate, FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 681 | 632 |
| 682 helper.FetchFavicon(page_url); | 633 helper.FetchFavicon(page_url); |
| 683 HistoryRequestHandler* history_handler = helper.history_handler(); | 634 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 684 // Ensure the data given to history is correct. | 635 // Ensure the data given to history is correct. |
| 685 ASSERT_TRUE(history_handler); | 636 ASSERT_TRUE(history_handler); |
| 686 EXPECT_EQ(page_url, history_handler->page_url_); | 637 EXPECT_EQ(page_url, history_handler->page_url_); |
| 687 EXPECT_EQ(GURL(), history_handler->icon_url_); | 638 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 688 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 639 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 689 | 640 |
| 690 // Set non empty but invalid data. | 641 // Set non empty but invalid data. |
| 691 favicon_base::FaviconRawBitmapResult bitmap_result; | 642 favicon_base::FaviconRawBitmapResult bitmap_result; |
| 692 bitmap_result.expired = false; | 643 bitmap_result.expired = false; |
| 693 // Empty bitmap data is invalid. | 644 // Empty bitmap data is invalid. |
| 694 bitmap_result.bitmap_data = new base::RefCountedBytes(); | 645 bitmap_result.bitmap_data = new base::RefCountedBytes(); |
| 695 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); | 646 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
| 696 bitmap_result.icon_type = favicon_base::FAVICON; | 647 bitmap_result.icon_type = favicon_base::FAVICON; |
| 697 bitmap_result.icon_url = icon_url; | 648 bitmap_result.icon_url = icon_url; |
| 698 history_handler->history_results_.clear(); | 649 history_handler->history_results_.clear(); |
| 699 history_handler->history_results_.push_back(bitmap_result); | 650 history_handler->history_results_.push_back(bitmap_result); |
| 700 | 651 |
| 701 // Send history response. | 652 // Send history response. |
| 702 history_handler->InvokeCallback(); | 653 history_handler->InvokeCallback(); |
| 703 // The NavigationEntry should not be set yet as the history data is invalid. | 654 // The NavigationEntry should not be set yet as the history data is invalid. |
| 704 EXPECT_EQ(0u, driver.num_notifications()); | 655 EXPECT_EQ(0u, delegate.num_notifications()); |
| 705 EXPECT_EQ(GURL(), driver.icon_url()); | 656 EXPECT_EQ(GURL(), delegate.icon_url()); |
| 706 | 657 |
| 707 // Reset the history_handler to verify whether new icon is requested from | 658 // Reset the history_handler to verify whether new icon is requested from |
| 708 // history. | 659 // history. |
| 709 helper.set_history_handler(nullptr); | 660 helper.set_history_handler(nullptr); |
| 710 | 661 |
| 711 // Simulates update with matching favicon URL. | 662 // Simulates update with matching favicon URL. |
| 712 std::vector<FaviconURL> urls; | 663 std::vector<FaviconURL> urls; |
| 713 urls.push_back( | 664 urls.push_back( |
| 714 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 665 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
| 715 helper.OnUpdateFaviconURL(page_url, urls); | 666 helper.OnUpdateFaviconURL(page_url, urls); |
| 716 | 667 |
| 717 // A download for the favicon should be requested, and we should not do | 668 // A download for the favicon should be requested, and we should not do |
| 718 // another history request. | 669 // another history request. |
| 719 DownloadHandler* download_handler = helper.download_handler(); | 670 DownloadHandler* download_handler = delegate.download_handler(); |
| 720 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 671 EXPECT_TRUE(delegate.download_handler()->HasDownload()); |
| 721 EXPECT_EQ(nullptr, helper.history_handler()); | 672 EXPECT_EQ(nullptr, helper.history_handler()); |
| 722 | 673 |
| 723 // Verify the download request. | 674 // Verify the download request. |
| 724 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 675 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
| 725 | 676 |
| 726 // Simulates download done. | 677 // Simulates download done. |
| 727 download_handler->InvokeCallback(); | 678 download_handler->InvokeCallback(); |
| 728 | 679 |
| 729 // New icon should be saved to history backend and navigation entry. | 680 // New icon should be saved to history backend and navigation entry. |
| 730 history_handler = helper.history_handler(); | 681 history_handler = helper.history_handler(); |
| 731 ASSERT_TRUE(history_handler); | 682 ASSERT_TRUE(history_handler); |
| 732 EXPECT_EQ(icon_url, history_handler->icon_url_); | 683 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 733 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 684 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 734 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 685 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 735 EXPECT_EQ(page_url, history_handler->page_url_); | 686 EXPECT_EQ(page_url, history_handler->page_url_); |
| 736 | 687 |
| 737 // Verify NavigationEntry. | 688 // Verify NavigationEntry. |
| 738 EXPECT_EQ(1u, driver.num_notifications()); | 689 EXPECT_EQ(1u, delegate.num_notifications()); |
| 739 EXPECT_EQ(icon_url, driver.icon_url()); | 690 EXPECT_EQ(icon_url, delegate.icon_url()); |
| 740 EXPECT_FALSE(driver.image().IsEmpty()); | 691 EXPECT_FALSE(delegate.image().IsEmpty()); |
| 741 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 692 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); |
| 742 } | 693 } |
| 743 | 694 |
| 744 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 695 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
| 745 const GURL page_url("http://www.google.com"); | 696 const GURL page_url("http://www.google.com"); |
| 746 const GURL icon_url("http://www.google.com/favicon"); | 697 const GURL icon_url("http://www.google.com/favicon"); |
| 747 const GURL new_icon_url("http://www.google.com/new_favicon"); | 698 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 748 | 699 |
| 749 TestFaviconDriver driver; | 700 TestDelegate delegate; |
| 750 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 701 TestFaviconHandler helper(&delegate, FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 751 | 702 |
| 752 helper.FetchFavicon(page_url); | 703 helper.FetchFavicon(page_url); |
| 753 HistoryRequestHandler* history_handler = helper.history_handler(); | 704 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 754 // Ensure the data given to history is correct. | 705 // Ensure the data given to history is correct. |
| 755 ASSERT_TRUE(history_handler); | 706 ASSERT_TRUE(history_handler); |
| 756 EXPECT_EQ(page_url, history_handler->page_url_); | 707 EXPECT_EQ(page_url, history_handler->page_url_); |
| 757 EXPECT_EQ(GURL(), history_handler->icon_url_); | 708 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 758 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 709 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 759 | 710 |
| 760 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 711 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
| 761 | 712 |
| 762 // Send history response. | 713 // Send history response. |
| 763 history_handler->InvokeCallback(); | 714 history_handler->InvokeCallback(); |
| 764 // Verify FaviconHandler status. | 715 // Verify FaviconHandler status. |
| 765 EXPECT_EQ(1u, driver.num_notifications()); | 716 EXPECT_EQ(1u, delegate.num_notifications()); |
| 766 EXPECT_EQ(icon_url, driver.icon_url()); | 717 EXPECT_EQ(icon_url, delegate.icon_url()); |
| 767 | 718 |
| 768 // Reset the history_handler to verify whether new icon is requested from | 719 // Reset the history_handler to verify whether new icon is requested from |
| 769 // history. | 720 // history. |
| 770 helper.set_history_handler(nullptr); | 721 helper.set_history_handler(nullptr); |
| 771 | 722 |
| 772 // Simulates update with the different favicon url. | 723 // Simulates update with the different favicon url. |
| 773 std::vector<FaviconURL> urls; | 724 std::vector<FaviconURL> urls; |
| 774 urls.push_back(FaviconURL( | 725 urls.push_back(FaviconURL( |
| 775 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 726 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
| 776 helper.OnUpdateFaviconURL(page_url, urls); | 727 helper.OnUpdateFaviconURL(page_url, urls); |
| 777 | 728 |
| 778 // Verify FaviconHandler status. | 729 // Verify FaviconHandler status. |
| 779 EXPECT_EQ(1u, helper.image_urls().size()); | 730 EXPECT_EQ(1u, helper.image_urls().size()); |
| 780 ASSERT_TRUE(helper.current_candidate()); | 731 ASSERT_TRUE(helper.current_candidate()); |
| 781 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 732 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
| 782 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 733 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
| 783 | 734 |
| 784 // Favicon should be requested from history. | 735 // Favicon should be requested from history. |
| 785 history_handler = helper.history_handler(); | 736 history_handler = helper.history_handler(); |
| 786 ASSERT_TRUE(history_handler); | 737 ASSERT_TRUE(history_handler); |
| 787 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 738 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 788 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 739 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 789 EXPECT_EQ(page_url, history_handler->page_url_); | 740 EXPECT_EQ(page_url, history_handler->page_url_); |
| 790 | 741 |
| 791 // Simulate find icon. | 742 // Simulate find icon. |
| 792 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); | 743 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); |
| 793 history_handler->InvokeCallback(); | 744 history_handler->InvokeCallback(); |
| 794 | 745 |
| 795 // Shouldn't request download favicon | 746 // Shouldn't request download favicon |
| 796 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 747 EXPECT_FALSE(delegate.download_handler()->HasDownload()); |
| 797 | 748 |
| 798 // Verify the favicon status. | 749 // Verify the favicon status. |
| 799 EXPECT_EQ(2u, driver.num_notifications()); | 750 EXPECT_EQ(2u, delegate.num_notifications()); |
| 800 EXPECT_EQ(new_icon_url, driver.icon_url()); | 751 EXPECT_EQ(new_icon_url, delegate.icon_url()); |
| 801 EXPECT_FALSE(driver.image().IsEmpty()); | 752 EXPECT_FALSE(delegate.image().IsEmpty()); |
| 802 } | 753 } |
| 803 | 754 |
| 804 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 755 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
| 805 const GURL page_url("http://www.google.com"); | 756 const GURL page_url("http://www.google.com"); |
| 806 const GURL icon_url("http://www.google.com/favicon"); | 757 const GURL icon_url("http://www.google.com/favicon"); |
| 807 const GURL new_icon_url("http://www.google.com/new_favicon"); | 758 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 808 | 759 |
| 809 TestFaviconDriver driver; | 760 TestDelegate delegate; |
| 810 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); | 761 TestFaviconHandler helper(&delegate, FaviconDriverObserver::TOUCH_LARGEST); |
| 811 std::set<GURL> fail_downloads; | 762 std::set<GURL> fail_downloads; |
| 812 fail_downloads.insert(icon_url); | 763 fail_downloads.insert(icon_url); |
| 813 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); | 764 delegate.download_handler()->FailDownloadForIconURLs(fail_downloads); |
| 814 | 765 |
| 815 helper.FetchFavicon(page_url); | 766 helper.FetchFavicon(page_url); |
| 816 HistoryRequestHandler* history_handler = helper.history_handler(); | 767 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 817 // Ensure the data given to history is correct. | 768 // Ensure the data given to history is correct. |
| 818 ASSERT_TRUE(history_handler); | 769 ASSERT_TRUE(history_handler); |
| 819 EXPECT_EQ(page_url, history_handler->page_url_); | 770 EXPECT_EQ(page_url, history_handler->page_url_); |
| 820 EXPECT_EQ(GURL(), history_handler->icon_url_); | 771 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 821 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 772 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
| 822 history_handler->icon_type_); | 773 history_handler->icon_type_); |
| 823 | 774 |
| 824 // Icon not found. | 775 // Icon not found. |
| 825 history_handler->history_results_.clear(); | 776 history_handler->history_results_.clear(); |
| 826 // Send history response. | 777 // Send history response. |
| 827 history_handler->InvokeCallback(); | 778 history_handler->InvokeCallback(); |
| 828 // Verify FaviconHandler status. | 779 // Verify FaviconHandler status. |
| 829 EXPECT_EQ(0u, driver.num_notifications()); | 780 EXPECT_EQ(0u, delegate.num_notifications()); |
| 830 EXPECT_EQ(GURL(), driver.icon_url()); | 781 EXPECT_EQ(GURL(), delegate.icon_url()); |
| 831 | 782 |
| 832 // Reset the history_handler to verify whether new icon is requested from | 783 // Reset the history_handler to verify whether new icon is requested from |
| 833 // history. | 784 // history. |
| 834 helper.set_history_handler(nullptr); | 785 helper.set_history_handler(nullptr); |
| 835 | 786 |
| 836 // Simulates update with the different favicon url. | 787 // Simulates update with the different favicon url. |
| 837 std::vector<FaviconURL> urls; | 788 std::vector<FaviconURL> urls; |
| 838 urls.push_back(FaviconURL(icon_url, | 789 urls.push_back(FaviconURL(icon_url, |
| 839 favicon_base::TOUCH_PRECOMPOSED_ICON, | 790 favicon_base::TOUCH_PRECOMPOSED_ICON, |
| 840 std::vector<gfx::Size>())); | 791 std::vector<gfx::Size>())); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 857 ASSERT_TRUE(history_handler); | 808 ASSERT_TRUE(history_handler); |
| 858 EXPECT_EQ(icon_url, history_handler->icon_url_); | 809 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 859 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 810 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
| 860 EXPECT_EQ(page_url, history_handler->page_url_); | 811 EXPECT_EQ(page_url, history_handler->page_url_); |
| 861 | 812 |
| 862 // Simulate not find icon. | 813 // Simulate not find icon. |
| 863 history_handler->history_results_.clear(); | 814 history_handler->history_results_.clear(); |
| 864 history_handler->InvokeCallback(); | 815 history_handler->InvokeCallback(); |
| 865 | 816 |
| 866 // Should request download favicon. | 817 // Should request download favicon. |
| 867 DownloadHandler* download_handler = helper.download_handler(); | 818 DownloadHandler* download_handler = delegate.download_handler(); |
| 868 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 819 EXPECT_TRUE(delegate.download_handler()->HasDownload()); |
| 869 | 820 |
| 870 // Verify the download request. | 821 // Verify the download request. |
| 871 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 822 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
| 872 | 823 |
| 873 // Reset the history_handler to verify whether favicon is request from | 824 // Reset the history_handler to verify whether favicon is request from |
| 874 // history. | 825 // history. |
| 875 helper.set_history_handler(nullptr); | 826 helper.set_history_handler(nullptr); |
| 876 download_handler->InvokeCallback(); | 827 download_handler->InvokeCallback(); |
| 877 | 828 |
| 878 // Left 1 url. | 829 // Left 1 url. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 892 download_handler->Reset(); | 843 download_handler->Reset(); |
| 893 | 844 |
| 894 // Simulates getting a expired icon from history. | 845 // Simulates getting a expired icon from history. |
| 895 SetFaviconRawBitmapResult(new_icon_url, | 846 SetFaviconRawBitmapResult(new_icon_url, |
| 896 favicon_base::TOUCH_ICON, | 847 favicon_base::TOUCH_ICON, |
| 897 true /* expired */, | 848 true /* expired */, |
| 898 &history_handler->history_results_); | 849 &history_handler->history_results_); |
| 899 history_handler->InvokeCallback(); | 850 history_handler->InvokeCallback(); |
| 900 | 851 |
| 901 // Verify the download request. | 852 // Verify the download request. |
| 902 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 853 EXPECT_TRUE(delegate.download_handler()->HasDownload()); |
| 903 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 854 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
| 904 | 855 |
| 905 helper.set_history_handler(nullptr); | 856 helper.set_history_handler(nullptr); |
| 906 | 857 |
| 907 // Simulates icon being downloaded. | 858 // Simulates icon being downloaded. |
| 908 download_handler->InvokeCallback(); | 859 download_handler->InvokeCallback(); |
| 909 | 860 |
| 910 // New icon should be saved to history backend. | 861 // New icon should be saved to history backend. |
| 911 history_handler = helper.history_handler(); | 862 history_handler = helper.history_handler(); |
| 912 ASSERT_TRUE(history_handler); | 863 ASSERT_TRUE(history_handler); |
| 913 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 864 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 914 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); | 865 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); |
| 915 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 866 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 916 EXPECT_EQ(page_url, history_handler->page_url_); | 867 EXPECT_EQ(page_url, history_handler->page_url_); |
| 917 } | 868 } |
| 918 | 869 |
| 919 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 870 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
| 920 const GURL page_url("http://www.google.com"); | 871 const GURL page_url("http://www.google.com"); |
| 921 const GURL icon_url("http://www.google.com/favicon"); | 872 const GURL icon_url("http://www.google.com/favicon"); |
| 922 const GURL new_icon_url("http://www.google.com/new_favicon"); | 873 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 923 | 874 |
| 924 TestFaviconDriver driver; | 875 TestDelegate delegate; |
| 925 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); | 876 TestFaviconHandler helper(&delegate, FaviconDriverObserver::TOUCH_LARGEST); |
| 926 | 877 |
| 927 helper.FetchFavicon(page_url); | 878 helper.FetchFavicon(page_url); |
| 928 HistoryRequestHandler* history_handler = helper.history_handler(); | 879 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 929 // Ensure the data given to history is correct. | 880 // Ensure the data given to history is correct. |
| 930 ASSERT_TRUE(history_handler); | 881 ASSERT_TRUE(history_handler); |
| 931 EXPECT_EQ(page_url, history_handler->page_url_); | 882 EXPECT_EQ(page_url, history_handler->page_url_); |
| 932 EXPECT_EQ(GURL(), history_handler->icon_url_); | 883 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 933 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 884 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
| 934 history_handler->icon_type_); | 885 history_handler->icon_type_); |
| 935 | 886 |
| 936 // Icon not found. | 887 // Icon not found. |
| 937 history_handler->history_results_.clear(); | 888 history_handler->history_results_.clear(); |
| 938 // Send history response. | 889 // Send history response. |
| 939 history_handler->InvokeCallback(); | 890 history_handler->InvokeCallback(); |
| 940 // Verify FaviconHandler status. | 891 // Verify FaviconHandler status. |
| 941 EXPECT_EQ(0u, driver.num_notifications()); | 892 EXPECT_EQ(0u, delegate.num_notifications()); |
| 942 EXPECT_EQ(GURL(), driver.icon_url()); | 893 EXPECT_EQ(GURL(), delegate.icon_url()); |
| 943 | 894 |
| 944 // Reset the history_handler to verify whether new icon is requested from | 895 // Reset the history_handler to verify whether new icon is requested from |
| 945 // history. | 896 // history. |
| 946 helper.set_history_handler(nullptr); | 897 helper.set_history_handler(nullptr); |
| 947 | 898 |
| 948 // Simulates update with the different favicon url. | 899 // Simulates update with the different favicon url. |
| 949 std::vector<FaviconURL> urls; | 900 std::vector<FaviconURL> urls; |
| 950 urls.push_back(FaviconURL(icon_url, | 901 urls.push_back(FaviconURL(icon_url, |
| 951 favicon_base::TOUCH_PRECOMPOSED_ICON, | 902 favicon_base::TOUCH_PRECOMPOSED_ICON, |
| 952 std::vector<gfx::Size>())); | 903 std::vector<gfx::Size>())); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 968 ASSERT_TRUE(history_handler); | 919 ASSERT_TRUE(history_handler); |
| 969 EXPECT_EQ(icon_url, history_handler->icon_url_); | 920 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 970 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 921 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
| 971 EXPECT_EQ(page_url, history_handler->page_url_); | 922 EXPECT_EQ(page_url, history_handler->page_url_); |
| 972 | 923 |
| 973 // Simulate not find icon. | 924 // Simulate not find icon. |
| 974 history_handler->history_results_.clear(); | 925 history_handler->history_results_.clear(); |
| 975 history_handler->InvokeCallback(); | 926 history_handler->InvokeCallback(); |
| 976 | 927 |
| 977 // Should request download favicon. | 928 // Should request download favicon. |
| 978 DownloadHandler* download_handler = helper.download_handler(); | 929 DownloadHandler* download_handler = delegate.download_handler(); |
| 979 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 930 EXPECT_TRUE(delegate.download_handler()->HasDownload()); |
| 980 | 931 |
| 981 // Verify the download request. | 932 // Verify the download request. |
| 982 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 933 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
| 983 | 934 |
| 984 // Reset the history_handler to verify whether favicon is request from | 935 // Reset the history_handler to verify whether favicon is request from |
| 985 // history. | 936 // history. |
| 986 helper.set_history_handler(nullptr); | 937 helper.set_history_handler(nullptr); |
| 987 const GURL latest_icon_url("http://www.google.com/latest_favicon"); | 938 const GURL latest_icon_url("http://www.google.com/latest_favicon"); |
| 988 std::vector<FaviconURL> latest_urls; | 939 std::vector<FaviconURL> latest_urls; |
| 989 latest_urls.push_back(FaviconURL( | 940 latest_urls.push_back(FaviconURL( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 const GURL icon_url1("http://www.google.com/favicon1"); | 987 const GURL icon_url1("http://www.google.com/favicon1"); |
| 1037 const GURL icon_url2("http://www.google.com/favicon2"); | 988 const GURL icon_url2("http://www.google.com/favicon2"); |
| 1038 std::vector<FaviconURL> favicon_urls; | 989 std::vector<FaviconURL> favicon_urls; |
| 1039 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), | 990 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), |
| 1040 favicon_base::FAVICON, | 991 favicon_base::FAVICON, |
| 1041 std::vector<gfx::Size>())); | 992 std::vector<gfx::Size>())); |
| 1042 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), | 993 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), |
| 1043 favicon_base::FAVICON, | 994 favicon_base::FAVICON, |
| 1044 std::vector<gfx::Size>())); | 995 std::vector<gfx::Size>())); |
| 1045 | 996 |
| 1046 TestFaviconDriver driver; | 997 TestDelegate delegate; |
| 1047 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 998 TestFaviconHandler helper(&delegate, FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1048 | 999 |
| 1049 // Initiate a request for favicon data for |page_url|. History does not know | 1000 // Initiate a request for favicon data for |page_url|. History does not know |
| 1050 // about the page URL or the icon URLs. | 1001 // about the page URL or the icon URLs. |
| 1051 helper.FetchFavicon(page_url); | 1002 helper.FetchFavicon(page_url); |
| 1052 helper.history_handler()->InvokeCallback(); | 1003 helper.history_handler()->InvokeCallback(); |
| 1053 helper.set_history_handler(nullptr); | 1004 helper.set_history_handler(nullptr); |
| 1054 | 1005 |
| 1055 // Got icon URLs. | 1006 // Got icon URLs. |
| 1056 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1007 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
| 1057 | 1008 |
| 1058 // There should be an ongoing history request for |icon_url1|. | 1009 // There should be an ongoing history request for |icon_url1|. |
| 1059 ASSERT_EQ(2u, helper.image_urls().size()); | 1010 ASSERT_EQ(2u, helper.image_urls().size()); |
| 1060 ASSERT_EQ(0u, helper.current_candidate_index()); | 1011 ASSERT_EQ(0u, helper.current_candidate_index()); |
| 1061 HistoryRequestHandler* history_handler = helper.history_handler(); | 1012 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 1062 ASSERT_TRUE(history_handler); | 1013 ASSERT_TRUE(history_handler); |
| 1063 | 1014 |
| 1064 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. | 1015 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. |
| 1065 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1016 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
| 1066 EXPECT_EQ(history_handler, helper.history_handler()); | 1017 EXPECT_EQ(history_handler, helper.history_handler()); |
| 1067 | 1018 |
| 1068 // Complete history request for |icon_url1| and do download. | 1019 // Complete history request for |icon_url1| and do download. |
| 1069 helper.history_handler()->InvokeCallback(); | 1020 helper.history_handler()->InvokeCallback(); |
| 1070 helper.set_history_handler(nullptr); | 1021 helper.set_history_handler(nullptr); |
| 1071 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); | 1022 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); |
| 1072 helper.download_handler()->InvokeCallback(); | 1023 delegate.download_handler()->InvokeCallback(); |
| 1073 helper.download_handler()->Reset(); | 1024 delegate.download_handler()->Reset(); |
| 1074 | 1025 |
| 1075 // There should now be an ongoing history request for |icon_url2|. | 1026 // There should now be an ongoing history request for |icon_url2|. |
| 1076 ASSERT_EQ(1u, helper.current_candidate_index()); | 1027 ASSERT_EQ(1u, helper.current_candidate_index()); |
| 1077 history_handler = helper.history_handler(); | 1028 history_handler = helper.history_handler(); |
| 1078 ASSERT_TRUE(history_handler); | 1029 ASSERT_TRUE(history_handler); |
| 1079 | 1030 |
| 1080 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. | 1031 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. |
| 1081 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1032 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
| 1082 EXPECT_EQ(history_handler, helper.history_handler()); | 1033 EXPECT_EQ(history_handler, helper.history_handler()); |
| 1083 } | 1034 } |
| 1084 | 1035 |
| 1085 // Fixes crbug.com/544560 | 1036 // Fixes crbug.com/544560 |
| 1086 TEST_F(FaviconHandlerTest, | 1037 TEST_F(FaviconHandlerTest, |
| 1087 OnFaviconAvailableNotificationSentAfterIconURLChange) { | 1038 OnFaviconAvailableNotificationSentAfterIconURLChange) { |
| 1088 const GURL kPageURL("http://www.page_which_animates_favicon.com"); | 1039 const GURL kPageURL("http://www.page_which_animates_favicon.com"); |
| 1089 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png")
; | 1040 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png")
; |
| 1090 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png")
; | 1041 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png")
; |
| 1091 | 1042 |
| 1092 TestFaviconDriver driver; | 1043 TestDelegate delegate; |
| 1093 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1044 TestFaviconHandler helper(&delegate, FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1094 | 1045 |
| 1095 // Initial state: | 1046 // Initial state: |
| 1096 // - The database does not know about |kPageURL|. | 1047 // - The database does not know about |kPageURL|. |
| 1097 // - The page uses |kIconURL1| and |kIconURL2|. | 1048 // - The page uses |kIconURL1| and |kIconURL2|. |
| 1098 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons | 1049 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons |
| 1099 // are expired in the database. | 1050 // are expired in the database. |
| 1100 helper.FetchFavicon(kPageURL); | 1051 helper.FetchFavicon(kPageURL); |
| 1101 ASSERT_TRUE(helper.history_handler()); | 1052 ASSERT_TRUE(helper.history_handler()); |
| 1102 helper.history_handler()->InvokeCallback(); | 1053 helper.history_handler()->InvokeCallback(); |
| 1103 { | 1054 { |
| 1104 std::vector<FaviconURL> icon_urls; | 1055 std::vector<FaviconURL> icon_urls; |
| 1105 icon_urls.push_back( | 1056 icon_urls.push_back( |
| 1106 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>())); | 1057 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>())); |
| 1107 icon_urls.push_back( | 1058 icon_urls.push_back( |
| 1108 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>())); | 1059 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>())); |
| 1109 helper.OnUpdateFaviconURL(kPageURL, icon_urls); | 1060 helper.OnUpdateFaviconURL(kPageURL, icon_urls); |
| 1110 } | 1061 } |
| 1111 | 1062 |
| 1112 // FaviconHandler should request from history and download |kIconURL1| and | 1063 // FaviconHandler should request from history and download |kIconURL1| and |
| 1113 // |kIconURL2|. |kIconURL1| is the better match. A | 1064 // |kIconURL2|. |kIconURL1| is the better match. A |
| 1114 // FaviconDriver::OnFaviconUpdated() notification should be sent for | 1065 // FaviconDriver::OnFaviconUpdated() notification should be sent for |
| 1115 // |kIconURL1|. | 1066 // |kIconURL1|. |
| 1116 ASSERT_EQ(0u, driver.num_notifications()); | 1067 ASSERT_EQ(0u, delegate.num_notifications()); |
| 1117 ASSERT_TRUE(helper.history_handler()); | 1068 ASSERT_TRUE(helper.history_handler()); |
| 1118 SetFaviconRawBitmapResult(kIconURL1, | 1069 SetFaviconRawBitmapResult(kIconURL1, |
| 1119 favicon_base::FAVICON, | 1070 favicon_base::FAVICON, |
| 1120 true /* expired */, | 1071 true /* expired */, |
| 1121 &helper.history_handler()->history_results_); | 1072 &helper.history_handler()->history_results_); |
| 1122 helper.history_handler()->InvokeCallback(); | 1073 helper.history_handler()->InvokeCallback(); |
| 1123 helper.set_history_handler(nullptr); | 1074 helper.set_history_handler(nullptr); |
| 1124 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1075 ASSERT_TRUE(delegate.download_handler()->HasDownload()); |
| 1125 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); | 1076 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); |
| 1126 helper.download_handler()->InvokeCallback(); | 1077 delegate.download_handler()->InvokeCallback(); |
| 1127 helper.download_handler()->Reset(); | 1078 delegate.download_handler()->Reset(); |
| 1128 | 1079 |
| 1129 ASSERT_TRUE(helper.history_handler()); | 1080 ASSERT_TRUE(helper.history_handler()); |
| 1130 helper.history_handler()->InvokeCallback(); | 1081 helper.history_handler()->InvokeCallback(); |
| 1131 SetFaviconRawBitmapResult(kIconURL2, | 1082 SetFaviconRawBitmapResult(kIconURL2, |
| 1132 favicon_base::FAVICON, | 1083 favicon_base::FAVICON, |
| 1133 true /* expired */, | 1084 true /* expired */, |
| 1134 &helper.history_handler()->history_results_); | 1085 &helper.history_handler()->history_results_); |
| 1135 helper.history_handler()->InvokeCallback(); | 1086 helper.history_handler()->InvokeCallback(); |
| 1136 helper.set_history_handler(nullptr); | 1087 helper.set_history_handler(nullptr); |
| 1137 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1088 ASSERT_TRUE(delegate.download_handler()->HasDownload()); |
| 1138 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); | 1089 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); |
| 1139 helper.download_handler()->InvokeCallback(); | 1090 delegate.download_handler()->InvokeCallback(); |
| 1140 helper.download_handler()->Reset(); | 1091 delegate.download_handler()->Reset(); |
| 1141 | 1092 |
| 1142 ASSERT_LT(0u, driver.num_notifications()); | 1093 ASSERT_LT(0u, delegate.num_notifications()); |
| 1143 ASSERT_EQ(kIconURL1, driver.icon_url()); | 1094 ASSERT_EQ(kIconURL1, delegate.icon_url()); |
| 1144 | 1095 |
| 1145 // Clear the history handler because SetHistoryFavicons() sets it. | 1096 // Clear the history handler because SetHistoryFavicons() sets it. |
| 1146 helper.set_history_handler(nullptr); | 1097 helper.set_history_handler(nullptr); |
| 1147 | 1098 |
| 1148 // Simulate the page changing it's icon URL to just |kIconURL2| via | 1099 // Simulate the page changing it's icon URL to just |kIconURL2| via |
| 1149 // Javascript. | 1100 // Javascript. |
| 1150 helper.OnUpdateFaviconURL( | 1101 helper.OnUpdateFaviconURL( |
| 1151 kPageURL, | 1102 kPageURL, |
| 1152 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON, | 1103 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON, |
| 1153 std::vector<gfx::Size>()))); | 1104 std::vector<gfx::Size>()))); |
| 1154 | 1105 |
| 1155 // FaviconHandler should request from history and download |kIconURL2|. A | 1106 // FaviconHandler should request from history and download |kIconURL2|. A |
| 1156 // FaviconDriver::OnFaviconUpdated() notification should be sent for | 1107 // FaviconDriver::OnFaviconUpdated() notification should be sent for |
| 1157 // |kIconURL2|. | 1108 // |kIconURL2|. |
| 1158 driver.ResetNumNotifications(); | 1109 delegate.ResetNumNotifications(); |
| 1159 ASSERT_TRUE(helper.history_handler()); | 1110 ASSERT_TRUE(helper.history_handler()); |
| 1160 SetFaviconRawBitmapResult(kIconURL2, | 1111 SetFaviconRawBitmapResult(kIconURL2, |
| 1161 favicon_base::FAVICON, | 1112 favicon_base::FAVICON, |
| 1162 true /* expired */, | 1113 true /* expired */, |
| 1163 &helper.history_handler()->history_results_); | 1114 &helper.history_handler()->history_results_); |
| 1164 helper.history_handler()->InvokeCallback(); | 1115 helper.history_handler()->InvokeCallback(); |
| 1165 helper.set_history_handler(nullptr); | 1116 helper.set_history_handler(nullptr); |
| 1166 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1117 ASSERT_TRUE(delegate.download_handler()->HasDownload()); |
| 1167 helper.download_handler()->InvokeCallback(); | 1118 delegate.download_handler()->InvokeCallback(); |
| 1168 helper.download_handler()->Reset(); | 1119 delegate.download_handler()->Reset(); |
| 1169 ASSERT_LT(0u, driver.num_notifications()); | 1120 ASSERT_LT(0u, delegate.num_notifications()); |
| 1170 EXPECT_EQ(kIconURL2, driver.icon_url()); | 1121 EXPECT_EQ(kIconURL2, delegate.icon_url()); |
| 1171 } | 1122 } |
| 1172 | 1123 |
| 1173 // Test the favicon which is selected when the web page provides several | 1124 // Test the favicon which is selected when the web page provides several |
| 1174 // favicons and none of the favicons are cached in history. | 1125 // favicons and none of the favicons are cached in history. |
| 1175 // The goal of this test is to be more of an integration test than | 1126 // The goal of this test is to be more of an integration test than |
| 1176 // SelectFaviconFramesTest.*. | 1127 // SelectFaviconFramesTest.*. |
| 1177 TEST_F(FaviconHandlerTest, MultipleFavicons) { | 1128 TEST_F(FaviconHandlerTest, MultipleFavicons) { |
| 1178 const GURL kPageURL("http://www.google.com"); | 1129 const GURL kPageURL("http://www.google.com"); |
| 1179 const FaviconURL kSourceIconURLs[] = { | 1130 const FaviconURL kSourceIconURLs[] = { |
| 1180 FaviconURL(GURL("http://www.google.com/a"), | 1131 FaviconURL(GURL("http://www.google.com/a"), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1195 | 1146 |
| 1196 // Set the supported scale factors to 1x and 2x. This affects the behavior of | 1147 // Set the supported scale factors to 1x and 2x. This affects the behavior of |
| 1197 // SelectFaviconFrames(). | 1148 // SelectFaviconFrames(). |
| 1198 std::vector<ui::ScaleFactor> scale_factors; | 1149 std::vector<ui::ScaleFactor> scale_factors; |
| 1199 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1150 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 1200 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1151 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
| 1201 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1152 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
| 1202 | 1153 |
| 1203 // 1) Test that if there are several single resolution favicons to choose from | 1154 // 1) Test that if there are several single resolution favicons to choose from |
| 1204 // that the largest exact match is chosen. | 1155 // that the largest exact match is chosen. |
| 1205 TestFaviconDriver driver1; | 1156 TestDelegate delegate1; |
| 1206 TestFaviconHandler handler1(&driver1, | 1157 TestFaviconHandler handler1(&delegate1, |
| 1207 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1158 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1208 | 1159 |
| 1209 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1160 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
| 1210 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1161 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1211 kSourceIconURLs + arraysize(kSizes1)); | 1162 kSourceIconURLs + arraysize(kSizes1)); |
| 1212 DownloadTillDoneIgnoringHistory( | 1163 DownloadTillDoneIgnoringHistory(&delegate1, &handler1, kPageURL, urls1, |
| 1213 &driver1, &handler1, kPageURL, urls1, kSizes1); | 1164 kSizes1); |
| 1214 | 1165 |
| 1215 EXPECT_EQ(nullptr, handler1.current_candidate()); | 1166 EXPECT_EQ(nullptr, handler1.current_candidate()); |
| 1216 EXPECT_EQ(1u, driver1.num_notifications()); | 1167 EXPECT_EQ(1u, delegate1.num_notifications()); |
| 1217 EXPECT_FALSE(driver1.image().IsEmpty()); | 1168 EXPECT_FALSE(delegate1.image().IsEmpty()); |
| 1218 EXPECT_EQ(gfx::kFaviconSize, driver1.image().Width()); | 1169 EXPECT_EQ(gfx::kFaviconSize, delegate1.image().Width()); |
| 1219 | 1170 |
| 1220 size_t expected_index = 2u; | 1171 size_t expected_index = 2u; |
| 1221 EXPECT_EQ(32, kSizes1[expected_index]); | 1172 EXPECT_EQ(32, kSizes1[expected_index]); |
| 1222 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver1.icon_url()); | 1173 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate1.icon_url()); |
| 1223 | 1174 |
| 1224 // 2) Test that if there are several single resolution favicons to choose | 1175 // 2) Test that if there are several single resolution favicons to choose |
| 1225 // from, the exact match is preferred even if it results in upsampling. | 1176 // from, the exact match is preferred even if it results in upsampling. |
| 1226 TestFaviconDriver driver2; | 1177 TestDelegate delegate2; |
| 1227 TestFaviconHandler handler2(&driver2, | 1178 TestFaviconHandler handler2(&delegate2, |
| 1228 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1179 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1229 | 1180 |
| 1230 const int kSizes2[] = { 16, 24, 48, 256 }; | 1181 const int kSizes2[] = { 16, 24, 48, 256 }; |
| 1231 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1182 std::vector<FaviconURL> urls2(kSourceIconURLs, |
| 1232 kSourceIconURLs + arraysize(kSizes2)); | 1183 kSourceIconURLs + arraysize(kSizes2)); |
| 1233 DownloadTillDoneIgnoringHistory( | 1184 DownloadTillDoneIgnoringHistory(&delegate2, &handler2, kPageURL, urls2, |
| 1234 &driver2, &handler2, kPageURL, urls2, kSizes2); | 1185 kSizes2); |
| 1235 EXPECT_EQ(1u, driver2.num_notifications()); | 1186 EXPECT_EQ(1u, delegate2.num_notifications()); |
| 1236 expected_index = 0u; | 1187 expected_index = 0u; |
| 1237 EXPECT_EQ(16, kSizes2[expected_index]); | 1188 EXPECT_EQ(16, kSizes2[expected_index]); |
| 1238 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver2.icon_url()); | 1189 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate2.icon_url()); |
| 1239 | 1190 |
| 1240 // 3) Test that favicons which need to be upsampled a little or downsampled | 1191 // 3) Test that favicons which need to be upsampled a little or downsampled |
| 1241 // a little are preferred over huge favicons. | 1192 // a little are preferred over huge favicons. |
| 1242 TestFaviconDriver driver3; | 1193 TestDelegate delegate3; |
| 1243 TestFaviconHandler handler3(&driver3, | 1194 TestFaviconHandler handler3(&delegate3, |
| 1244 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1195 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1245 | 1196 |
| 1246 const int kSizes3[] = { 256, 48 }; | 1197 const int kSizes3[] = { 256, 48 }; |
| 1247 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1198 std::vector<FaviconURL> urls3(kSourceIconURLs, |
| 1248 kSourceIconURLs + arraysize(kSizes3)); | 1199 kSourceIconURLs + arraysize(kSizes3)); |
| 1249 DownloadTillDoneIgnoringHistory( | 1200 DownloadTillDoneIgnoringHistory(&delegate3, &handler3, kPageURL, urls3, |
| 1250 &driver3, &handler3, kPageURL, urls3, kSizes3); | 1201 kSizes3); |
| 1251 EXPECT_EQ(1u, driver3.num_notifications()); | 1202 EXPECT_EQ(1u, delegate3.num_notifications()); |
| 1252 expected_index = 1u; | 1203 expected_index = 1u; |
| 1253 EXPECT_EQ(48, kSizes3[expected_index]); | 1204 EXPECT_EQ(48, kSizes3[expected_index]); |
| 1254 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url()); | 1205 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate3.icon_url()); |
| 1255 | 1206 |
| 1256 TestFaviconDriver driver4; | 1207 TestDelegate delegate4; |
| 1257 TestFaviconHandler handler4(&driver4, | 1208 TestFaviconHandler handler4(&delegate4, |
| 1258 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1209 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1259 | 1210 |
| 1260 const int kSizes4[] = { 17, 256 }; | 1211 const int kSizes4[] = { 17, 256 }; |
| 1261 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1212 std::vector<FaviconURL> urls4(kSourceIconURLs, |
| 1262 kSourceIconURLs + arraysize(kSizes4)); | 1213 kSourceIconURLs + arraysize(kSizes4)); |
| 1263 DownloadTillDoneIgnoringHistory( | 1214 DownloadTillDoneIgnoringHistory(&delegate4, &handler4, kPageURL, urls4, |
| 1264 &driver4, &handler4, kPageURL, urls4, kSizes4); | 1215 kSizes4); |
| 1265 EXPECT_EQ(1u, driver4.num_notifications()); | 1216 EXPECT_EQ(1u, delegate4.num_notifications()); |
| 1266 expected_index = 0u; | 1217 expected_index = 0u; |
| 1267 EXPECT_EQ(17, kSizes4[expected_index]); | 1218 EXPECT_EQ(17, kSizes4[expected_index]); |
| 1268 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver4.icon_url()); | 1219 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate4.icon_url()); |
| 1269 } | 1220 } |
| 1270 | 1221 |
| 1271 // Test that the best favicon is selected when: | 1222 // Test that the best favicon is selected when: |
| 1272 // - The page provides several favicons. | 1223 // - The page provides several favicons. |
| 1273 // - Downloading one of the page's icon URLs previously returned a 404. | 1224 // - Downloading one of the page's icon URLs previously returned a 404. |
| 1274 // - None of the favicons are cached in the Favicons database. | 1225 // - None of the favicons are cached in the Favicons database. |
| 1275 TEST_F(FaviconHandlerTest, MultipleFavicons404) { | 1226 TEST_F(FaviconHandlerTest, MultipleFavicons404) { |
| 1276 const GURL kPageURL("http://www.google.com"); | 1227 const GURL kPageURL("http://www.google.com"); |
| 1277 const GURL k404IconURL("http://www.google.com/404.png"); | 1228 const GURL k404IconURL("http://www.google.com/404.png"); |
| 1278 const FaviconURL k404FaviconURL( | 1229 const FaviconURL k404FaviconURL( |
| 1279 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>()); | 1230 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>()); |
| 1280 const FaviconURL kFaviconURLs[] = { | 1231 const FaviconURL kFaviconURLs[] = { |
| 1281 FaviconURL(GURL("http://www.google.com/a"), | 1232 FaviconURL(GURL("http://www.google.com/a"), |
| 1282 favicon_base::FAVICON, | 1233 favicon_base::FAVICON, |
| 1283 std::vector<gfx::Size>()), | 1234 std::vector<gfx::Size>()), |
| 1284 k404FaviconURL, | 1235 k404FaviconURL, |
| 1285 FaviconURL(GURL("http://www.google.com/c"), | 1236 FaviconURL(GURL("http://www.google.com/c"), |
| 1286 favicon_base::FAVICON, | 1237 favicon_base::FAVICON, |
| 1287 std::vector<gfx::Size>()), | 1238 std::vector<gfx::Size>()), |
| 1288 }; | 1239 }; |
| 1289 | 1240 |
| 1290 TestFaviconDriver driver; | 1241 TestDelegate delegate; |
| 1291 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1242 TestFaviconHandler handler(&delegate, |
| 1292 DownloadHandler* download_handler = handler.download_handler(); | 1243 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1244 DownloadHandler* download_handler = delegate.download_handler(); |
| 1293 | 1245 |
| 1294 std::set<GURL> k404URLs; | 1246 std::set<GURL> k404URLs; |
| 1295 k404URLs.insert(k404IconURL); | 1247 k404URLs.insert(k404IconURL); |
| 1296 download_handler->FailDownloadForIconURLs(k404URLs); | 1248 download_handler->FailDownloadForIconURLs(k404URLs); |
| 1297 | 1249 |
| 1298 // Make the initial download for |k404IconURL| fail. | 1250 // Make the initial download for |k404IconURL| fail. |
| 1299 const int kSizes1[] = { 0 }; | 1251 const int kSizes1[] = { 0 }; |
| 1300 std::vector<FaviconURL> urls1(1u, k404FaviconURL); | 1252 std::vector<FaviconURL> urls1(1u, k404FaviconURL); |
| 1301 DownloadTillDoneIgnoringHistory( | 1253 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls1, |
| 1302 &driver, &handler, kPageURL, urls1, kSizes1); | 1254 kSizes1); |
| 1303 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); | 1255 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); |
| 1304 | 1256 |
| 1305 // Do a fetch now that the initial download for |k404IconURL| has failed. The | 1257 // Do a fetch now that the initial download for |k404IconURL| has failed. The |
| 1306 // behavior is different because OnDidDownloadFavicon() is invoked | 1258 // behavior is different because OnDidDownloadFavicon() is invoked |
| 1307 // synchronously from DownloadFavicon(). | 1259 // synchronously from DownloadFavicon(). |
| 1308 const int kSizes2[] = { 10, 0, 16 }; | 1260 const int kSizes2[] = { 10, 0, 16 }; |
| 1309 std::vector<FaviconURL> urls2(kFaviconURLs, | 1261 std::vector<FaviconURL> urls2(kFaviconURLs, |
| 1310 kFaviconURLs + arraysize(kFaviconURLs)); | 1262 kFaviconURLs + arraysize(kFaviconURLs)); |
| 1311 DownloadTillDoneIgnoringHistory( | 1263 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls2, |
| 1312 &driver, &handler, kPageURL, urls2, kSizes2); | 1264 kSizes2); |
| 1313 | 1265 |
| 1314 EXPECT_EQ(nullptr, handler.current_candidate()); | 1266 EXPECT_EQ(nullptr, handler.current_candidate()); |
| 1315 EXPECT_EQ(1u, driver.num_notifications()); | 1267 EXPECT_EQ(1u, delegate.num_notifications()); |
| 1316 EXPECT_FALSE(driver.image().IsEmpty()); | 1268 EXPECT_FALSE(delegate.image().IsEmpty()); |
| 1317 int expected_index = 2u; | 1269 int expected_index = 2u; |
| 1318 EXPECT_EQ(16, kSizes2[expected_index]); | 1270 EXPECT_EQ(16, kSizes2[expected_index]); |
| 1319 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, driver.icon_url()); | 1271 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, delegate.icon_url()); |
| 1320 } | 1272 } |
| 1321 | 1273 |
| 1322 // Test that no favicon is selected when: | 1274 // Test that no favicon is selected when: |
| 1323 // - The page provides several favicons. | 1275 // - The page provides several favicons. |
| 1324 // - Downloading the page's icons has previously returned a 404. | 1276 // - Downloading the page's icons has previously returned a 404. |
| 1325 // - None of the favicons are cached in the Favicons database. | 1277 // - None of the favicons are cached in the Favicons database. |
| 1326 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { | 1278 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { |
| 1327 const GURL kPageURL("http://www.google.com"); | 1279 const GURL kPageURL("http://www.google.com"); |
| 1328 const GURL k404IconURL1("http://www.google.com/4041.png"); | 1280 const GURL k404IconURL1("http://www.google.com/4041.png"); |
| 1329 const GURL k404IconURL2("http://www.google.com/4042.png"); | 1281 const GURL k404IconURL2("http://www.google.com/4042.png"); |
| 1330 const FaviconURL kFaviconURLs[] = { | 1282 const FaviconURL kFaviconURLs[] = { |
| 1331 FaviconURL(k404IconURL1, | 1283 FaviconURL(k404IconURL1, |
| 1332 favicon_base::FAVICON, | 1284 favicon_base::FAVICON, |
| 1333 std::vector<gfx::Size>()), | 1285 std::vector<gfx::Size>()), |
| 1334 FaviconURL(k404IconURL2, | 1286 FaviconURL(k404IconURL2, |
| 1335 favicon_base::FAVICON, | 1287 favicon_base::FAVICON, |
| 1336 std::vector<gfx::Size>()), | 1288 std::vector<gfx::Size>()), |
| 1337 }; | 1289 }; |
| 1338 | 1290 |
| 1339 TestFaviconDriver driver; | 1291 TestDelegate delegate; |
| 1340 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1292 TestFaviconHandler handler(&delegate, |
| 1341 DownloadHandler* download_handler = handler.download_handler(); | 1293 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1294 DownloadHandler* download_handler = delegate.download_handler(); |
| 1342 | 1295 |
| 1343 std::set<GURL> k404URLs; | 1296 std::set<GURL> k404URLs; |
| 1344 k404URLs.insert(k404IconURL1); | 1297 k404URLs.insert(k404IconURL1); |
| 1345 k404URLs.insert(k404IconURL2); | 1298 k404URLs.insert(k404IconURL2); |
| 1346 download_handler->FailDownloadForIconURLs(k404URLs); | 1299 download_handler->FailDownloadForIconURLs(k404URLs); |
| 1347 | 1300 |
| 1348 // Make the initial downloads for |kFaviconURLs| fail. | 1301 // Make the initial downloads for |kFaviconURLs| fail. |
| 1349 for (const FaviconURL& favicon_url : kFaviconURLs) { | 1302 for (const FaviconURL& favicon_url : kFaviconURLs) { |
| 1350 const int kSizes[] = { 0 }; | 1303 const int kSizes[] = { 0 }; |
| 1351 std::vector<FaviconURL> urls(1u, favicon_url); | 1304 std::vector<FaviconURL> urls(1u, favicon_url); |
| 1352 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); | 1305 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls, |
| 1306 kSizes); |
| 1353 } | 1307 } |
| 1354 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); | 1308 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); |
| 1355 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); | 1309 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); |
| 1356 | 1310 |
| 1357 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. | 1311 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. |
| 1358 // The behavior is different because OnDidDownloadFavicon() is invoked | 1312 // The behavior is different because OnDidDownloadFavicon() is invoked |
| 1359 // synchronously from DownloadFavicon(). | 1313 // synchronously from DownloadFavicon(). |
| 1360 const int kSizes[] = { 0, 0 }; | 1314 const int kSizes[] = { 0, 0 }; |
| 1361 std::vector<FaviconURL> urls(kFaviconURLs, | 1315 std::vector<FaviconURL> urls(kFaviconURLs, |
| 1362 kFaviconURLs + arraysize(kFaviconURLs)); | 1316 kFaviconURLs + arraysize(kFaviconURLs)); |
| 1363 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); | 1317 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls, kSizes); |
| 1364 | 1318 |
| 1365 EXPECT_EQ(nullptr, handler.current_candidate()); | 1319 EXPECT_EQ(nullptr, handler.current_candidate()); |
| 1366 EXPECT_EQ(0u, driver.num_notifications()); | 1320 EXPECT_EQ(0u, delegate.num_notifications()); |
| 1367 EXPECT_TRUE(driver.image().IsEmpty()); | 1321 EXPECT_TRUE(delegate.image().IsEmpty()); |
| 1368 } | 1322 } |
| 1369 | 1323 |
| 1370 // Test that no favicon is selected when the page's only icon uses an invalid | 1324 // Test that no favicon is selected when the page's only icon uses an invalid |
| 1371 // URL syntax. | 1325 // URL syntax. |
| 1372 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { | 1326 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { |
| 1373 const GURL kPageURL("http://www.google.com"); | 1327 const GURL kPageURL("http://www.google.com"); |
| 1374 const GURL kInvalidFormatURL("invalid"); | 1328 const GURL kInvalidFormatURL("invalid"); |
| 1375 ASSERT_TRUE(kInvalidFormatURL.is_empty()); | 1329 ASSERT_TRUE(kInvalidFormatURL.is_empty()); |
| 1376 | 1330 |
| 1377 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, | 1331 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, |
| 1378 std::vector<gfx::Size>()); | 1332 std::vector<gfx::Size>()); |
| 1379 | 1333 |
| 1380 TestFaviconDriver driver; | 1334 TestDelegate delegate; |
| 1381 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1335 TestFaviconHandler handler(&delegate, |
| 1382 UpdateFaviconURL(&driver, &handler, kPageURL, | 1336 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1337 UpdateFaviconURL(&delegate, &handler, kPageURL, |
| 1383 std::vector<FaviconURL>(1u, favicon_url)); | 1338 std::vector<FaviconURL>(1u, favicon_url)); |
| 1384 EXPECT_EQ(0u, handler.image_urls().size()); | 1339 EXPECT_EQ(0u, handler.image_urls().size()); |
| 1385 } | 1340 } |
| 1386 | 1341 |
| 1387 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 1342 TEST_F(FaviconHandlerTest, TestSortFavicon) { |
| 1388 const GURL kPageURL("http://www.google.com"); | 1343 const GURL kPageURL("http://www.google.com"); |
| 1389 std::vector<gfx::Size> icon1; | 1344 std::vector<gfx::Size> icon1; |
| 1390 icon1.push_back(gfx::Size(1024, 1024)); | 1345 icon1.push_back(gfx::Size(1024, 1024)); |
| 1391 icon1.push_back(gfx::Size(512, 512)); | 1346 icon1.push_back(gfx::Size(512, 512)); |
| 1392 | 1347 |
| 1393 std::vector<gfx::Size> icon2; | 1348 std::vector<gfx::Size> icon2; |
| 1394 icon2.push_back(gfx::Size(15, 15)); | 1349 icon2.push_back(gfx::Size(15, 15)); |
| 1395 icon2.push_back(gfx::Size(16, 16)); | 1350 icon2.push_back(gfx::Size(16, 16)); |
| 1396 | 1351 |
| 1397 std::vector<gfx::Size> icon3; | 1352 std::vector<gfx::Size> icon3; |
| 1398 icon3.push_back(gfx::Size(16, 16)); | 1353 icon3.push_back(gfx::Size(16, 16)); |
| 1399 icon3.push_back(gfx::Size(14, 14)); | 1354 icon3.push_back(gfx::Size(14, 14)); |
| 1400 | 1355 |
| 1401 const FaviconURL kSourceIconURLs[] = { | 1356 const FaviconURL kSourceIconURLs[] = { |
| 1402 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, icon1), | 1357 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, icon1), |
| 1403 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), | 1358 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
| 1404 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1359 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
| 1405 FaviconURL(GURL("http://www.google.com/d"), | 1360 FaviconURL(GURL("http://www.google.com/d"), |
| 1406 favicon_base::FAVICON, | 1361 favicon_base::FAVICON, |
| 1407 std::vector<gfx::Size>()), | 1362 std::vector<gfx::Size>()), |
| 1408 FaviconURL(GURL("http://www.google.com/e"), | 1363 FaviconURL(GURL("http://www.google.com/e"), |
| 1409 favicon_base::FAVICON, | 1364 favicon_base::FAVICON, |
| 1410 std::vector<gfx::Size>())}; | 1365 std::vector<gfx::Size>())}; |
| 1411 | 1366 |
| 1412 TestFaviconDriver driver1; | 1367 TestDelegate delegate1; |
| 1413 TestFaviconHandler handler1(&driver1, | 1368 TestFaviconHandler handler1(&delegate1, |
| 1414 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1369 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1415 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1370 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1416 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1371 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1417 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1372 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
| 1418 | 1373 |
| 1419 struct ExpectedResult { | 1374 struct ExpectedResult { |
| 1420 // The favicon's index in kSourceIconURLs. | 1375 // The favicon's index in kSourceIconURLs. |
| 1421 size_t favicon_index; | 1376 size_t favicon_index; |
| 1422 // Width of largest bitmap. | 1377 // Width of largest bitmap. |
| 1423 int width; | 1378 int width; |
| 1424 } results[] = { | 1379 } results[] = { |
| 1425 // First is icon1, though its size larger than maximal. | 1380 // First is icon1, though its size larger than maximal. |
| 1426 {0, 1024}, | 1381 {0, 1024}, |
| 1427 // Second is icon2 | 1382 // Second is icon2 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), | 1420 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
| 1466 FaviconURL( | 1421 FaviconURL( |
| 1467 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1422 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
| 1468 FaviconURL(GURL("http://www.google.com/d"), | 1423 FaviconURL(GURL("http://www.google.com/d"), |
| 1469 favicon_base::FAVICON, | 1424 favicon_base::FAVICON, |
| 1470 std::vector<gfx::Size>()), | 1425 std::vector<gfx::Size>()), |
| 1471 FaviconURL(GURL("http://www.google.com/e"), | 1426 FaviconURL(GURL("http://www.google.com/e"), |
| 1472 favicon_base::FAVICON, | 1427 favicon_base::FAVICON, |
| 1473 std::vector<gfx::Size>())}; | 1428 std::vector<gfx::Size>())}; |
| 1474 | 1429 |
| 1475 TestFaviconDriver driver1; | 1430 TestDelegate delegate1; |
| 1476 TestFaviconHandler handler1(&driver1, | 1431 TestFaviconHandler handler1(&delegate1, |
| 1477 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1432 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1478 | 1433 |
| 1479 std::set<GURL> fail_icon_urls; | 1434 std::set<GURL> fail_icon_urls; |
| 1480 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { | 1435 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { |
| 1481 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); | 1436 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); |
| 1482 } | 1437 } |
| 1483 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); | 1438 delegate1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); |
| 1484 | 1439 |
| 1485 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1440 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1486 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1441 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1487 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1442 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
| 1488 | 1443 |
| 1489 // Simulate the download failed, to check whether the icons were requested | 1444 // Simulate the download failed, to check whether the icons were requested |
| 1490 // to download according their size. | 1445 // to download according their size. |
| 1491 struct ExpectedResult { | 1446 struct ExpectedResult { |
| 1492 // The favicon's index in kSourceIconURLs. | 1447 // The favicon's index in kSourceIconURLs. |
| 1493 size_t favicon_index; | 1448 size_t favicon_index; |
| 1494 // Width of largest bitmap. | 1449 // Width of largest bitmap. |
| 1495 int width; | 1450 int width; |
| 1496 } results[] = { | 1451 } results[] = { |
| 1497 {0, 1024}, | 1452 {0, 1024}, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1508 if (results[i].width != -1) { | 1463 if (results[i].width != -1) { |
| 1509 EXPECT_EQ(results[i].width, handler1.current_candidate()-> | 1464 EXPECT_EQ(results[i].width, handler1.current_candidate()-> |
| 1510 icon_sizes[0].width()); | 1465 icon_sizes[0].width()); |
| 1511 } | 1466 } |
| 1512 | 1467 |
| 1513 // Simulate no favicon from history. | 1468 // Simulate no favicon from history. |
| 1514 handler1.history_handler()->history_results_.clear(); | 1469 handler1.history_handler()->history_results_.clear(); |
| 1515 handler1.history_handler()->InvokeCallback(); | 1470 handler1.history_handler()->InvokeCallback(); |
| 1516 | 1471 |
| 1517 // Verify download request | 1472 // Verify download request |
| 1518 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1473 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
| 1519 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, | 1474 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, |
| 1520 handler1.download_handler()->GetImageUrl()); | 1475 delegate1.download_handler()->GetImageUrl()); |
| 1521 | 1476 |
| 1522 handler1.download_handler()->InvokeCallback(); | 1477 delegate1.download_handler()->InvokeCallback(); |
| 1523 handler1.download_handler()->Reset(); | 1478 delegate1.download_handler()->Reset(); |
| 1524 } | 1479 } |
| 1525 } | 1480 } |
| 1526 | 1481 |
| 1527 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { | 1482 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { |
| 1528 const GURL kPageURL("http://www.google.com"); | 1483 const GURL kPageURL("http://www.google.com"); |
| 1529 | 1484 |
| 1530 std::vector<gfx::Size> one_icon; | 1485 std::vector<gfx::Size> one_icon; |
| 1531 one_icon.push_back(gfx::Size(15, 15)); | 1486 one_icon.push_back(gfx::Size(15, 15)); |
| 1532 | 1487 |
| 1533 std::vector<gfx::Size> two_icons; | 1488 std::vector<gfx::Size> two_icons; |
| 1534 two_icons.push_back(gfx::Size(14, 14)); | 1489 two_icons.push_back(gfx::Size(14, 14)); |
| 1535 two_icons.push_back(gfx::Size(16, 16)); | 1490 two_icons.push_back(gfx::Size(16, 16)); |
| 1536 | 1491 |
| 1537 const FaviconURL kSourceIconURLs[] = { | 1492 const FaviconURL kSourceIconURLs[] = { |
| 1538 FaviconURL( | 1493 FaviconURL( |
| 1539 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), | 1494 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), |
| 1540 FaviconURL( | 1495 FaviconURL( |
| 1541 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; | 1496 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; |
| 1542 | 1497 |
| 1543 TestFaviconDriver driver1; | 1498 TestDelegate delegate1; |
| 1544 TestFaviconHandler handler1(&driver1, | 1499 TestFaviconHandler handler1(&delegate1, |
| 1545 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1500 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1546 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1501 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1547 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1502 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1548 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1503 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
| 1549 | 1504 |
| 1550 ASSERT_EQ(2u, handler1.image_urls().size()); | 1505 ASSERT_EQ(2u, handler1.image_urls().size()); |
| 1551 | 1506 |
| 1552 // Index of largest favicon in kSourceIconURLs. | 1507 // Index of largest favicon in kSourceIconURLs. |
| 1553 size_t i = 1; | 1508 size_t i = 1; |
| 1554 // The largest bitmap's index in Favicon . | 1509 // The largest bitmap's index in Favicon . |
| 1555 int b = 1; | 1510 int b = 1; |
| 1556 | 1511 |
| 1557 // Verify the icon_bitmaps_ was initialized correctly. | 1512 // Verify the icon_bitmaps_ was initialized correctly. |
| 1558 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1513 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
| 1559 handler1.current_candidate()->icon_url); | 1514 handler1.current_candidate()->icon_url); |
| 1560 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1515 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
| 1561 handler1.current_candidate()->icon_sizes[0]); | 1516 handler1.current_candidate()->icon_sizes[0]); |
| 1562 | 1517 |
| 1563 // Simulate no favicon from history. | 1518 // Simulate no favicon from history. |
| 1564 handler1.history_handler()->history_results_.clear(); | 1519 handler1.history_handler()->history_results_.clear(); |
| 1565 handler1.history_handler()->InvokeCallback(); | 1520 handler1.history_handler()->InvokeCallback(); |
| 1566 | 1521 |
| 1567 // Verify download request | 1522 // Verify download request |
| 1568 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1523 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
| 1569 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1524 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
| 1570 handler1.download_handler()->GetImageUrl()); | 1525 delegate1.download_handler()->GetImageUrl()); |
| 1571 | 1526 |
| 1572 // Give the correct download result. | 1527 // Give the correct download result. |
| 1573 std::vector<int> sizes; | 1528 std::vector<int> sizes; |
| 1574 for (std::vector<gfx::Size>::const_iterator j = | 1529 for (std::vector<gfx::Size>::const_iterator j = |
| 1575 kSourceIconURLs[i].icon_sizes.begin(); | 1530 kSourceIconURLs[i].icon_sizes.begin(); |
| 1576 j != kSourceIconURLs[i].icon_sizes.end(); ++j) | 1531 j != kSourceIconURLs[i].icon_sizes.end(); ++j) |
| 1577 sizes.push_back(j->width()); | 1532 sizes.push_back(j->width()); |
| 1578 | 1533 |
| 1579 handler1.download_handler()->SetImageSizes(sizes); | 1534 delegate1.download_handler()->SetImageSizes(sizes); |
| 1580 handler1.download_handler()->InvokeCallback(); | 1535 delegate1.download_handler()->InvokeCallback(); |
| 1581 | 1536 |
| 1582 // Verify the largest bitmap has been saved into history. | 1537 // Verify the largest bitmap has been saved into history. |
| 1583 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1538 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
| 1584 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1539 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
| 1585 handler1.history_handler()->size_); | 1540 handler1.history_handler()->size_); |
| 1586 // Verify NotifyFaviconAvailable(). | 1541 // Verify NotifyFaviconAvailable(). |
| 1587 EXPECT_EQ(1u, driver1.num_notifications()); | 1542 EXPECT_EQ(1u, delegate1.num_notifications()); |
| 1588 EXPECT_EQ(kSourceIconURLs[i].icon_url, driver1.icon_url()); | 1543 EXPECT_EQ(kSourceIconURLs[i].icon_url, delegate1.icon_url()); |
| 1589 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], driver1.image().Size()); | 1544 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], delegate1.image().Size()); |
| 1590 } | 1545 } |
| 1591 | 1546 |
| 1592 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1547 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
| 1593 const GURL kPageURL("http://www.google.com"); | 1548 const GURL kPageURL("http://www.google.com"); |
| 1594 const int kMaximalSize = | 1549 const int kMaximalSize = |
| 1595 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); | 1550 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); |
| 1596 | 1551 |
| 1597 std::vector<gfx::Size> icon1; | 1552 std::vector<gfx::Size> icon1; |
| 1598 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); | 1553 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); |
| 1599 | 1554 |
| 1600 std::vector<gfx::Size> icon2; | 1555 std::vector<gfx::Size> icon2; |
| 1601 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); | 1556 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); |
| 1602 | 1557 |
| 1603 const FaviconURL kSourceIconURLs[] = { | 1558 const FaviconURL kSourceIconURLs[] = { |
| 1604 FaviconURL( | 1559 FaviconURL( |
| 1605 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1560 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
| 1606 FaviconURL( | 1561 FaviconURL( |
| 1607 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; | 1562 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; |
| 1608 | 1563 |
| 1609 TestFaviconDriver driver1; | 1564 TestDelegate delegate1; |
| 1610 TestFaviconHandler handler1(&driver1, | 1565 TestFaviconHandler handler1(&delegate1, |
| 1611 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1566 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1612 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1567 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1613 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1568 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1614 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1569 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
| 1615 | 1570 |
| 1616 ASSERT_EQ(2u, handler1.image_urls().size()); | 1571 ASSERT_EQ(2u, handler1.image_urls().size()); |
| 1617 | 1572 |
| 1618 // Index of largest favicon in kSourceIconURLs. | 1573 // Index of largest favicon in kSourceIconURLs. |
| 1619 size_t i = 1; | 1574 size_t i = 1; |
| 1620 // The largest bitmap's index in Favicon . | 1575 // The largest bitmap's index in Favicon . |
| 1621 int b = 0; | 1576 int b = 0; |
| 1622 | 1577 |
| 1623 // Verify the icon_bitmaps_ was initialized correctly. | 1578 // Verify the icon_bitmaps_ was initialized correctly. |
| 1624 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1579 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
| 1625 handler1.current_candidate()->icon_url); | 1580 handler1.current_candidate()->icon_url); |
| 1626 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1581 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
| 1627 handler1.current_candidate()->icon_sizes[0]); | 1582 handler1.current_candidate()->icon_sizes[0]); |
| 1628 | 1583 |
| 1629 // Simulate no favicon from history. | 1584 // Simulate no favicon from history. |
| 1630 handler1.history_handler()->history_results_.clear(); | 1585 handler1.history_handler()->history_results_.clear(); |
| 1631 handler1.history_handler()->InvokeCallback(); | 1586 handler1.history_handler()->InvokeCallback(); |
| 1632 | 1587 |
| 1633 // Verify download request | 1588 // Verify download request |
| 1634 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1589 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
| 1635 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1590 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
| 1636 handler1.download_handler()->GetImageUrl()); | 1591 delegate1.download_handler()->GetImageUrl()); |
| 1637 | 1592 |
| 1638 // Give the scaled download bitmap. | 1593 // Give the scaled download bitmap. |
| 1639 std::vector<int> sizes; | 1594 std::vector<int> sizes; |
| 1640 sizes.push_back(kMaximalSize); | 1595 sizes.push_back(kMaximalSize); |
| 1641 | 1596 |
| 1642 handler1.download_handler()->SetImageSizes(sizes); | 1597 delegate1.download_handler()->SetImageSizes(sizes); |
| 1643 handler1.download_handler()->InvokeCallback(); | 1598 delegate1.download_handler()->InvokeCallback(); |
| 1644 | 1599 |
| 1645 // Verify the largest bitmap has been saved into history though it was | 1600 // Verify the largest bitmap has been saved into history though it was |
| 1646 // scaled down to maximal size and smaller than icon1 now. | 1601 // scaled down to maximal size and smaller than icon1 now. |
| 1647 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1602 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
| 1648 EXPECT_EQ(gfx::Size(kMaximalSize, kMaximalSize), | 1603 EXPECT_EQ(gfx::Size(kMaximalSize, kMaximalSize), |
| 1649 handler1.history_handler()->size_); | 1604 handler1.history_handler()->size_); |
| 1650 } | 1605 } |
| 1651 | 1606 |
| 1652 TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) { | 1607 TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) { |
| 1653 const GURL kPageURL("http://www.google.com"); | 1608 const GURL kPageURL("http://www.google.com"); |
| 1654 | 1609 |
| 1655 std::vector<gfx::Size> icon1; | 1610 std::vector<gfx::Size> icon1; |
| 1656 icon1.push_back(gfx::Size(16, 16)); | 1611 icon1.push_back(gfx::Size(16, 16)); |
| 1657 const int actual_size1 = 10; | 1612 const int actual_size1 = 10; |
| 1658 | 1613 |
| 1659 std::vector<gfx::Size> icon2; | 1614 std::vector<gfx::Size> icon2; |
| 1660 icon2.push_back(gfx::Size(15, 15)); | 1615 icon2.push_back(gfx::Size(15, 15)); |
| 1661 const int actual_size2 = 12; | 1616 const int actual_size2 = 12; |
| 1662 | 1617 |
| 1663 const FaviconURL kSourceIconURLs[] = { | 1618 const FaviconURL kSourceIconURLs[] = { |
| 1664 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1619 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
| 1665 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), | 1620 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), |
| 1666 FaviconURL(GURL("http://www.google.com/d"), | 1621 FaviconURL(GURL("http://www.google.com/d"), |
| 1667 favicon_base::FAVICON, | 1622 favicon_base::FAVICON, |
| 1668 std::vector<gfx::Size>())}; | 1623 std::vector<gfx::Size>())}; |
| 1669 | 1624 |
| 1670 TestFaviconDriver driver1; | 1625 TestDelegate delegate1; |
| 1671 TestFaviconHandler handler1(&driver1, | 1626 TestFaviconHandler handler1(&delegate1, |
| 1672 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1627 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1673 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1628 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1674 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1629 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1675 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1630 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); |
| 1676 ASSERT_EQ(3u, handler1.image_urls().size()); | 1631 ASSERT_EQ(3u, handler1.image_urls().size()); |
| 1677 | 1632 |
| 1678 // Simulate no favicon from history. | 1633 // Simulate no favicon from history. |
| 1679 handler1.history_handler()->history_results_.clear(); | 1634 handler1.history_handler()->history_results_.clear(); |
| 1680 handler1.history_handler()->InvokeCallback(); | 1635 handler1.history_handler()->InvokeCallback(); |
| 1681 | 1636 |
| 1682 // Verify the first icon was request to download | 1637 // Verify the first icon was request to download |
| 1683 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1638 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
| 1684 EXPECT_EQ(kSourceIconURLs[0].icon_url, | 1639 EXPECT_EQ(kSourceIconURLs[0].icon_url, |
| 1685 handler1.download_handler()->GetImageUrl()); | 1640 delegate1.download_handler()->GetImageUrl()); |
| 1686 | 1641 |
| 1687 // Give the incorrect size. | 1642 // Give the incorrect size. |
| 1688 std::vector<int> sizes; | 1643 std::vector<int> sizes; |
| 1689 sizes.push_back(actual_size1); | 1644 sizes.push_back(actual_size1); |
| 1690 handler1.download_handler()->SetImageSizes(sizes); | 1645 delegate1.download_handler()->SetImageSizes(sizes); |
| 1691 handler1.download_handler()->InvokeCallback(); | 1646 delegate1.download_handler()->InvokeCallback(); |
| 1692 handler1.download_handler()->Reset(); | 1647 delegate1.download_handler()->Reset(); |
| 1693 | 1648 |
| 1694 // Simulate no favicon from history. | 1649 // Simulate no favicon from history. |
| 1695 handler1.history_handler()->history_results_.clear(); | 1650 handler1.history_handler()->history_results_.clear(); |
| 1696 handler1.history_handler()->InvokeCallback(); | 1651 handler1.history_handler()->InvokeCallback(); |
| 1697 | 1652 |
| 1698 // Verify the 2nd icon was request to download | 1653 // Verify the 2nd icon was request to download |
| 1699 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1654 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); |
| 1700 EXPECT_EQ(kSourceIconURLs[1].icon_url, | 1655 EXPECT_EQ(kSourceIconURLs[1].icon_url, |
| 1701 handler1.download_handler()->GetImageUrl()); | 1656 delegate1.download_handler()->GetImageUrl()); |
| 1702 | 1657 |
| 1703 // Very the best candidate is icon1 | 1658 // Very the best candidate is icon1 |
| 1704 EXPECT_EQ(kSourceIconURLs[0].icon_url, | 1659 EXPECT_EQ(kSourceIconURLs[0].icon_url, |
| 1705 handler1.best_favicon_candidate().image_url); | 1660 handler1.best_favicon_candidate().image_url); |
| 1706 EXPECT_EQ(gfx::Size(actual_size1, actual_size1), | 1661 EXPECT_EQ(gfx::Size(actual_size1, actual_size1), |
| 1707 handler1.best_favicon_candidate().image.Size()); | 1662 handler1.best_favicon_candidate().image.Size()); |
| 1708 | 1663 |
| 1709 // Give the incorrect size. | 1664 // Give the incorrect size. |
| 1710 sizes.clear(); | 1665 sizes.clear(); |
| 1711 sizes.push_back(actual_size2); | 1666 sizes.push_back(actual_size2); |
| 1712 handler1.download_handler()->SetImageSizes(sizes); | 1667 delegate1.download_handler()->SetImageSizes(sizes); |
| 1713 handler1.download_handler()->InvokeCallback(); | 1668 delegate1.download_handler()->InvokeCallback(); |
| 1714 handler1.download_handler()->Reset(); | 1669 delegate1.download_handler()->Reset(); |
| 1715 | 1670 |
| 1716 // Verify icon2 has been saved into history. | 1671 // Verify icon2 has been saved into history. |
| 1717 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); | 1672 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); |
| 1718 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), | 1673 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), |
| 1719 handler1.history_handler()->size_); | 1674 handler1.history_handler()->size_); |
| 1720 } | 1675 } |
| 1721 | 1676 |
| 1722 } // namespace | 1677 } // namespace |
| 1723 } // namespace favicon | 1678 } // namespace favicon |
| OLD | NEW |