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
{}
18 // MenuTestBase overrides:
19 void BuildMenu(views::MenuItemView
* menu
) override
{
20 ASSERT_NE(ui::VKEY_DIVIDE
, '/');
21 menu
->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One&/"));
22 menu
->AppendMenuItemWithLabel(2, base::ASCIIToUTF16("Two"));
25 void DoTestWithMenuOpen() override
{
26 ASSERT_TRUE(menu()->GetSubmenu()->IsShowing());
28 CreateEventTask(this, &MenuControllerMnemonicTest::Step2
));
32 ASSERT_EQ(EXPECTED_COMMAND
, last_command());
33 if (EXPECTED_COMMAND
== 0) {
34 KeyPress(ui::VKEY_ESCAPE
,
35 CreateEventTask(this, &MenuControllerMnemonicTest::Step3
));
37 ASSERT_FALSE(menu()->GetSubmenu()->IsShowing());
43 ASSERT_FALSE(menu()->GetSubmenu()->IsShowing());
48 DISALLOW_COPY_AND_ASSIGN(MenuControllerMnemonicTest
);
51 // Pressing the mnemonic for a menu item should execute the command for that
53 typedef MenuControllerMnemonicTest
<ui::VKEY_DIVIDE
, 1>
54 MenuControllerMnemonicTestMnemonicMatch
;
55 VIEW_TEST(MenuControllerMnemonicTestMnemonicMatch
, MnemonicMatch
);
57 // Pressing a key which matches the first letter of the menu item's title
58 // should execute the command for that menu item.
59 typedef MenuControllerMnemonicTest
<ui::VKEY_T
, 2>
60 MenuControllerMnemonicTestTitleMatch
;
61 VIEW_TEST(MenuControllerMnemonicTestTitleMatch
, TitleMatch
);
63 // Pressing an arbitrary key should not execute any commands.
64 typedef MenuControllerMnemonicTest
<ui::VKEY_A
, 0>
65 MenuControllerMnemonicTestNoMatch
;
66 VIEW_TEST(MenuControllerMnemonicTestNoMatch
, NoMatch
);