Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/ui/views/button_dropdown_test.cc

Issue 7044016: Replace ButtonDropDown menu implementation (Menu2) with MenuItemView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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() : button_(NULL),
sky 2011/05/31 23:10:40 nit: if you can't fit all the members on the initi
rhashimoto 2011/05/31 23:36:49 Done.
16 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)),
17 menu_shown_(false),
18 menu_closed_(false) {
19 }
20
21 virtual ~ButtonDropDownDragTest() {
22 }
23
24 // ViewEventTestBase implementation.
25 virtual void SetUp() OVERRIDE {
26 button_ = new views::ButtonDropDown(NULL, &menu_model_);
27
28 ViewEventTestBase::SetUp();
29 }
30
31 virtual void TearDown() OVERRIDE {
32 ViewEventTestBase::TearDown();
33 }
34
35 virtual views::View* CreateContentsView() OVERRIDE {
36 return button_;
37 }
38
39 virtual gfx::Size GetPreferredSize() OVERRIDE {
40 return button_->GetPreferredSize();
41 }
42
43 // ui::SimpleMenuModel::Delegate implementation.
44 virtual bool IsCommandIdChecked(int id) const OVERRIDE {
45 return false;
46 }
47
48 virtual bool IsCommandIdEnabled(int id) const OVERRIDE {
49 return true;
50 }
51
52 virtual bool GetAcceleratorForCommandId(
53 int id,
54 ui::Accelerator* accelerator) OVERRIDE {
55 return false;
56 }
57
58 virtual void ExecuteCommand(int id) OVERRIDE {
59 }
60
61 virtual void MenuWillShow() OVERRIDE {
62 menu_shown_ = true;
63 }
64
65 virtual void MenuClosed() OVERRIDE {
66 menu_closed_ = true;
67 }
68
69 // ViewEventTestBase implementation.
70 virtual void DoTestOnMessageLoop() OVERRIDE {
71 // Click on the ButtonDropDown.
72 ui_controls::MoveMouseToCenterAndPress(
73 button_,
74 ui_controls::LEFT,
75 ui_controls::DOWN,
76 CreateEventTask(this, &ButtonDropDownDragTest::Step1));
77 }
78
79 void Step1() {
80 // Drag to invoke the menu.
81 gfx::Point view_center;
82 views::View::ConvertPointToScreen(button_, &view_center);
83 ui_controls::SendMouseMoveNotifyWhenDone(
84 view_center.x(), view_center.y() + button_->height(),
85 CreateEventTask(this, &ButtonDropDownDragTest::Step2));
86 }
87
88 void Step2() {
89 ASSERT_TRUE(menu_shown_);
90
91 // Release.
92 ui_controls::SendMouseEventsNotifyWhenDone(
93 ui_controls::LEFT,
94 ui_controls::UP,
95 CreateEventTask(this, &ButtonDropDownDragTest::Step3));
96 }
97
98 void Step3() {
99 // Click mouse to dismiss menu. The views menu does not dismiss the
100 // menu on click-drag-release unless an item is selected.
101 ui_controls::MoveMouseToCenterAndPress(
102 button_,
103 ui_controls::LEFT,
104 ui_controls::DOWN,
105 CreateEventTask(this, &ButtonDropDownDragTest::Step4));
106 }
107
108 void Step4() {
109 // One more hop is required because ui::SimpleMenuModel calls
110 // ui::SimpleMenuModel::Delegate::MenuClosed() via a posted
111 // task.
112 MessageLoopForUI::current()->PostTask(
113 FROM_HERE,
114 CreateEventTask(this, &ButtonDropDownDragTest::Step5));
115 }
116
117 void Step5() {
118 ASSERT_TRUE(menu_closed_);
119 Done();
120 }
121
122 private:
123 views::ButtonDropDown* button_;
124 ui::SimpleMenuModel menu_model_;
125 bool menu_shown_;
126 bool menu_closed_;
127 };
128
129 VIEW_TEST(ButtonDropDownDragTest, DragActivation)
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698