OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_UI_VIEWS_MENU_TEST_BASE_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_MENU_TEST_BASE_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_MENU_TEST_BASE_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_MENU_TEST_BASE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "chrome/test/base/view_event_test_base.h" | 10 #include "chrome/test/base/view_event_test_base.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // KeyPress() to post a key press | 30 // KeyPress() to post a key press |
31 // | 31 // |
32 // Although it should be possible to post a menu multiple times, | 32 // Although it should be possible to post a menu multiple times, |
33 // MenuItemView prevents repeated activation of a menu by clicks too | 33 // MenuItemView prevents repeated activation of a menu by clicks too |
34 // close in time. | 34 // close in time. |
35 class MenuTestBase : public ViewEventTestBase, | 35 class MenuTestBase : public ViewEventTestBase, |
36 public views::MenuButtonListener, | 36 public views::MenuButtonListener, |
37 public views::MenuDelegate { | 37 public views::MenuDelegate { |
38 public: | 38 public: |
39 MenuTestBase(); | 39 MenuTestBase(); |
40 virtual ~MenuTestBase(); | 40 ~MenuTestBase() override; |
41 | 41 |
42 // Generate a mouse click and run |next| once the event has been processed. | 42 // Generate a mouse click and run |next| once the event has been processed. |
43 virtual void Click(views::View* view, const base::Closure& next); | 43 virtual void Click(views::View* view, const base::Closure& next); |
44 | 44 |
45 // Generate a keypress and run |next| once the event has been processed. | 45 // Generate a keypress and run |next| once the event has been processed. |
46 void KeyPress(ui::KeyboardCode keycode, const base::Closure& next); | 46 void KeyPress(ui::KeyboardCode keycode, const base::Closure& next); |
47 | 47 |
48 views::MenuItemView* menu() { | 48 views::MenuItemView* menu() { |
49 return menu_; | 49 return menu_; |
50 } | 50 } |
51 | 51 |
52 int last_command() const { | 52 int last_command() const { |
53 return last_command_; | 53 return last_command_; |
54 } | 54 } |
55 | 55 |
56 protected: | 56 protected: |
57 // Called to populate the menu. | 57 // Called to populate the menu. |
58 virtual void BuildMenu(views::MenuItemView* menu) = 0; | 58 virtual void BuildMenu(views::MenuItemView* menu) = 0; |
59 | 59 |
60 // Called once the menu is open. | 60 // Called once the menu is open. |
61 virtual void DoTestWithMenuOpen() = 0; | 61 virtual void DoTestWithMenuOpen() = 0; |
62 | 62 |
63 // Returns a bitmask of flags to use when creating the |menu_runner_|. By | 63 // Returns a bitmask of flags to use when creating the |menu_runner_|. By |
64 // default, this is only views::MenuRunner::HAS_MNEMONICS. | 64 // default, this is only views::MenuRunner::HAS_MNEMONICS. |
65 virtual int GetMenuRunnerFlags(); | 65 virtual int GetMenuRunnerFlags(); |
66 | 66 |
67 // ViewEventTestBase implementation. | 67 // ViewEventTestBase implementation. |
68 virtual void SetUp() override; | 68 void SetUp() override; |
69 virtual void TearDown() override; | 69 void TearDown() override; |
70 virtual views::View* CreateContentsView() override; | 70 views::View* CreateContentsView() override; |
71 virtual void DoTestOnMessageLoop() override; | 71 void DoTestOnMessageLoop() override; |
72 virtual gfx::Size GetPreferredSize() const override; | 72 gfx::Size GetPreferredSize() const override; |
73 | 73 |
74 // views::MenuButtonListener implementation | 74 // views::MenuButtonListener implementation |
75 virtual void OnMenuButtonClicked(views::View* source, | 75 void OnMenuButtonClicked(views::View* source, |
76 const gfx::Point& point) override; | 76 const gfx::Point& point) override; |
77 | 77 |
78 // views::MenuDelegate implementation | 78 // views::MenuDelegate implementation |
79 virtual void ExecuteCommand(int id) override; | 79 void ExecuteCommand(int id) override; |
80 | 80 |
81 private: | 81 private: |
82 views::MenuButton* button_; | 82 views::MenuButton* button_; |
83 views::MenuItemView* menu_; | 83 views::MenuItemView* menu_; |
84 scoped_ptr<views::MenuRunner> menu_runner_; | 84 scoped_ptr<views::MenuRunner> menu_runner_; |
85 | 85 |
86 // The command id of the last pressed menu item since the menu was opened. | 86 // The command id of the last pressed menu item since the menu was opened. |
87 int last_command_; | 87 int last_command_; |
88 | 88 |
89 DISALLOW_COPY_AND_ASSIGN(MenuTestBase); | 89 DISALLOW_COPY_AND_ASSIGN(MenuTestBase); |
90 }; | 90 }; |
91 | 91 |
92 #endif // CHROME_BROWSER_UI_VIEWS_MENU_TEST_BASE_H_ | 92 #endif // CHROME_BROWSER_UI_VIEWS_MENU_TEST_BASE_H_ |
OLD | NEW |