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

Side by Side Diff: ui/views/touchui/touch_selection_menu_runner_views_unittest.cc

Issue 2488393003: Changes views_aura_mus_unittests to create DesktopNativeWidgetAura (Closed)
Patch Set: remove this and fix mac Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/macros.h" 5 #include "base/macros.h"
6 #include "ui/events/event_utils.h" 6 #include "ui/events/event_utils.h"
7 #include "ui/strings/grit/ui_strings.h" 7 #include "ui/strings/grit/ui_strings.h"
8 #include "ui/touch_selection/touch_selection_menu_runner.h" 8 #include "ui/touch_selection/touch_selection_menu_runner.h"
9 #include "ui/views/controls/button/button.h" 9 #include "ui/views/controls/button/button.h"
10 #include "ui/views/test/views_test_base.h" 10 #include "ui/views/test/views_test_base.h"
(...skipping 14 matching lines...) Expand all
25 class TouchSelectionMenuRunnerViewsTest : public ViewsTestBase, 25 class TouchSelectionMenuRunnerViewsTest : public ViewsTestBase,
26 public ui::TouchSelectionMenuClient { 26 public ui::TouchSelectionMenuClient {
27 public: 27 public:
28 TouchSelectionMenuRunnerViewsTest() 28 TouchSelectionMenuRunnerViewsTest()
29 : no_command_available_(false), last_executed_command_id_(0) {} 29 : no_command_available_(false), last_executed_command_id_(0) {}
30 ~TouchSelectionMenuRunnerViewsTest() override {} 30 ~TouchSelectionMenuRunnerViewsTest() override {}
31 31
32 protected: 32 protected:
33 void SetUp() override { 33 void SetUp() override {
34 ViewsTestBase::SetUp(); 34 ViewsTestBase::SetUp();
35 // These tests expect NativeWidgetAura, force its creation. 35 // These tests expect NativeWidgetAura and so aren't applicable to
36 // TODO(sky): the reason these end up using NativeWidgetAura is because they 36 // aura-mus-client. http://crbug.com/663561.
37 // create a widget parented to GetContext(). GetContext() currently always
38 // returns an aura::Window in a fake WindowTreeHost. For aura-mus we should
39 // not create a fake WindowTreeHost. http://crbug.com/663561.
40 ViewsDelegate::GetInstance()->set_native_widget_factory(
41 ViewsDelegate::NativeWidgetFactory());
42 } 37 }
43 38
44 void set_no_commmand_available(bool no_command) { 39 void set_no_commmand_available(bool no_command) {
45 no_command_available_ = no_command; 40 no_command_available_ = no_command;
46 } 41 }
47 42
48 int last_executed_command_id() const { return last_executed_command_id_; } 43 int last_executed_command_id() const { return last_executed_command_id_; }
49 44
50 private: 45 private:
51 // ui::TouchSelectionMenuClient: 46 // ui::TouchSelectionMenuClient:
(...skipping 12 matching lines...) Expand all
64 bool no_command_available_; 59 bool no_command_available_;
65 60
66 int last_executed_command_id_; 61 int last_executed_command_id_;
67 62
68 DISALLOW_COPY_AND_ASSIGN(TouchSelectionMenuRunnerViewsTest); 63 DISALLOW_COPY_AND_ASSIGN(TouchSelectionMenuRunnerViewsTest);
69 }; 64 };
70 65
71 // Tests that the default touch selection menu runner is installed and opening 66 // Tests that the default touch selection menu runner is installed and opening
72 // and closing the menu works properly. 67 // and closing the menu works properly.
73 TEST_F(TouchSelectionMenuRunnerViewsTest, InstalledAndWorksProperly) { 68 TEST_F(TouchSelectionMenuRunnerViewsTest, InstalledAndWorksProperly) {
69 // See comment in SetUp().
70 if (IsAuraMusClient())
71 return;
72
74 gfx::Rect menu_anchor(0, 0, 10, 10); 73 gfx::Rect menu_anchor(0, 0, 10, 10);
75 gfx::Size handle_size(10, 10); 74 gfx::Size handle_size(10, 10);
76 75
77 // Menu runner instance should be installed, but no menu should be running. 76 // Menu runner instance should be installed, but no menu should be running.
78 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()); 77 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance());
79 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 78 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
80 79
81 // Run menu. Since commands are available, this should bring up menus. 80 // Run menu. Since commands are available, this should bring up menus.
82 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu( 81 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu(
83 this, menu_anchor, handle_size, GetContext()); 82 this, menu_anchor, handle_size, GetContext());
84 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 83 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
85 84
86 // Close menu. 85 // Close menu.
87 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu(); 86 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu();
88 RunPendingMessages(); 87 RunPendingMessages();
89 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 88 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
90 89
91 // Try running menu when no commands is available. Menu should not be shown. 90 // Try running menu when no commands is available. Menu should not be shown.
92 set_no_commmand_available(true); 91 set_no_commmand_available(true);
93 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu( 92 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu(
94 this, menu_anchor, handle_size, GetContext()); 93 this, menu_anchor, handle_size, GetContext());
95 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 94 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
96 } 95 }
97 96
98 // Tests that anchor rect for the quick menu is adjusted correctly based on the 97 // Tests that anchor rect for the quick menu is adjusted correctly based on the
99 // distance of handles. 98 // distance of handles.
100 TEST_F(TouchSelectionMenuRunnerViewsTest, QuickMenuAdjustsAnchorRect) { 99 TEST_F(TouchSelectionMenuRunnerViewsTest, QuickMenuAdjustsAnchorRect) {
100 // See comment in SetUp().
101 if (IsAuraMusClient())
102 return;
103
101 gfx::Size handle_size(10, 10); 104 gfx::Size handle_size(10, 10);
102 TouchSelectionMenuRunnerViews::TestApi test_api( 105 TouchSelectionMenuRunnerViews::TestApi test_api(
103 static_cast<TouchSelectionMenuRunnerViews*>( 106 static_cast<TouchSelectionMenuRunnerViews*>(
104 ui::TouchSelectionMenuRunner::GetInstance())); 107 ui::TouchSelectionMenuRunner::GetInstance()));
105 108
106 // Calculate the width of quick menu. In addition to |kMenuCommandCount| 109 // Calculate the width of quick menu. In addition to |kMenuCommandCount|
107 // commands, there is an item for ellipsis. 110 // commands, there is an item for ellipsis.
108 int quick_menu_width = 111 int quick_menu_width =
109 (kMenuCommandCount + 1) * kMenuButtonWidth + kMenuCommandCount; 112 (kMenuCommandCount + 1) * kMenuButtonWidth + kMenuCommandCount;
110 113
(...skipping 12 matching lines...) Expand all
123 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu( 126 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu(
124 this, anchor_rect, handle_size, GetContext()); 127 this, anchor_rect, handle_size, GetContext());
125 EXPECT_EQ(anchor_rect, test_api.GetAnchorRect()); 128 EXPECT_EQ(anchor_rect, test_api.GetAnchorRect());
126 129
127 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu(); 130 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu();
128 RunPendingMessages(); 131 RunPendingMessages();
129 } 132 }
130 133
131 // Tests that running one of menu actions closes the menu properly. 134 // Tests that running one of menu actions closes the menu properly.
132 TEST_F(TouchSelectionMenuRunnerViewsTest, RunningActionClosesProperly) { 135 TEST_F(TouchSelectionMenuRunnerViewsTest, RunningActionClosesProperly) {
136 // See comment in SetUp().
137 if (IsAuraMusClient())
138 return;
139
133 gfx::Rect menu_anchor(0, 0, 10, 10); 140 gfx::Rect menu_anchor(0, 0, 10, 10);
134 gfx::Size handle_size(10, 10); 141 gfx::Size handle_size(10, 10);
135 TouchSelectionMenuRunnerViews::TestApi test_api( 142 TouchSelectionMenuRunnerViews::TestApi test_api(
136 static_cast<TouchSelectionMenuRunnerViews*>( 143 static_cast<TouchSelectionMenuRunnerViews*>(
137 ui::TouchSelectionMenuRunner::GetInstance())); 144 ui::TouchSelectionMenuRunner::GetInstance()));
138 145
139 // Initially, no menu should be running. 146 // Initially, no menu should be running.
140 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 147 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
141 148
142 // Run menu. Since commands are available, this should bring up menus. 149 // Run menu. Since commands are available, this should bring up menus.
(...skipping 11 matching lines...) Expand all
154 ui::GestureEvent tap(button_center.x(), button_center.y(), 0, 161 ui::GestureEvent tap(button_center.x(), button_center.y(), 0,
155 ui::EventTimeForNow(), details); 162 ui::EventTimeForNow(), details);
156 button->OnGestureEvent(&tap); 163 button->OnGestureEvent(&tap);
157 RunPendingMessages(); 164 RunPendingMessages();
158 EXPECT_NE(0, last_executed_command_id()); 165 EXPECT_NE(0, last_executed_command_id());
159 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 166 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
160 } 167 }
161 168
162 // Tests that closing the menu widget cleans up the menu runner state properly. 169 // Tests that closing the menu widget cleans up the menu runner state properly.
163 TEST_F(TouchSelectionMenuRunnerViewsTest, ClosingWidgetClosesProperly) { 170 TEST_F(TouchSelectionMenuRunnerViewsTest, ClosingWidgetClosesProperly) {
171 // See comment in SetUp().
172 if (IsAuraMusClient())
173 return;
174
164 gfx::Rect menu_anchor(0, 0, 10, 10); 175 gfx::Rect menu_anchor(0, 0, 10, 10);
165 gfx::Size handle_size(10, 10); 176 gfx::Size handle_size(10, 10);
166 TouchSelectionMenuRunnerViews::TestApi test_api( 177 TouchSelectionMenuRunnerViews::TestApi test_api(
167 static_cast<TouchSelectionMenuRunnerViews*>( 178 static_cast<TouchSelectionMenuRunnerViews*>(
168 ui::TouchSelectionMenuRunner::GetInstance())); 179 ui::TouchSelectionMenuRunner::GetInstance()));
169 180
170 // Initially, no menu should be running. 181 // Initially, no menu should be running.
171 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 182 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
172 183
173 // Run menu. Since commands are available, this should bring up menus. 184 // Run menu. Since commands are available, this should bring up menus.
174 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu( 185 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu(
175 this, menu_anchor, handle_size, GetContext()); 186 this, menu_anchor, handle_size, GetContext());
176 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 187 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
177 188
178 // Close the menu widget and check that menu runner correctly knows that menu 189 // Close the menu widget and check that menu runner correctly knows that menu
179 // is not running anymore. 190 // is not running anymore.
180 Widget* widget = test_api.GetWidget(); 191 Widget* widget = test_api.GetWidget();
181 DCHECK(widget); 192 DCHECK(widget);
182 widget->Close(); 193 widget->Close();
183 RunPendingMessages(); 194 RunPendingMessages();
184 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 195 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
185 } 196 }
186 197
187 } // namespace views 198 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/touchui/touch_selection_controller_impl_unittest.cc ('k') | ui/views/view_unittest_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698