diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.h | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.mm | 45 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 28 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.h | 8 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 24 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.h | 13 | ||||
-rw-r--r-- | chrome/browser/wrench_menu_model.cc | 110 | ||||
-rw-r--r-- | chrome/browser/wrench_menu_model.h | 22 | ||||
-rw-r--r-- | chrome/browser/wrench_menu_model_unittest.cc | 54 |
9 files changed, 145 insertions, 164 deletions
diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h index 68b57bf..525cf11 100644 --- a/chrome/browser/cocoa/toolbar_controller.h +++ b/chrome/browser/cocoa/toolbar_controller.h @@ -28,8 +28,8 @@ class LocationBar; class LocationBarViewMac; @class MenuButton; namespace ToolbarControllerInternal { -class MenuDelegate; class NotificationBridge; +class WrenchAcceleratorDelegate; } // namespace ToolbarControllerInternal class Profile; @class ReloadButton; @@ -74,7 +74,8 @@ class WrenchMenuModel; // Lazily-instantiated model and delegate for the menu on the // wrench button. Once visible, it will be non-null, but will not // reaped when the menu is hidden once it is initially shown. - scoped_ptr<ToolbarControllerInternal::MenuDelegate> menuDelegate_; + scoped_ptr<ToolbarControllerInternal::WrenchAcceleratorDelegate> + acceleratorDelegate_; scoped_ptr<WrenchMenuModel> wrenchMenuModel_; // Used for monitoring the optional toolbar button prefs. diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index edbdcbd..eb64950 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -95,24 +95,9 @@ const CGFloat kWrenchMenuLeftPadding = 3.0; namespace ToolbarControllerInternal { -// A C++ delegate that handles enabling/disabling menu items and handling when -// a menu command is chosen. -class MenuDelegate : public menus::SimpleMenuModel::Delegate { +// A C++ delegate that handles the accelerators in the wrench menu. +class WrenchAcceleratorDelegate : public menus::AcceleratorProvider { public: - explicit MenuDelegate(Browser* browser) - : browser_(browser) { } - - // Overridden from menus::SimpleMenuModel::Delegate - virtual bool IsCommandIdChecked(int command_id) const { - if (command_id == IDC_SHOW_BOOKMARK_BAR) { - return browser_->profile()->GetPrefs()->GetBoolean( - prefs::kShowBookmarkBar); - } - return false; - } - virtual bool IsCommandIdEnabled(int command_id) const { - return browser_->command_updater()->IsCommandEnabled(command_id); - } virtual bool GetAcceleratorForCommandId(int command_id, menus::Accelerator* accelerator_generic) { // Downcast so that when the copy constructor is invoked below, the key @@ -128,26 +113,6 @@ class MenuDelegate : public menus::SimpleMenuModel::Delegate { } return false; } - virtual void ExecuteCommand(int command_id) { - browser_->ExecuteCommand(command_id); - } - virtual bool IsLabelForCommandIdDynamic(int command_id) const { - // On Mac, switch between "Enter Full Screen" and "Exit Full Screen". - return (command_id == IDC_FULLSCREEN); - } - virtual string16 GetLabelForCommandId(int command_id) const { - if (command_id == IDC_FULLSCREEN) { - int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. - // Note: On startup, |window()| may be NULL. - if (browser_->window() && browser_->window()->IsFullscreen()) - string_id = IDS_EXIT_FULLSCREEN_MAC; - return l10n_util::GetStringUTF16(string_id); - } - return menus::SimpleMenuModel::Delegate::GetLabelForCommandId(command_id); - } - - private: - Browser* browser_; }; // A class registered for C++ notifications. This is used to detect changes in @@ -547,9 +512,11 @@ class NotificationBridge : public NotificationObserver { - (void)installWrenchMenu { if (wrenchMenuModel_.get()) return; - menuDelegate_.reset(new ToolbarControllerInternal::MenuDelegate(browser_)); + acceleratorDelegate_.reset( + new ToolbarControllerInternal::WrenchAcceleratorDelegate()); - wrenchMenuModel_.reset(new WrenchMenuModel(menuDelegate_.get(), browser_)); + wrenchMenuModel_.reset(new WrenchMenuModel( + acceleratorDelegate_.get(), browser_)); [wrenchMenuController_ setModel:wrenchMenuModel_.get()]; [wrenchMenuController_ setUseWithPopUpButtonCell:YES]; [wrenchButton_ setAttachedMenu:[wrenchMenuController_ menu]]; diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 3f50b49..f0a5ad9 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -333,33 +333,7 @@ GtkIconSet* BrowserToolbarGtk::GetIconSetForId(int idr) { return theme_provider_->GetIconSetForId(idr); } -// menus::SimpleMenuModel::Delegate - -bool BrowserToolbarGtk::IsCommandIdEnabled(int id) const { - return browser_->command_updater()->IsCommandEnabled(id); -} - -bool BrowserToolbarGtk::IsCommandIdChecked(int id) const { - if (!profile_) - return false; - - EncodingMenuController controller; - if (id == IDC_SHOW_BOOKMARK_BAR) { - return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); - } else if (controller.DoesCommandBelongToEncodingMenu(id)) { - TabContents* tab_contents = browser_->GetSelectedTabContents(); - if (tab_contents) { - return controller.IsItemChecked(profile_, tab_contents->encoding(), - id); - } - } - - return false; -} - -void BrowserToolbarGtk::ExecuteCommand(int id) { - browser_->ExecuteCommand(id); -} +// menus::AcceleratorProvider bool BrowserToolbarGtk::GetAcceleratorForCommandId( int id, diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h index 09f04f1..1018dc0 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_gtk.h @@ -12,6 +12,7 @@ #include "app/active_window_watcher_x.h" #include "app/gtk_signal.h" #include "app/gtk_signal_registrar.h" +#include "app/menus/accelerator.h" #include "app/menus/simple_menu_model.h" #include "app/throb_animation.h" #include "base/scoped_ptr.h" @@ -40,7 +41,7 @@ class ToolbarModel; // View class that displays the GTK version of the toolbar and routes gtk // events back to the Browser. class BrowserToolbarGtk : public CommandUpdater::CommandObserver, - public menus::SimpleMenuModel::Delegate, + public menus::AcceleratorProvider, public MenuGtk::Delegate, public NotificationObserver, public AnimationDelegate, @@ -94,10 +95,7 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, virtual void StoppedShowing(); virtual GtkIconSet* GetIconSetForId(int idr); - // Overridden from menus::SimpleMenuModel::Delegate: - virtual bool IsCommandIdEnabled(int id) const; - virtual bool IsCommandIdChecked(int id) const; - virtual void ExecuteCommand(int id); + // Overridden from menus::AcceleratorProvider: virtual bool GetAcceleratorForCommandId(int id, menus::Accelerator* accelerator); diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 5f919a8..2f8c44d 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -110,7 +110,7 @@ void ToolbarView::Init(Profile* profile) { browser_, BackForwardMenuModel::BACKWARD_MENU)); forward_menu_model_.reset(new BackForwardMenuModel( browser_, BackForwardMenuModel::FORWARD_MENU)); - app_menu_model_.reset(new WrenchMenuModel(this, browser_)); + wrench_menu_model_.reset(new WrenchMenuModel(this, browser_)); back_ = new views::ButtonDropDown(this, back_menu_model_.get()); back_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | @@ -248,7 +248,7 @@ void ToolbarView::RunMenu(views::View* source, const gfx::Point& /*pt*/) { bool destroyed_flag = false; destroyed_flag_ = &destroyed_flag; wrench_menu_.reset(new WrenchMenu(browser_)); - wrench_menu_->Init(app_menu_model_.get()); + wrench_menu_->Init(wrench_menu_model_.get()); for (size_t i = 0; i < menu_listeners_.size(); ++i) menu_listeners_[i]->OnMenuOpened(); @@ -344,21 +344,7 @@ void ToolbarView::Observe(NotificationType type, } //////////////////////////////////////////////////////////////////////////////// -// ToolbarView, menus::SimpleMenuModel::Delegate implementation: - -bool ToolbarView::IsCommandIdChecked(int command_id) const { -#if defined(OS_CHROMEOS) - if (command_id == IDC_TOGGLE_VERTICAL_TABS) { - return browser_->UseVerticalTabs(); - } -#endif - return (command_id == IDC_SHOW_BOOKMARK_BAR) && - profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); -} - -bool ToolbarView::IsCommandIdEnabled(int command_id) const { - return browser_->command_updater()->IsCommandEnabled(command_id); -} +// ToolbarView, menus::AcceleratorProvider implementation: bool ToolbarView::GetAcceleratorForCommandId(int command_id, menus::Accelerator* accelerator) { @@ -380,10 +366,6 @@ bool ToolbarView::GetAcceleratorForCommandId(int command_id, return GetWidget()->GetAccelerator(command_id, accelerator); } -void ToolbarView::ExecuteCommand(int command_id) { - browser_->ExecuteCommand(command_id); -} - //////////////////////////////////////////////////////////////////////////////// // ToolbarView, views::View overrides: diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index af73d60..218ca28 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -8,7 +8,7 @@ #include <vector> -#include "app/menus/simple_menu_model.h" +#include "app/menus/accelerator.h" #include "app/slide_animation.h" #include "base/scoped_ptr.h" #include "chrome/browser/back_forward_menu_model.h" @@ -31,7 +31,7 @@ class WrenchMenu; // The Browser Window's toolbar. class ToolbarView : public AccessibleToolbarView, public views::ViewMenuDelegate, - public menus::SimpleMenuModel::Delegate, + public menus::AcceleratorProvider, public LocationBarView::Delegate, public AnimationDelegate, public NotificationObserver, @@ -104,12 +104,9 @@ class ToolbarView : public AccessibleToolbarView, const NotificationSource& source, const NotificationDetails& details); - // Overridden from menus::SimpleMenuModel::Delegate: - virtual bool IsCommandIdChecked(int command_id) const; - virtual bool IsCommandIdEnabled(int command_id) const; + // Overridden from menus::AcceleratorProvider: virtual bool GetAcceleratorForCommandId(int command_id, menus::Accelerator* accelerator); - virtual void ExecuteCommand(int command_id); // Overridden from views::View: virtual gfx::Size GetPreferredSize(); @@ -184,8 +181,8 @@ class ToolbarView : public AccessibleToolbarView, // The display mode used when laying out the toolbar. DisplayMode display_mode_; - // The contents of the app menu. - scoped_ptr<menus::SimpleMenuModel> app_menu_model_; + // The contents of the wrench menu. + scoped_ptr<menus::SimpleMenuModel> wrench_menu_model_; // Wrench menu. scoped_ptr<WrenchMenu> wrench_menu_; diff --git a/chrome/browser/wrench_menu_model.cc b/chrome/browser/wrench_menu_model.cc index df4b2e6..0159a74 100644 --- a/chrome/browser/wrench_menu_model.cc +++ b/chrome/browser/wrench_menu_model.cc @@ -20,6 +20,7 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/encoding_menu_controller.h" #include "chrome/browser/host_zoom_map.h" +#include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/sync_ui_util.h" @@ -29,6 +30,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" +#include "chrome/common/pref_names.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -38,6 +40,10 @@ #include "chrome/browser/gtk/gtk_util.h" #endif +#if defined(OS_MACOSX) +#include "chrome/browser/browser_window.h" +#endif + //////////////////////////////////////////////////////////////////////////////// // EncodingMenuModel @@ -164,10 +170,10 @@ void ToolsMenuModel::Build(Browser* browser) { //////////////////////////////////////////////////////////////////////////////// // WrenchMenuModel -WrenchMenuModel::WrenchMenuModel(menus::SimpleMenuModel::Delegate* delegate, +WrenchMenuModel::WrenchMenuModel(menus::AcceleratorProvider* provider, Browser* browser) - : menus::SimpleMenuModel(delegate), - delegate_(delegate), + : ALLOW_THIS_IN_INITIALIZER_LIST(menus::SimpleMenuModel(this)), + provider_(provider), browser_(browser), tabstrip_model_(browser_->tabstrip_model()) { Build(); @@ -186,50 +192,64 @@ WrenchMenuModel::~WrenchMenuModel() { tabstrip_model_->RemoveObserver(this); } -bool WrenchMenuModel::IsLabelDynamicAt(int index) const { - return IsDynamicItem(index) || SimpleMenuModel::IsLabelDynamicAt(index); +bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const { + return command_id == IDC_ZOOM_PERCENT_DISPLAY || + command_id == IDC_SYNC_BOOKMARKS || +#if defined(OS_MACOSX) + command_id == IDC_FULLSCREEN || +#endif + command_id == IDC_ABOUT; } -string16 WrenchMenuModel::GetLabelAt(int index) const { - if (!IsDynamicItem(index)) - return SimpleMenuModel::GetLabelAt(index); - - int command_id = GetCommandIdAt(index); - +string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { switch (command_id) { case IDC_ABOUT: return GetAboutEntryMenuLabel(); case IDC_SYNC_BOOKMARKS: return GetSyncMenuLabel(); + case IDC_ZOOM_PERCENT_DISPLAY: + return zoom_label_; +#if defined(OS_MACOSX) + case IDC_FULLSCREEN: { + int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. + // Note: On startup, |window()| may be NULL. + if (browser_->window() && browser_->window()->IsFullscreen()) + string_id = IDS_EXIT_FULLSCREEN_MAC; + return l10n_util::GetStringUTF16(string_id); + } +#endif default: NOTREACHED(); return string16(); } } -bool WrenchMenuModel::GetIconAt(int index, SkBitmap* icon) const { - if (GetCommandIdAt(index) == IDC_ABOUT && - Singleton<UpgradeDetector>::get()->notify_upgrade()) { - // Show the exclamation point next to the menu item. - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - *icon = *rb.GetBitmapNamed(IDR_UPDATE_AVAILABLE); - return true; - } - return false; +void WrenchMenuModel::ExecuteCommand(int command_id) { + browser_->ExecuteCommand(command_id); } -bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const { - return command_id == IDC_ZOOM_PERCENT_DISPLAY; +bool WrenchMenuModel::IsCommandIdChecked(int command_id) const { +#if defined(OS_CHROMEOS) + if (command_id == IDC_TOGGLE_VERTICAL_TABS) { + return browser_->UseVerticalTabs(); + } +#endif + + if (command_id == IDC_SHOW_BOOKMARK_BAR) { + return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); + } + + return false; } -string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { - DCHECK_EQ(IDC_ZOOM_PERCENT_DISPLAY, command_id); - return zoom_label_; +bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const { + return browser_->command_updater()->IsCommandEnabled(command_id); } -void WrenchMenuModel::ExecuteCommand(int command_id) { - if (delegate_) - delegate_->ExecuteCommand(command_id); +bool WrenchMenuModel::GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { + return provider_->GetAcceleratorForCommandId(command_id, accelerator); } void WrenchMenuModel::TabSelectedAt(TabContents* old_contents, @@ -259,10 +279,19 @@ void WrenchMenuModel::Observe(NotificationType type, UpdateZoomControls(); } +// For testing. +WrenchMenuModel::WrenchMenuModel() + : ALLOW_THIS_IN_INITIALIZER_LIST(menus::SimpleMenuModel(this)), + provider_(NULL), + browser_(NULL), + tabstrip_model_(NULL) { +} + void WrenchMenuModel::Build() { AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); - AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW); + AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, + IDS_NEW_INCOGNITO_WINDOW); AddSeparator(); #if defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) @@ -304,7 +333,7 @@ void WrenchMenuModel::Build() { AddItemWithStringId(IDC_FIND, IDS_FIND); AddItemWithStringId(IDC_PRINT, IDS_PRINT); - tools_menu_model_.reset(new ToolsMenuModel(delegate(), browser_)); + tools_menu_model_.reset(new ToolsMenuModel(this, browser_)); AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_TOOLS_MENU, tools_menu_model_.get()); @@ -337,6 +366,12 @@ void WrenchMenuModel::Build() { IDS_TAB_CXMENU_USE_VERTICAL_TABS); #endif + // TODO(erg): This entire section needs to be reworked and is out of scope of + // the first cleanup patch I'm doing. Part 1 (crbug.com/47320) is moving most + // of the logic from each platform specific UI code into the model here. Part + // 2 (crbug.com/46221) is normalizing the about menu item/hidden update menu + // item behaviour across the three platforms. + // On Mac, there is no About item unless it is replaced with the update // available notification. if (browser_defaults::kShowAboutMenuItem || @@ -345,6 +380,9 @@ void WrenchMenuModel::Build() { l10n_util::GetStringFUTF16( IDS_ABOUT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); + // ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + // SetIcon(GetIndexOfCommandId(IDC_ABOUT), + // *rb.GetBitmapNamed(IDR_UPDATE_AVAILABLE)); } AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); if (browser_defaults::kShowExitMenuItem) { @@ -414,15 +452,3 @@ string16 WrenchMenuModel::GetAboutEntryMenuLabel() const { return l10n_util::GetStringFUTF16( IDS_ABOUT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); } - -bool WrenchMenuModel::IsDynamicItem(int index) const { - int command_id = GetCommandIdAt(index); - return command_id == IDC_SYNC_BOOKMARKS || - command_id == IDC_ABOUT; -} - -bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const { - if (delegate_) - return delegate_->IsCommandIdEnabled(command_id); - return true; -} diff --git a/chrome/browser/wrench_menu_model.h b/chrome/browser/wrench_menu_model.h index 3bf6c24..b3e2298 100644 --- a/chrome/browser/wrench_menu_model.h +++ b/chrome/browser/wrench_menu_model.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_WRENCH_MENU_MODEL_H_ #pragma once +#include "app/menus/accelerator.h" #include "app/menus/button_menu_item_model.h" #include "app/menus/simple_menu_model.h" #include "base/scoped_ptr.h" @@ -68,25 +69,23 @@ class ToolsMenuModel : public menus::SimpleMenuModel { // A menu model that builds the contents of the wrench menu. class WrenchMenuModel : public menus::SimpleMenuModel, + public menus::SimpleMenuModel::Delegate, public menus::ButtonMenuItemModel::Delegate, public TabStripModelObserver, public NotificationObserver { public: - WrenchMenuModel(menus::SimpleMenuModel::Delegate* delegate, - Browser* browser); + WrenchMenuModel(menus::AcceleratorProvider* provider, Browser* browser); virtual ~WrenchMenuModel(); - // Overridden from menus::SimpleMenuModel: - virtual bool IsLabelDynamicAt(int index) const; - virtual string16 GetLabelAt(int index) const; - virtual bool HasIcons() const { return true; } - virtual bool GetIconAt(int index, SkBitmap* icon) const; - - // Overridden from menus::ButtonMenuItemModel::Delegate: + // Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel: virtual bool IsLabelForCommandIdDynamic(int command_id) const; virtual string16 GetLabelForCommandId(int command_id) const; virtual void ExecuteCommand(int command_id); + virtual bool IsCommandIdChecked(int command_id) const; virtual bool IsCommandIdEnabled(int command_id) const; + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator); // Overridden from TabStripModelObserver: virtual void TabSelectedAt(TabContents* old_contents, @@ -111,7 +110,7 @@ class WrenchMenuModel : public menus::SimpleMenuModel, private: // Testing constructor used for mocking. friend class ::MockWrenchMenuModel; - WrenchMenuModel() : menus::SimpleMenuModel(NULL) {} + WrenchMenuModel(); void Build(); @@ -125,7 +124,6 @@ class WrenchMenuModel : public menus::SimpleMenuModel, string16 GetSyncMenuLabel() const; string16 GetAboutEntryMenuLabel() const; - bool IsDynamicItem(int index) const; // Models for the special menu items with buttons. scoped_ptr<menus::ButtonMenuItemModel> edit_menu_item_model_; @@ -137,7 +135,7 @@ class WrenchMenuModel : public menus::SimpleMenuModel, // Tools menu. scoped_ptr<ToolsMenuModel> tools_menu_model_; - menus::SimpleMenuModel::Delegate* delegate_; // weak + menus::AcceleratorProvider* provider_; // weak Browser* browser_; // weak TabStripModel* tabstrip_model_; // weak diff --git a/chrome/browser/wrench_menu_model_unittest.cc b/chrome/browser/wrench_menu_model_unittest.cc index 62ead13..9561158 100644 --- a/chrome/browser/wrench_menu_model_unittest.cc +++ b/chrome/browser/wrench_menu_model_unittest.cc @@ -13,11 +13,49 @@ #include "testing/gtest/include/gtest/gtest.h" class WrenchMenuModelTest : public BrowserWithTestWindowTest, - public MenuModelTest { + public menus::AcceleratorProvider { + public: + // Don't handle accelerators. + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { return false; } +}; + +// Copies parts of MenuModelTest::Delegate and combines them with the +// WrenchMenuModel since WrenchMenuModel is now a SimpleMenuModel::Delegate and +// not derived from SimpleMenuModel. +class TestWrenchMenuModel : public WrenchMenuModel { + public: + TestWrenchMenuModel(menus::AcceleratorProvider* provider, + Browser* browser) + : WrenchMenuModel(provider, browser), + execute_count_(0), + checked_count_(0), + enable_count_(0) { + } + + // Testing overrides to menus::SimpleMenuModel::Delegate: + virtual bool IsCommandIdChecked(int command_id) const { + bool val = WrenchMenuModel::IsCommandIdChecked(command_id); + if (val) + checked_count_++; + return val; + } + + virtual bool IsCommandIdEnabled(int command_id) const { + ++enable_count_; + return true; + } + + virtual void ExecuteCommand(int command_id) { ++execute_count_; } + + int execute_count_; + mutable int checked_count_; + mutable int enable_count_; }; TEST_F(WrenchMenuModelTest, Basics) { - WrenchMenuModel model(&delegate_, browser()); + TestWrenchMenuModel model(this, browser()); int itemCount = model.GetItemCount(); // Verify it has items. The number varies by platform, so we don't check @@ -32,11 +70,11 @@ TEST_F(WrenchMenuModelTest, Basics) { // Make sure to use the index that is not separator in all configurations. model.ActivatedAt(2); EXPECT_TRUE(model.IsEnabledAt(2)); - EXPECT_EQ(delegate_.execute_count_, 2); - EXPECT_EQ(delegate_.enable_count_, 2); + EXPECT_EQ(model.execute_count_, 2); + EXPECT_EQ(model.enable_count_, 2); - delegate_.execute_count_ = 0; - delegate_.enable_count_ = 0; + model.execute_count_ = 0; + model.enable_count_ = 0; // Choose something from the tools submenu and make sure it makes it back to // the delegate as well. Use the first submenu as the tools one. @@ -53,8 +91,8 @@ TEST_F(WrenchMenuModelTest, Basics) { EXPECT_GT(toolsModel->GetItemCount(), 2); toolsModel->ActivatedAt(2); EXPECT_TRUE(toolsModel->IsEnabledAt(2)); - EXPECT_EQ(delegate_.execute_count_, 1); - EXPECT_EQ(delegate_.enable_count_, 1); + EXPECT_EQ(model.execute_count_, 1); + EXPECT_EQ(model.enable_count_, 1); } class EncodingMenuModelTest : public BrowserWithTestWindowTest, |