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

Unified Diff: chrome/browser/ui/views/menu_test_base.h

Issue 168033003: Pass in correct parameter to MenuController::SelectByChar() on Linux Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix BookmarkBarViewTest10.KeyEvents Created 6 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
« no previous file with comments | « chrome/browser/ui/views/menu_item_view_test.cc ('k') | chrome/browser/ui/views/menu_test_base.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/menu_test_base.h
diff --git a/chrome/browser/ui/views/menu_test_base.h b/chrome/browser/ui/views/menu_test_base.h
new file mode 100644
index 0000000000000000000000000000000000000000..ccb8a23bcf5c72d40238f7da1db62a4281ab53fa
--- /dev/null
+++ b/chrome/browser/ui/views/menu_test_base.h
@@ -0,0 +1,88 @@
+// Copyright 2014 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_UI_VIEWS_MENU_TEST_BASE_H_
+#define CHROME_BROWSER_UI_VIEWS_MENU_TEST_BASE_H_
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/test/base/view_event_test_base.h"
+#include "ui/events/keycodes/keyboard_codes.h"
+#include "ui/views/controls/button/menu_button_listener.h"
+#include "ui/views/controls/menu/menu_delegate.h"
+
+namespace views {
+class MenuButton;
+class MenuItemView;
+class MenuRunner;
+}
+
+// This is a convenience base class for menu related tests to provide some
+// common functionality.
+//
+// Subclasses should implement:
+// BuildMenu() populate the menu
+// DoTestWithMenuOpen() initiate the test
+//
+// Subclasses can call:
+// Click() to post a mouse click on a View
+// KeyPress() to post a key press
+//
+// Although it should be possible to post a menu multiple times,
+// MenuItemView prevents repeated activation of a menu by clicks too
+// close in time.
+class MenuTestBase : public ViewEventTestBase,
+ public views::MenuButtonListener,
+ public views::MenuDelegate {
+ public:
+ MenuTestBase();
+ virtual ~MenuTestBase();
+
+ // Generate a mouse click and run |next| once the event has been processed.
+ virtual void Click(views::View* view, const base::Closure& next);
+
+ // Generate a keypress and run |next| once the event has been processed.
+ void KeyPress(ui::KeyboardCode keycode, const base::Closure& next);
+
+ views::MenuItemView* menu() {
+ return menu_;
+ }
+
+ int last_command() const {
+ return last_command_;
+ }
+
+ protected:
+ // Called to populate the menu.
+ virtual void BuildMenu(views::MenuItemView* menu) = 0;
+
+ // Called once the menu is open.
+ virtual void DoTestWithMenuOpen() = 0;
+
+ // ViewEventTestBase implementation.
+ virtual void SetUp() OVERRIDE;
+ virtual void TearDown() OVERRIDE;
+ virtual views::View* CreateContentsView() OVERRIDE;
+ virtual void DoTestOnMessageLoop() OVERRIDE;
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+
+ // views::MenuButtonListener implementation
+ virtual void OnMenuButtonClicked(views::View* source,
+ const gfx::Point& point) OVERRIDE;
+
+ // views::MenuDelegate implementation
+ virtual void ExecuteCommand(int id) OVERRIDE;
+
+ private:
+ views::MenuButton* button_;
+ views::MenuItemView* menu_;
+ scoped_ptr<views::MenuRunner> menu_runner_;
+
+ // The command id of the last pressed menu item since the menu was opened.
+ int last_command_;
+
+ DISALLOW_COPY_AND_ASSIGN(MenuTestBase);
+};
+
+#endif // CHROME_BROWSER_UI_VIEWS_MENU_TEST_BASE_H_
« no previous file with comments | « chrome/browser/ui/views/menu_item_view_test.cc ('k') | chrome/browser/ui/views/menu_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698