OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #include "base/message_loop.h" |
| 6 #include "base/utf_string_conversions.h" |
| 7 #include "ui/base/models/simple_menu_model.h" |
| 8 #include "chrome/browser/automation/ui_controls.h" |
| 9 #include "chrome/test/interactive_ui/view_event_test_base.h" |
| 10 #include "views/controls/button/button_dropdown.h" |
| 11 |
| 12 class ButtonDropDownDragTest : public ViewEventTestBase, |
| 13 ui::SimpleMenuModel::Delegate { |
| 14 public: |
| 15 ButtonDropDownDragTest() |
| 16 : button_(NULL), |
| 17 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), |
| 18 menu_shown_(false), |
| 19 menu_closed_(false) { |
| 20 } |
| 21 |
| 22 virtual ~ButtonDropDownDragTest() { |
| 23 } |
| 24 |
| 25 // ViewEventTestBase implementation. |
| 26 virtual void SetUp() OVERRIDE { |
| 27 button_ = new views::ButtonDropDown(NULL, &menu_model_); |
| 28 |
| 29 ViewEventTestBase::SetUp(); |
| 30 } |
| 31 |
| 32 virtual void TearDown() OVERRIDE { |
| 33 ViewEventTestBase::TearDown(); |
| 34 } |
| 35 |
| 36 virtual views::View* CreateContentsView() OVERRIDE { |
| 37 return button_; |
| 38 } |
| 39 |
| 40 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 41 return button_->GetPreferredSize(); |
| 42 } |
| 43 |
| 44 // ui::SimpleMenuModel::Delegate implementation. |
| 45 virtual bool IsCommandIdChecked(int id) const OVERRIDE { |
| 46 return false; |
| 47 } |
| 48 |
| 49 virtual bool IsCommandIdEnabled(int id) const OVERRIDE { |
| 50 return true; |
| 51 } |
| 52 |
| 53 virtual bool GetAcceleratorForCommandId( |
| 54 int id, |
| 55 ui::Accelerator* accelerator) OVERRIDE { |
| 56 return false; |
| 57 } |
| 58 |
| 59 virtual void ExecuteCommand(int id) OVERRIDE { |
| 60 } |
| 61 |
| 62 virtual void MenuWillShow() OVERRIDE { |
| 63 menu_shown_ = true; |
| 64 } |
| 65 |
| 66 virtual void MenuClosed() OVERRIDE { |
| 67 menu_closed_ = true; |
| 68 } |
| 69 |
| 70 // ViewEventTestBase implementation. |
| 71 virtual void DoTestOnMessageLoop() OVERRIDE { |
| 72 // Click on the ButtonDropDown. |
| 73 ui_controls::MoveMouseToCenterAndPress( |
| 74 button_, |
| 75 ui_controls::LEFT, |
| 76 ui_controls::DOWN, |
| 77 CreateEventTask(this, &ButtonDropDownDragTest::Step1)); |
| 78 } |
| 79 |
| 80 void Step1() { |
| 81 // Drag to invoke the menu. |
| 82 gfx::Point view_center; |
| 83 views::View::ConvertPointToScreen(button_, &view_center); |
| 84 ui_controls::SendMouseMoveNotifyWhenDone( |
| 85 view_center.x(), view_center.y() + button_->height(), |
| 86 CreateEventTask(this, &ButtonDropDownDragTest::Step2)); |
| 87 } |
| 88 |
| 89 void Step2() { |
| 90 ASSERT_TRUE(menu_shown_); |
| 91 |
| 92 // Release. |
| 93 ui_controls::SendMouseEventsNotifyWhenDone( |
| 94 ui_controls::LEFT, |
| 95 ui_controls::UP, |
| 96 CreateEventTask(this, &ButtonDropDownDragTest::Step3)); |
| 97 } |
| 98 |
| 99 void Step3() { |
| 100 // Click mouse to dismiss menu. The views menu does not dismiss the |
| 101 // menu on click-drag-release unless an item is selected. |
| 102 ui_controls::MoveMouseToCenterAndPress( |
| 103 button_, |
| 104 ui_controls::LEFT, |
| 105 ui_controls::DOWN | ui_controls::UP, |
| 106 CreateEventTask(this, &ButtonDropDownDragTest::Step4)); |
| 107 } |
| 108 |
| 109 void Step4() { |
| 110 // One more hop is required because ui::SimpleMenuModel calls |
| 111 // ui::SimpleMenuModel::Delegate::MenuClosed() via a posted |
| 112 // task. |
| 113 MessageLoopForUI::current()->PostTask( |
| 114 FROM_HERE, |
| 115 CreateEventTask(this, &ButtonDropDownDragTest::Step5)); |
| 116 } |
| 117 |
| 118 void Step5() { |
| 119 ASSERT_TRUE(menu_closed_); |
| 120 Done(); |
| 121 } |
| 122 |
| 123 private: |
| 124 views::ButtonDropDown* button_; |
| 125 ui::SimpleMenuModel menu_model_; |
| 126 bool menu_shown_; |
| 127 bool menu_closed_; |
| 128 }; |
| 129 |
| 130 VIEW_TEST(ButtonDropDownDragTest, DragActivation) |
OLD | NEW |