| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/automation/ui_controls.h" | |
| 8 #include "chrome/test/base/view_event_test_base.h" | 7 #include "chrome/test/base/view_event_test_base.h" |
| 8 #include "chrome/test/base/ui_test_utils.h" |
| 9 #include "ui/base/models/simple_menu_model.h" | 9 #include "ui/base/models/simple_menu_model.h" |
| 10 #include "ui/ui_controls/ui_controls.h" |
| 10 #include "ui/views/controls/button/button_dropdown.h" | 11 #include "ui/views/controls/button/button_dropdown.h" |
| 11 | 12 |
| 12 class ButtonDropDownDragTest : public ViewEventTestBase, | 13 class ButtonDropDownDragTest : public ViewEventTestBase, |
| 13 ui::SimpleMenuModel::Delegate { | 14 ui::SimpleMenuModel::Delegate { |
| 14 public: | 15 public: |
| 15 ButtonDropDownDragTest() | 16 ButtonDropDownDragTest() |
| 16 : button_(NULL), | 17 : button_(NULL), |
| 17 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), | 18 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), |
| 18 menu_shown_(false), | 19 menu_shown_(false), |
| 19 menu_closed_(false) { | 20 menu_closed_(false) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 menu_shown_ = true; | 64 menu_shown_ = true; |
| 64 } | 65 } |
| 65 | 66 |
| 66 virtual void MenuClosed(ui::SimpleMenuModel* /*source*/) OVERRIDE { | 67 virtual void MenuClosed(ui::SimpleMenuModel* /*source*/) OVERRIDE { |
| 67 menu_closed_ = true; | 68 menu_closed_ = true; |
| 68 } | 69 } |
| 69 | 70 |
| 70 // ViewEventTestBase implementation. | 71 // ViewEventTestBase implementation. |
| 71 virtual void DoTestOnMessageLoop() OVERRIDE { | 72 virtual void DoTestOnMessageLoop() OVERRIDE { |
| 72 // Click on the ButtonDropDown. | 73 // Click on the ButtonDropDown. |
| 73 ui_controls::MoveMouseToCenterAndPress( | 74 ui_test_utils::MoveMouseToCenterAndPress( |
| 74 button_, | 75 button_, |
| 75 ui_controls::LEFT, | 76 ui_controls::LEFT, |
| 76 ui_controls::DOWN, | 77 ui_controls::DOWN, |
| 77 CreateEventTask(this, &ButtonDropDownDragTest::Step1)); | 78 CreateEventTask(this, &ButtonDropDownDragTest::Step1)); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void Step1() { | 81 void Step1() { |
| 81 // Drag to invoke the menu. | 82 // Drag to invoke the menu. |
| 82 gfx::Point view_center; | 83 gfx::Point view_center; |
| 83 views::View::ConvertPointToScreen(button_, &view_center); | 84 views::View::ConvertPointToScreen(button_, &view_center); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 94 // Release. | 95 // Release. |
| 95 ui_controls::SendMouseEventsNotifyWhenDone( | 96 ui_controls::SendMouseEventsNotifyWhenDone( |
| 96 ui_controls::LEFT, | 97 ui_controls::LEFT, |
| 97 ui_controls::UP, | 98 ui_controls::UP, |
| 98 CreateEventTask(this, &ButtonDropDownDragTest::Step3)); | 99 CreateEventTask(this, &ButtonDropDownDragTest::Step3)); |
| 99 } | 100 } |
| 100 | 101 |
| 101 void Step3() { | 102 void Step3() { |
| 102 // Click mouse to dismiss menu. The views menu does not dismiss the | 103 // Click mouse to dismiss menu. The views menu does not dismiss the |
| 103 // menu on click-drag-release unless an item is selected. | 104 // menu on click-drag-release unless an item is selected. |
| 104 ui_controls::MoveMouseToCenterAndPress( | 105 ui_test_utils::MoveMouseToCenterAndPress( |
| 105 button_, | 106 button_, |
| 106 ui_controls::LEFT, | 107 ui_controls::LEFT, |
| 107 ui_controls::DOWN | ui_controls::UP, | 108 ui_controls::DOWN | ui_controls::UP, |
| 108 CreateEventTask(this, &ButtonDropDownDragTest::Step4)); | 109 CreateEventTask(this, &ButtonDropDownDragTest::Step4)); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void Step4() { | 112 void Step4() { |
| 112 // One more hop is required because ui::SimpleMenuModel calls | 113 // One more hop is required because ui::SimpleMenuModel calls |
| 113 // ui::SimpleMenuModel::Delegate::MenuClosed() via a posted | 114 // ui::SimpleMenuModel::Delegate::MenuClosed() via a posted |
| 114 // task. | 115 // task. |
| 115 MessageLoopForUI::current()->PostTask( | 116 MessageLoopForUI::current()->PostTask( |
| 116 FROM_HERE, | 117 FROM_HERE, |
| 117 CreateEventTask(this, &ButtonDropDownDragTest::Step5)); | 118 CreateEventTask(this, &ButtonDropDownDragTest::Step5)); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void Step5() { | 121 void Step5() { |
| 121 ASSERT_TRUE(menu_closed_); | 122 ASSERT_TRUE(menu_closed_); |
| 122 Done(); | 123 Done(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 private: | 126 private: |
| 126 views::ButtonDropDown* button_; | 127 views::ButtonDropDown* button_; |
| 127 ui::SimpleMenuModel menu_model_; | 128 ui::SimpleMenuModel menu_model_; |
| 128 bool menu_shown_; | 129 bool menu_shown_; |
| 129 bool menu_closed_; | 130 bool menu_closed_; |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 VIEW_TEST(ButtonDropDownDragTest, DragActivation) | 133 VIEW_TEST(ButtonDropDownDragTest, DragActivation) |
| OLD | NEW |