Chromium Code Reviews| 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(); | |
|
stevenjb
2012/08/15 22:59:18
nit: use constructor
| |
| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 &delegate, FaviconHandler::FAVICON); | 333 &delegate, FaviconHandler::FAVICON); |
| 319 | 334 |
| 320 helper.FetchFavicon(page_url); | 335 helper.FetchFavicon(page_url); |
| 321 HistoryRequestHandler* history_handler = helper.history_handler(); | 336 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 322 // Ensure the data given to history is correct. | 337 // Ensure the data given to history is correct. |
| 323 ASSERT_TRUE(history_handler); | 338 ASSERT_TRUE(history_handler); |
| 324 EXPECT_EQ(page_url, history_handler->page_url_); | 339 EXPECT_EQ(page_url, history_handler->page_url_); |
| 325 EXPECT_EQ(GURL(), history_handler->icon_url_); | 340 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 326 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 341 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 327 | 342 |
| 328 // Set valid icon data. | 343 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 329 history_handler->favicon_data_.known_icon = true; | |
| 330 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 331 history_handler->favicon_data_.expired = false; | |
| 332 history_handler->favicon_data_.icon_url = icon_url; | |
| 333 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 334 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 335 history_handler->favicon_data_.image_data = data; | |
| 336 | 344 |
| 337 // Send history response. | 345 // Send history response. |
| 338 history_handler->InvokeCallback(); | 346 history_handler->InvokeCallback(); |
| 339 // Verify FaviconHandler status | 347 // Verify FaviconHandler status |
| 340 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 348 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 341 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 349 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 342 | 350 |
| 343 // Simulates update favicon url. | 351 // Simulates update favicon url. |
| 344 std::vector<FaviconURL> urls; | 352 std::vector<FaviconURL> urls; |
| 345 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 353 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 370 // Ensure the data given to history is correct. | 378 // Ensure the data given to history is correct. |
| 371 ASSERT_TRUE(history_handler); | 379 ASSERT_TRUE(history_handler); |
| 372 EXPECT_EQ(page_url, history_handler->page_url_); | 380 EXPECT_EQ(page_url, history_handler->page_url_); |
| 373 EXPECT_EQ(GURL(), history_handler->icon_url_); | 381 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 374 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 382 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 375 | 383 |
| 376 // Set icon data expired | 384 // Set icon data expired |
| 377 history_handler->favicon_data_.known_icon = true; | 385 history_handler->favicon_data_.known_icon = true; |
| 378 history_handler->favicon_data_.icon_type = history::FAVICON; | 386 history_handler->favicon_data_.icon_type = history::FAVICON; |
| 379 history_handler->favicon_data_.expired = true; | 387 history_handler->favicon_data_.expired = true; |
| 380 history_handler->favicon_data_.icon_url = icon_url; | 388 history::FaviconDataElement element; |
| 389 element.icon_url = icon_url; | |
| 390 history_handler->favicon_data_.elements.push_back(element); | |
| 381 // Send history response. | 391 // Send history response. |
| 382 history_handler->InvokeCallback(); | 392 history_handler->InvokeCallback(); |
| 383 // Verify FaviconHandler status | 393 // Verify FaviconHandler status |
| 384 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 394 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 385 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 395 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 386 | 396 |
| 387 // Simulates update favicon url. | 397 // Simulates update favicon url. |
| 388 std::vector<FaviconURL> urls; | 398 std::vector<FaviconURL> urls; |
| 389 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 399 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
| 390 helper.OnUpdateFaviconURL(0, urls); | 400 helper.OnUpdateFaviconURL(0, urls); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 407 helper.set_history_handler(NULL); | 417 helper.set_history_handler(NULL); |
| 408 | 418 |
| 409 // Smulates download done. | 419 // Smulates download done. |
| 410 download_handler->InvokeCallback(); | 420 download_handler->InvokeCallback(); |
| 411 | 421 |
| 412 // New icon should be saved to history backend and navigation entry. | 422 // New icon should be saved to history backend and navigation entry. |
| 413 history_handler = helper.history_handler(); | 423 history_handler = helper.history_handler(); |
| 414 ASSERT_TRUE(history_handler); | 424 ASSERT_TRUE(history_handler); |
| 415 EXPECT_EQ(icon_url, history_handler->icon_url_); | 425 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 416 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 426 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 417 EXPECT_LT(0U, history_handler->image_data_.size()); | 427 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 418 EXPECT_EQ(page_url, history_handler->page_url_); | 428 EXPECT_EQ(page_url, history_handler->page_url_); |
| 419 | 429 |
| 420 // Verify NavigationEntry. | 430 // Verify NavigationEntry. |
| 421 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 431 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 422 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 432 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 423 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 433 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 424 } | 434 } |
| 425 | 435 |
| 426 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 436 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
| 427 const GURL page_url("http://www.google.com"); | 437 const GURL page_url("http://www.google.com"); |
| 428 const GURL icon_url("http://www.google.com/favicon"); | 438 const GURL icon_url("http://www.google.com/favicon"); |
| 429 const GURL new_icon_url("http://www.google.com/new_favicon"); | 439 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 430 | 440 |
| 431 TestFaviconHandlerDelegate delegate(contents()); | 441 TestFaviconHandlerDelegate delegate(contents()); |
| 432 Profile* profile = Profile::FromBrowserContext( | 442 Profile* profile = Profile::FromBrowserContext( |
| 433 contents()->GetBrowserContext()); | 443 contents()->GetBrowserContext()); |
| 434 TestFaviconHandler helper(page_url, profile, | 444 TestFaviconHandler helper(page_url, profile, |
| 435 &delegate, FaviconHandler::FAVICON); | 445 &delegate, FaviconHandler::FAVICON); |
| 436 | 446 |
| 437 helper.FetchFavicon(page_url); | 447 helper.FetchFavicon(page_url); |
| 438 HistoryRequestHandler* history_handler = helper.history_handler(); | 448 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 439 // Ensure the data given to history is correct. | 449 // Ensure the data given to history is correct. |
| 440 ASSERT_TRUE(history_handler); | 450 ASSERT_TRUE(history_handler); |
| 441 EXPECT_EQ(page_url, history_handler->page_url_); | 451 EXPECT_EQ(page_url, history_handler->page_url_); |
| 442 EXPECT_EQ(GURL(), history_handler->icon_url_); | 452 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 443 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 453 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 444 | 454 |
| 445 // Set valid icon data. | 455 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 446 history_handler->favicon_data_.known_icon = true; | |
| 447 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 448 history_handler->favicon_data_.expired = false; | |
| 449 history_handler->favicon_data_.icon_url = icon_url; | |
| 450 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 451 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 452 history_handler->favicon_data_.image_data = data; | |
| 453 | 456 |
| 454 // Send history response. | 457 // Send history response. |
| 455 history_handler->InvokeCallback(); | 458 history_handler->InvokeCallback(); |
| 456 // Verify FaviconHandler status. | 459 // Verify FaviconHandler status. |
| 457 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 460 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 458 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 461 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 459 | 462 |
| 460 // Reset the history_handler to verify whether new icon is requested from | 463 // Reset the history_handler to verify whether new icon is requested from |
| 461 // history. | 464 // history. |
| 462 helper.set_history_handler(NULL); | 465 helper.set_history_handler(NULL); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 helper.set_history_handler(NULL); | 500 helper.set_history_handler(NULL); |
| 498 | 501 |
| 499 // Smulates download done. | 502 // Smulates download done. |
| 500 download_handler->InvokeCallback(); | 503 download_handler->InvokeCallback(); |
| 501 | 504 |
| 502 // New icon should be saved to history backend and navigation entry. | 505 // New icon should be saved to history backend and navigation entry. |
| 503 history_handler = helper.history_handler(); | 506 history_handler = helper.history_handler(); |
| 504 ASSERT_TRUE(history_handler); | 507 ASSERT_TRUE(history_handler); |
| 505 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 508 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 506 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 509 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 507 EXPECT_LT(0U, history_handler->image_data_.size()); | 510 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 508 EXPECT_EQ(page_url, history_handler->page_url_); | 511 EXPECT_EQ(page_url, history_handler->page_url_); |
| 509 | 512 |
| 510 // Verify NavigationEntry. | 513 // Verify NavigationEntry. |
| 511 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 514 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 512 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 515 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 513 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 516 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 514 } | 517 } |
| 515 | 518 |
| 516 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 519 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
| 517 const GURL page_url("http://www.google.com"); | 520 const GURL page_url("http://www.google.com"); |
| 518 const GURL icon_url("http://www.google.com/favicon"); | 521 const GURL icon_url("http://www.google.com/favicon"); |
| 519 const GURL new_icon_url("http://www.google.com/new_favicon"); | 522 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 520 | 523 |
| 521 TestFaviconHandlerDelegate delegate(contents()); | 524 TestFaviconHandlerDelegate delegate(contents()); |
| 522 Profile* profile = Profile::FromBrowserContext( | 525 Profile* profile = Profile::FromBrowserContext( |
| 523 contents()->GetBrowserContext()); | 526 contents()->GetBrowserContext()); |
| 524 TestFaviconHandler helper(page_url, profile, | 527 TestFaviconHandler helper(page_url, profile, |
| 525 &delegate, FaviconHandler::FAVICON); | 528 &delegate, FaviconHandler::FAVICON); |
| 526 | 529 |
| 527 helper.FetchFavicon(page_url); | 530 helper.FetchFavicon(page_url); |
| 528 HistoryRequestHandler* history_handler = helper.history_handler(); | 531 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 529 // Ensure the data given to history is correct. | 532 // Ensure the data given to history is correct. |
| 530 ASSERT_TRUE(history_handler); | 533 ASSERT_TRUE(history_handler); |
| 531 EXPECT_EQ(page_url, history_handler->page_url_); | 534 EXPECT_EQ(page_url, history_handler->page_url_); |
| 532 EXPECT_EQ(GURL(), history_handler->icon_url_); | 535 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 533 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 536 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 534 | 537 |
| 535 // Set valid icon data. | 538 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 536 history_handler->favicon_data_.known_icon = true; | |
| 537 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 538 history_handler->favicon_data_.expired = false; | |
| 539 history_handler->favicon_data_.icon_url = icon_url; | |
| 540 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 541 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 542 history_handler->favicon_data_.image_data = data; | |
| 543 | 539 |
| 544 // Send history response. | 540 // Send history response. |
| 545 history_handler->InvokeCallback(); | 541 history_handler->InvokeCallback(); |
| 546 // Verify FaviconHandler status. | 542 // Verify FaviconHandler status. |
| 547 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 543 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 548 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 544 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 549 | 545 |
| 550 // Reset the history_handler to verify whether new icon is requested from | 546 // Reset the history_handler to verify whether new icon is requested from |
| 551 // history. | 547 // history. |
| 552 helper.set_history_handler(NULL); | 548 helper.set_history_handler(NULL); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 568 history_handler = helper.history_handler(); | 564 history_handler = helper.history_handler(); |
| 569 ASSERT_TRUE(history_handler); | 565 ASSERT_TRUE(history_handler); |
| 570 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 566 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 571 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 567 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 572 EXPECT_EQ(page_url, history_handler->page_url_); | 568 EXPECT_EQ(page_url, history_handler->page_url_); |
| 573 | 569 |
| 574 // Simulate find icon. | 570 // Simulate find icon. |
| 575 history_handler->favicon_data_.known_icon = true; | 571 history_handler->favicon_data_.known_icon = true; |
| 576 history_handler->favicon_data_.icon_type = history::FAVICON; | 572 history_handler->favicon_data_.icon_type = history::FAVICON; |
| 577 history_handler->favicon_data_.expired = false; | 573 history_handler->favicon_data_.expired = false; |
| 578 history_handler->favicon_data_.icon_url = new_icon_url; | 574 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); |
|
stevenjb
2012/08/15 22:59:18
nit: use constructor
| |
| 579 history_handler->favicon_data_.image_data = data; | 575 history::FaviconDataElement element; |
| 576 element.bitmap_data = data; | |
| 577 element.icon_url = new_icon_url; | |
| 578 history_handler->favicon_data_.elements.push_back(element); | |
| 580 history_handler->InvokeCallback(); | 579 history_handler->InvokeCallback(); |
| 581 | 580 |
| 582 // Shouldn't request download favicon | 581 // Shouldn't request download favicon |
| 583 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 582 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
| 584 | 583 |
| 585 // Verify the favicon status. | 584 // Verify the favicon status. |
| 586 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 585 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 587 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 586 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 588 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 587 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 589 } | 588 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 672 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 674 EXPECT_EQ(page_url, history_handler->page_url_); | 673 EXPECT_EQ(page_url, history_handler->page_url_); |
| 675 | 674 |
| 676 // Reset download handler | 675 // Reset download handler |
| 677 download_handler->Reset(); | 676 download_handler->Reset(); |
| 678 | 677 |
| 679 // Smulates getting a expired icon from history. | 678 // Smulates getting a expired icon from history. |
| 680 history_handler->favicon_data_.known_icon = true; | 679 history_handler->favicon_data_.known_icon = true; |
| 681 history_handler->favicon_data_.icon_type = history::TOUCH_ICON; | 680 history_handler->favicon_data_.icon_type = history::TOUCH_ICON; |
| 682 history_handler->favicon_data_.expired = true; | 681 history_handler->favicon_data_.expired = true; |
| 683 history_handler->favicon_data_.icon_url = new_icon_url; | |
| 684 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | 682 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); |
| 685 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 683 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 686 history_handler->favicon_data_.image_data = data; | 684 history::FaviconDataElement element; |
| 685 element.bitmap_data = data; | |
| 686 element.icon_url = new_icon_url; | |
| 687 history_handler->favicon_data_.elements.push_back(element); | |
| 687 history_handler->InvokeCallback(); | 688 history_handler->InvokeCallback(); |
| 688 | 689 |
| 689 // Verify the download request. | 690 // Verify the download request. |
| 690 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 691 EXPECT_TRUE(helper.download_handler()->HasDownload()); |
| 691 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 692 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
| 692 EXPECT_EQ(0, download_handler->GetImageSize()); | 693 EXPECT_EQ(0, download_handler->GetImageSize()); |
| 693 | 694 |
| 694 helper.set_history_handler(NULL); | 695 helper.set_history_handler(NULL); |
| 695 | 696 |
| 696 // Simulates icon being downloaded. | 697 // Simulates icon being downloaded. |
| 697 download_handler->InvokeCallback(); | 698 download_handler->InvokeCallback(); |
| 698 | 699 |
| 699 // New icon should be saved to history backend. | 700 // New icon should be saved to history backend. |
| 700 history_handler = helper.history_handler(); | 701 history_handler = helper.history_handler(); |
| 701 ASSERT_TRUE(history_handler); | 702 ASSERT_TRUE(history_handler); |
| 702 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 703 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 703 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 704 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 704 EXPECT_LT(0U, history_handler->image_data_.size()); | 705 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 705 EXPECT_EQ(page_url, history_handler->page_url_); | 706 EXPECT_EQ(page_url, history_handler->page_url_); |
| 706 } | 707 } |
| 707 | 708 |
| 708 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 709 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
| 709 const GURL page_url("http://www.google.com"); | 710 const GURL page_url("http://www.google.com"); |
| 710 const GURL icon_url("http://www.google.com/favicon"); | 711 const GURL icon_url("http://www.google.com/favicon"); |
| 711 const GURL new_icon_url("http://www.google.com/new_favicon"); | 712 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 712 | 713 |
| 713 TestFaviconHandlerDelegate delegate(contents()); | 714 TestFaviconHandlerDelegate delegate(contents()); |
| 714 Profile* profile = Profile::FromBrowserContext( | 715 Profile* profile = Profile::FromBrowserContext( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 802 | 803 |
| 803 download_handler->Reset(); | 804 download_handler->Reset(); |
| 804 | 805 |
| 805 // Simulates getting the icon from history. | 806 // Simulates getting the icon from history. |
| 806 scoped_ptr<HistoryRequestHandler> handler; | 807 scoped_ptr<HistoryRequestHandler> handler; |
| 807 handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, | 808 handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, |
| 808 history::TOUCH_ICON, callback)); | 809 history::TOUCH_ICON, callback)); |
| 809 handler->favicon_data_.known_icon = true; | 810 handler->favicon_data_.known_icon = true; |
| 810 handler->favicon_data_.expired = false; | 811 handler->favicon_data_.expired = false; |
| 811 handler->favicon_data_.icon_type = history::TOUCH_ICON; | 812 handler->favicon_data_.icon_type = history::TOUCH_ICON; |
| 812 handler->favicon_data_.icon_url = latest_icon_url; | |
| 813 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | 813 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); |
| 814 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 814 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 815 handler->favicon_data_.image_data = data; | 815 history::FaviconDataElement element; |
| 816 element.bitmap_data = data; | |
| 817 element.icon_url = latest_icon_url; | |
| 818 handler->favicon_data_.elements.push_back(element); | |
| 816 | 819 |
| 817 handler->InvokeCallback(); | 820 handler->InvokeCallback(); |
| 818 | 821 |
| 819 // No download request. | 822 // No download request. |
| 820 EXPECT_FALSE(download_handler->HasDownload()); | 823 EXPECT_FALSE(download_handler->HasDownload()); |
| 821 } | 824 } |
| 822 | 825 |
| 823 TEST_F(FaviconHandlerTest, MultipleFavicon) { | 826 TEST_F(FaviconHandlerTest, MultipleFavicon) { |
| 824 const GURL page_url("http://www.google.com"); | 827 const GURL page_url("http://www.google.com"); |
| 825 const GURL icon_url("http://www.google.com/favicon"); | 828 const GURL icon_url("http://www.google.com/favicon"); |
| 826 const GURL icon_url_small("http://www.google.com/favicon_small"); | 829 const GURL icon_url_small("http://www.google.com/favicon_small"); |
| 827 const GURL icon_url_large("http://www.google.com/favicon_large"); | 830 const GURL icon_url_large("http://www.google.com/favicon_large"); |
| 828 const GURL icon_url_preferred1("http://www.google.com/favicon_preferred1"); | 831 const GURL icon_url_preferred1("http://www.google.com/favicon_preferred1"); |
| 829 const GURL icon_url_preferred2("http://www.google.com/favicon_preferred2"); | 832 const GURL icon_url_preferred2("http://www.google.com/favicon_preferred2"); |
| 830 | 833 |
| 831 TestFaviconHandlerDelegate delegate(contents()); | 834 TestFaviconHandlerDelegate delegate(contents()); |
| 832 Profile* profile = Profile::FromBrowserContext( | 835 Profile* profile = Profile::FromBrowserContext( |
| 833 contents()->GetBrowserContext()); | 836 contents()->GetBrowserContext()); |
| 834 TestFaviconHandler handler(page_url, profile, | 837 TestFaviconHandler handler(page_url, profile, |
| 835 &delegate, FaviconHandler::FAVICON); | 838 &delegate, FaviconHandler::FAVICON); |
| 836 | 839 |
| 837 handler.FetchFavicon(page_url); | 840 handler.FetchFavicon(page_url); |
| 838 HistoryRequestHandler* history_handler = handler.history_handler(); | 841 HistoryRequestHandler* history_handler = handler.history_handler(); |
| 839 | 842 |
| 840 // Set valid icon data. | 843 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 841 history_handler->favicon_data_.known_icon = true; | |
| 842 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 843 history_handler->favicon_data_.expired = false; | |
| 844 history_handler->favicon_data_.icon_url = icon_url; | |
| 845 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 846 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 847 history_handler->favicon_data_.image_data = data; | |
| 848 | 844 |
| 849 // Send history response. | 845 // Send history response. |
| 850 history_handler->InvokeCallback(); | 846 history_handler->InvokeCallback(); |
| 851 | 847 |
| 852 // Simulates update with the different favicon url. | 848 // Simulates update with the different favicon url. |
| 853 std::vector<FaviconURL> urls; | 849 std::vector<FaviconURL> urls; |
| 854 // Note: the code will stop making requests when an icon matching the | 850 // Note: the code will stop making requests when an icon matching the |
| 855 // preferred size is found, so icon_url_preferred must be last. | 851 // preferred size is found, so icon_url_preferred must be last. |
| 856 urls.push_back(FaviconURL(icon_url_small, FaviconURL::FAVICON)); | 852 urls.push_back(FaviconURL(icon_url_small, FaviconURL::FAVICON)); |
| 857 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); | 853 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 | 902 |
| 907 TestFaviconHandlerDelegate delegate(contents()); | 903 TestFaviconHandlerDelegate delegate(contents()); |
| 908 Profile* profile = Profile::FromBrowserContext( | 904 Profile* profile = Profile::FromBrowserContext( |
| 909 contents()->GetBrowserContext()); | 905 contents()->GetBrowserContext()); |
| 910 TestFaviconHandler handler(page_url, profile, | 906 TestFaviconHandler handler(page_url, profile, |
| 911 &delegate, FaviconHandler::FAVICON); | 907 &delegate, FaviconHandler::FAVICON); |
| 912 | 908 |
| 913 handler.FetchFavicon(page_url); | 909 handler.FetchFavicon(page_url); |
| 914 HistoryRequestHandler* history_handler = handler.history_handler(); | 910 HistoryRequestHandler* history_handler = handler.history_handler(); |
| 915 | 911 |
| 916 // Set valid icon data. | 912 SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_); |
| 917 history_handler->favicon_data_.known_icon = true; | |
| 918 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 919 history_handler->favicon_data_.expired = false; | |
| 920 history_handler->favicon_data_.icon_url = icon_url; | |
| 921 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | |
| 922 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 923 history_handler->favicon_data_.image_data = data; | |
| 924 | 913 |
| 925 // Send history response. | 914 // Send history response. |
| 926 history_handler->InvokeCallback(); | 915 history_handler->InvokeCallback(); |
| 927 | 916 |
| 928 // Simulates update with the different favicon url. | 917 // Simulates update with the different favicon url. |
| 929 std::vector<FaviconURL> urls; | 918 std::vector<FaviconURL> urls; |
| 930 // Note: the code will stop making requests when an icon matching the | 919 // Note: the code will stop making requests when an icon matching the |
| 931 // preferred size is found, so icon_url_preferred must be last. | 920 // preferred size is found, so icon_url_preferred must be last. |
| 932 urls.push_back(FaviconURL(icon_url_preferred1, FaviconURL::FAVICON)); | 921 urls.push_back(FaviconURL(icon_url_preferred1, FaviconURL::FAVICON)); |
| 933 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); | 922 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 948 | 937 |
| 949 // Verify correct icon size chosen. | 938 // Verify correct icon size chosen. |
| 950 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); | 939 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); |
| 951 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); | 940 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); |
| 952 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); | 941 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); |
| 953 EXPECT_EQ(gfx::kFaviconSize, | 942 EXPECT_EQ(gfx::kFaviconSize, |
| 954 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); | 943 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); |
| 955 } | 944 } |
| 956 | 945 |
| 957 } // namespace. | 946 } // namespace. |
| OLD | NEW |