| 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 profile()->CreateHistoryService(true, false); | 502 profile()->CreateHistoryService(true, false); |
| 503 profile()->CreateFaviconService(); | 503 profile()->CreateFaviconService(); |
| 504 Browser browser(Browser::TYPE_TABBED, profile()); | 504 Browser browser(Browser::TYPE_TABBED, profile()); |
| 505 FaviconDelegate favicon_delegate; | 505 FaviconDelegate favicon_delegate; |
| 506 | 506 |
| 507 BackForwardMenuModel back_model( | 507 BackForwardMenuModel back_model( |
| 508 &browser, BackForwardMenuModel::BACKWARD_MENU); | 508 &browser, BackForwardMenuModel::BACKWARD_MENU); |
| 509 back_model.set_test_web_contents(controller().GetWebContents()); | 509 back_model.set_test_web_contents(controller().GetWebContents()); |
| 510 back_model.SetMenuModelDelegate(&favicon_delegate); | 510 back_model.SetMenuModelDelegate(&favicon_delegate); |
| 511 | 511 |
| 512 SkBitmap new_icon(CreateBitmap(SK_ColorRED)); | 512 SkBitmap new_icon_bitmap(CreateBitmap(SK_ColorRED)); |
| 513 std::vector<unsigned char> icon_data; | 513 std::vector<unsigned char> icon_data; |
| 514 gfx::PNGCodec::EncodeBGRASkBitmap(new_icon, false, &icon_data); | 514 gfx::PNGCodec::EncodeBGRASkBitmap(new_icon_bitmap, false, &icon_data); |
| 515 | 515 |
| 516 GURL url1 = GURL("http://www.a.com/1"); | 516 GURL url1 = GURL("http://www.a.com/1"); |
| 517 GURL url2 = GURL("http://www.a.com/2"); | 517 GURL url2 = GURL("http://www.a.com/2"); |
| 518 GURL url1_favicon("http://www.a.com/1/favicon.ico"); | 518 GURL url1_favicon("http://www.a.com/1/favicon.ico"); |
| 519 | 519 |
| 520 NavigateAndCommit(url1); | 520 NavigateAndCommit(url1); |
| 521 // Navigate to a new URL so that url1 will be in the BackForwardMenuModel. | 521 // Navigate to a new URL so that url1 will be in the BackForwardMenuModel. |
| 522 NavigateAndCommit(url2); | 522 NavigateAndCommit(url2); |
| 523 | 523 |
| 524 // Set the desired favicon for url1. | 524 // Set the desired favicon for url1. |
| 525 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPage(url1, | 525 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPage(url1, |
| 526 history::SOURCE_BROWSED); | 526 history::SOURCE_BROWSED); |
| 527 profile()->GetFaviconService(Profile::EXPLICIT_ACCESS)->SetFavicon(url1, | 527 profile()->GetFaviconService(Profile::EXPLICIT_ACCESS)->SetFavicon(url1, |
| 528 url1_favicon, icon_data, history::FAVICON); | 528 url1_favicon, icon_data, history::FAVICON); |
| 529 | 529 |
| 530 // Will return the current icon (default) but start an anync call | 530 // Will return the current icon (default) but start an anync call |
| 531 // to retrieve the favicon from the favicon service. | 531 // to retrieve the favicon from the favicon service. |
| 532 SkBitmap default_icon; | 532 gfx::ImageSkia default_icon; |
| 533 back_model.GetIconAt(0, &default_icon); | 533 back_model.GetIconAt(0, &default_icon); |
| 534 | 534 |
| 535 // Make the favicon service run GetFavIconForURL, | 535 // Make the favicon service run GetFavIconForURL, |
| 536 // FaviconDelegate.OnIconChanged will be called. | 536 // FaviconDelegate.OnIconChanged will be called. |
| 537 MessageLoop::current()->Run(); | 537 MessageLoop::current()->Run(); |
| 538 | 538 |
| 539 // Verify that the callback executed. | 539 // Verify that the callback executed. |
| 540 EXPECT_TRUE(favicon_delegate.was_called()); | 540 EXPECT_TRUE(favicon_delegate.was_called()); |
| 541 | 541 |
| 542 // Verify the bitmaps match. | 542 // Verify the bitmaps match. |
| 543 SkBitmap valid_icon; | 543 gfx::ImageSkia valid_icon; |
| 544 // This time we will get the new favicon returned. | 544 // This time we will get the new favicon returned. |
| 545 back_model.GetIconAt(0, &valid_icon); | 545 back_model.GetIconAt(0, &valid_icon); |
| 546 SkAutoLockPixels a(new_icon); | 546 |
| 547 SkAutoLockPixels b(valid_icon); | 547 SkBitmap default_icon_bitmap = *default_icon.bitmap(); |
| 548 SkAutoLockPixels c(default_icon); | 548 SkBitmap valid_icon_bitmap = *valid_icon.bitmap(); |
| 549 |
| 550 SkAutoLockPixels a(new_icon_bitmap); |
| 551 SkAutoLockPixels b(valid_icon_bitmap); |
| 552 SkAutoLockPixels c(default_icon_bitmap); |
| 549 // Verify we did not get the default favicon. | 553 // Verify we did not get the default favicon. |
| 550 EXPECT_NE(0, memcmp(default_icon.getPixels(), valid_icon.getPixels(), | 554 EXPECT_NE(0, memcmp(default_icon_bitmap.getPixels(), |
| 551 default_icon.getSize())); | 555 valid_icon_bitmap.getPixels(), |
| 556 default_icon_bitmap.getSize())); |
| 552 // Verify we did get the expected favicon. | 557 // Verify we did get the expected favicon. |
| 553 EXPECT_EQ(0, memcmp(new_icon.getPixels(), valid_icon.getPixels(), | 558 EXPECT_EQ(0, memcmp(new_icon_bitmap.getPixels(), |
| 554 new_icon.getSize())); | 559 valid_icon_bitmap.getPixels(), |
| 560 new_icon_bitmap.getSize())); |
| 555 | 561 |
| 556 // Make sure the browser deconstructor doesn't have problems. | 562 // Make sure the browser deconstructor doesn't have problems. |
| 557 browser.CloseAllTabs(); | 563 browser.CloseAllTabs(); |
| 558 // This is required to prevent the message loop from hanging. | 564 // This is required to prevent the message loop from hanging. |
| 559 profile()->DestroyHistoryService(); | 565 profile()->DestroyHistoryService(); |
| 560 } | 566 } |
| 561 | |
| OLD | NEW |