OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 scoped_ptr<Browser> browser( | 508 scoped_ptr<Browser> browser( |
509 chrome::CreateBrowserWithTestWindowForProfile(profile())); | 509 chrome::CreateBrowserWithTestWindowForProfile(profile())); |
510 FaviconDelegate favicon_delegate; | 510 FaviconDelegate favicon_delegate; |
511 | 511 |
512 BackForwardMenuModel back_model( | 512 BackForwardMenuModel back_model( |
513 browser.get(), BackForwardMenuModel::BACKWARD_MENU); | 513 browser.get(), BackForwardMenuModel::BACKWARD_MENU); |
514 back_model.set_test_web_contents(controller().GetWebContents()); | 514 back_model.set_test_web_contents(controller().GetWebContents()); |
515 back_model.SetMenuModelDelegate(&favicon_delegate); | 515 back_model.SetMenuModelDelegate(&favicon_delegate); |
516 | 516 |
517 SkBitmap new_icon_bitmap(CreateBitmap(SK_ColorRED)); | 517 SkBitmap new_icon_bitmap(CreateBitmap(SK_ColorRED)); |
518 std::vector<unsigned char> icon_data; | |
519 gfx::PNGCodec::EncodeBGRASkBitmap(new_icon_bitmap, false, &icon_data); | |
520 | 518 |
521 GURL url1 = GURL("http://www.a.com/1"); | 519 GURL url1 = GURL("http://www.a.com/1"); |
522 GURL url2 = GURL("http://www.a.com/2"); | 520 GURL url2 = GURL("http://www.a.com/2"); |
523 GURL url1_favicon("http://www.a.com/1/favicon.ico"); | 521 GURL url1_favicon("http://www.a.com/1/favicon.ico"); |
524 | 522 |
525 NavigateAndCommit(url1); | 523 NavigateAndCommit(url1); |
526 // Navigate to a new URL so that url1 will be in the BackForwardMenuModel. | 524 // Navigate to a new URL so that url1 will be in the BackForwardMenuModel. |
527 NavigateAndCommit(url2); | 525 NavigateAndCommit(url2); |
528 | 526 |
529 // Set the desired favicon for url1. | 527 // Set the desired favicon for url1. |
530 HistoryServiceFactory::GetForProfile( | 528 HistoryServiceFactory::GetForProfile( |
531 profile(), Profile::EXPLICIT_ACCESS)->AddPage( | 529 profile(), Profile::EXPLICIT_ACCESS)->AddPage( |
532 url1, history::SOURCE_BROWSED); | 530 url1, history::SOURCE_BROWSED); |
533 FaviconServiceFactory::GetForProfile( | 531 FaviconServiceFactory::GetForProfile( |
534 profile(), Profile::EXPLICIT_ACCESS)->SetFavicon( | 532 profile(), Profile::EXPLICIT_ACCESS)->SetFavicons( |
535 url1, url1_favicon, icon_data, history::FAVICON); | 533 url1, url1_favicon, history::FAVICON, gfx::Image(new_icon_bitmap)); |
536 | 534 |
537 // Will return the current icon (default) but start an anync call | 535 // Will return the current icon (default) but start an anync call |
538 // to retrieve the favicon from the favicon service. | 536 // to retrieve the favicon from the favicon service. |
539 gfx::Image default_icon; | 537 gfx::Image default_icon; |
540 back_model.GetIconAt(0, &default_icon); | 538 back_model.GetIconAt(0, &default_icon); |
541 | 539 |
542 // Make the favicon service run GetFavIconForURL, | 540 // Make the favicon service run GetFavIconForURL, |
543 // FaviconDelegate.OnIconChanged will be called. | 541 // FaviconDelegate.OnIconChanged will be called. |
544 MessageLoop::current()->Run(); | 542 MessageLoop::current()->Run(); |
545 | 543 |
(...skipping 18 matching lines...) Expand all Loading... |
564 // Verify we did get the expected favicon. | 562 // Verify we did get the expected favicon. |
565 EXPECT_EQ(0, memcmp(new_icon_bitmap.getPixels(), | 563 EXPECT_EQ(0, memcmp(new_icon_bitmap.getPixels(), |
566 valid_icon_bitmap.getPixels(), | 564 valid_icon_bitmap.getPixels(), |
567 new_icon_bitmap.getSize())); | 565 new_icon_bitmap.getSize())); |
568 | 566 |
569 // Make sure the browser deconstructor doesn't have problems. | 567 // Make sure the browser deconstructor doesn't have problems. |
570 chrome::CloseAllTabs(browser.get()); | 568 chrome::CloseAllTabs(browser.get()); |
571 // This is required to prevent the message loop from hanging. | 569 // This is required to prevent the message loop from hanging. |
572 profile()->DestroyHistoryService(); | 570 profile()->DestroyHistoryService(); |
573 } | 571 } |
OLD | NEW |