Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4425)

Unified Diff: chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc

Issue 2928005: Retrieve favicons from history as NavigationEntries are converted from TabNav... Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Updated to compile against trunk. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc
diff --git a/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc b/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc
index 2e4b988b6061a9422427546055f8241689c41ec5..436d98f52b477cfbb96a569363ed5423bc657d34 100644
--- a/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc
@@ -7,14 +7,49 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/history/history.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/test_tab_contents.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/common/url_constants.h"
+#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/codec/png_codec.h"
+
+namespace {
+
+ // Creates a bitmap of the specified color.
+ SkBitmap CreateBitmap(SkColor color) {
sky 2011/02/22 18:28:28 This shouldn't be indented.
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ bitmap.allocPixels();
+ bitmap.eraseColor(color);
+ return bitmap;
+ }
+
+class FaviconDelegate : public ui::MenuModel::Delegate {
+ public:
+ explicit FaviconDelegate() : was_called_(false) {}
+
+ void OnIconChanged(int model_index) {
+ was_called_ = true;
+ MessageLoop::current()->Quit();
+ }
+
+ bool was_called() { return was_called_; }
+
+ private:
+ bool was_called_;
+ DISALLOW_COPY_AND_ASSIGN(FaviconDelegate);
+};
+
+} // namespace
class BackFwdMenuModelTest : public RenderViewHostTestHarness {
public:
@@ -420,3 +455,66 @@ TEST_F(BackFwdMenuModelTest, ChapterStops) {
EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(2, false));
EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false));
}
+
+// Test asynchronous loading of favicon from history service.
+TEST_F(BackFwdMenuModelTest, FaviconLoadTest) {
+ profile()->CreateHistoryService(true, false);
+ profile()->CreateFaviconService();
+ Browser browser(Browser::TYPE_NORMAL, profile());
+ FaviconDelegate favicon_delegate;
+
+ scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel(
sky 2011/02/22 18:28:28 How come you put this in a scoped_ptr instead of o
dill 2011/02/24 15:00:28 Leftover from experimentation, back to stack. On
+ &browser, BackForwardMenuModel::BACKWARD_MENU));
+ back_model->set_test_tab_contents(controller().tab_contents());
+ back_model->SetDelegate(&favicon_delegate);
+
+ SkBitmap new_icon(CreateBitmap(SK_ColorRED));
+ std::vector<unsigned char> icon_data;
+ gfx::PNGCodec::EncodeBGRASkBitmap(new_icon, false, &icon_data);
+
+ GURL url1 = GURL("http://www.a.com/1");
+ GURL url2 = GURL("http://www.a.com/2");
+ GURL url1_favicon("http://www.a.com/1/favicon.ico");
+
+ NavigateAndCommit(url1);
+ // Navigate to a new URL so that url1 will be in the BackForwardMenuModel.
+ NavigateAndCommit(url2);
+
+ // Set the desired favicon for url1.
+ profile()->GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPage(url1,
+ history::SOURCE_BROWSED);
+ profile()->GetFaviconService(Profile::EXPLICIT_ACCESS)->SetFavicon(url1,
+ url1_favicon, icon_data);
+
+ // Will return the current icon (default) but start an anync call
+ // to retrieve the favicon from the favicon service.
+ SkBitmap default_icon;
+ back_model->GetIconAt(0, &default_icon);
+
+ // Make the favicon service run GetFavIconForURL,
+ // FaviconDelegate.OnIconChanged will be called.
+ MessageLoop::current()->Run();
+
+ // Verify that the callback executed.
+ EXPECT_TRUE(favicon_delegate.was_called());
+
+ // Verify the bitmaps match.
+ SkBitmap valid_icon;
+ // This time we will get the new favicon returned.
+ back_model->GetIconAt(0, &valid_icon);
+ SkAutoLockPixels a(new_icon);
+ SkAutoLockPixels b(valid_icon);
+ SkAutoLockPixels c(default_icon);
+ // Verify we did not get the default favicon.
+ EXPECT_NE(0, memcmp(default_icon.getPixels(), valid_icon.getPixels(),
+ default_icon.getSize()));
+ // Verify we did get the expected favicon.
+ EXPECT_EQ(0, memcmp(new_icon.getPixels(), valid_icon.getPixels(),
+ new_icon.getSize()));
+
+ // Make sure the browser deconstructor doesn't have problems.
+ browser.CloseAllTabs();
+ // This is required to prevent the message loop from hanging.
+ profile()->DestroyHistoryService();
+}
+

Powered by Google App Engine
This is Rietveld 408576698