[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / menu_controller_interactive_uitest.cc
blob3d85b8487e255770caf85e188cfbdd0a6de1c5d3
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 {
12 public:
13 MenuControllerMnemonicTest() {
16 virtual ~MenuControllerMnemonicTest() {
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"));
26 virtual void DoTestWithMenuOpen() {
27 ASSERT_TRUE(menu()->GetSubmenu()->IsShowing());
28 KeyPress(KEYCODE,
29 CreateEventTask(this, &MenuControllerMnemonicTest::Step2));
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();
43 void Step3() {
44 ASSERT_FALSE(menu()->GetSubmenu()->IsShowing());
45 Done();
48 private:
49 DISALLOW_COPY_AND_ASSIGN(MenuControllerMnemonicTest);
52 // Pressing the mnemonic for a menu item should execute the command for that
53 // menu item.
54 typedef MenuControllerMnemonicTest<ui::VKEY_DIVIDE,1>
55 MenuControllerMnemonicTestMnemonicMatch;
56 VIEW_TEST(MenuControllerMnemonicTestMnemonicMatch, MnemonicMatch);
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);
64 // Pressing an arbitrary key should not execute any commands.
65 typedef MenuControllerMnemonicTest<ui::VKEY_A,0>
66 MenuControllerMnemonicTestNoMatch;
67 VIEW_TEST(MenuControllerMnemonicTestNoMatch, NoMatch);