1 // Copyright 2013 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/message_loop/message_loop.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
8 #include "chrome/test/base/interactive_test_utils.h"
9 #include "chrome/test/base/ui_test_utils.h"
10 #include "chrome/test/base/view_event_test_base.h"
11 #include "ui/base/models/simple_menu_model.h"
12 #include "ui/base/test/ui_controls.h"
14 class ToolbarButtonDragTest
: public ViewEventTestBase
,
15 ui::SimpleMenuModel::Delegate
{
17 ToolbarButtonDragTest()
23 virtual ~ToolbarButtonDragTest() {
26 // ViewEventTestBase implementation.
27 virtual void SetUp() OVERRIDE
{
28 button_
= new ToolbarButton(NULL
, new ui::SimpleMenuModel(this));
30 ViewEventTestBase::SetUp();
33 virtual void TearDown() OVERRIDE
{
34 ViewEventTestBase::TearDown();
37 virtual views::View
* CreateContentsView() OVERRIDE
{
41 virtual gfx::Size
GetPreferredSize() const OVERRIDE
{
42 return button_
->GetPreferredSize();
45 // ui::SimpleMenuModel::Delegate implementation.
46 virtual bool IsCommandIdChecked(int id
) const OVERRIDE
{
50 virtual bool IsCommandIdEnabled(int id
) const OVERRIDE
{
54 virtual bool GetAcceleratorForCommandId(
56 ui::Accelerator
* accelerator
) OVERRIDE
{
60 virtual void ExecuteCommand(int id
, int event_flags
) OVERRIDE
{
63 virtual void MenuWillShow(ui::SimpleMenuModel
* /*source*/) OVERRIDE
{
67 virtual void MenuClosed(ui::SimpleMenuModel
* /*source*/) OVERRIDE
{
71 // ViewEventTestBase implementation.
72 virtual void DoTestOnMessageLoop() OVERRIDE
{
73 // Click on the ToolbarButton.
74 ui_test_utils::MoveMouseToCenterAndPress(
78 CreateEventTask(this, &ToolbarButtonDragTest::Step1
));
82 // Drag to invoke the menu.
83 gfx::Point view_center
;
84 views::View::ConvertPointToScreen(button_
, &view_center
);
85 // The 50 is a bit arbitrary. We just need a value greater than the drag
87 ui_controls::SendMouseMoveNotifyWhenDone(
88 view_center
.x(), view_center
.y() + 50,
89 CreateEventTask(this, &ToolbarButtonDragTest::Step2
));
93 ASSERT_TRUE(menu_shown_
);
96 ui_controls::SendMouseEventsNotifyWhenDone(
99 CreateEventTask(this, &ToolbarButtonDragTest::Step3
));
103 // Click mouse to dismiss menu. The views menu does not dismiss the
104 // menu on click-drag-release unless an item is selected.
105 ui_test_utils::MoveMouseToCenterAndPress(
108 ui_controls::DOWN
| ui_controls::UP
,
109 CreateEventTask(this, &ToolbarButtonDragTest::Step4
));
113 // One more hop is required because ui::SimpleMenuModel calls
114 // ui::SimpleMenuModel::Delegate::MenuClosed() via a posted
116 base::MessageLoopForUI::current()->PostTask(
117 FROM_HERE
, CreateEventTask(this, &ToolbarButtonDragTest::Step5
));
121 ASSERT_TRUE(menu_closed_
);
126 ToolbarButton
* button_
;
131 // Broken since landed. crbug.com/325055
132 VIEW_TEST(ToolbarButtonDragTest
, DISABLED_DragActivation
)