| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/favicon/favicon_handler.h" | 5 #include "chrome/browser/favicon/favicon_handler.h" |
| 6 #include "chrome/browser/profiles/profile.h" | 6 #include "chrome/browser/profiles/profile.h" |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 8 #include "content/browser/tab_contents/test_tab_contents.h" | 8 #include "content/browser/tab_contents/test_tab_contents.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 27 matching lines...) Expand all Loading... |
| 38 void FillBitmap(int w, int h, std::vector<unsigned char>* output) { | 38 void FillBitmap(int w, int h, std::vector<unsigned char>* output) { |
| 39 SkBitmap bitmap; | 39 SkBitmap bitmap; |
| 40 FillDataToBitmap(w, h, &bitmap); | 40 FillDataToBitmap(w, h, &bitmap); |
| 41 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output); | 41 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // This class is used to save the download request for verifying with test case. | 44 // This class is used to save the download request for verifying with test case. |
| 45 // It also will be used to invoke the onDidDownload callback. | 45 // It also will be used to invoke the onDidDownload callback. |
| 46 class DownloadHandler { | 46 class DownloadHandler { |
| 47 public: | 47 public: |
| 48 DownloadHandler(int download_id, | 48 explicit DownloadHandler(TestFaviconHandler* favicon_helper) |
| 49 const GURL& image_url, | 49 : favicon_helper_(favicon_helper), |
| 50 int image_size, | 50 failed_(false), |
| 51 TestFaviconHandler* favicon_helper) | 51 downloads_sent_(0) { |
| 52 : image_url_(image_url), | |
| 53 image_size_(image_size), | |
| 54 failed_(false), | |
| 55 download_id_(download_id), | |
| 56 favicon_helper_(favicon_helper) { | |
| 57 FillDataToBitmap(16, 16, &bitmap_); | |
| 58 } | 52 } |
| 59 | 53 |
| 60 virtual ~DownloadHandler() { | 54 virtual ~DownloadHandler() { |
| 61 } | 55 } |
| 62 | 56 |
| 63 static void UpdateFaviconURL(FaviconHandler* helper, | 57 void Reset() { |
| 64 const std::vector<FaviconURL> urls); | 58 downloads_.clear(); |
| 59 failed_ = false; |
| 60 downloads_sent_ = 0; |
| 61 } |
| 62 |
| 63 void AddDownload(int download_id, const GURL& image_url, int image_size) { |
| 64 downloads_.push_back(Download(download_id, image_url, image_size, false)); |
| 65 } |
| 65 | 66 |
| 66 void InvokeCallback(); | 67 void InvokeCallback(); |
| 67 | 68 |
| 68 void UpdateFaviconURL(const std::vector<FaviconURL> urls); | 69 void set_failed(bool failed) { failed_ = failed; } |
| 69 | 70 |
| 70 const GURL image_url_; | 71 int NumDownloads() const { return downloads_.size(); } |
| 71 const int image_size_; | 72 const GURL& GetImageUrl(int idx) const { return downloads_[idx].image_url; } |
| 72 | 73 int GetImageSize(int idx) const { return downloads_[idx].image_size; } |
| 73 // Simulates download failed or not. | 74 void SetImageSize(int idx, int size) { downloads_[idx].image_size = size; } |
| 74 bool failed_; | |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 // Identified the specific download, will also be passed in | 77 struct Download { |
| 78 // OnDidDownloadFavicon callback. | 78 Download(int id, GURL url, int size, bool failed) |
| 79 int download_id_; | 79 : download_id(id), |
| 80 image_url(url), |
| 81 image_size(size) {} |
| 82 ~Download() {} |
| 83 int download_id; |
| 84 GURL image_url; |
| 85 int image_size; |
| 86 }; |
| 87 |
| 80 TestFaviconHandler* favicon_helper_; | 88 TestFaviconHandler* favicon_helper_; |
| 81 SkBitmap bitmap_; | 89 std::vector<Download> downloads_; |
| 90 bool failed_; |
| 91 int downloads_sent_; |
| 82 | 92 |
| 83 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); | 93 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); |
| 84 }; | 94 }; |
| 85 | 95 |
| 86 // This class is used to save the history request for verifying with test case. | 96 // This class is used to save the history request for verifying with test case. |
| 87 // It also will be used to simulate the history response. | 97 // It also will be used to simulate the history response. |
| 88 class HistoryRequestHandler { | 98 class HistoryRequestHandler { |
| 89 public: | 99 public: |
| 90 HistoryRequestHandler(const GURL& page_url, | 100 HistoryRequestHandler(const GURL& page_url, |
| 91 const GURL& icon_url, | 101 const GURL& icon_url, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 public: | 172 public: |
| 163 TestFaviconHandler(const GURL& page_url, | 173 TestFaviconHandler(const GURL& page_url, |
| 164 Profile* profile, | 174 Profile* profile, |
| 165 FaviconHandlerDelegate* delegate, | 175 FaviconHandlerDelegate* delegate, |
| 166 Type type) | 176 Type type) |
| 167 : FaviconHandler(profile, delegate, type), | 177 : FaviconHandler(profile, delegate, type), |
| 168 download_image_size_(0), | 178 download_image_size_(0), |
| 169 entry_(NavigationEntry::Create()), | 179 entry_(NavigationEntry::Create()), |
| 170 download_id_(0) { | 180 download_id_(0) { |
| 171 entry_->SetURL(page_url); | 181 entry_->SetURL(page_url); |
| 182 download_handler_.reset(new DownloadHandler(this)); |
| 172 } | 183 } |
| 173 | 184 |
| 174 virtual ~TestFaviconHandler() { | 185 virtual ~TestFaviconHandler() { |
| 175 } | 186 } |
| 176 | 187 |
| 177 HistoryRequestHandler* history_handler() { | 188 HistoryRequestHandler* history_handler() { |
| 178 return history_handler_.get(); | 189 return history_handler_.get(); |
| 179 } | 190 } |
| 180 | 191 |
| 181 // This method will take the ownership of the given handler. | 192 // This method will take the ownership of the given handler. |
| 182 void set_history_handler(HistoryRequestHandler* handler) { | 193 void set_history_handler(HistoryRequestHandler* handler) { |
| 183 history_handler_.reset(handler); | 194 history_handler_.reset(handler); |
| 184 } | 195 } |
| 185 | 196 |
| 186 DownloadHandler* download_handler() { | 197 DownloadHandler* download_handler() { |
| 187 return download_handler_.get(); | 198 return download_handler_.get(); |
| 188 } | 199 } |
| 189 | 200 |
| 190 // This method will take the ownership of the given download_handler. | |
| 191 void set_download_handler(DownloadHandler* download_handler) { | |
| 192 download_handler_.reset(download_handler); | |
| 193 } | |
| 194 | |
| 195 virtual NavigationEntry* GetEntry() { | 201 virtual NavigationEntry* GetEntry() { |
| 196 return entry_.get(); | 202 return entry_.get(); |
| 197 } | 203 } |
| 198 | 204 |
| 199 const std::vector<FaviconURL>& urls() { | 205 const std::vector<FaviconURL>& urls() { |
| 200 return urls_; | 206 return urls_; |
| 201 } | 207 } |
| 202 | 208 |
| 203 void FetchFavicon(const GURL& url) { | 209 void FetchFavicon(const GURL& url) { |
| 204 FaviconHandler::FetchFavicon(url); | 210 FaviconHandler::FetchFavicon(url); |
| 205 } | 211 } |
| 206 | 212 |
| 207 // The methods to access favicon internal. | 213 // The methods to access favicon internal. |
| 208 FaviconURL* current_candidate() { | 214 FaviconURL* current_candidate() { |
| 209 return FaviconHandler::current_candidate(); | 215 return FaviconHandler::current_candidate(); |
| 210 } | 216 } |
| 211 | 217 |
| 212 void OnDidDownloadFavicon(int id, | |
| 213 const GURL& image_url, | |
| 214 bool errored, | |
| 215 gfx::Image& image) { | |
| 216 FaviconHandler::OnDidDownloadFavicon(id, image_url, errored, image); | |
| 217 } | |
| 218 | |
| 219 protected: | 218 protected: |
| 220 virtual void UpdateFaviconMappingAndFetch( | 219 virtual void UpdateFaviconMappingAndFetch( |
| 221 const GURL& page_url, | 220 const GURL& page_url, |
| 222 const GURL& icon_url, | 221 const GURL& icon_url, |
| 223 history::IconType icon_type, | 222 history::IconType icon_type, |
| 224 CancelableRequestConsumerBase* consumer, | 223 CancelableRequestConsumerBase* consumer, |
| 225 const FaviconService::FaviconDataCallback& callback) OVERRIDE { | 224 const FaviconService::FaviconDataCallback& callback) OVERRIDE { |
| 226 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, | 225 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, |
| 227 icon_type, callback)); | 226 icon_type, callback)); |
| 228 } | 227 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 240 const GURL& page_url, | 239 const GURL& page_url, |
| 241 int icon_types, | 240 int icon_types, |
| 242 CancelableRequestConsumerBase* consumer, | 241 CancelableRequestConsumerBase* consumer, |
| 243 const FaviconService::FaviconDataCallback& callback) OVERRIDE { | 242 const FaviconService::FaviconDataCallback& callback) OVERRIDE { |
| 244 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), | 243 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), |
| 245 icon_types, callback)); | 244 icon_types, callback)); |
| 246 } | 245 } |
| 247 | 246 |
| 248 virtual int DownloadFavicon(const GURL& image_url, int image_size) OVERRIDE { | 247 virtual int DownloadFavicon(const GURL& image_url, int image_size) OVERRIDE { |
| 249 download_id_++; | 248 download_id_++; |
| 250 download_handler_.reset(new DownloadHandler(download_id_, image_url, | 249 download_handler_->AddDownload(download_id_, image_url, image_size); |
| 251 image_size, this)); | |
| 252 return download_id_; | 250 return download_id_; |
| 253 } | 251 } |
| 254 | 252 |
| 255 virtual void SetHistoryFavicon(const GURL& page_url, | 253 virtual void SetHistoryFavicon(const GURL& page_url, |
| 256 const GURL& icon_url, | 254 const GURL& icon_url, |
| 257 const std::vector<unsigned char>& image_data, | 255 const std::vector<unsigned char>& image_data, |
| 258 history::IconType icon_type) OVERRIDE { | 256 history::IconType icon_type) OVERRIDE { |
| 259 history_handler_.reset(new HistoryRequestHandler( | 257 history_handler_.reset(new HistoryRequestHandler( |
| 260 page_url, icon_url,icon_type, image_data, | 258 page_url, icon_url,icon_type, image_data, |
| 261 FaviconService::FaviconDataCallback())); | 259 FaviconService::FaviconDataCallback())); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 283 int download_id_; | 281 int download_id_; |
| 284 | 282 |
| 285 scoped_ptr<DownloadHandler> download_handler_; | 283 scoped_ptr<DownloadHandler> download_handler_; |
| 286 scoped_ptr<HistoryRequestHandler> history_handler_; | 284 scoped_ptr<HistoryRequestHandler> history_handler_; |
| 287 | 285 |
| 288 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | 286 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); |
| 289 }; | 287 }; |
| 290 | 288 |
| 291 namespace { | 289 namespace { |
| 292 | 290 |
| 293 void DownloadHandler::UpdateFaviconURL(FaviconHandler* helper, | |
| 294 const std::vector<FaviconURL> urls) { | |
| 295 helper->OnUpdateFaviconURL(0, urls); | |
| 296 } | |
| 297 | |
| 298 void DownloadHandler::UpdateFaviconURL(const std::vector<FaviconURL> urls) { | |
| 299 UpdateFaviconURL(favicon_helper_, urls); | |
| 300 } | |
| 301 | |
| 302 void DownloadHandler::InvokeCallback() { | |
| 303 gfx::Image image(new SkBitmap(bitmap_)); | |
| 304 favicon_helper_->OnDidDownloadFavicon(download_id_, image_url_, failed_, | |
| 305 image); | |
| 306 } | |
| 307 | |
| 308 void HistoryRequestHandler::InvokeCallback() { | 291 void HistoryRequestHandler::InvokeCallback() { |
| 309 callback_.Run(0, favicon_data_); | 292 callback_.Run(0, favicon_data_); |
| 310 } | 293 } |
| 311 | 294 |
| 295 void DownloadHandler::InvokeCallback() { |
| 296 for (size_t i = downloads_sent_; i < downloads_.size(); ++i) { |
| 297 Download& download(downloads_[i]); |
| 298 SkBitmap bitmap; |
| 299 int bitmap_size = |
| 300 (download.image_size > 0) ? download.image_size : gfx::kFaviconSize; |
| 301 FillDataToBitmap(bitmap_size, bitmap_size, &bitmap); |
| 302 gfx::Image image(bitmap); |
| 303 favicon_helper_->OnDidDownloadFavicon( |
| 304 download.download_id, download.image_url, failed_, image); |
| 305 } |
| 306 downloads_sent_ = downloads_.size(); |
| 307 } |
| 308 |
| 312 class FaviconHandlerTest : public ChromeRenderViewHostTestHarness { | 309 class FaviconHandlerTest : public ChromeRenderViewHostTestHarness { |
| 313 }; | 310 }; |
| 314 | 311 |
| 315 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 312 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 316 const GURL page_url("http://www.google.com"); | 313 const GURL page_url("http://www.google.com"); |
| 317 const GURL icon_url("http://www.google.com/favicon"); | 314 const GURL icon_url("http://www.google.com/favicon"); |
| 318 | 315 |
| 319 TestFaviconHandlerDelegate delegate(contents()); | 316 TestFaviconHandlerDelegate delegate(contents()); |
| 320 Profile* profile = Profile::FromBrowserContext( | 317 Profile* profile = Profile::FromBrowserContext( |
| 321 contents()->GetBrowserContext()); | 318 contents()->GetBrowserContext()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 341 | 338 |
| 342 // Send history response. | 339 // Send history response. |
| 343 history_handler->InvokeCallback(); | 340 history_handler->InvokeCallback(); |
| 344 // Verify FaviconHandler status | 341 // Verify FaviconHandler status |
| 345 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 342 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 346 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 343 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 347 | 344 |
| 348 // Simulates update favicon url. | 345 // Simulates update favicon url. |
| 349 std::vector<FaviconURL> urls; | 346 std::vector<FaviconURL> urls; |
| 350 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 347 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
| 351 DownloadHandler::UpdateFaviconURL(&helper, urls); | 348 helper.OnUpdateFaviconURL(0, urls); |
| 352 | 349 |
| 353 // Verify FaviconHandler status | 350 // Verify FaviconHandler status |
| 354 EXPECT_EQ(1U, helper.urls().size()); | 351 EXPECT_EQ(1U, helper.urls().size()); |
| 355 ASSERT_TRUE(helper.current_candidate()); | 352 ASSERT_TRUE(helper.current_candidate()); |
| 356 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 353 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
| 357 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 354 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
| 358 | 355 |
| 359 // Favicon shouldn't request to download icon. | 356 // Favicon shouldn't request to download icon. |
| 360 DownloadHandler* download_handler = helper.download_handler(); | 357 EXPECT_EQ(0, helper.download_handler()->NumDownloads()); |
| 361 ASSERT_FALSE(download_handler); | |
| 362 } | 358 } |
| 363 | 359 |
| 364 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 360 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
| 365 const GURL page_url("http://www.google.com"); | 361 const GURL page_url("http://www.google.com"); |
| 366 const GURL icon_url("http://www.google.com/favicon"); | 362 const GURL icon_url("http://www.google.com/favicon"); |
| 367 | 363 |
| 368 TestFaviconHandlerDelegate delegate(contents()); | 364 TestFaviconHandlerDelegate delegate(contents()); |
| 369 Profile* profile = Profile::FromBrowserContext( | 365 Profile* profile = Profile::FromBrowserContext( |
| 370 contents()->GetBrowserContext()); | 366 contents()->GetBrowserContext()); |
| 371 TestFaviconHandler helper(page_url, profile, | 367 TestFaviconHandler helper(page_url, profile, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 386 history_handler->favicon_data_.icon_url = icon_url; | 382 history_handler->favicon_data_.icon_url = icon_url; |
| 387 // Send history response. | 383 // Send history response. |
| 388 history_handler->InvokeCallback(); | 384 history_handler->InvokeCallback(); |
| 389 // Verify FaviconHandler status | 385 // Verify FaviconHandler status |
| 390 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 386 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 391 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 387 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 392 | 388 |
| 393 // Simulates update favicon url. | 389 // Simulates update favicon url. |
| 394 std::vector<FaviconURL> urls; | 390 std::vector<FaviconURL> urls; |
| 395 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 391 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
| 396 DownloadHandler::UpdateFaviconURL(&helper, urls); | 392 helper.OnUpdateFaviconURL(0, urls); |
| 397 | 393 |
| 398 // Verify FaviconHandler status | 394 // Verify FaviconHandler status |
| 399 EXPECT_EQ(1U, helper.urls().size()); | 395 EXPECT_EQ(1U, helper.urls().size()); |
| 400 ASSERT_TRUE(helper.current_candidate()); | 396 ASSERT_TRUE(helper.current_candidate()); |
| 401 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 397 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
| 402 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 398 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
| 403 | 399 |
| 404 // Favicon should request to download icon now. | 400 // Favicon should request to download icon now. |
| 405 DownloadHandler* download_handler = helper.download_handler(); | 401 DownloadHandler* download_handler = helper.download_handler(); |
| 406 ASSERT_TRUE(download_handler); | 402 EXPECT_EQ(1, download_handler->NumDownloads()); |
| 407 // Verify the download request. | 403 // Verify the download request. |
| 408 EXPECT_EQ(icon_url, download_handler->image_url_); | 404 EXPECT_EQ(icon_url, download_handler->GetImageUrl(0)); |
| 409 EXPECT_EQ(gfx::kFaviconSize, download_handler->image_size_); | 405 EXPECT_EQ(gfx::kFaviconSize, download_handler->GetImageSize(0)); |
| 410 | 406 |
| 411 // Reset the history_handler to verify whether favicon is set. | 407 // Reset the history_handler to verify whether favicon is set. |
| 412 helper.set_history_handler(NULL); | 408 helper.set_history_handler(NULL); |
| 413 | 409 |
| 414 // Smulates download done. | 410 // Smulates download done. |
| 415 download_handler->InvokeCallback(); | 411 download_handler->InvokeCallback(); |
| 416 | 412 |
| 417 // New icon should be saved to history backend and navigation entry. | 413 // New icon should be saved to history backend and navigation entry. |
| 418 history_handler = helper.history_handler(); | 414 history_handler = helper.history_handler(); |
| 419 ASSERT_TRUE(history_handler); | 415 ASSERT_TRUE(history_handler); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 458 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 463 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 459 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 464 | 460 |
| 465 // Reset the history_handler to verify whether new icon is requested from | 461 // Reset the history_handler to verify whether new icon is requested from |
| 466 // history. | 462 // history. |
| 467 helper.set_history_handler(NULL); | 463 helper.set_history_handler(NULL); |
| 468 | 464 |
| 469 // Simulates update with the different favicon url. | 465 // Simulates update with the different favicon url. |
| 470 std::vector<FaviconURL> urls; | 466 std::vector<FaviconURL> urls; |
| 471 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON)); | 467 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON)); |
| 472 DownloadHandler::UpdateFaviconURL(&helper, urls); | 468 helper.OnUpdateFaviconURL(0, urls); |
| 473 | 469 |
| 474 // Verify FaviconHandler status. | 470 // Verify FaviconHandler status. |
| 475 EXPECT_EQ(1U, helper.urls().size()); | 471 EXPECT_EQ(1U, helper.urls().size()); |
| 476 ASSERT_TRUE(helper.current_candidate()); | 472 ASSERT_TRUE(helper.current_candidate()); |
| 477 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 473 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
| 478 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 474 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
| 479 // The favicon status's url should be updated. | 475 // The favicon status's url should be updated. |
| 480 ASSERT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 476 ASSERT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 481 | 477 |
| 482 // Favicon should be requested from history. | 478 // Favicon should be requested from history. |
| 483 history_handler = helper.history_handler(); | 479 history_handler = helper.history_handler(); |
| 484 ASSERT_TRUE(history_handler); | 480 ASSERT_TRUE(history_handler); |
| 485 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 481 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 486 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 482 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 487 EXPECT_EQ(page_url, history_handler->page_url_); | 483 EXPECT_EQ(page_url, history_handler->page_url_); |
| 488 | 484 |
| 489 // Simulate not find icon. | 485 // Simulate not find icon. |
| 490 history_handler->favicon_data_.known_icon = false; | 486 history_handler->favicon_data_.known_icon = false; |
| 491 history_handler->InvokeCallback(); | 487 history_handler->InvokeCallback(); |
| 492 | 488 |
| 493 // Favicon should request to download icon now. | 489 // Favicon should request to download icon now. |
| 494 DownloadHandler* download_handler = helper.download_handler(); | 490 DownloadHandler* download_handler = helper.download_handler(); |
| 495 ASSERT_TRUE(download_handler); | 491 EXPECT_EQ(1, download_handler->NumDownloads()); |
| 496 // Verify the download request. | 492 // Verify the download request. |
| 497 EXPECT_EQ(new_icon_url, download_handler->image_url_); | 493 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl(0)); |
| 498 EXPECT_EQ(gfx::kFaviconSize, download_handler->image_size_); | 494 EXPECT_EQ(gfx::kFaviconSize, download_handler->GetImageSize(0)); |
| 499 | 495 |
| 500 // Reset the history_handler to verify whether favicon is set. | 496 // Reset the history_handler to verify whether favicon is set. |
| 501 helper.set_history_handler(NULL); | 497 helper.set_history_handler(NULL); |
| 502 | 498 |
| 503 // Smulates download done. | 499 // Smulates download done. |
| 504 download_handler->InvokeCallback(); | 500 download_handler->InvokeCallback(); |
| 505 | 501 |
| 506 // New icon should be saved to history backend and navigation entry. | 502 // New icon should be saved to history backend and navigation entry. |
| 507 history_handler = helper.history_handler(); | 503 history_handler = helper.history_handler(); |
| 508 ASSERT_TRUE(history_handler); | 504 ASSERT_TRUE(history_handler); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 547 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 552 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 548 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
| 553 | 549 |
| 554 // Reset the history_handler to verify whether new icon is requested from | 550 // Reset the history_handler to verify whether new icon is requested from |
| 555 // history. | 551 // history. |
| 556 helper.set_history_handler(NULL); | 552 helper.set_history_handler(NULL); |
| 557 | 553 |
| 558 // Simulates update with the different favicon url. | 554 // Simulates update with the different favicon url. |
| 559 std::vector<FaviconURL> urls; | 555 std::vector<FaviconURL> urls; |
| 560 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON)); | 556 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON)); |
| 561 DownloadHandler::UpdateFaviconURL(&helper, urls); | 557 helper.OnUpdateFaviconURL(0, urls); |
| 562 | 558 |
| 563 // Verify FaviconHandler status. | 559 // Verify FaviconHandler status. |
| 564 EXPECT_EQ(1U, helper.urls().size()); | 560 EXPECT_EQ(1U, helper.urls().size()); |
| 565 ASSERT_TRUE(helper.current_candidate()); | 561 ASSERT_TRUE(helper.current_candidate()); |
| 566 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 562 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
| 567 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 563 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
| 568 // The favicon status's url should be updated. | 564 // The favicon status's url should be updated. |
| 569 ASSERT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 565 ASSERT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 570 | 566 |
| 571 // Favicon should be requested from history. | 567 // Favicon should be requested from history. |
| 572 history_handler = helper.history_handler(); | 568 history_handler = helper.history_handler(); |
| 573 ASSERT_TRUE(history_handler); | 569 ASSERT_TRUE(history_handler); |
| 574 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 570 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 575 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); | 571 EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_); |
| 576 EXPECT_EQ(page_url, history_handler->page_url_); | 572 EXPECT_EQ(page_url, history_handler->page_url_); |
| 577 | 573 |
| 578 // Simulate find icon. | 574 // Simulate find icon. |
| 579 history_handler->favicon_data_.known_icon = true; | 575 history_handler->favicon_data_.known_icon = true; |
| 580 history_handler->favicon_data_.icon_type = history::FAVICON; | 576 history_handler->favicon_data_.icon_type = history::FAVICON; |
| 581 history_handler->favicon_data_.expired = false; | 577 history_handler->favicon_data_.expired = false; |
| 582 history_handler->favicon_data_.icon_url = new_icon_url; | 578 history_handler->favicon_data_.icon_url = new_icon_url; |
| 583 history_handler->favicon_data_.image_data = data; | 579 history_handler->favicon_data_.image_data = data; |
| 584 history_handler->InvokeCallback(); | 580 history_handler->InvokeCallback(); |
| 585 | 581 |
| 586 // Shouldn't request download favicon | 582 // Shouldn't request download favicon |
| 587 EXPECT_FALSE(helper.download_handler()); | 583 EXPECT_EQ(0, helper.download_handler()->NumDownloads()); |
| 588 | 584 |
| 589 // Verify the favicon status. | 585 // Verify the favicon status. |
| 590 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 586 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 591 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 587 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 592 EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); | 588 EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); |
| 593 } | 589 } |
| 594 | 590 |
| 595 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 591 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
| 596 const GURL page_url("http://www.google.com"); | 592 const GURL page_url("http://www.google.com"); |
| 597 const GURL icon_url("http://www.google.com/favicon"); | 593 const GURL icon_url("http://www.google.com/favicon"); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 622 | 618 |
| 623 // Reset the history_handler to verify whether new icon is requested from | 619 // Reset the history_handler to verify whether new icon is requested from |
| 624 // history. | 620 // history. |
| 625 helper.set_history_handler(NULL); | 621 helper.set_history_handler(NULL); |
| 626 | 622 |
| 627 // Simulates update with the different favicon url. | 623 // Simulates update with the different favicon url. |
| 628 std::vector<FaviconURL> urls; | 624 std::vector<FaviconURL> urls; |
| 629 urls.push_back(FaviconURL(icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON)); | 625 urls.push_back(FaviconURL(icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON)); |
| 630 urls.push_back(FaviconURL(new_icon_url, FaviconURL::TOUCH_ICON)); | 626 urls.push_back(FaviconURL(new_icon_url, FaviconURL::TOUCH_ICON)); |
| 631 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON)); | 627 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON)); |
| 632 | 628 helper.OnUpdateFaviconURL(0, urls); |
| 633 DownloadHandler::UpdateFaviconURL(&helper, urls); | |
| 634 | 629 |
| 635 // Verify FaviconHandler status. | 630 // Verify FaviconHandler status. |
| 636 EXPECT_EQ(2U, helper.urls().size()); | 631 EXPECT_EQ(2U, helper.urls().size()); |
| 637 ASSERT_TRUE(helper.current_candidate()); | 632 ASSERT_TRUE(helper.current_candidate()); |
| 638 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 633 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
| 639 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, | 634 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, |
| 640 helper.current_candidate()->icon_type); | 635 helper.current_candidate()->icon_type); |
| 641 | 636 |
| 642 // Favicon should be requested from history. | 637 // Favicon should be requested from history. |
| 643 history_handler = helper.history_handler(); | 638 history_handler = helper.history_handler(); |
| 644 ASSERT_TRUE(history_handler); | 639 ASSERT_TRUE(history_handler); |
| 645 EXPECT_EQ(icon_url, history_handler->icon_url_); | 640 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 646 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 641 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
| 647 EXPECT_EQ(page_url, history_handler->page_url_); | 642 EXPECT_EQ(page_url, history_handler->page_url_); |
| 648 | 643 |
| 649 // Simulate not find icon. | 644 // Simulate not find icon. |
| 650 history_handler->favicon_data_.known_icon = false; | 645 history_handler->favicon_data_.known_icon = false; |
| 651 history_handler->InvokeCallback(); | 646 history_handler->InvokeCallback(); |
| 652 | 647 |
| 653 // Should request download favicon. | 648 // Should request download favicon. |
| 654 DownloadHandler* download_handler = helper.download_handler(); | 649 DownloadHandler* download_handler = helper.download_handler(); |
| 655 EXPECT_TRUE(download_handler); | 650 EXPECT_EQ(1, download_handler->NumDownloads()); |
| 656 // Verify the download request. | 651 // Verify the download request. |
| 657 EXPECT_EQ(icon_url, download_handler->image_url_); | 652 EXPECT_EQ(icon_url, download_handler->GetImageUrl(0)); |
| 658 EXPECT_EQ(0, download_handler->image_size_); | 653 EXPECT_EQ(0, download_handler->GetImageSize(0)); |
| 659 | 654 |
| 660 // Reset the history_handler to verify whether favicon is request from | 655 // Reset the history_handler to verify whether favicon is request from |
| 661 // history. | 656 // history. |
| 662 helper.set_history_handler(NULL); | 657 helper.set_history_handler(NULL); |
| 663 // Smulates download failed. | 658 // Smulates download failed. |
| 664 download_handler->failed_ = true; | 659 download_handler->set_failed(true); |
| 665 download_handler->InvokeCallback(); | 660 download_handler->InvokeCallback(); |
| 666 | 661 |
| 667 // Left 1 url. | 662 // Left 1 url. |
| 668 EXPECT_EQ(1U, helper.urls().size()); | 663 EXPECT_EQ(1U, helper.urls().size()); |
| 669 ASSERT_TRUE(helper.current_candidate()); | 664 ASSERT_TRUE(helper.current_candidate()); |
| 670 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 665 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
| 671 EXPECT_EQ(FaviconURL::TOUCH_ICON, helper.current_candidate()->icon_type); | 666 EXPECT_EQ(FaviconURL::TOUCH_ICON, helper.current_candidate()->icon_type); |
| 672 | 667 |
| 673 // Favicon should be requested from history. | 668 // Favicon should be requested from history. |
| 674 history_handler = helper.history_handler(); | 669 history_handler = helper.history_handler(); |
| 675 ASSERT_TRUE(history_handler); | 670 ASSERT_TRUE(history_handler); |
| 676 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 671 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| 677 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 672 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 678 EXPECT_EQ(page_url, history_handler->page_url_); | 673 EXPECT_EQ(page_url, history_handler->page_url_); |
| 679 | 674 |
| 680 // Reset download handler | 675 // Reset download handler |
| 681 helper.set_download_handler(NULL); | 676 download_handler->Reset(); |
| 682 | 677 |
| 683 // Smulates getting a expired icon from history. | 678 // Smulates getting a expired icon from history. |
| 684 history_handler->favicon_data_.known_icon = true; | 679 history_handler->favicon_data_.known_icon = true; |
| 685 history_handler->favicon_data_.icon_type = history::TOUCH_ICON; | 680 history_handler->favicon_data_.icon_type = history::TOUCH_ICON; |
| 686 history_handler->favicon_data_.expired = true; | 681 history_handler->favicon_data_.expired = true; |
| 687 history_handler->favicon_data_.icon_url = new_icon_url; | 682 history_handler->favicon_data_.icon_url = new_icon_url; |
| 688 scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); | 683 scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); |
| 689 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 684 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 690 history_handler->favicon_data_.image_data = data; | 685 history_handler->favicon_data_.image_data = data; |
| 691 history_handler->InvokeCallback(); | 686 history_handler->InvokeCallback(); |
| 692 | 687 |
| 693 // Verify the download request. | 688 // Verify the download request. |
| 694 download_handler = helper.download_handler(); | 689 EXPECT_EQ(1, download_handler->NumDownloads()); |
| 695 EXPECT_TRUE(download_handler); | 690 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl(0)); |
| 696 EXPECT_EQ(new_icon_url, download_handler->image_url_); | 691 EXPECT_EQ(0, download_handler->GetImageSize(0)); |
| 697 EXPECT_EQ(0, download_handler->image_size_); | |
| 698 | 692 |
| 699 helper.set_history_handler(NULL); | 693 helper.set_history_handler(NULL); |
| 700 | 694 |
| 701 // Simulates icon being downloaded. | 695 // Simulates icon being downloaded. |
| 702 download_handler->InvokeCallback(); | 696 download_handler->InvokeCallback(); |
| 703 | 697 |
| 704 // New icon should be saved to history backend. | 698 // New icon should be saved to history backend. |
| 705 history_handler = helper.history_handler(); | 699 history_handler = helper.history_handler(); |
| 706 ASSERT_TRUE(history_handler); | 700 ASSERT_TRUE(history_handler); |
| 707 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 701 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 734 |
| 741 // Reset the history_handler to verify whether new icon is requested from | 735 // Reset the history_handler to verify whether new icon is requested from |
| 742 // history. | 736 // history. |
| 743 helper.set_history_handler(NULL); | 737 helper.set_history_handler(NULL); |
| 744 | 738 |
| 745 // Simulates update with the different favicon url. | 739 // Simulates update with the different favicon url. |
| 746 std::vector<FaviconURL> urls; | 740 std::vector<FaviconURL> urls; |
| 747 urls.push_back(FaviconURL(icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON)); | 741 urls.push_back(FaviconURL(icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON)); |
| 748 urls.push_back(FaviconURL(new_icon_url, FaviconURL::TOUCH_ICON)); | 742 urls.push_back(FaviconURL(new_icon_url, FaviconURL::TOUCH_ICON)); |
| 749 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON)); | 743 urls.push_back(FaviconURL(new_icon_url, FaviconURL::FAVICON)); |
| 750 | 744 helper.OnUpdateFaviconURL(0, urls); |
| 751 DownloadHandler::UpdateFaviconURL(&helper, urls); | |
| 752 | 745 |
| 753 // Verify FaviconHandler status. | 746 // Verify FaviconHandler status. |
| 754 EXPECT_EQ(2U, helper.urls().size()); | 747 EXPECT_EQ(2U, helper.urls().size()); |
| 755 ASSERT_TRUE(helper.current_candidate()); | 748 ASSERT_TRUE(helper.current_candidate()); |
| 756 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 749 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
| 757 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, | 750 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, |
| 758 helper.current_candidate()->icon_type); | 751 helper.current_candidate()->icon_type); |
| 759 | 752 |
| 760 // Favicon should be requested from history. | 753 // Favicon should be requested from history. |
| 761 history_handler = helper.history_handler(); | 754 history_handler = helper.history_handler(); |
| 762 ASSERT_TRUE(history_handler); | 755 ASSERT_TRUE(history_handler); |
| 763 EXPECT_EQ(icon_url, history_handler->icon_url_); | 756 EXPECT_EQ(icon_url, history_handler->icon_url_); |
| 764 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 757 EXPECT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
| 765 EXPECT_EQ(page_url, history_handler->page_url_); | 758 EXPECT_EQ(page_url, history_handler->page_url_); |
| 766 | 759 |
| 767 // Simulate not find icon. | 760 // Simulate not find icon. |
| 768 history_handler->favicon_data_.known_icon = false; | 761 history_handler->favicon_data_.known_icon = false; |
| 769 history_handler->InvokeCallback(); | 762 history_handler->InvokeCallback(); |
| 770 | 763 |
| 771 // Should request download favicon. | 764 // Should request download favicon. |
| 772 DownloadHandler* download_handler = helper.download_handler(); | 765 DownloadHandler* download_handler = helper.download_handler(); |
| 773 EXPECT_TRUE(download_handler); | 766 EXPECT_EQ(1, download_handler->NumDownloads()); |
| 774 // Verify the download request. | 767 // Verify the download request. |
| 775 EXPECT_EQ(icon_url, download_handler->image_url_); | 768 EXPECT_EQ(icon_url, download_handler->GetImageUrl(0)); |
| 776 EXPECT_EQ(0, download_handler->image_size_); | 769 EXPECT_EQ(0, download_handler->GetImageSize(0)); |
| 777 | 770 |
| 778 // Reset the history_handler to verify whether favicon is request from | 771 // Reset the history_handler to verify whether favicon is request from |
| 779 // history. | 772 // history. |
| 780 helper.set_history_handler(NULL); | 773 helper.set_history_handler(NULL); |
| 781 const GURL latest_icon_url("http://www.google.com/latest_favicon"); | 774 const GURL latest_icon_url("http://www.google.com/latest_favicon"); |
| 782 std::vector<FaviconURL> latest_urls; | 775 std::vector<FaviconURL> latest_urls; |
| 783 latest_urls.push_back(FaviconURL(latest_icon_url, FaviconURL::TOUCH_ICON)); | 776 latest_urls.push_back(FaviconURL(latest_icon_url, FaviconURL::TOUCH_ICON)); |
| 784 DownloadHandler::UpdateFaviconURL(&helper, latest_urls); | 777 helper.OnUpdateFaviconURL(0, latest_urls); |
| 778 |
| 785 EXPECT_EQ(1U, helper.urls().size()); | 779 EXPECT_EQ(1U, helper.urls().size()); |
| 786 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); | 780 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); |
| 787 EXPECT_EQ(FaviconURL::TOUCH_ICON, helper.current_candidate()->icon_type); | 781 EXPECT_EQ(FaviconURL::TOUCH_ICON, helper.current_candidate()->icon_type); |
| 788 | 782 |
| 789 // Whether new icon is requested from history | 783 // Whether new icon is requested from history |
| 790 history_handler = helper.history_handler(); | 784 history_handler = helper.history_handler(); |
| 791 ASSERT_TRUE(history_handler); | 785 ASSERT_TRUE(history_handler); |
| 792 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); | 786 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); |
| 793 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 787 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 794 EXPECT_EQ(page_url, history_handler->page_url_); | 788 EXPECT_EQ(page_url, history_handler->page_url_); |
| 795 | 789 |
| 796 // Reset the history_handler to verify whether favicon is request from | 790 // Reset the history_handler to verify whether favicon is request from |
| 797 // history. | 791 // history. |
| 798 // Save the callback for late use. | 792 // Save the callback for late use. |
| 799 FaviconService::FaviconDataCallback callback = history_handler->callback_; | 793 FaviconService::FaviconDataCallback callback = history_handler->callback_; |
| 800 helper.set_history_handler(NULL); | 794 helper.set_history_handler(NULL); |
| 801 | 795 |
| 802 // Simulates download succeed. | 796 // Simulates download succeed. |
| 803 download_handler->InvokeCallback(); | 797 download_handler->InvokeCallback(); |
| 804 // The downloaded icon should be thrown away as there is favicon update. | 798 // The downloaded icon should be thrown away as there is favicon update. |
| 805 EXPECT_FALSE(helper.history_handler()); | 799 EXPECT_FALSE(helper.history_handler()); |
| 806 | 800 |
| 807 helper.set_download_handler(NULL); | 801 download_handler->Reset(); |
| 808 | 802 |
| 809 // Simulates getting the icon from history. | 803 // Simulates getting the icon from history. |
| 810 scoped_ptr<HistoryRequestHandler> handler; | 804 scoped_ptr<HistoryRequestHandler> handler; |
| 811 handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, | 805 handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, |
| 812 history::TOUCH_ICON, callback)); | 806 history::TOUCH_ICON, callback)); |
| 813 handler->favicon_data_.known_icon = true; | 807 handler->favicon_data_.known_icon = true; |
| 814 handler->favicon_data_.expired = false; | 808 handler->favicon_data_.expired = false; |
| 815 handler->favicon_data_.icon_type = history::TOUCH_ICON; | 809 handler->favicon_data_.icon_type = history::TOUCH_ICON; |
| 816 handler->favicon_data_.icon_url = latest_icon_url; | 810 handler->favicon_data_.icon_url = latest_icon_url; |
| 817 scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); | 811 scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); |
| 818 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 812 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 819 handler->favicon_data_.image_data = data; | 813 handler->favicon_data_.image_data = data; |
| 820 | 814 |
| 821 handler->InvokeCallback(); | 815 handler->InvokeCallback(); |
| 822 | 816 |
| 823 // No download request. | 817 // No download request. |
| 824 EXPECT_FALSE(helper.download_handler()); | 818 EXPECT_EQ(0, download_handler->NumDownloads()); |
| 819 } |
| 820 |
| 821 TEST_F(FaviconHandlerTest, MultipleFavicon) { |
| 822 const GURL page_url("http://www.google.com"); |
| 823 const GURL icon_url("http://www.google.com/favicon"); |
| 824 const GURL icon_url_small("http://www.google.com/favicon_small"); |
| 825 const GURL icon_url_preferred("http://www.google.com/favicon_preferred"); |
| 826 const GURL icon_url_large("http://www.google.com/favicon_large"); |
| 827 |
| 828 TestFaviconHandlerDelegate delegate(contents()); |
| 829 Profile* profile = Profile::FromBrowserContext( |
| 830 contents()->GetBrowserContext()); |
| 831 TestFaviconHandler helper(page_url, profile, |
| 832 &delegate, FaviconHandler::FAVICON); |
| 833 |
| 834 helper.FetchFavicon(page_url); |
| 835 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 836 |
| 837 // Set valid icon data. |
| 838 history_handler->favicon_data_.known_icon = true; |
| 839 history_handler->favicon_data_.icon_type = history::FAVICON; |
| 840 history_handler->favicon_data_.expired = false; |
| 841 history_handler->favicon_data_.icon_url = icon_url; |
| 842 scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); |
| 843 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 844 history_handler->favicon_data_.image_data = data; |
| 845 |
| 846 // Send history response. |
| 847 history_handler->InvokeCallback(); |
| 848 |
| 849 // Simulates update with the different favicon url. |
| 850 std::vector<FaviconURL> urls; |
| 851 urls.push_back(FaviconURL(icon_url_small, FaviconURL::FAVICON)); |
| 852 urls.push_back(FaviconURL(icon_url_preferred, FaviconURL::FAVICON)); |
| 853 urls.push_back(FaviconURL(icon_url_large, FaviconURL::FAVICON)); |
| 854 helper.OnUpdateFaviconURL(0, urls); |
| 855 |
| 856 DownloadHandler* download_handler = helper.download_handler(); |
| 857 |
| 858 // Download the first icon (set not in history). |
| 859 helper.history_handler()->favicon_data_.known_icon = false; |
| 860 helper.history_handler()->InvokeCallback(); |
| 861 EXPECT_EQ(1, download_handler->NumDownloads()); |
| 862 EXPECT_EQ(icon_url_small, download_handler->GetImageUrl(0)); |
| 863 download_handler->SetImageSize(0, gfx::kFaviconSize / 2); |
| 864 download_handler->InvokeCallback(); |
| 865 |
| 866 // Download the second icon (set not in history). |
| 867 helper.history_handler()->favicon_data_.known_icon = false; |
| 868 helper.history_handler()->InvokeCallback(); |
| 869 EXPECT_EQ(2, download_handler->NumDownloads()); |
| 870 EXPECT_EQ(icon_url_preferred, download_handler->GetImageUrl(1)); |
| 871 download_handler->SetImageSize(1, gfx::kFaviconSize); |
| 872 download_handler->InvokeCallback(); |
| 873 |
| 874 // Download the third icon (set not in history). |
| 875 helper.history_handler()->favicon_data_.known_icon = false; |
| 876 helper.history_handler()->InvokeCallback(); |
| 877 EXPECT_EQ(3, download_handler->NumDownloads()); |
| 878 EXPECT_EQ(icon_url_large, download_handler->GetImageUrl(2)); |
| 879 download_handler->SetImageSize(2, gfx::kFaviconSize * 2); |
| 880 download_handler->InvokeCallback(); |
| 881 |
| 882 // Verify correct icon size chosen. |
| 883 EXPECT_EQ(icon_url_preferred, helper.GetEntry()->GetFavicon().url); |
| 884 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 885 EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); |
| 886 EXPECT_EQ(gfx::kFaviconSize, helper.GetEntry()->GetFavicon().bitmap.width()); |
| 825 } | 887 } |
| 826 | 888 |
| 827 } // namespace. | 889 } // namespace. |
| OLD | NEW |