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