BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / views / menu_test_base.cc
blob5874c755c1575b8ea91f2f191025dddce6942733
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/base/test/ui_controls.h"
10 #include "ui/views/controls/button/menu_button.h"
11 #include "ui/views/controls/menu/menu_item_view.h"
12 #include "ui/views/controls/menu/menu_runner.h"
13 #include "ui/views/widget/widget.h"
15 MenuTestBase::MenuTestBase()
16 : ViewEventTestBase(),
17 button_(NULL),
18 menu_(NULL),
19 last_command_(0) {
22 MenuTestBase::~MenuTestBase() {
25 void MenuTestBase::Click(views::View* view, const base::Closure& next) {
26 ui_test_utils::MoveMouseToCenterAndPress(
27 view,
28 ui_controls::LEFT,
29 ui_controls::DOWN | ui_controls::UP,
30 next);
33 void MenuTestBase::KeyPress(ui::KeyboardCode keycode,
34 const base::Closure& next) {
35 ui_controls::SendKeyPressNotifyWhenDone(
36 GetWidget()->GetNativeWindow(), keycode, false, false,
37 false, false, next);
40 int MenuTestBase::GetMenuRunnerFlags() {
41 return views::MenuRunner::HAS_MNEMONICS;
44 void MenuTestBase::SetUp() {
45 button_ = new views::MenuButton(
46 NULL, base::ASCIIToUTF16("Menu Test"), this, true);
47 menu_ = new views::MenuItemView(this);
48 BuildMenu(menu_);
49 menu_runner_.reset(new views::MenuRunner(menu_, GetMenuRunnerFlags()));
51 ViewEventTestBase::SetUp();
54 void MenuTestBase::TearDown() {
55 // We cancel the menu first because certain operations (like a menu opened
56 // with views::MenuRunner::FOR_DROP) don't take kindly to simply pulling the
57 // runner out from under them.
58 menu_runner_->Cancel();
60 menu_runner_.reset();
61 menu_ = NULL;
62 ViewEventTestBase::TearDown();
65 views::View* MenuTestBase::CreateContentsView() {
66 return button_;
69 void MenuTestBase::DoTestOnMessageLoop() {
70 Click(button_, CreateEventTask(this, &MenuTestBase::DoTestWithMenuOpen));
73 gfx::Size MenuTestBase::GetPreferredSize() const {
74 return button_->GetPreferredSize();
77 void MenuTestBase::OnMenuButtonClicked(views::View* source,
78 const gfx::Point& point) {
79 gfx::Point screen_location;
80 views::View::ConvertPointToScreen(source, &screen_location);
81 gfx::Rect bounds(screen_location, source->size());
82 ignore_result(menu_runner_->RunMenuAt(source->GetWidget(),
83 button_,
84 bounds,
85 views::MENU_ANCHOR_TOPLEFT,
86 ui::MENU_SOURCE_NONE));
89 void MenuTestBase::ExecuteCommand(int id) {
90 last_command_ = id;