Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
sky
2014/02/18 17:43:28
Please name this _browsertest.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 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" | |
| 9 | |
| 10 template<ui::KeyboardCode KEYCODE, int EXPECTED_COMMAND> | |
| 11 class MenuControllerMnemonicTest : public MenuTestBase { | |
| 12 public: | |
| 13 MenuControllerMnemonicTest() { | |
| 14 } | |
| 15 | |
| 16 virtual ~MenuControllerMnemonicTest() { | |
| 17 } | |
| 18 | |
| 19 // MenuTestBase overrides: | |
| 20 virtual 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")); | |
| 24 } | |
| 25 | |
| 26 virtual void DoTestWithMenuOpen() { | |
| 27 ASSERT_TRUE(menu()->GetSubmenu()->IsShowing()); | |
| 28 KeyPress(KEYCODE, | |
| 29 CreateEventTask(this, &MenuControllerMnemonicTest::Step2)); | |
| 30 } | |
| 31 | |
| 32 void Step2() { | |
| 33 ASSERT_EQ(EXPECTED_COMMAND, last_command()); | |
| 34 if (EXPECTED_COMMAND == 0) { | |
| 35 KeyPress(ui::VKEY_ESCAPE, | |
| 36 CreateEventTask(this, &MenuControllerMnemonicTest::Step3)); | |
| 37 } else { | |
| 38 ASSERT_FALSE(menu()->GetSubmenu()->IsShowing()); | |
| 39 Done(); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 void Step3() { | |
| 44 ASSERT_FALSE(menu()->GetSubmenu()->IsShowing()); | |
| 45 Done(); | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 DISALLOW_COPY_AND_ASSIGN(MenuControllerMnemonicTest); | |
| 50 }; | |
| 51 | |
| 52 // Pressing the mnemonic for a menu item should execute the command for that | |
| 53 // menu item. | |
| 54 typedef MenuControllerMnemonicTest<ui::VKEY_DIVIDE,1> | |
|
sky
2014/02/18 17:43:28
nit: space after ',' here and other places.
| |
| 55 MenuControllerMnemonicTestMnemonicMatch; | |
| 56 VIEW_TEST(MenuControllerMnemonicTestMnemonicMatch, MnemonicMatch); | |
| 57 | |
| 58 // Pressing a key which matches the first letter of the menu item's title | |
| 59 // should execute the command for that menu item. | |
| 60 typedef MenuControllerMnemonicTest<ui::VKEY_T,2> | |
| 61 MenuControllerMnemonicTestTitleMatch; | |
| 62 VIEW_TEST(MenuControllerMnemonicTestTitleMatch, TitleMatch); | |
| 63 | |
| 64 // Pressing an arbitrary key should not execute any commands. | |
| 65 typedef MenuControllerMnemonicTest<ui::VKEY_A,0> | |
| 66 MenuControllerMnemonicTestNoMatch; | |
| 67 VIEW_TEST(MenuControllerMnemonicTestNoMatch, NoMatch); | |
| OLD | NEW |