summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/menu_controller_interactive_uitest.cc
blob: 498d2177c26b77c16a4bdfaac6505813b40c2b92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/views/menu_test_base.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/submenu_view.h"

template<ui::KeyboardCode KEYCODE, int EXPECTED_COMMAND>
class MenuControllerMnemonicTest : public MenuTestBase {
 public:
  MenuControllerMnemonicTest() {
  }

  ~MenuControllerMnemonicTest() override {
  }

  // MenuTestBase overrides:
  void BuildMenu(views::MenuItemView* menu) override {
    ASSERT_NE(ui::VKEY_DIVIDE, '/');
    menu->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One&/"));
    menu->AppendMenuItemWithLabel(2, base::ASCIIToUTF16("Two"));
  }

  void DoTestWithMenuOpen() override {
    ASSERT_TRUE(menu()->GetSubmenu()->IsShowing());
    KeyPress(KEYCODE,
             CreateEventTask(this, &MenuControllerMnemonicTest::Step2));
  }

  void Step2() {
    ASSERT_EQ(EXPECTED_COMMAND, last_command());
    if (EXPECTED_COMMAND == 0) {
      KeyPress(ui::VKEY_ESCAPE,
               CreateEventTask(this, &MenuControllerMnemonicTest::Step3));
    } else {
      ASSERT_FALSE(menu()->GetSubmenu()->IsShowing());
      Done();
    }
  }

  void Step3() {
    ASSERT_FALSE(menu()->GetSubmenu()->IsShowing());
    Done();
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(MenuControllerMnemonicTest);
};

// Pressing the mnemonic for a menu item should execute the command for that
// menu item.
typedef MenuControllerMnemonicTest<ui::VKEY_DIVIDE,1>
    MenuControllerMnemonicTestMnemonicMatch;

#if defined(USE_OZONE)
// ozone bringup - http://crbug.com/401304
#define MAYBE_MnemonicMatch DISABLED_MnemonicMatch
#else
// If this flakes, disable and log details in http://crbug.com/523255.
#define MAYBE_MnemonicMatch MnemonicMatch
#endif

VIEW_TEST(MenuControllerMnemonicTestMnemonicMatch, MAYBE_MnemonicMatch);

// Pressing a key which matches the first letter of the menu item's title
// should execute the command for that menu item.
typedef MenuControllerMnemonicTest<ui::VKEY_T,2>
    MenuControllerMnemonicTestTitleMatch;

#if defined(USE_OZONE)
// ozone bringup - http://crbug.com/401304
#define MAYBE_TitleMatch DISABLED_TitleMatch
#else
// If this flakes, disable and log details in http://crbug.com/523255.
#define MAYBE_TitleMatch TitleMatch
#endif

VIEW_TEST(MenuControllerMnemonicTestTitleMatch, MAYBE_TitleMatch);

// Pressing an arbitrary key should not execute any commands.
typedef MenuControllerMnemonicTest<ui::VKEY_A,0>
    MenuControllerMnemonicTestNoMatch;

#if defined(USE_OZONE)
// ozone bringup - http://crbug.com/401304
#define MAYBE_NoMatch DISABLED_NoMatch
#else
// If this flakes, disable and log details in http://crbug.com/523255.
#define MAYBE_NoMatch NoMatch
#endif

VIEW_TEST(MenuControllerMnemonicTestNoMatch, MAYBE_NoMatch);