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 "chrome/test/base/interactive_test_utils.h"
8 #include "chrome/test/base/ui_test_utils.h"
9 #include "ui/aura/window.h"
10 #include "ui/base/test/ui_controls.h"
11 #include "ui/views/controls/button/menu_button.h"
12 #include "ui/views/controls/menu/menu_item_view.h"
13 #include "ui/views/controls/menu/menu_runner.h"
15 MenuTestBase::MenuTestBase()
16 : ViewEventTestBase(),
22 MenuTestBase::~MenuTestBase() {
25 void MenuTestBase::Click(views::View
* view
, const base::Closure
& next
) {
26 ui_test_utils::MoveMouseToCenterAndPress(
29 ui_controls::DOWN
| ui_controls::UP
,
33 void MenuTestBase::KeyPress(ui::KeyboardCode keycode
,
34 const base::Closure
& next
) {
35 ui_controls::SendKeyPressNotifyWhenDone(
36 GetWidget()->GetNativeView()->GetRootWindow(), keycode
, false, false,
40 void MenuTestBase::SetUp() {
41 button_
= new views::MenuButton(
42 NULL
, base::ASCIIToUTF16("Menu Test"), this, true);
43 menu_
= new views::MenuItemView(this);
45 menu_runner_
.reset(new views::MenuRunner(menu_
));
47 ViewEventTestBase::SetUp();
50 void MenuTestBase::TearDown() {
53 ViewEventTestBase::TearDown();
56 views::View
* MenuTestBase::CreateContentsView() {
60 void MenuTestBase::DoTestOnMessageLoop() {
61 Click(button_
, CreateEventTask(this, &MenuTestBase::DoTestWithMenuOpen
));
64 gfx::Size
MenuTestBase::GetPreferredSize() const {
65 return button_
->GetPreferredSize();
68 void MenuTestBase::OnMenuButtonClicked(views::View
* source
,
69 const gfx::Point
& point
) {
70 gfx::Point screen_location
;
71 views::View::ConvertPointToScreen(source
, &screen_location
);
72 gfx::Rect
bounds(screen_location
, source
->size());
73 ignore_result(menu_runner_
->RunMenuAt(source
->GetWidget(),
76 views::MENU_ANCHOR_TOPLEFT
,
78 views::MenuRunner::HAS_MNEMONICS
));
81 void MenuTestBase::ExecuteCommand(int id
) {