| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/favicon/favicon_handler.h" | 6 #include "chrome/browser/favicon/favicon_handler.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 9 #include "content/public/browser/invalidate_type.h" | 9 #include "content/public/browser/invalidate_type.h" |
| 10 #include "content/public/browser/navigation_entry.h" | 10 #include "content/public/browser/navigation_entry.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Fill the given data buffer with valid png data. | 40 // Fill the given data buffer with valid png data. |
| 41 void FillBitmap(int w, int h, std::vector<unsigned char>* output) { | 41 void FillBitmap(int w, int h, std::vector<unsigned char>* output) { |
| 42 SkBitmap bitmap; | 42 SkBitmap bitmap; |
| 43 FillDataToBitmap(w, h, &bitmap); | 43 FillDataToBitmap(w, h, &bitmap); |
| 44 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output); | 44 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void SetFaviconDataWithOneBitmap(const GURL& icon_url, |
| 48 history::FaviconData* favicon_data) { |
| 49 favicon_data->known_icon = true; |
| 50 favicon_data->icon_type = history::FAVICON; |
| 51 favicon_data->expired = false; |
| 52 |
| 53 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
| 54 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 55 history::FaviconDataElement element; |
| 56 element.bitmap_data = data; |
| 57 element.pixel_size = gfx::Size(); |
| 58 element.icon_url = icon_url; |
| 59 favicon_data->elements.push_back(element); |
| 60 } |
| 61 |
| 47 // This class is used to save the download request for verifying with test case. | 62 // This class is used to save the download request for verifying with test case. |
| 48 // It also will be used to invoke the onDidDownload callback. | 63 // It also will be used to invoke the onDidDownload callback. |
| 49 class DownloadHandler { | 64 class DownloadHandler { |
| 50 public: | 65 public: |
| 51 explicit DownloadHandler(TestFaviconHandler* favicon_helper) | 66 explicit DownloadHandler(TestFaviconHandler* favicon_helper) |
| 52 : favicon_helper_(favicon_helper), | 67 : favicon_helper_(favicon_helper), |
| 53 failed_(false) { | 68 failed_(false) { |
| 54 } | 69 } |
| 55 | 70 |
| 56 virtual ~DownloadHandler() { | 71 virtual ~DownloadHandler() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 const FaviconService::FaviconDataCallback& callback) | 118 const FaviconService::FaviconDataCallback& callback) |
| 104 : page_url_(page_url), | 119 : page_url_(page_url), |
| 105 icon_url_(icon_url), | 120 icon_url_(icon_url), |
| 106 icon_type_(icon_type), | 121 icon_type_(icon_type), |
| 107 callback_(callback) { | 122 callback_(callback) { |
| 108 } | 123 } |
| 109 | 124 |
| 110 HistoryRequestHandler(const GURL& page_url, | 125 HistoryRequestHandler(const GURL& page_url, |
| 111 const GURL& icon_url, | 126 const GURL& icon_url, |
| 112 int icon_type, | 127 int icon_type, |
| 113 const std::vector<unsigned char>& image_data, | 128 const std::vector<unsigned char>& bitmap_data, |
| 114 const FaviconService::FaviconDataCallback& callback) | 129 const FaviconService::FaviconDataCallback& callback) |
| 115 : page_url_(page_url), | 130 : page_url_(page_url), |
| 116 icon_url_(icon_url), | 131 icon_url_(icon_url), |
| 117 icon_type_(icon_type), | 132 icon_type_(icon_type), |
| 118 image_data_(image_data), | 133 bitmap_data_(bitmap_data), |
| 119 callback_(callback) { | 134 callback_(callback) { |
| 120 } | 135 } |
| 121 | 136 |
| 122 virtual ~HistoryRequestHandler() {} | 137 virtual ~HistoryRequestHandler() {} |
| 123 void InvokeCallback(); | 138 void InvokeCallback(); |
| 124 | 139 |
| 125 const GURL page_url_; | 140 const GURL page_url_; |
| 126 const GURL icon_url_; | 141 const GURL icon_url_; |
| 127 const int icon_type_; | 142 const int icon_type_; |
| 128 const std::vector<unsigned char> image_data_; | 143 const std::vector<unsigned char> bitmap_data_; |
| 129 history::FaviconData favicon_data_; | 144 history::FaviconData favicon_data_; |
| 130 FaviconService::FaviconDataCallback callback_; | 145 FaviconService::FaviconDataCallback callback_; |
| 131 | 146 |
| 132 private: | 147 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 148 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
| 134 }; | 149 }; |
| 135 | 150 |
| 136 } // namespace | 151 } // namespace |
| 137 | 152 |
| 138 | 153 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 261 } |
| 247 | 262 |
| 248 virtual int DownloadFavicon(const GURL& image_url, int image_size) OVERRIDE { | 263 virtual int DownloadFavicon(const GURL& image_url, int image_size) OVERRIDE { |
| 249 download_id_++; | 264 download_id_++; |
| 250 download_handler_->AddDownload(download_id_, image_url, image_size); | 265 download_handler_->AddDownload(download_id_, image_url, image_size); |
| 251 return download_id_; | 266 return download_id_; |
| 252 } | 267 } |
| 253 | 268 |
| 254 virtual void SetHistoryFavicon(const GURL& page_url, | 269 virtual void SetHistoryFavicon(const GURL& page_url, |
| 255 const GURL& icon_url, | 270 const GURL& icon_url, |
| 256 const std::vector<unsigned char>& image_data, | 271 const std::vector<unsigned char>& bitmap_data, |
| 257 history::IconType icon_type) OVERRIDE { | 272 history::IconType icon_type) OVERRIDE { |
| 258 history_handler_.reset(new HistoryRequestHandler( | 273 history_handler_.reset(new HistoryRequestHandler( |
| 259 page_url, icon_url,icon_type, image_data, | 274 page_url, icon_url,icon_type, bitmap_data, |
| 260 FaviconService::FaviconDataCallback())); | 275 FaviconService::FaviconDataCallback())); |
| 261 } | 276 } |
| 262 | 277 |
| 263 virtual FaviconService* GetFaviconService() OVERRIDE { | 278 virtual FaviconService* GetFaviconService() OVERRIDE { |
| 264 // Just give none NULL value, so overridden methods can be hit. | 279 // Just give none NULL value, so overridden methods can be hit. |
| 265 return (FaviconService*)(1); | 280 return (FaviconService*)(1); |
| 266 } | 281 } |
| 267 | 282 |
| 268 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { | 283 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { |
| 269 return true; | 284 return true; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 &delegate, FaviconHandler::FAVICON); | 334 &delegate, FaviconHandler::FAVICON); |
| 320 | 335 |
| 321 helper.FetchFavicon(page_url); | 336 helper.FetchFavicon(page_url); |
| 322 HistoryRequestHandler* history_handler = helper.history_handler(); | 337 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 323 // Ensure the data given to history is correct. | 338 // Ensure the data given to history is correct. |
| 324 ASSERT_TRUE(history_handler); | 339 ASSERT_TRUE(history_handler); |
| 325 EXPECT_EQ(page_url, history_handler->page_url_); | 340 EXPECT_EQ(page_url, history_handler->page_url_); |
| 326 EXPECT_EQ(GURL(), history_handler->icon_url_); | 341 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 327 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 342 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 328 | 343 |
| 329 // Set valid icon data. | 344 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 330 history_handler->favicon_data_.known_icon = true; | |
| 331 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 332 history_handler->favicon_data_.expired = false; | |
| 333 history_handler->favicon_data_.icon_url = icon_url; | |
| 334 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 335 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 336 history_handler->favicon_data_.image_data = data; | |
| 337 | 345 |
| 338 // Send history response. | 346 // Send history response. |
| 339 history_handler->InvokeCallback(); | 347 history_handler->InvokeCallback(); |
| 340 // Verify FaviconHandler status | 348 // Verify FaviconHandler status |
| 341 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 349 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 342 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 350 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 343 | 351 |
| 344 // Simulates update favicon url. | 352 // Simulates update favicon url. |
| 345 std::vector<FaviconURL> urls; | 353 std::vector<FaviconURL> urls; |
| 346 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 354 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 371 // Ensure the data given to history is correct. | 379 // Ensure the data given to history is correct. |
| 372 ASSERT_TRUE(history_handler); | 380 ASSERT_TRUE(history_handler); |
| 373 EXPECT_EQ(page_url, history_handler->page_url_); | 381 EXPECT_EQ(page_url, history_handler->page_url_); |
| 374 EXPECT_EQ(GURL(), history_handler->icon_url_); | 382 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 375 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 383 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 376 | 384 |
| 377 // Set icon data expired | 385 // Set icon data expired |
| 378 history_handler->favicon_data_.known_icon = true; | 386 history_handler->favicon_data_.known_icon = true; |
| 379 history_handler->favicon_data_.icon_type = history::FAVICON; | 387 history_handler->favicon_data_.icon_type = history::FAVICON; |
| 380 history_handler->favicon_data_.expired = true; | 388 history_handler->favicon_data_.expired = true; |
| 381 history_handler->favicon_data_.icon_url = icon_url; | 389 history::FaviconDataElement element; |
| 390 element.icon_url = icon_url; |
| 391 history_handler->favicon_data_.elements.push_back(element); |
| 382 // Send history response. | 392 // Send history response. |
| 383 history_handler->InvokeCallback(); | 393 history_handler->InvokeCallback(); |
| 384 // Verify FaviconHandler status | 394 // Verify FaviconHandler status |
| 385 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 395 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 386 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 396 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 387 | 397 |
| 388 // Simulates update favicon url. | 398 // Simulates update favicon url. |
| 389 std::vector<FaviconURL> urls; | 399 std::vector<FaviconURL> urls; |
| 390 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 400 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
| 391 helper.OnUpdateFaviconURL(0, urls); | 401 helper.OnUpdateFaviconURL(0, urls); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 408 helper.set_history_handler(NULL); | 418 helper.set_history_handler(NULL); |
| 409 | 419 |
| 410 // Smulates download done. | 420 // Smulates download done. |
| 411 download_handler->InvokeCallback(); | 421 download_handler->InvokeCallback(); |
| 412 | 422 |
| 413 // New icon should be saved to history backend and navigation entry. | 423 // New icon should be saved to history backend and navigation entry. |
| 414 history_handler = helper.history_handler(); | 424 history_handler = helper.history_handler(); |
| 415 ASSERT_TRUE(history_handler); | 425 ASSERT_TRUE(history_handler); |
| 416 EXPECT_EQ(icon_url, history_handler->icon_url_); | 426 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 417 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 427 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 418 EXPECT_LT(0U, history_handler->image_data_.size()); | 428 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 419 EXPECT_EQ(page_url, history_handler->page_url_); | 429 EXPECT_EQ(page_url, history_handler->page_url_); |
| 420 | 430 |
| 421 // Verify NavigationEntry. | 431 // Verify NavigationEntry. |
| 422 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 432 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 423 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 433 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 424 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 434 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 425 } | 435 } |
| 426 | 436 |
| 427 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 437 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
| 428 const GURL page_url("http://www.google.com"); | 438 const GURL page_url("http://www.google.com"); |
| 429 const GURL icon_url("http://www.google.com/favicon"); | 439 const GURL icon_url("http://www.google.com/favicon"); |
| 430 const GURL new_icon_url("http://www.google.com/new_favicon"); | 440 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 431 | 441 |
| 432 TestFaviconHandlerDelegate delegate(contents()); | 442 TestFaviconHandlerDelegate delegate(contents()); |
| 433 Profile* profile = Profile::FromBrowserContext( | 443 Profile* profile = Profile::FromBrowserContext( |
| 434 contents()->GetBrowserContext()); | 444 contents()->GetBrowserContext()); |
| 435 TestFaviconHandler helper(page_url, profile, | 445 TestFaviconHandler helper(page_url, profile, |
| 436 &delegate, FaviconHandler::FAVICON); | 446 &delegate, FaviconHandler::FAVICON); |
| 437 | 447 |
| 438 helper.FetchFavicon(page_url); | 448 helper.FetchFavicon(page_url); |
| 439 HistoryRequestHandler* history_handler = helper.history_handler(); | 449 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 440 // Ensure the data given to history is correct. | 450 // Ensure the data given to history is correct. |
| 441 ASSERT_TRUE(history_handler); | 451 ASSERT_TRUE(history_handler); |
| 442 EXPECT_EQ(page_url, history_handler->page_url_); | 452 EXPECT_EQ(page_url, history_handler->page_url_); |
| 443 EXPECT_EQ(GURL(), history_handler->icon_url_); | 453 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 444 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 454 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 445 | 455 |
| 446 // Set valid icon data. | 456 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 447 history_handler->favicon_data_.known_icon = true; | |
| 448 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 449 history_handler->favicon_data_.expired = false; | |
| 450 history_handler->favicon_data_.icon_url = icon_url; | |
| 451 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 452 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 453 history_handler->favicon_data_.image_data = data; | |
| 454 | 457 |
| 455 // Send history response. | 458 // Send history response. |
| 456 history_handler->InvokeCallback(); | 459 history_handler->InvokeCallback(); |
| 457 // Verify FaviconHandler status. | 460 // Verify FaviconHandler status. |
| 458 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 461 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 459 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 462 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 460 | 463 |
| 461 // Reset the history_handler to verify whether new icon is requested from | 464 // Reset the history_handler to verify whether new icon is requested from |
| 462 // history. | 465 // history. |
| 463 helper.set_history_handler(NULL); | 466 helper.set_history_handler(NULL); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 helper.set_history_handler(NULL); | 501 helper.set_history_handler(NULL); |
| 499 | 502 |
| 500 // Smulates download done. | 503 // Smulates download done. |
| 501 download_handler->InvokeCallback(); | 504 download_handler->InvokeCallback(); |
| 502 | 505 |
| 503 // New icon should be saved to history backend and navigation entry. | 506 // New icon should be saved to history backend and navigation entry. |
| 504 history_handler = helper.history_handler(); | 507 history_handler = helper.history_handler(); |
| 505 ASSERT_TRUE(history_handler); | 508 ASSERT_TRUE(history_handler); |
| 506 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 509 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 507 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 510 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 508 EXPECT_LT(0U, history_handler->image_data_.size()); | 511 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 509 EXPECT_EQ(page_url, history_handler->page_url_); | 512 EXPECT_EQ(page_url, history_handler->page_url_); |
| 510 | 513 |
| 511 // Verify NavigationEntry. | 514 // Verify NavigationEntry. |
| 512 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 515 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 513 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 516 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 514 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 517 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 515 } | 518 } |
| 516 | 519 |
| 517 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 520 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
| 518 const GURL page_url("http://www.google.com"); | 521 const GURL page_url("http://www.google.com"); |
| 519 const GURL icon_url("http://www.google.com/favicon"); | 522 const GURL icon_url("http://www.google.com/favicon"); |
| 520 const GURL new_icon_url("http://www.google.com/new_favicon"); | 523 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 521 | 524 |
| 522 TestFaviconHandlerDelegate delegate(contents()); | 525 TestFaviconHandlerDelegate delegate(contents()); |
| 523 Profile* profile = Profile::FromBrowserContext( | 526 Profile* profile = Profile::FromBrowserContext( |
| 524 contents()->GetBrowserContext()); | 527 contents()->GetBrowserContext()); |
| 525 TestFaviconHandler helper(page_url, profile, | 528 TestFaviconHandler helper(page_url, profile, |
| 526 &delegate, FaviconHandler::FAVICON); | 529 &delegate, FaviconHandler::FAVICON); |
| 527 | 530 |
| 528 helper.FetchFavicon(page_url); | 531 helper.FetchFavicon(page_url); |
| 529 HistoryRequestHandler* history_handler = helper.history_handler(); | 532 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 530 // Ensure the data given to history is correct. | 533 // Ensure the data given to history is correct. |
| 531 ASSERT_TRUE(history_handler); | 534 ASSERT_TRUE(history_handler); |
| 532 EXPECT_EQ(page_url, history_handler->page_url_); | 535 EXPECT_EQ(page_url, history_handler->page_url_); |
| 533 EXPECT_EQ(GURL(), history_handler->icon_url_); | 536 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 534 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 537 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 535 | 538 |
| 536 // Set valid icon data. | 539 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 537 history_handler->favicon_data_.known_icon = true; | |
| 538 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 539 history_handler->favicon_data_.expired = false; | |
| 540 history_handler->favicon_data_.icon_url = icon_url; | |
| 541 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 542 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 543 history_handler->favicon_data_.image_data = data; | |
| 544 | 540 |
| 545 // Send history response. | 541 // Send history response. |
| 546 history_handler->InvokeCallback(); | 542 history_handler->InvokeCallback(); |
| 547 // Verify FaviconHandler status. | 543 // Verify FaviconHandler status. |
| 548 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 544 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 549 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 545 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 550 | 546 |
| 551 // Reset the history_handler to verify whether new icon is requested from | 547 // Reset the history_handler to verify whether new icon is requested from |
| 552 // history. | 548 // history. |
| 553 helper.set_history_handler(NULL); | 549 helper.set_history_handler(NULL); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 569 history_handler = helper.history_handler(); | 565 history_handler = helper.history_handler(); |
| 570 ASSERT_TRUE(history_handler); | 566 ASSERT_TRUE(history_handler); |
| 571 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 567 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 572 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 568 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 573 EXPECT_EQ(page_url, history_handler->page_url_); | 569 EXPECT_EQ(page_url, history_handler->page_url_); |
| 574 | 570 |
| 575 // Simulate find icon. | 571 // Simulate find icon. |
| 576 history_handler->favicon_data_.known_icon = true; | 572 history_handler->favicon_data_.known_icon = true; |
| 577 history_handler->favicon_data_.icon_type = history::FAVICON; | 573 history_handler->favicon_data_.icon_type = history::FAVICON; |
| 578 history_handler->favicon_data_.expired = false; | 574 history_handler->favicon_data_.expired = false; |
| 579 history_handler->favicon_data_.icon_url = new_icon_url; | 575 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
| 580 history_handler->favicon_data_.image_data = data; | 576 history::FaviconDataElement element; |
| 577 element.bitmap_data = data; |
| 578 element.icon_url = new_icon_url; |
| 579 history_handler->favicon_data_.elements.push_back(element); |
| 581 history_handler->InvokeCallback(); | 580 history_handler->InvokeCallback(); |
| 582 | 581 |
| 583 // Shouldn't request download favicon | 582 // Shouldn't request download favicon |
| 584 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 583 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
| 585 | 584 |
| 586 // Verify the favicon status. | 585 // Verify the favicon status. |
| 587 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 586 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 588 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 587 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 589 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 588 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 590 } | 589 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 673 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 675 EXPECT_EQ(page_url, history_handler->page_url_); | 674 EXPECT_EQ(page_url, history_handler->page_url_); |
| 676 | 675 |
| 677 // Reset download handler | 676 // Reset download handler |
| 678 download_handler->Reset(); | 677 download_handler->Reset(); |
| 679 | 678 |
| 680 // Smulates getting a expired icon from history. | 679 // Smulates getting a expired icon from history. |
| 681 history_handler->favicon_data_.known_icon = true; | 680 history_handler->favicon_data_.known_icon = true; |
| 682 history_handler->favicon_data_.icon_type = history::TOUCH_ICON; | 681 history_handler->favicon_data_.icon_type = history::TOUCH_ICON; |
| 683 history_handler->favicon_data_.expired = true; | 682 history_handler->favicon_data_.expired = true; |
| 684 history_handler->favicon_data_.icon_url = new_icon_url; | |
| 685 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | 683 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); |
| 686 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 684 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 687 history_handler->favicon_data_.image_data = data; | 685 history::FaviconDataElement element; |
| 686 element.bitmap_data = data; |
| 687 element.icon_url = new_icon_url; |
| 688 history_handler->favicon_data_.elements.push_back(element); |
| 688 history_handler->InvokeCallback(); | 689 history_handler->InvokeCallback(); |
| 689 | 690 |
| 690 // Verify the download request. | 691 // Verify the download request. |
| 691 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 692 EXPECT_TRUE(helper.download_handler()->HasDownload()); |
| 692 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 693 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
| 693 EXPECT_EQ(0, download_handler->GetImageSize()); | 694 EXPECT_EQ(0, download_handler->GetImageSize()); |
| 694 | 695 |
| 695 helper.set_history_handler(NULL); | 696 helper.set_history_handler(NULL); |
| 696 | 697 |
| 697 // Simulates icon being downloaded. | 698 // Simulates icon being downloaded. |
| 698 download_handler->InvokeCallback(); | 699 download_handler->InvokeCallback(); |
| 699 | 700 |
| 700 // New icon should be saved to history backend. | 701 // New icon should be saved to history backend. |
| 701 history_handler = helper.history_handler(); | 702 history_handler = helper.history_handler(); |
| 702 ASSERT_TRUE(history_handler); | 703 ASSERT_TRUE(history_handler); |
| 703 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 704 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 704 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 705 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 705 EXPECT_LT(0U, history_handler->image_data_.size()); | 706 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 706 EXPECT_EQ(page_url, history_handler->page_url_); | 707 EXPECT_EQ(page_url, history_handler->page_url_); |
| 707 } | 708 } |
| 708 | 709 |
| 709 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 710 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
| 710 const GURL page_url("http://www.google.com"); | 711 const GURL page_url("http://www.google.com"); |
| 711 const GURL icon_url("http://www.google.com/favicon"); | 712 const GURL icon_url("http://www.google.com/favicon"); |
| 712 const GURL new_icon_url("http://www.google.com/new_favicon"); | 713 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 713 | 714 |
| 714 TestFaviconHandlerDelegate delegate(contents()); | 715 TestFaviconHandlerDelegate delegate(contents()); |
| 715 Profile* profile = Profile::FromBrowserContext( | 716 Profile* profile = Profile::FromBrowserContext( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 | 804 |
| 804 download_handler->Reset(); | 805 download_handler->Reset(); |
| 805 | 806 |
| 806 // Simulates getting the icon from history. | 807 // Simulates getting the icon from history. |
| 807 scoped_ptr<HistoryRequestHandler> handler; | 808 scoped_ptr<HistoryRequestHandler> handler; |
| 808 handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, | 809 handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, |
| 809 history::TOUCH_ICON, callback)); | 810 history::TOUCH_ICON, callback)); |
| 810 handler->favicon_data_.known_icon = true; | 811 handler->favicon_data_.known_icon = true; |
| 811 handler->favicon_data_.expired = false; | 812 handler->favicon_data_.expired = false; |
| 812 handler->favicon_data_.icon_type = history::TOUCH_ICON; | 813 handler->favicon_data_.icon_type = history::TOUCH_ICON; |
| 813 handler->favicon_data_.icon_url = latest_icon_url; | |
| 814 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | 814 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); |
| 815 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 815 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 816 handler->favicon_data_.image_data = data; | 816 history::FaviconDataElement element; |
| 817 element.bitmap_data = data; |
| 818 element.icon_url = latest_icon_url; |
| 819 handler->favicon_data_.elements.push_back(element); |
| 817 | 820 |
| 818 handler->InvokeCallback(); | 821 handler->InvokeCallback(); |
| 819 | 822 |
| 820 // No download request. | 823 // No download request. |
| 821 EXPECT_FALSE(download_handler->HasDownload()); | 824 EXPECT_FALSE(download_handler->HasDownload()); |
| 822 } | 825 } |
| 823 | 826 |
| 824 TEST_F(FaviconHandlerTest, MultipleFavicon) { | 827 TEST_F(FaviconHandlerTest, MultipleFavicon) { |
| 825 const GURL page_url("http://www.google.com"); | 828 const GURL page_url("http://www.google.com"); |
| 826 const GURL icon_url("http://www.google.com/favicon"); | 829 const GURL icon_url("http://www.google.com/favicon"); |
| 827 const GURL icon_url_small("http://www.google.com/favicon_small"); | 830 const GURL icon_url_small("http://www.google.com/favicon_small"); |
| 828 const GURL icon_url_large("http://www.google.com/favicon_large"); | 831 const GURL icon_url_large("http://www.google.com/favicon_large"); |
| 829 const GURL icon_url_preferred1("http://www.google.com/favicon_preferred1"); | 832 const GURL icon_url_preferred1("http://www.google.com/favicon_preferred1"); |
| 830 const GURL icon_url_preferred2("http://www.google.com/favicon_preferred2"); | 833 const GURL icon_url_preferred2("http://www.google.com/favicon_preferred2"); |
| 831 | 834 |
| 832 TestFaviconHandlerDelegate delegate(contents()); | 835 TestFaviconHandlerDelegate delegate(contents()); |
| 833 Profile* profile = Profile::FromBrowserContext( | 836 Profile* profile = Profile::FromBrowserContext( |
| 834 contents()->GetBrowserContext()); | 837 contents()->GetBrowserContext()); |
| 835 TestFaviconHandler handler(page_url, profile, | 838 TestFaviconHandler handler(page_url, profile, |
| 836 &delegate, FaviconHandler::FAVICON); | 839 &delegate, FaviconHandler::FAVICON); |
| 837 | 840 |
| 838 handler.FetchFavicon(page_url); | 841 handler.FetchFavicon(page_url); |
| 839 HistoryRequestHandler* history_handler = handler.history_handler(); | 842 HistoryRequestHandler* history_handler = handler.history_handler(); |
| 840 | 843 |
| 841 // Set valid icon data. | 844 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 842 history_handler->favicon_data_.known_icon = true; | |
| 843 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 844 history_handler->favicon_data_.expired = false; | |
| 845 history_handler->favicon_data_.icon_url = icon_url; | |
| 846 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 847 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 848 history_handler->favicon_data_.image_data = data; | |
| 849 | 845 |
| 850 // Send history response. | 846 // Send history response. |
| 851 history_handler->InvokeCallback(); | 847 history_handler->InvokeCallback(); |
| 852 | 848 |
| 853 // Simulates update with the different favicon url. | 849 // Simulates update with the different favicon url. |
| 854 std::vector<FaviconURL> urls; | 850 std::vector<FaviconURL> urls; |
| 855 // Note: the code will stop making requests when an icon matching the | 851 // Note: the code will stop making requests when an icon matching the |
| 856 // preferred size is found, so icon_url_preferred must be last. | 852 // preferred size is found, so icon_url_preferred must be last. |
| 857 urls.push_back(FaviconURL(icon_url_small, FaviconURL::FAVICON)); | 853 urls.push_back(FaviconURL(icon_url_small, FaviconURL::FAVICON)); |
| 858 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); | 854 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 | 903 |
| 908 TestFaviconHandlerDelegate delegate(contents()); | 904 TestFaviconHandlerDelegate delegate(contents()); |
| 909 Profile* profile = Profile::FromBrowserContext( | 905 Profile* profile = Profile::FromBrowserContext( |
| 910 contents()->GetBrowserContext()); | 906 contents()->GetBrowserContext()); |
| 911 TestFaviconHandler handler(page_url, profile, | 907 TestFaviconHandler handler(page_url, profile, |
| 912 &delegate, FaviconHandler::FAVICON); | 908 &delegate, FaviconHandler::FAVICON); |
| 913 | 909 |
| 914 handler.FetchFavicon(page_url); | 910 handler.FetchFavicon(page_url); |
| 915 HistoryRequestHandler* history_handler = handler.history_handler(); | 911 HistoryRequestHandler* history_handler = handler.history_handler(); |
| 916 | 912 |
| 917 // Set valid icon data. | 913 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 918 history_handler->favicon_data_.known_icon = true; | |
| 919 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 920 history_handler->favicon_data_.expired = false; | |
| 921 history_handler->favicon_data_.icon_url = icon_url; | |
| 922 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 923 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 924 history_handler->favicon_data_.image_data = data; | |
| 925 | 914 |
| 926 // Send history response. | 915 // Send history response. |
| 927 history_handler->InvokeCallback(); | 916 history_handler->InvokeCallback(); |
| 928 | 917 |
| 929 // Simulates update with the different favicon url. | 918 // Simulates update with the different favicon url. |
| 930 std::vector<FaviconURL> urls; | 919 std::vector<FaviconURL> urls; |
| 931 // Note: the code will stop making requests when an icon matching the | 920 // Note: the code will stop making requests when an icon matching the |
| 932 // preferred size is found, so icon_url_preferred must be last. | 921 // preferred size is found, so icon_url_preferred must be last. |
| 933 urls.push_back(FaviconURL(icon_url_preferred1, FaviconURL::FAVICON)); | 922 urls.push_back(FaviconURL(icon_url_preferred1, FaviconURL::FAVICON)); |
| 934 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); | 923 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 949 | 938 |
| 950 // Verify correct icon size chosen. | 939 // Verify correct icon size chosen. |
| 951 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); | 940 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); |
| 952 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); | 941 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); |
| 953 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); | 942 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); |
| 954 EXPECT_EQ(gfx::kFaviconSize, | 943 EXPECT_EQ(gfx::kFaviconSize, |
| 955 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); | 944 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); |
| 956 } | 945 } |
| 957 | 946 |
| 958 } // namespace. | 947 } // namespace. |
| OLD | NEW |