diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 21:32:34 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 21:32:34 +0000 |
commit | 4e797d9ac6f59ac71613ffac7123ae0d16b65a26 (patch) | |
tree | 5427a10e4702df0566d11ee2f0881832ed35d9e6 | |
parent | e3d60e5dbbe1a30ee38ad470a5d6040011aea60a (diff) | |
download | chromium_src-4e797d9ac6f59ac71613ffac7123ae0d16b65a26.zip chromium_src-4e797d9ac6f59ac71613ffac7123ae0d16b65a26.tar.gz chromium_src-4e797d9ac6f59ac71613ffac7123ae0d16b65a26.tar.bz2 |
GTK: Add three simple unit tests to the bookmark bar.
Review URL: http://codereview.chromium.org/249004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27251 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk_unittest.cc | 76 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.h | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/tabstrip_origin_provider.h | 26 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 |
7 files changed, 122 insertions, 14 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index a2c3791..89c78bf 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -25,6 +25,7 @@ #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/tabstrip_origin_provider.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/metrics/user_metrics.h" @@ -93,11 +94,11 @@ void SetToolBarStyle() { } // namespace BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser, - BrowserWindowGtk* window) + TabstripOriginProvider* tabstrip_origin_provider) : profile_(NULL), page_navigator_(NULL), browser_(browser), - window_(window), + tabstrip_origin_provider_(tabstrip_origin_provider), model_(NULL), instructions_(NULL), dragged_node_(NULL), @@ -923,7 +924,7 @@ gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget, event->area.width, event->area.height); cairo_clip(cr); gfx::Point tabstrip_origin = - bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); + bar->tabstrip_origin_provider_->GetTabStripOriginForWidget(widget); GtkThemeProvider* theme_provider = bar->theme_provider_; CairoCachedSurface* background = theme_provider->GetSurfaceNamed( diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index 65c7d82..28e1d33 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -18,6 +18,7 @@ #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/owned_widget_gtk.h" +#include "testing/gtest/include/gtest/gtest_prod.h" class BookmarkContextMenu; class BookmarkMenuController; @@ -26,15 +27,19 @@ class BrowserWindowGtk; class CustomContainerButton; class PageNavigator; class Profile; +class TabstripOriginProvider; struct GtkThemeProvider; class BookmarkBarGtk : public AnimationDelegate, public BookmarkModelObserver, public MenuBarHelper::Delegate, public NotificationObserver { + FRIEND_TEST(BookmarkBarGtkUnittest, DisplaysHelpMessageOnEmpty); + FRIEND_TEST(BookmarkBarGtkUnittest, HidesHelpMessageWithBookmark); + FRIEND_TEST(BookmarkBarGtkUnittest, BuildsButtons); public: explicit BookmarkBarGtk(Profile* profile, Browser* browser, - BrowserWindowGtk* window); + TabstripOriginProvider* tabstrip_origin_provider); virtual ~BookmarkBarGtk(); // Resets the profile. This removes any buttons for the current profile and @@ -90,6 +95,7 @@ class BookmarkBarGtk : public AnimationDelegate, virtual void PopupForButton(GtkWidget* button); virtual void PopupForButtonNextTo(GtkWidget* button, GtkMenuDirectionType dir); + private: // Helper function which generates GtkToolItems for |bookmark_toolbar_|. void CreateAllBookmarkButtons(); @@ -230,7 +236,9 @@ class BookmarkBarGtk : public AnimationDelegate, PageNavigator* page_navigator_; Browser* browser_; - BrowserWindowGtk* window_; + + // Provides us with the offset into the background theme image. + TabstripOriginProvider* tabstrip_origin_provider_; // Model providing details as to the starred entries/groups that should be // shown. This is owned by the Profile. diff --git a/chrome/browser/gtk/bookmark_bar_gtk_unittest.cc b/chrome/browser/gtk/bookmark_bar_gtk_unittest.cc new file mode 100644 index 0000000..c878d51 --- /dev/null +++ b/chrome/browser/gtk/bookmark_bar_gtk_unittest.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/gtk/bookmark_bar_gtk.h" + +#include "chrome/browser/browser.h" +#include "chrome/browser/gtk/tabstrip_origin_provider.h" +#include "base/task.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "chrome/test/testing_profile.h" + +// Dummy implementation that's good enough for the tests; we don't test +// rendering here so all we need is a non-NULL object. +class EmptyTabstripOriginProvider : public TabstripOriginProvider { + public: + virtual gfx::Point GetTabStripOriginForWidget(GtkWidget* widget) { + return gfx::Point(0, 0); + } +}; + +class BookmarkBarGtkUnittest : public ::testing::Test { + protected: + BookmarkBarGtkUnittest() { + profile_.reset(new TestingProfile()); + profile_->CreateBookmarkModel(true); + browser_.reset(new Browser(Browser::TYPE_NORMAL, profile_.get())); + + origin_provider_.reset(new EmptyTabstripOriginProvider); + bookmark_bar_.reset(new BookmarkBarGtk(profile_.get(), browser_.get(), + origin_provider_.get())); + } + + scoped_ptr<TestingProfile> profile_; + scoped_ptr<Browser> browser_; + scoped_ptr<TabstripOriginProvider> origin_provider_; + scoped_ptr<BookmarkBarGtk> bookmark_bar_; +}; + +TEST_F(BookmarkBarGtkUnittest, DisplaysHelpMessageOnEmpty) { + BookmarkModel* model = profile_->GetBookmarkModel(); + bookmark_bar_->Loaded(model); + + // There are no bookmarks in the model by default. Expect that the + // |instructions_label| is shown. + EXPECT_TRUE(bookmark_bar_->show_instructions_); +} + +TEST_F(BookmarkBarGtkUnittest, HidesHelpMessageWithBookmark) { + BookmarkModel* model = profile_->GetBookmarkModel(); + + const BookmarkNode* parent = model->GetBookmarkBarNode(); + model->AddURL(parent, parent->GetChildCount(), + L"title", GURL("http://one.com")); + + bookmark_bar_->Loaded(model); + EXPECT_FALSE(bookmark_bar_->show_instructions_); +} + +TEST_F(BookmarkBarGtkUnittest, BuildsButtons) { + BookmarkModel* model = profile_->GetBookmarkModel(); + + const BookmarkNode* parent = model->GetBookmarkBarNode(); + model->AddURL(parent, parent->GetChildCount(), + L"title", GURL("http://one.com")); + model->AddURL(parent, parent->GetChildCount(), + L"other", GURL("http://two.com")); + + bookmark_bar_->Loaded(model); + + // We should expect two children to the bookmark bar's toolbar. + GList* children = gtk_container_get_children( + GTK_CONTAINER(bookmark_bar_->bookmark_toolbar_.get())); + EXPECT_EQ(2U, g_list_length(children)); + g_list_free(children); +} diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 0235e15..430963c 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -1629,7 +1629,7 @@ void BrowserWindowGtk::InitWidgets() { if (IsBookmarkBarSupported()) { bookmark_bar_.reset(new BookmarkBarGtk(browser_->profile(), browser_.get(), - this)); + tabstrip_.get())); gtk_box_pack_start(GTK_BOX(window_vbox_), bookmark_bar_->widget(), FALSE, FALSE, 0); gtk_widget_show(bookmark_bar_->widget()); diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h index c72fc44..21c5c18 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.h +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h @@ -12,6 +12,7 @@ #include "base/gfx/rect.h" #include "base/task.h" #include "base/message_loop.h" +#include "chrome/browser/gtk/tabstrip_origin_provider.h" #include "chrome/browser/gtk/tabs/tab_gtk.h" #include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/tabs/tab_strip_model.h" @@ -27,6 +28,7 @@ class TabStripGtk : public TabStripModelObserver, public TabGtk::TabDelegate, public MessageLoopForUI::Observer, public NotificationObserver, + public TabstripOriginProvider, public ViewIDUtil::Delegate { public: class TabAnimation; @@ -82,14 +84,8 @@ class TabStripGtk : public TabStripModelObserver, // Retrieve the ideal bounds for the Tab at the specified index. gfx::Rect GetIdealBounds(int index); - // Return the origin of the tab strip in coordinates relative to where we - // start drawing the background theme image. This is the x coordinate of - // the origin of the GdkWindow of widget(), but the y coordinate of the origin - // of widget() itself. - // Used to help other widgets draw their background relative to the tabstrip. - // Should only be called after both the tabstrip and |widget| have been - // allocated. - gfx::Point GetTabStripOriginForWidget(GtkWidget* widget); + // TabstripOriginProvider implementation ------------------------------------- + virtual gfx::Point GetTabStripOriginForWidget(GtkWidget* widget); // ViewIDUtil::Delegate implementation --------------------------------------- virtual GtkWidget* GetWidgetForViewID(ViewID id); diff --git a/chrome/browser/gtk/tabstrip_origin_provider.h b/chrome/browser/gtk/tabstrip_origin_provider.h new file mode 100644 index 0000000..027f049 --- /dev/null +++ b/chrome/browser/gtk/tabstrip_origin_provider.h @@ -0,0 +1,26 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_GTK_TABSTRIP_ORIGIN_PROVIDER_H_ +#define CHROME_BROWSER_GTK_TABSTRIP_ORIGIN_PROVIDER_H_ + +// Abstract interface that provides an offset of a widget. Many pieces of the +// UI don't need the full BrowserWindowGtk, but just need information about +// it's position relative to the tabstrip to draw correctly. This interface +// exists to make it easier to test piece by piece. +class TabstripOriginProvider { + public: + virtual ~TabstripOriginProvider() { } + + // Return the origin of the tab strip in coordinates relative to where we + // start drawing the background theme image. This is the x coordinate of + // the origin of the GdkWindow of widget(), but the y coordinate of the origin + // of widget() itself. + // Used to help other widgets draw their background relative to the tabstrip. + // Should only be called after both the tabstrip and |widget| have been + // allocated. + virtual gfx::Point GetTabStripOriginForWidget(GtkWidget* widget) = 0; +}; + +#endif // CHROME_BROWSER_GTK_TABSTRIP_ORIGIN_PROVIDER_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index c95383b..f4e2153 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -4187,6 +4187,7 @@ 'browser/global_keyboard_shortcuts_mac_unittest.cc', 'browser/google_url_tracker_unittest.cc', 'browser/google_update_settings_posix_unittest.cc', + 'browser/gtk/bookmark_bar_gtk_unittest.cc', 'browser/gtk/bookmark_editor_gtk_unittest.cc', 'browser/gtk/gtk_theme_provider_unittest.cc', 'browser/gtk/go_button_gtk_unittest.cc', |