OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/test/base/interactive_test_utils.h" | 7 #include "chrome/test/base/interactive_test_utils.h" |
8 #include "chrome/test/base/ui_test_utils.h" | 8 #include "chrome/test/base/ui_test_utils.h" |
9 #include "chrome/test/base/view_event_test_base.h" | 9 #include "chrome/test/base/view_event_test_base.h" |
10 #include "ui/base/models/menu_model.h" | 10 #include "ui/base/models/menu_model.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 class CommonMenuModel : public ui::MenuModel { | 34 class CommonMenuModel : public ui::MenuModel { |
35 public: | 35 public: |
36 CommonMenuModel() { | 36 CommonMenuModel() { |
37 } | 37 } |
38 | 38 |
39 virtual ~CommonMenuModel() { | 39 virtual ~CommonMenuModel() { |
40 } | 40 } |
41 | 41 |
42 protected: | 42 protected: |
43 // ui::MenuModel implementation. | 43 // ui::MenuModel implementation. |
44 virtual bool HasIcons() const OVERRIDE { | 44 virtual bool HasIcons() const override { |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
48 virtual bool IsItemDynamicAt(int index) const OVERRIDE { | 48 virtual bool IsItemDynamicAt(int index) const override { |
49 return false; | 49 return false; |
50 } | 50 } |
51 | 51 |
52 virtual bool GetAcceleratorAt(int index, | 52 virtual bool GetAcceleratorAt(int index, |
53 ui::Accelerator* accelerator) const OVERRIDE { | 53 ui::Accelerator* accelerator) const override { |
54 return false; | 54 return false; |
55 } | 55 } |
56 | 56 |
57 virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const OVERRIDE { | 57 virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const override { |
58 return ui::NORMAL_SEPARATOR; | 58 return ui::NORMAL_SEPARATOR; |
59 } | 59 } |
60 | 60 |
61 virtual bool IsItemCheckedAt(int index) const OVERRIDE { | 61 virtual bool IsItemCheckedAt(int index) const override { |
62 return false; | 62 return false; |
63 } | 63 } |
64 | 64 |
65 virtual int GetGroupIdAt(int index) const OVERRIDE { | 65 virtual int GetGroupIdAt(int index) const override { |
66 return 0; | 66 return 0; |
67 } | 67 } |
68 | 68 |
69 virtual bool GetIconAt(int index, gfx::Image* icon) OVERRIDE { | 69 virtual bool GetIconAt(int index, gfx::Image* icon) override { |
70 return false; | 70 return false; |
71 } | 71 } |
72 | 72 |
73 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( | 73 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( |
74 int index) const OVERRIDE { | 74 int index) const override { |
75 return NULL; | 75 return NULL; |
76 } | 76 } |
77 | 77 |
78 virtual bool IsEnabledAt(int index) const OVERRIDE { | 78 virtual bool IsEnabledAt(int index) const override { |
79 return true; | 79 return true; |
80 } | 80 } |
81 | 81 |
82 virtual ui::MenuModel* GetSubmenuModelAt(int index) const OVERRIDE { | 82 virtual ui::MenuModel* GetSubmenuModelAt(int index) const override { |
83 return NULL; | 83 return NULL; |
84 } | 84 } |
85 | 85 |
86 virtual void HighlightChangedTo(int index) OVERRIDE { | 86 virtual void HighlightChangedTo(int index) override { |
87 } | 87 } |
88 | 88 |
89 virtual void ActivatedAt(int index) OVERRIDE { | 89 virtual void ActivatedAt(int index) override { |
90 } | 90 } |
91 | 91 |
92 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate) OVERRIDE { | 92 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate) override { |
93 } | 93 } |
94 | 94 |
95 virtual ui::MenuModelDelegate* GetMenuModelDelegate() const OVERRIDE { | 95 virtual ui::MenuModelDelegate* GetMenuModelDelegate() const override { |
96 return NULL; | 96 return NULL; |
97 } | 97 } |
98 | 98 |
99 private: | 99 private: |
100 DISALLOW_COPY_AND_ASSIGN(CommonMenuModel); | 100 DISALLOW_COPY_AND_ASSIGN(CommonMenuModel); |
101 }; | 101 }; |
102 | 102 |
103 class SubMenuModel : public CommonMenuModel { | 103 class SubMenuModel : public CommonMenuModel { |
104 public: | 104 public: |
105 SubMenuModel() | 105 SubMenuModel() |
106 : showing_(false) { | 106 : showing_(false) { |
107 } | 107 } |
108 | 108 |
109 virtual ~SubMenuModel() { | 109 virtual ~SubMenuModel() { |
110 } | 110 } |
111 | 111 |
112 bool showing() const { | 112 bool showing() const { |
113 return showing_; | 113 return showing_; |
114 } | 114 } |
115 | 115 |
116 private: | 116 private: |
117 // ui::MenuModel implementation. | 117 // ui::MenuModel implementation. |
118 virtual int GetItemCount() const OVERRIDE { | 118 virtual int GetItemCount() const override { |
119 return 1; | 119 return 1; |
120 } | 120 } |
121 | 121 |
122 virtual ItemType GetTypeAt(int index) const OVERRIDE { | 122 virtual ItemType GetTypeAt(int index) const override { |
123 return TYPE_COMMAND; | 123 return TYPE_COMMAND; |
124 } | 124 } |
125 | 125 |
126 virtual int GetCommandIdAt(int index) const OVERRIDE { | 126 virtual int GetCommandIdAt(int index) const override { |
127 return index + kSubMenuBaseId; | 127 return index + kSubMenuBaseId; |
128 } | 128 } |
129 | 129 |
130 virtual base::string16 GetLabelAt(int index) const OVERRIDE { | 130 virtual base::string16 GetLabelAt(int index) const override { |
131 return base::ASCIIToUTF16("Item"); | 131 return base::ASCIIToUTF16("Item"); |
132 } | 132 } |
133 | 133 |
134 virtual void MenuWillShow() OVERRIDE { | 134 virtual void MenuWillShow() override { |
135 showing_ = true; | 135 showing_ = true; |
136 } | 136 } |
137 | 137 |
138 // Called when the menu has been closed. | 138 // Called when the menu has been closed. |
139 virtual void MenuClosed() OVERRIDE { | 139 virtual void MenuClosed() override { |
140 showing_ = false; | 140 showing_ = false; |
141 } | 141 } |
142 | 142 |
143 bool showing_; | 143 bool showing_; |
144 | 144 |
145 DISALLOW_COPY_AND_ASSIGN(SubMenuModel); | 145 DISALLOW_COPY_AND_ASSIGN(SubMenuModel); |
146 }; | 146 }; |
147 | 147 |
148 class TopMenuModel : public CommonMenuModel { | 148 class TopMenuModel : public CommonMenuModel { |
149 public: | 149 public: |
150 TopMenuModel() { | 150 TopMenuModel() { |
151 } | 151 } |
152 | 152 |
153 virtual ~TopMenuModel() { | 153 virtual ~TopMenuModel() { |
154 } | 154 } |
155 | 155 |
156 bool IsSubmenuShowing() { | 156 bool IsSubmenuShowing() { |
157 return sub_menu_model_.showing(); | 157 return sub_menu_model_.showing(); |
158 } | 158 } |
159 | 159 |
160 private: | 160 private: |
161 // ui::MenuModel implementation. | 161 // ui::MenuModel implementation. |
162 virtual int GetItemCount() const OVERRIDE { | 162 virtual int GetItemCount() const override { |
163 return 1; | 163 return 1; |
164 } | 164 } |
165 | 165 |
166 virtual ItemType GetTypeAt(int index) const OVERRIDE { | 166 virtual ItemType GetTypeAt(int index) const override { |
167 return TYPE_SUBMENU; | 167 return TYPE_SUBMENU; |
168 } | 168 } |
169 | 169 |
170 virtual int GetCommandIdAt(int index) const OVERRIDE { | 170 virtual int GetCommandIdAt(int index) const override { |
171 return index + kTopMenuBaseId; | 171 return index + kTopMenuBaseId; |
172 } | 172 } |
173 | 173 |
174 virtual base::string16 GetLabelAt(int index) const OVERRIDE { | 174 virtual base::string16 GetLabelAt(int index) const override { |
175 return base::ASCIIToUTF16("submenu"); | 175 return base::ASCIIToUTF16("submenu"); |
176 } | 176 } |
177 | 177 |
178 virtual MenuModel* GetSubmenuModelAt(int index) const OVERRIDE { | 178 virtual MenuModel* GetSubmenuModelAt(int index) const override { |
179 return &sub_menu_model_; | 179 return &sub_menu_model_; |
180 } | 180 } |
181 | 181 |
182 mutable SubMenuModel sub_menu_model_; | 182 mutable SubMenuModel sub_menu_model_; |
183 | 183 |
184 DISALLOW_COPY_AND_ASSIGN(TopMenuModel); | 184 DISALLOW_COPY_AND_ASSIGN(TopMenuModel); |
185 }; | 185 }; |
186 | 186 |
187 } // namespace | 187 } // namespace |
188 | 188 |
189 class MenuModelAdapterTest : public ViewEventTestBase, | 189 class MenuModelAdapterTest : public ViewEventTestBase, |
190 public views::MenuButtonListener { | 190 public views::MenuButtonListener { |
191 public: | 191 public: |
192 MenuModelAdapterTest() | 192 MenuModelAdapterTest() |
193 : ViewEventTestBase(), | 193 : ViewEventTestBase(), |
194 button_(NULL), | 194 button_(NULL), |
195 menu_model_adapter_(&top_menu_model_), | 195 menu_model_adapter_(&top_menu_model_), |
196 menu_(NULL) { | 196 menu_(NULL) { |
197 } | 197 } |
198 | 198 |
199 virtual ~MenuModelAdapterTest() { | 199 virtual ~MenuModelAdapterTest() { |
200 } | 200 } |
201 | 201 |
202 // ViewEventTestBase implementation. | 202 // ViewEventTestBase implementation. |
203 | 203 |
204 virtual void SetUp() OVERRIDE { | 204 virtual void SetUp() override { |
205 button_ = new views::MenuButton( | 205 button_ = new views::MenuButton( |
206 NULL, base::ASCIIToUTF16("Menu Adapter Test"), this, true); | 206 NULL, base::ASCIIToUTF16("Menu Adapter Test"), this, true); |
207 | 207 |
208 menu_ = menu_model_adapter_.CreateMenu(); | 208 menu_ = menu_model_adapter_.CreateMenu(); |
209 menu_runner_.reset( | 209 menu_runner_.reset( |
210 new views::MenuRunner(menu_, views::MenuRunner::HAS_MNEMONICS)); | 210 new views::MenuRunner(menu_, views::MenuRunner::HAS_MNEMONICS)); |
211 | 211 |
212 ViewEventTestBase::SetUp(); | 212 ViewEventTestBase::SetUp(); |
213 } | 213 } |
214 | 214 |
215 virtual void TearDown() OVERRIDE { | 215 virtual void TearDown() override { |
216 menu_runner_.reset(NULL); | 216 menu_runner_.reset(NULL); |
217 menu_ = NULL; | 217 menu_ = NULL; |
218 ViewEventTestBase::TearDown(); | 218 ViewEventTestBase::TearDown(); |
219 } | 219 } |
220 | 220 |
221 virtual views::View* CreateContentsView() OVERRIDE { | 221 virtual views::View* CreateContentsView() override { |
222 return button_; | 222 return button_; |
223 } | 223 } |
224 | 224 |
225 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 225 virtual gfx::Size GetPreferredSize() const override { |
226 return button_->GetPreferredSize(); | 226 return button_->GetPreferredSize(); |
227 } | 227 } |
228 | 228 |
229 // views::MenuButtonListener implementation. | 229 // views::MenuButtonListener implementation. |
230 virtual void OnMenuButtonClicked(views::View* source, | 230 virtual void OnMenuButtonClicked(views::View* source, |
231 const gfx::Point& point) OVERRIDE { | 231 const gfx::Point& point) override { |
232 gfx::Point screen_location; | 232 gfx::Point screen_location; |
233 views::View::ConvertPointToScreen(source, &screen_location); | 233 views::View::ConvertPointToScreen(source, &screen_location); |
234 gfx::Rect bounds(screen_location, source->size()); | 234 gfx::Rect bounds(screen_location, source->size()); |
235 ignore_result(menu_runner_->RunMenuAt(source->GetWidget(), | 235 ignore_result(menu_runner_->RunMenuAt(source->GetWidget(), |
236 button_, | 236 button_, |
237 bounds, | 237 bounds, |
238 views::MENU_ANCHOR_TOPLEFT, | 238 views::MENU_ANCHOR_TOPLEFT, |
239 ui::MENU_SOURCE_NONE)); | 239 ui::MENU_SOURCE_NONE)); |
240 } | 240 } |
241 | 241 |
242 // ViewEventTestBase implementation | 242 // ViewEventTestBase implementation |
243 virtual void DoTestOnMessageLoop() OVERRIDE { | 243 virtual void DoTestOnMessageLoop() override { |
244 Click(button_, CreateEventTask(this, &MenuModelAdapterTest::Step1)); | 244 Click(button_, CreateEventTask(this, &MenuModelAdapterTest::Step1)); |
245 } | 245 } |
246 | 246 |
247 // Open the submenu. | 247 // Open the submenu. |
248 void Step1() { | 248 void Step1() { |
249 views::SubmenuView* topmenu = menu_->GetSubmenu(); | 249 views::SubmenuView* topmenu = menu_->GetSubmenu(); |
250 ASSERT_TRUE(topmenu); | 250 ASSERT_TRUE(topmenu); |
251 ASSERT_TRUE(topmenu->IsShowing()); | 251 ASSERT_TRUE(topmenu->IsShowing()); |
252 ASSERT_FALSE(top_menu_model_.IsSubmenuShowing()); | 252 ASSERT_FALSE(top_menu_model_.IsSubmenuShowing()); |
253 | 253 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 303 } |
304 | 304 |
305 views::MenuButton* button_; | 305 views::MenuButton* button_; |
306 TopMenuModel top_menu_model_; | 306 TopMenuModel top_menu_model_; |
307 views::MenuModelAdapter menu_model_adapter_; | 307 views::MenuModelAdapter menu_model_adapter_; |
308 views::MenuItemView* menu_; | 308 views::MenuItemView* menu_; |
309 scoped_ptr<views::MenuRunner> menu_runner_; | 309 scoped_ptr<views::MenuRunner> menu_runner_; |
310 }; | 310 }; |
311 | 311 |
312 VIEW_TEST(MenuModelAdapterTest, RebuildMenu) | 312 VIEW_TEST(MenuModelAdapterTest, RebuildMenu) |
OLD | NEW |