[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / menu_test_base.cc
blob4e358dc7903a29ef9940adb40cc5895fd39b0b23
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(),
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()->GetNativeView()->GetRootWindow(), keycode, false, false,
37 false, false, next);
40 void MenuTestBase::SetUp() {
41 button_ = new views::MenuButton(
42 NULL, base::ASCIIToUTF16("Menu Test"), this, true);
43 menu_ = new views::MenuItemView(this);
44 BuildMenu(menu_);
45 menu_runner_.reset(new views::MenuRunner(menu_));
47 ViewEventTestBase::SetUp();
50 void MenuTestBase::TearDown() {
51 menu_runner_.reset();
52 menu_ = NULL;
53 ViewEventTestBase::TearDown();
56 views::View* MenuTestBase::CreateContentsView() {
57 return button_;
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(),
74 button_,
75 bounds,
76 views::MENU_ANCHOR_TOPLEFT,
77 ui::MENU_SOURCE_NONE,
78 views::MenuRunner::HAS_MNEMONICS));
81 void MenuTestBase::ExecuteCommand(int id) {
82 last_command_ = id;