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
3 // found in the LICENSE file.
5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/ui/views/menu_test_base.h"
7 #include "ui/views/controls/menu/menu_item_view.h"
8 #include "ui/views/controls/menu/submenu_view.h"
10 template<ui::KeyboardCode KEYCODE
, int EXPECTED_COMMAND
>
11 class MenuControllerMnemonicTest
: public MenuTestBase
{
13 MenuControllerMnemonicTest() {
16 ~MenuControllerMnemonicTest() override
{
19 // MenuTestBase overrides:
20 void BuildMenu(views::MenuItemView
* menu
) override
{
21 ASSERT_NE(ui::VKEY_DIVIDE
, '/');
22 menu
->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One&/"));
23 menu
->AppendMenuItemWithLabel(2, base::ASCIIToUTF16("Two"));
26 void DoTestWithMenuOpen() override
{
27 ASSERT_TRUE(menu()->GetSubmenu()->IsShowing());
29 CreateEventTask(this, &MenuControllerMnemonicTest::Step2
));
33 ASSERT_EQ(EXPECTED_COMMAND
, last_command());
34 if (EXPECTED_COMMAND
== 0) {
35 KeyPress(ui::VKEY_ESCAPE
,
36 CreateEventTask(this, &MenuControllerMnemonicTest::Step3
));
38 ASSERT_FALSE(menu()->GetSubmenu()->IsShowing());
44 ASSERT_FALSE(menu()->GetSubmenu()->IsShowing());
49 DISALLOW_COPY_AND_ASSIGN(MenuControllerMnemonicTest
);
52 // Pressing the mnemonic for a menu item should execute the command for that
54 typedef MenuControllerMnemonicTest
<ui::VKEY_DIVIDE
,1>
55 MenuControllerMnemonicTestMnemonicMatch
;
57 #if defined(USE_OZONE) || defined(OS_WIN)
58 // ozone bringup - http://crbug.com/401304
59 // flaky on windows - http://crbug.com/523255
60 #define MAYBE_MnemonicMatch DISABLED_MnemonicMatch
62 #define MAYBE_MnemonicMatch MnemonicMatch
65 VIEW_TEST(MenuControllerMnemonicTestMnemonicMatch
, MAYBE_MnemonicMatch
);
67 // Pressing a key which matches the first letter of the menu item's title
68 // should execute the command for that menu item.
69 typedef MenuControllerMnemonicTest
<ui::VKEY_T
,2>
70 MenuControllerMnemonicTestTitleMatch
;
72 #if defined(USE_OZONE) || defined(OS_WIN)
73 // ozone bringup - http://crbug.com/401304
74 // flaky on windows - http://crbug.com/523255
75 #define MAYBE_TitleMatch DISABLED_TitleMatch
77 #define MAYBE_TitleMatch TitleMatch
80 VIEW_TEST(MenuControllerMnemonicTestTitleMatch
, MAYBE_TitleMatch
);
82 // Pressing an arbitrary key should not execute any commands.
83 typedef MenuControllerMnemonicTest
<ui::VKEY_A
,0>
84 MenuControllerMnemonicTestNoMatch
;
86 #if defined(USE_OZONE) || defined(OS_WIN)
87 // ozone bringup - http://crbug.com/401304
88 // flaky on windows - http://crbug.com/523255
89 #define MAYBE_NoMatch DISABLED_NoMatch
91 #define MAYBE_NoMatch NoMatch
94 VIEW_TEST(MenuControllerMnemonicTestNoMatch
, MAYBE_NoMatch
);