| 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 SetFaviconBitmapResult( |
| 48 const GURL& icon_url, |
| 49 history::IconType icon_type, |
| 50 bool expired, |
| 51 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) { |
| 52 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
| 53 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 54 history::FaviconBitmapResult bitmap_result; |
| 55 bitmap_result.expired = expired; |
| 56 bitmap_result.bitmap_data = data; |
| 57 bitmap_result.pixel_size = gfx::Size(); |
| 58 bitmap_result.icon_type = icon_type; |
| 59 bitmap_result.icon_url = icon_url; |
| 60 |
| 61 favicon_bitmap_results->push_back(bitmap_result); |
| 62 } |
| 63 |
| 64 void SetFaviconBitmapResult( |
| 65 const GURL& icon_url, |
| 66 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) { |
| 67 SetFaviconBitmapResult(icon_url, history::FAVICON, false /* expired */, |
| 68 favicon_bitmap_results); |
| 69 } |
| 70 |
| 47 // This class is used to save the download request for verifying with test case. | 71 // 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. | 72 // It also will be used to invoke the onDidDownload callback. |
| 49 class DownloadHandler { | 73 class DownloadHandler { |
| 50 public: | 74 public: |
| 51 explicit DownloadHandler(TestFaviconHandler* favicon_helper) | 75 explicit DownloadHandler(TestFaviconHandler* favicon_helper) |
| 52 : favicon_helper_(favicon_helper), | 76 : favicon_helper_(favicon_helper), |
| 53 failed_(false) { | 77 failed_(false) { |
| 54 } | 78 } |
| 55 | 79 |
| 56 virtual ~DownloadHandler() { | 80 virtual ~DownloadHandler() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); | 117 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); |
| 94 }; | 118 }; |
| 95 | 119 |
| 96 // This class is used to save the history request for verifying with test case. | 120 // This class is used to save the history request for verifying with test case. |
| 97 // It also will be used to simulate the history response. | 121 // It also will be used to simulate the history response. |
| 98 class HistoryRequestHandler { | 122 class HistoryRequestHandler { |
| 99 public: | 123 public: |
| 100 HistoryRequestHandler(const GURL& page_url, | 124 HistoryRequestHandler(const GURL& page_url, |
| 101 const GURL& icon_url, | 125 const GURL& icon_url, |
| 102 int icon_type, | 126 int icon_type, |
| 103 const FaviconService::FaviconDataCallback& callback) | 127 const FaviconService::FaviconResultsCallback& callback) |
| 104 : page_url_(page_url), | 128 : page_url_(page_url), |
| 105 icon_url_(icon_url), | 129 icon_url_(icon_url), |
| 106 icon_type_(icon_type), | 130 icon_type_(icon_type), |
| 107 callback_(callback) { | 131 callback_(callback) { |
| 108 } | 132 } |
| 109 | 133 |
| 110 HistoryRequestHandler(const GURL& page_url, | 134 HistoryRequestHandler(const GURL& page_url, |
| 111 const GURL& icon_url, | 135 const GURL& icon_url, |
| 112 int icon_type, | 136 int icon_type, |
| 113 const std::vector<unsigned char>& image_data, | 137 const std::vector<unsigned char>& bitmap_data, |
| 114 const FaviconService::FaviconDataCallback& callback) | 138 const FaviconService::FaviconResultsCallback& callback) |
| 115 : page_url_(page_url), | 139 : page_url_(page_url), |
| 116 icon_url_(icon_url), | 140 icon_url_(icon_url), |
| 117 icon_type_(icon_type), | 141 icon_type_(icon_type), |
| 118 image_data_(image_data), | 142 bitmap_data_(bitmap_data), |
| 119 callback_(callback) { | 143 callback_(callback) { |
| 120 } | 144 } |
| 121 | 145 |
| 122 virtual ~HistoryRequestHandler() {} | 146 virtual ~HistoryRequestHandler() {} |
| 123 void InvokeCallback(); | 147 void InvokeCallback(); |
| 124 | 148 |
| 125 const GURL page_url_; | 149 const GURL page_url_; |
| 126 const GURL icon_url_; | 150 const GURL icon_url_; |
| 127 const int icon_type_; | 151 const int icon_type_; |
| 128 const std::vector<unsigned char> image_data_; | 152 const std::vector<unsigned char> bitmap_data_; |
| 129 history::FaviconData favicon_data_; | 153 std::vector<history::FaviconBitmapResult> history_results_; |
| 130 FaviconService::FaviconDataCallback callback_; | 154 FaviconService::FaviconResultsCallback callback_; |
| 131 | 155 |
| 132 private: | 156 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 157 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
| 134 }; | 158 }; |
| 135 | 159 |
| 136 } // namespace | 160 } // namespace |
| 137 | 161 |
| 138 | 162 |
| 139 // This class is used as a temporary hack to provide working implementations of | 163 // This class is used as a temporary hack to provide working implementations of |
| 140 // the various delegate methods. Most of these methods are actually never | 164 // the various delegate methods. Most of these methods are actually never |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 FaviconURL* current_candidate() { | 239 FaviconURL* current_candidate() { |
| 216 return FaviconHandler::current_candidate(); | 240 return FaviconHandler::current_candidate(); |
| 217 } | 241 } |
| 218 | 242 |
| 219 protected: | 243 protected: |
| 220 virtual void UpdateFaviconMappingAndFetch( | 244 virtual void UpdateFaviconMappingAndFetch( |
| 221 const GURL& page_url, | 245 const GURL& page_url, |
| 222 const GURL& icon_url, | 246 const GURL& icon_url, |
| 223 history::IconType icon_type, | 247 history::IconType icon_type, |
| 224 CancelableRequestConsumerBase* consumer, | 248 CancelableRequestConsumerBase* consumer, |
| 225 const FaviconService::FaviconDataCallback& callback) OVERRIDE { | 249 const FaviconService::FaviconResultsCallback& callback) OVERRIDE { |
| 226 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, | 250 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, |
| 227 icon_type, callback)); | 251 icon_type, callback)); |
| 228 } | 252 } |
| 229 | 253 |
| 230 virtual void GetFavicon( | 254 virtual void GetFavicon( |
| 231 const GURL& icon_url, | 255 const GURL& icon_url, |
| 232 history::IconType icon_type, | 256 history::IconType icon_type, |
| 233 CancelableRequestConsumerBase* consumer, | 257 CancelableRequestConsumerBase* consumer, |
| 234 const FaviconService::FaviconDataCallback& callback) OVERRIDE { | 258 const FaviconService::FaviconResultsCallback& callback) OVERRIDE { |
| 235 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, | 259 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, |
| 236 icon_type, callback)); | 260 icon_type, callback)); |
| 237 } | 261 } |
| 238 | 262 |
| 239 virtual void GetFaviconForURL( | 263 virtual void GetFaviconForURL( |
| 240 const GURL& page_url, | 264 const GURL& page_url, |
| 241 int icon_types, | 265 int icon_types, |
| 242 CancelableRequestConsumerBase* consumer, | 266 CancelableRequestConsumerBase* consumer, |
| 243 const FaviconService::FaviconDataCallback& callback) OVERRIDE { | 267 const FaviconService::FaviconResultsCallback& callback) OVERRIDE { |
| 244 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), | 268 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), |
| 245 icon_types, callback)); | 269 icon_types, callback)); |
| 246 } | 270 } |
| 247 | 271 |
| 248 virtual int DownloadFavicon(const GURL& image_url, int image_size) OVERRIDE { | 272 virtual int DownloadFavicon(const GURL& image_url, int image_size) OVERRIDE { |
| 249 download_id_++; | 273 download_id_++; |
| 250 download_handler_->AddDownload(download_id_, image_url, image_size); | 274 download_handler_->AddDownload(download_id_, image_url, image_size); |
| 251 return download_id_; | 275 return download_id_; |
| 252 } | 276 } |
| 253 | 277 |
| 254 virtual void SetHistoryFavicon(const GURL& page_url, | 278 virtual void SetHistoryFavicon(const GURL& page_url, |
| 255 const GURL& icon_url, | 279 const GURL& icon_url, |
| 256 const std::vector<unsigned char>& image_data, | 280 const std::vector<unsigned char>& bitmap_data, |
| 257 history::IconType icon_type) OVERRIDE { | 281 history::IconType icon_type) OVERRIDE { |
| 258 history_handler_.reset(new HistoryRequestHandler( | 282 history_handler_.reset(new HistoryRequestHandler( |
| 259 page_url, icon_url,icon_type, image_data, | 283 page_url, icon_url,icon_type, bitmap_data, |
| 260 FaviconService::FaviconDataCallback())); | 284 FaviconService::FaviconResultsCallback())); |
| 261 } | 285 } |
| 262 | 286 |
| 263 virtual FaviconService* GetFaviconService() OVERRIDE { | 287 virtual FaviconService* GetFaviconService() OVERRIDE { |
| 264 // Just give none NULL value, so overridden methods can be hit. | 288 // Just give none NULL value, so overridden methods can be hit. |
| 265 return (FaviconService*)(1); | 289 return (FaviconService*)(1); |
| 266 } | 290 } |
| 267 | 291 |
| 268 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { | 292 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { |
| 269 return true; | 293 return true; |
| 270 } | 294 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 284 scoped_ptr<DownloadHandler> download_handler_; | 308 scoped_ptr<DownloadHandler> download_handler_; |
| 285 scoped_ptr<HistoryRequestHandler> history_handler_; | 309 scoped_ptr<HistoryRequestHandler> history_handler_; |
| 286 | 310 |
| 287 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | 311 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); |
| 288 }; | 312 }; |
| 289 | 313 |
| 290 namespace { | 314 namespace { |
| 291 | 315 |
| 292 void HistoryRequestHandler::InvokeCallback() { | 316 void HistoryRequestHandler::InvokeCallback() { |
| 293 if (!callback_.is_null()) | 317 if (!callback_.is_null()) |
| 294 callback_.Run(0, favicon_data_); | 318 callback_.Run(0, history_results_, history::IconURLSizesMap()); |
| 295 } | 319 } |
| 296 | 320 |
| 297 void DownloadHandler::InvokeCallback() { | 321 void DownloadHandler::InvokeCallback() { |
| 298 SkBitmap bitmap; | 322 SkBitmap bitmap; |
| 299 int bitmap_size = (download_->image_size > 0) ? | 323 int bitmap_size = (download_->image_size > 0) ? |
| 300 download_->image_size : gfx::kFaviconSize; | 324 download_->image_size : gfx::kFaviconSize; |
| 301 FillDataToBitmap(bitmap_size, bitmap_size, &bitmap); | 325 FillDataToBitmap(bitmap_size, bitmap_size, &bitmap); |
| 302 gfx::Image image(bitmap); | 326 gfx::Image image(bitmap); |
| 303 favicon_helper_->OnDidDownloadFavicon( | 327 favicon_helper_->OnDidDownloadFavicon( |
| 304 download_->download_id, download_->image_url, failed_, image, | 328 download_->download_id, download_->image_url, failed_, image, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 319 &delegate, FaviconHandler::FAVICON); | 343 &delegate, FaviconHandler::FAVICON); |
| 320 | 344 |
| 321 helper.FetchFavicon(page_url); | 345 helper.FetchFavicon(page_url); |
| 322 HistoryRequestHandler* history_handler = helper.history_handler(); | 346 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 323 // Ensure the data given to history is correct. | 347 // Ensure the data given to history is correct. |
| 324 ASSERT_TRUE(history_handler); | 348 ASSERT_TRUE(history_handler); |
| 325 EXPECT_EQ(page_url, history_handler->page_url_); | 349 EXPECT_EQ(page_url, history_handler->page_url_); |
| 326 EXPECT_EQ(GURL(), history_handler->icon_url_); | 350 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 327 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 351 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 328 | 352 |
| 329 // Set valid icon data. | 353 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
| 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 | 354 |
| 338 // Send history response. | 355 // Send history response. |
| 339 history_handler->InvokeCallback(); | 356 history_handler->InvokeCallback(); |
| 340 // Verify FaviconHandler status | 357 // Verify FaviconHandler status |
| 341 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 358 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 342 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 359 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 343 | 360 |
| 344 // Simulates update favicon url. | 361 // Simulates update favicon url. |
| 345 std::vector<FaviconURL> urls; | 362 std::vector<FaviconURL> urls; |
| 346 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 363 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 368 | 385 |
| 369 helper.FetchFavicon(page_url); | 386 helper.FetchFavicon(page_url); |
| 370 HistoryRequestHandler* history_handler = helper.history_handler(); | 387 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 371 // Ensure the data given to history is correct. | 388 // Ensure the data given to history is correct. |
| 372 ASSERT_TRUE(history_handler); | 389 ASSERT_TRUE(history_handler); |
| 373 EXPECT_EQ(page_url, history_handler->page_url_); | 390 EXPECT_EQ(page_url, history_handler->page_url_); |
| 374 EXPECT_EQ(GURL(), history_handler->icon_url_); | 391 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 375 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 392 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 376 | 393 |
| 377 // Set icon data expired | 394 // Set icon data expired |
| 378 history_handler->favicon_data_.known_icon = true; | 395 SetFaviconBitmapResult(icon_url, history::FAVICON, true /* expired */, |
| 379 history_handler->favicon_data_.icon_type = history::FAVICON; | 396 &history_handler->history_results_); |
| 380 history_handler->favicon_data_.expired = true; | |
| 381 history_handler->favicon_data_.icon_url = icon_url; | |
| 382 // Send history response. | 397 // Send history response. |
| 383 history_handler->InvokeCallback(); | 398 history_handler->InvokeCallback(); |
| 384 // Verify FaviconHandler status | 399 // Verify FaviconHandler status |
| 385 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 400 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 386 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 401 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 387 | 402 |
| 388 // Simulates update favicon url. | 403 // Simulates update favicon url. |
| 389 std::vector<FaviconURL> urls; | 404 std::vector<FaviconURL> urls; |
| 390 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 405 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
| 391 helper.OnUpdateFaviconURL(0, urls); | 406 helper.OnUpdateFaviconURL(0, urls); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 408 helper.set_history_handler(NULL); | 423 helper.set_history_handler(NULL); |
| 409 | 424 |
| 410 // Smulates download done. | 425 // Smulates download done. |
| 411 download_handler->InvokeCallback(); | 426 download_handler->InvokeCallback(); |
| 412 | 427 |
| 413 // New icon should be saved to history backend and navigation entry. | 428 // New icon should be saved to history backend and navigation entry. |
| 414 history_handler = helper.history_handler(); | 429 history_handler = helper.history_handler(); |
| 415 ASSERT_TRUE(history_handler); | 430 ASSERT_TRUE(history_handler); |
| 416 EXPECT_EQ(icon_url, history_handler->icon_url_); | 431 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 417 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 432 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 418 EXPECT_LT(0U, history_handler->image_data_.size()); | 433 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 419 EXPECT_EQ(page_url, history_handler->page_url_); | 434 EXPECT_EQ(page_url, history_handler->page_url_); |
| 420 | 435 |
| 421 // Verify NavigationEntry. | 436 // Verify NavigationEntry. |
| 422 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 437 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 423 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 438 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 424 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 439 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 425 } | 440 } |
| 426 | 441 |
| 427 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 442 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
| 428 const GURL page_url("http://www.google.com"); | 443 const GURL page_url("http://www.google.com"); |
| 429 const GURL icon_url("http://www.google.com/favicon"); | 444 const GURL icon_url("http://www.google.com/favicon"); |
| 430 const GURL new_icon_url("http://www.google.com/new_favicon"); | 445 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 431 | 446 |
| 432 TestFaviconHandlerDelegate delegate(contents()); | 447 TestFaviconHandlerDelegate delegate(contents()); |
| 433 Profile* profile = Profile::FromBrowserContext( | 448 Profile* profile = Profile::FromBrowserContext( |
| 434 contents()->GetBrowserContext()); | 449 contents()->GetBrowserContext()); |
| 435 TestFaviconHandler helper(page_url, profile, | 450 TestFaviconHandler helper(page_url, profile, |
| 436 &delegate, FaviconHandler::FAVICON); | 451 &delegate, FaviconHandler::FAVICON); |
| 437 | 452 |
| 438 helper.FetchFavicon(page_url); | 453 helper.FetchFavicon(page_url); |
| 439 HistoryRequestHandler* history_handler = helper.history_handler(); | 454 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 440 // Ensure the data given to history is correct. | 455 // Ensure the data given to history is correct. |
| 441 ASSERT_TRUE(history_handler); | 456 ASSERT_TRUE(history_handler); |
| 442 EXPECT_EQ(page_url, history_handler->page_url_); | 457 EXPECT_EQ(page_url, history_handler->page_url_); |
| 443 EXPECT_EQ(GURL(), history_handler->icon_url_); | 458 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 444 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 459 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 445 | 460 |
| 446 // Set valid icon data. | 461 // Set valid icon data. |
| 447 history_handler->favicon_data_.known_icon = true; | 462 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
| 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 | 463 |
| 455 // Send history response. | 464 // Send history response. |
| 456 history_handler->InvokeCallback(); | 465 history_handler->InvokeCallback(); |
| 457 // Verify FaviconHandler status. | 466 // Verify FaviconHandler status. |
| 458 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 467 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 459 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 468 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 460 | 469 |
| 461 // Reset the history_handler to verify whether new icon is requested from | 470 // Reset the history_handler to verify whether new icon is requested from |
| 462 // history. | 471 // history. |
| 463 helper.set_history_handler(NULL); | 472 helper.set_history_handler(NULL); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 476 ASSERT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 485 ASSERT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 477 | 486 |
| 478 // Favicon should be requested from history. | 487 // Favicon should be requested from history. |
| 479 history_handler = helper.history_handler(); | 488 history_handler = helper.history_handler(); |
| 480 ASSERT_TRUE(history_handler); | 489 ASSERT_TRUE(history_handler); |
| 481 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 490 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 482 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 491 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 483 EXPECT_EQ(page_url, history_handler->page_url_); | 492 EXPECT_EQ(page_url, history_handler->page_url_); |
| 484 | 493 |
| 485 // Simulate not find icon. | 494 // Simulate not find icon. |
| 486 history_handler->favicon_data_.known_icon = false; | 495 history_handler->history_results_.clear(); |
| 487 history_handler->InvokeCallback(); | 496 history_handler->InvokeCallback(); |
| 488 | 497 |
| 489 // Favicon should request to download icon now. | 498 // Favicon should request to download icon now. |
| 490 DownloadHandler* download_handler = helper.download_handler(); | 499 DownloadHandler* download_handler = helper.download_handler(); |
| 491 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 500 EXPECT_TRUE(helper.download_handler()->HasDownload()); |
| 492 | 501 |
| 493 // Verify the download request. | 502 // Verify the download request. |
| 494 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 503 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
| 495 EXPECT_EQ(gfx::kFaviconSize, download_handler->GetImageSize()); | 504 EXPECT_EQ(gfx::kFaviconSize, download_handler->GetImageSize()); |
| 496 | 505 |
| 497 // Reset the history_handler to verify whether favicon is set. | 506 // Reset the history_handler to verify whether favicon is set. |
| 498 helper.set_history_handler(NULL); | 507 helper.set_history_handler(NULL); |
| 499 | 508 |
| 500 // Smulates download done. | 509 // Smulates download done. |
| 501 download_handler->InvokeCallback(); | 510 download_handler->InvokeCallback(); |
| 502 | 511 |
| 503 // New icon should be saved to history backend and navigation entry. | 512 // New icon should be saved to history backend and navigation entry. |
| 504 history_handler = helper.history_handler(); | 513 history_handler = helper.history_handler(); |
| 505 ASSERT_TRUE(history_handler); | 514 ASSERT_TRUE(history_handler); |
| 506 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 515 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 507 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 516 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 508 EXPECT_LT(0U, history_handler->image_data_.size()); | 517 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 509 EXPECT_EQ(page_url, history_handler->page_url_); | 518 EXPECT_EQ(page_url, history_handler->page_url_); |
| 510 | 519 |
| 511 // Verify NavigationEntry. | 520 // Verify NavigationEntry. |
| 512 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 521 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 513 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 522 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 514 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 523 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 515 } | 524 } |
| 516 | 525 |
| 517 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 526 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
| 518 const GURL page_url("http://www.google.com"); | 527 const GURL page_url("http://www.google.com"); |
| 519 const GURL icon_url("http://www.google.com/favicon"); | 528 const GURL icon_url("http://www.google.com/favicon"); |
| 520 const GURL new_icon_url("http://www.google.com/new_favicon"); | 529 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 521 | 530 |
| 522 TestFaviconHandlerDelegate delegate(contents()); | 531 TestFaviconHandlerDelegate delegate(contents()); |
| 523 Profile* profile = Profile::FromBrowserContext( | 532 Profile* profile = Profile::FromBrowserContext( |
| 524 contents()->GetBrowserContext()); | 533 contents()->GetBrowserContext()); |
| 525 TestFaviconHandler helper(page_url, profile, | 534 TestFaviconHandler helper(page_url, profile, |
| 526 &delegate, FaviconHandler::FAVICON); | 535 &delegate, FaviconHandler::FAVICON); |
| 527 | 536 |
| 528 helper.FetchFavicon(page_url); | 537 helper.FetchFavicon(page_url); |
| 529 HistoryRequestHandler* history_handler = helper.history_handler(); | 538 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 530 // Ensure the data given to history is correct. | 539 // Ensure the data given to history is correct. |
| 531 ASSERT_TRUE(history_handler); | 540 ASSERT_TRUE(history_handler); |
| 532 EXPECT_EQ(page_url, history_handler->page_url_); | 541 EXPECT_EQ(page_url, history_handler->page_url_); |
| 533 EXPECT_EQ(GURL(), history_handler->icon_url_); | 542 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 534 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); | 543 EXPECT_EQ(history::FAVICON, history_handler->icon_type_); |
| 535 | 544 |
| 536 // Set valid icon data. | 545 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
| 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 | 546 |
| 545 // Send history response. | 547 // Send history response. |
| 546 history_handler->InvokeCallback(); | 548 history_handler->InvokeCallback(); |
| 547 // Verify FaviconHandler status. | 549 // Verify FaviconHandler status. |
| 548 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 550 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 549 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 551 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 550 | 552 |
| 551 // Reset the history_handler to verify whether new icon is requested from | 553 // Reset the history_handler to verify whether new icon is requested from |
| 552 // history. | 554 // history. |
| 553 helper.set_history_handler(NULL); | 555 helper.set_history_handler(NULL); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 566 ASSERT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 568 ASSERT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 567 | 569 |
| 568 // Favicon should be requested from history. | 570 // Favicon should be requested from history. |
| 569 history_handler = helper.history_handler(); | 571 history_handler = helper.history_handler(); |
| 570 ASSERT_TRUE(history_handler); | 572 ASSERT_TRUE(history_handler); |
| 571 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 573 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 572 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 574 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 573 EXPECT_EQ(page_url, history_handler->page_url_); | 575 EXPECT_EQ(page_url, history_handler->page_url_); |
| 574 | 576 |
| 575 // Simulate find icon. | 577 // Simulate find icon. |
| 576 history_handler->favicon_data_.known_icon = true; | 578 SetFaviconBitmapResult(new_icon_url, &history_handler->history_results_); |
| 577 history_handler->favicon_data_.icon_type = history::FAVICON; | |
| 578 history_handler->favicon_data_.expired = false; | |
| 579 history_handler->favicon_data_.icon_url = new_icon_url; | |
| 580 history_handler->favicon_data_.image_data = data; | |
| 581 history_handler->InvokeCallback(); | 579 history_handler->InvokeCallback(); |
| 582 | 580 |
| 583 // Shouldn't request download favicon | 581 // Shouldn't request download favicon |
| 584 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 582 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
| 585 | 583 |
| 586 // Verify the favicon status. | 584 // Verify the favicon status. |
| 587 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 585 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 588 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 586 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 589 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 587 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 590 } | 588 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 603 helper.FetchFavicon(page_url); | 601 helper.FetchFavicon(page_url); |
| 604 HistoryRequestHandler* history_handler = helper.history_handler(); | 602 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 605 // Ensure the data given to history is correct. | 603 // Ensure the data given to history is correct. |
| 606 ASSERT_TRUE(history_handler); | 604 ASSERT_TRUE(history_handler); |
| 607 EXPECT_EQ(page_url, history_handler->page_url_); | 605 EXPECT_EQ(page_url, history_handler->page_url_); |
| 608 EXPECT_EQ(GURL(), history_handler->icon_url_); | 606 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 609 EXPECT_EQ(history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON, | 607 EXPECT_EQ(history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON, |
| 610 history_handler->icon_type_); | 608 history_handler->icon_type_); |
| 611 | 609 |
| 612 // Icon not found. | 610 // Icon not found. |
| 613 history_handler->favicon_data_.known_icon = false; | 611 history_handler->history_results_.clear(); |
| 614 // Send history response. | 612 // Send history response. |
| 615 history_handler->InvokeCallback(); | 613 history_handler->InvokeCallback(); |
| 616 // Verify FaviconHandler status. | 614 // Verify FaviconHandler status. |
| 617 EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); | 615 EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); |
| 618 EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); | 616 EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); |
| 619 | 617 |
| 620 // Reset the history_handler to verify whether new icon is requested from | 618 // Reset the history_handler to verify whether new icon is requested from |
| 621 // history. | 619 // history. |
| 622 helper.set_history_handler(NULL); | 620 helper.set_history_handler(NULL); |
| 623 | 621 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 636 helper.current_candidate()->icon_type); | 634 helper.current_candidate()->icon_type); |
| 637 | 635 |
| 638 // Favicon should be requested from history. | 636 // Favicon should be requested from history. |
| 639 history_handler = helper.history_handler(); | 637 history_handler = helper.history_handler(); |
| 640 ASSERT_TRUE(history_handler); | 638 ASSERT_TRUE(history_handler); |
| 641 EXPECT_EQ(icon_url, history_handler->icon_url_); | 639 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 642 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 640 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
| 643 EXPECT_EQ(page_url, history_handler->page_url_); | 641 EXPECT_EQ(page_url, history_handler->page_url_); |
| 644 | 642 |
| 645 // Simulate not find icon. | 643 // Simulate not find icon. |
| 646 history_handler->favicon_data_.known_icon = false; | 644 history_handler->history_results_.clear(); |
| 647 history_handler->InvokeCallback(); | 645 history_handler->InvokeCallback(); |
| 648 | 646 |
| 649 // Should request download favicon. | 647 // Should request download favicon. |
| 650 DownloadHandler* download_handler = helper.download_handler(); | 648 DownloadHandler* download_handler = helper.download_handler(); |
| 651 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 649 EXPECT_TRUE(helper.download_handler()->HasDownload()); |
| 652 | 650 |
| 653 // Verify the download request. | 651 // Verify the download request. |
| 654 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 652 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
| 655 EXPECT_EQ(0, download_handler->GetImageSize()); | 653 EXPECT_EQ(0, download_handler->GetImageSize()); |
| 656 | 654 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 670 // Favicon should be requested from history. | 668 // Favicon should be requested from history. |
| 671 history_handler = helper.history_handler(); | 669 history_handler = helper.history_handler(); |
| 672 ASSERT_TRUE(history_handler); | 670 ASSERT_TRUE(history_handler); |
| 673 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 671 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 674 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 672 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 675 EXPECT_EQ(page_url, history_handler->page_url_); | 673 EXPECT_EQ(page_url, history_handler->page_url_); |
| 676 | 674 |
| 677 // Reset download handler | 675 // Reset download handler |
| 678 download_handler->Reset(); | 676 download_handler->Reset(); |
| 679 | 677 |
| 680 // Smulates getting a expired icon from history. | 678 // Simulates getting a expired icon from history. |
| 681 history_handler->favicon_data_.known_icon = true; | 679 SetFaviconBitmapResult(new_icon_url, history::TOUCH_ICON, |
| 682 history_handler->favicon_data_.icon_type = history::TOUCH_ICON; | 680 true /* expired */, &history_handler->history_results_); |
| 683 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(); | |
| 686 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 687 history_handler->favicon_data_.image_data = data; | |
| 688 history_handler->InvokeCallback(); | 681 history_handler->InvokeCallback(); |
| 689 | 682 |
| 690 // Verify the download request. | 683 // Verify the download request. |
| 691 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 684 EXPECT_TRUE(helper.download_handler()->HasDownload()); |
| 692 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 685 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
| 693 EXPECT_EQ(0, download_handler->GetImageSize()); | 686 EXPECT_EQ(0, download_handler->GetImageSize()); |
| 694 | 687 |
| 695 helper.set_history_handler(NULL); | 688 helper.set_history_handler(NULL); |
| 696 | 689 |
| 697 // Simulates icon being downloaded. | 690 // Simulates icon being downloaded. |
| 698 download_handler->InvokeCallback(); | 691 download_handler->InvokeCallback(); |
| 699 | 692 |
| 700 // New icon should be saved to history backend. | 693 // New icon should be saved to history backend. |
| 701 history_handler = helper.history_handler(); | 694 history_handler = helper.history_handler(); |
| 702 ASSERT_TRUE(history_handler); | 695 ASSERT_TRUE(history_handler); |
| 703 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 696 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 704 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 697 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 705 EXPECT_LT(0U, history_handler->image_data_.size()); | 698 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 706 EXPECT_EQ(page_url, history_handler->page_url_); | 699 EXPECT_EQ(page_url, history_handler->page_url_); |
| 707 } | 700 } |
| 708 | 701 |
| 709 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 702 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
| 710 const GURL page_url("http://www.google.com"); | 703 const GURL page_url("http://www.google.com"); |
| 711 const GURL icon_url("http://www.google.com/favicon"); | 704 const GURL icon_url("http://www.google.com/favicon"); |
| 712 const GURL new_icon_url("http://www.google.com/new_favicon"); | 705 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 713 | 706 |
| 714 TestFaviconHandlerDelegate delegate(contents()); | 707 TestFaviconHandlerDelegate delegate(contents()); |
| 715 Profile* profile = Profile::FromBrowserContext( | 708 Profile* profile = Profile::FromBrowserContext( |
| 716 contents()->GetBrowserContext()); | 709 contents()->GetBrowserContext()); |
| 717 TestFaviconHandler helper(page_url, profile, | 710 TestFaviconHandler helper(page_url, profile, |
| 718 &delegate, FaviconHandler::TOUCH); | 711 &delegate, FaviconHandler::TOUCH); |
| 719 | 712 |
| 720 helper.FetchFavicon(page_url); | 713 helper.FetchFavicon(page_url); |
| 721 HistoryRequestHandler* history_handler = helper.history_handler(); | 714 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 722 // Ensure the data given to history is correct. | 715 // Ensure the data given to history is correct. |
| 723 ASSERT_TRUE(history_handler); | 716 ASSERT_TRUE(history_handler); |
| 724 EXPECT_EQ(page_url, history_handler->page_url_); | 717 EXPECT_EQ(page_url, history_handler->page_url_); |
| 725 EXPECT_EQ(GURL(), history_handler->icon_url_); | 718 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 726 EXPECT_EQ(history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON, | 719 EXPECT_EQ(history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON, |
| 727 history_handler->icon_type_); | 720 history_handler->icon_type_); |
| 728 | 721 |
| 729 // Icon not found. | 722 // Icon not found. |
| 730 history_handler->favicon_data_.known_icon = false; | 723 history_handler->history_results_.clear(); |
| 731 // Send history response. | 724 // Send history response. |
| 732 history_handler->InvokeCallback(); | 725 history_handler->InvokeCallback(); |
| 733 // Verify FaviconHandler status. | 726 // Verify FaviconHandler status. |
| 734 EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); | 727 EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); |
| 735 EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); | 728 EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); |
| 736 | 729 |
| 737 // Reset the history_handler to verify whether new icon is requested from | 730 // Reset the history_handler to verify whether new icon is requested from |
| 738 // history. | 731 // history. |
| 739 helper.set_history_handler(NULL); | 732 helper.set_history_handler(NULL); |
| 740 | 733 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 753 helper.current_candidate()->icon_type); | 746 helper.current_candidate()->icon_type); |
| 754 | 747 |
| 755 // Favicon should be requested from history. | 748 // Favicon should be requested from history. |
| 756 history_handler = helper.history_handler(); | 749 history_handler = helper.history_handler(); |
| 757 ASSERT_TRUE(history_handler); | 750 ASSERT_TRUE(history_handler); |
| 758 EXPECT_EQ(icon_url, history_handler->icon_url_); | 751 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 759 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 752 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
| 760 EXPECT_EQ(page_url, history_handler->page_url_); | 753 EXPECT_EQ(page_url, history_handler->page_url_); |
| 761 | 754 |
| 762 // Simulate not find icon. | 755 // Simulate not find icon. |
| 763 history_handler->favicon_data_.known_icon = false; | 756 history_handler->history_results_.clear(); |
| 764 history_handler->InvokeCallback(); | 757 history_handler->InvokeCallback(); |
| 765 | 758 |
| 766 // Should request download favicon. | 759 // Should request download favicon. |
| 767 DownloadHandler* download_handler = helper.download_handler(); | 760 DownloadHandler* download_handler = helper.download_handler(); |
| 768 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 761 EXPECT_TRUE(helper.download_handler()->HasDownload()); |
| 769 | 762 |
| 770 // Verify the download request. | 763 // Verify the download request. |
| 771 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 764 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
| 772 EXPECT_EQ(0, download_handler->GetImageSize()); | 765 EXPECT_EQ(0, download_handler->GetImageSize()); |
| 773 | 766 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 786 // Whether new icon is requested from history | 779 // Whether new icon is requested from history |
| 787 history_handler = helper.history_handler(); | 780 history_handler = helper.history_handler(); |
| 788 ASSERT_TRUE(history_handler); | 781 ASSERT_TRUE(history_handler); |
| 789 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); | 782 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); |
| 790 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 783 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 791 EXPECT_EQ(page_url, history_handler->page_url_); | 784 EXPECT_EQ(page_url, history_handler->page_url_); |
| 792 | 785 |
| 793 // Reset the history_handler to verify whether favicon is request from | 786 // Reset the history_handler to verify whether favicon is request from |
| 794 // history. | 787 // history. |
| 795 // Save the callback for late use. | 788 // Save the callback for late use. |
| 796 FaviconService::FaviconDataCallback callback = history_handler->callback_; | 789 FaviconService::FaviconResultsCallback callback = history_handler->callback_; |
| 797 helper.set_history_handler(NULL); | 790 helper.set_history_handler(NULL); |
| 798 | 791 |
| 799 // Simulates download succeed. | 792 // Simulates download succeed. |
| 800 download_handler->InvokeCallback(); | 793 download_handler->InvokeCallback(); |
| 801 // The downloaded icon should be thrown away as there is favicon update. | 794 // The downloaded icon should be thrown away as there is favicon update. |
| 802 EXPECT_FALSE(helper.history_handler()); | 795 EXPECT_FALSE(helper.history_handler()); |
| 803 | 796 |
| 804 download_handler->Reset(); | 797 download_handler->Reset(); |
| 805 | 798 |
| 806 // Simulates getting the icon from history. | 799 // Simulates getting the icon from history. |
| 807 scoped_ptr<HistoryRequestHandler> handler; | 800 scoped_ptr<HistoryRequestHandler> handler; |
| 808 handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, | 801 handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, |
| 809 history::TOUCH_ICON, callback)); | 802 history::TOUCH_ICON, callback)); |
| 810 handler->favicon_data_.known_icon = true; | 803 SetFaviconBitmapResult(latest_icon_url, history::TOUCH_ICON, |
| 811 handler->favicon_data_.expired = false; | 804 false /* expired */, &handler->history_results_); |
| 812 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(); | |
| 815 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 816 handler->favicon_data_.image_data = data; | |
| 817 | |
| 818 handler->InvokeCallback(); | 805 handler->InvokeCallback(); |
| 819 | 806 |
| 820 // No download request. | 807 // No download request. |
| 821 EXPECT_FALSE(download_handler->HasDownload()); | 808 EXPECT_FALSE(download_handler->HasDownload()); |
| 822 } | 809 } |
| 823 | 810 |
| 824 TEST_F(FaviconHandlerTest, MultipleFavicon) { | 811 TEST_F(FaviconHandlerTest, MultipleFavicon) { |
| 825 const GURL page_url("http://www.google.com"); | 812 const GURL page_url("http://www.google.com"); |
| 826 const GURL icon_url("http://www.google.com/favicon"); | 813 const GURL icon_url("http://www.google.com/favicon"); |
| 827 const GURL icon_url_small("http://www.google.com/favicon_small"); | 814 const GURL icon_url_small("http://www.google.com/favicon_small"); |
| 828 const GURL icon_url_large("http://www.google.com/favicon_large"); | 815 const GURL icon_url_large("http://www.google.com/favicon_large"); |
| 829 const GURL icon_url_preferred1("http://www.google.com/favicon_preferred1"); | 816 const GURL icon_url_preferred1("http://www.google.com/favicon_preferred1"); |
| 830 const GURL icon_url_preferred2("http://www.google.com/favicon_preferred2"); | 817 const GURL icon_url_preferred2("http://www.google.com/favicon_preferred2"); |
| 831 | 818 |
| 832 TestFaviconHandlerDelegate delegate(contents()); | 819 TestFaviconHandlerDelegate delegate(contents()); |
| 833 Profile* profile = Profile::FromBrowserContext( | 820 Profile* profile = Profile::FromBrowserContext( |
| 834 contents()->GetBrowserContext()); | 821 contents()->GetBrowserContext()); |
| 835 TestFaviconHandler handler(page_url, profile, | 822 TestFaviconHandler handler(page_url, profile, |
| 836 &delegate, FaviconHandler::FAVICON); | 823 &delegate, FaviconHandler::FAVICON); |
| 837 | 824 |
| 838 handler.FetchFavicon(page_url); | 825 handler.FetchFavicon(page_url); |
| 839 HistoryRequestHandler* history_handler = handler.history_handler(); | 826 HistoryRequestHandler* history_handler = handler.history_handler(); |
| 840 | 827 |
| 841 // Set valid icon data. | 828 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
| 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 | 829 |
| 850 // Send history response. | 830 // Send history response. |
| 851 history_handler->InvokeCallback(); | 831 history_handler->InvokeCallback(); |
| 852 | 832 |
| 853 // Simulates update with the different favicon url. | 833 // Simulates update with the different favicon url. |
| 854 std::vector<FaviconURL> urls; | 834 std::vector<FaviconURL> urls; |
| 855 // Note: the code will stop making requests when an icon matching the | 835 // Note: the code will stop making requests when an icon matching the |
| 856 // preferred size is found, so icon_url_preferred must be last. | 836 // preferred size is found, so icon_url_preferred must be last. |
| 857 urls.push_back(FaviconURL(icon_url_small, FaviconURL::FAVICON)); | 837 urls.push_back(FaviconURL(icon_url_small, FaviconURL::FAVICON)); |
| 858 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); | 838 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); |
| 859 urls.push_back(FaviconURL(icon_url_preferred1, FaviconURL::FAVICON)); | 839 urls.push_back(FaviconURL(icon_url_preferred1, FaviconURL::FAVICON)); |
| 860 urls.push_back(FaviconURL(icon_url_preferred2, FaviconURL::FAVICON)); | 840 urls.push_back(FaviconURL(icon_url_preferred2, FaviconURL::FAVICON)); |
| 861 handler.OnUpdateFaviconURL(0, urls); | 841 handler.OnUpdateFaviconURL(0, urls); |
| 862 EXPECT_EQ(4U, handler.image_urls().size()); | 842 EXPECT_EQ(4U, handler.image_urls().size()); |
| 863 | 843 |
| 864 DownloadHandler* download_handler = handler.download_handler(); | 844 DownloadHandler* download_handler = handler.download_handler(); |
| 865 | 845 |
| 866 // Download the first icon (set not in history). | 846 // Download the first icon (set not in history). |
| 867 handler.history_handler()->favicon_data_.known_icon = false; | 847 handler.history_handler()->history_results_.clear(); |
| 868 handler.history_handler()->InvokeCallback(); | 848 handler.history_handler()->InvokeCallback(); |
| 869 ASSERT_TRUE(download_handler->HasDownload()); | 849 ASSERT_TRUE(download_handler->HasDownload()); |
| 870 EXPECT_EQ(icon_url_small, download_handler->GetImageUrl()); | 850 EXPECT_EQ(icon_url_small, download_handler->GetImageUrl()); |
| 871 download_handler->SetImageSize(gfx::kFaviconSize / 2); | 851 download_handler->SetImageSize(gfx::kFaviconSize / 2); |
| 872 download_handler->InvokeCallback(); | 852 download_handler->InvokeCallback(); |
| 873 EXPECT_EQ(3U, handler.image_urls().size()); | 853 EXPECT_EQ(3U, handler.image_urls().size()); |
| 874 | 854 |
| 875 // Download the second icon (set not in history). | 855 // Download the second icon (set not in history). |
| 876 handler.history_handler()->favicon_data_.known_icon = false; | 856 handler.history_handler()->history_results_.clear(); |
| 877 handler.history_handler()->InvokeCallback(); | 857 handler.history_handler()->InvokeCallback(); |
| 878 ASSERT_TRUE(download_handler->HasDownload()); | 858 ASSERT_TRUE(download_handler->HasDownload()); |
| 879 EXPECT_EQ(icon_url_large, download_handler->GetImageUrl()); | 859 EXPECT_EQ(icon_url_large, download_handler->GetImageUrl()); |
| 880 download_handler->SetImageSize(gfx::kFaviconSize * 2); | 860 download_handler->SetImageSize(gfx::kFaviconSize * 2); |
| 881 download_handler->InvokeCallback(); | 861 download_handler->InvokeCallback(); |
| 882 EXPECT_EQ(2U, handler.image_urls().size()); | 862 EXPECT_EQ(2U, handler.image_urls().size()); |
| 883 | 863 |
| 884 // Download the third icon (set not in history). | 864 // Download the third icon (set not in history). |
| 885 handler.history_handler()->favicon_data_.known_icon = false; | 865 handler.history_handler()->history_results_.clear(); |
| 886 handler.history_handler()->InvokeCallback(); | 866 handler.history_handler()->InvokeCallback(); |
| 887 ASSERT_TRUE(download_handler->HasDownload()); | 867 ASSERT_TRUE(download_handler->HasDownload()); |
| 888 EXPECT_EQ(icon_url_preferred1, download_handler->GetImageUrl()); | 868 EXPECT_EQ(icon_url_preferred1, download_handler->GetImageUrl()); |
| 889 download_handler->SetImageSize(gfx::kFaviconSize); | 869 download_handler->SetImageSize(gfx::kFaviconSize); |
| 890 download_handler->InvokeCallback(); | 870 download_handler->InvokeCallback(); |
| 891 // Verify that this was detected as an exact match and image_urls_ is cleared. | 871 // Verify that this was detected as an exact match and image_urls_ is cleared. |
| 892 EXPECT_EQ(0U, handler.image_urls().size()); | 872 EXPECT_EQ(0U, handler.image_urls().size()); |
| 893 | 873 |
| 894 // Verify correct icon size chosen. | 874 // Verify correct icon size chosen. |
| 895 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); | 875 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 908 TestFaviconHandlerDelegate delegate(contents()); | 888 TestFaviconHandlerDelegate delegate(contents()); |
| 909 Profile* profile = Profile::FromBrowserContext( | 889 Profile* profile = Profile::FromBrowserContext( |
| 910 contents()->GetBrowserContext()); | 890 contents()->GetBrowserContext()); |
| 911 TestFaviconHandler handler(page_url, profile, | 891 TestFaviconHandler handler(page_url, profile, |
| 912 &delegate, FaviconHandler::FAVICON); | 892 &delegate, FaviconHandler::FAVICON); |
| 913 | 893 |
| 914 handler.FetchFavicon(page_url); | 894 handler.FetchFavicon(page_url); |
| 915 HistoryRequestHandler* history_handler = handler.history_handler(); | 895 HistoryRequestHandler* history_handler = handler.history_handler(); |
| 916 | 896 |
| 917 // Set valid icon data. | 897 // Set valid icon data. |
| 918 history_handler->favicon_data_.known_icon = true; | 898 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
| 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 | 899 |
| 926 // Send history response. | 900 // Send history response. |
| 927 history_handler->InvokeCallback(); | 901 history_handler->InvokeCallback(); |
| 928 | 902 |
| 929 // Simulates update with the different favicon url. | 903 // Simulates update with the different favicon url. |
| 930 std::vector<FaviconURL> urls; | 904 std::vector<FaviconURL> urls; |
| 931 // Note: the code will stop making requests when an icon matching the | 905 // Note: the code will stop making requests when an icon matching the |
| 932 // preferred size is found, so icon_url_preferred must be last. | 906 // preferred size is found, so icon_url_preferred must be last. |
| 933 urls.push_back(FaviconURL(icon_url_preferred1, FaviconURL::FAVICON)); | 907 urls.push_back(FaviconURL(icon_url_preferred1, FaviconURL::FAVICON)); |
| 934 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); | 908 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); |
| 935 handler.OnUpdateFaviconURL(0, urls); | 909 handler.OnUpdateFaviconURL(0, urls); |
| 936 EXPECT_EQ(2U, handler.image_urls().size()); | 910 EXPECT_EQ(2U, handler.image_urls().size()); |
| 937 | 911 |
| 938 DownloadHandler* download_handler = handler.download_handler(); | 912 DownloadHandler* download_handler = handler.download_handler(); |
| 939 | 913 |
| 940 // Download the first icon (set not in history). | 914 // Download the first icon (set not in history). |
| 941 handler.history_handler()->favicon_data_.known_icon = false; | 915 handler.history_handler()->history_results_.clear(); |
| 942 handler.history_handler()->InvokeCallback(); | 916 handler.history_handler()->InvokeCallback(); |
| 943 ASSERT_TRUE(download_handler->HasDownload()); | 917 ASSERT_TRUE(download_handler->HasDownload()); |
| 944 EXPECT_EQ(icon_url_preferred1, download_handler->GetImageUrl()); | 918 EXPECT_EQ(icon_url_preferred1, download_handler->GetImageUrl()); |
| 945 download_handler->SetImageSize(gfx::kFaviconSize); | 919 download_handler->SetImageSize(gfx::kFaviconSize); |
| 946 download_handler->InvokeCallback(); | 920 download_handler->InvokeCallback(); |
| 947 // Verify that this was detected as an exact match and image_urls_ is cleared. | 921 // Verify that this was detected as an exact match and image_urls_ is cleared. |
| 948 EXPECT_EQ(0U, handler.image_urls().size()); | 922 EXPECT_EQ(0U, handler.image_urls().size()); |
| 949 | 923 |
| 950 // Verify correct icon size chosen. | 924 // Verify correct icon size chosen. |
| 951 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); | 925 EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); |
| 952 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); | 926 EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); |
| 953 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); | 927 EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty()); |
| 954 EXPECT_EQ(gfx::kFaviconSize, | 928 EXPECT_EQ(gfx::kFaviconSize, |
| 955 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); | 929 handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width()); |
| 956 } | 930 } |
| 957 | 931 |
| 958 } // namespace. | 932 } // namespace. |
| OLD | NEW |