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

Side by Side Diff: ash/wm/workspace/multi_window_resize_controller_unittest.cc

Issue 771543002: Improve the logic for hiding the multi-window resize handle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_multi_window
Patch Set: Created 6 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/wm/workspace/multi_window_resize_controller.h" 5 #include "ash/wm/workspace/multi_window_resize_controller.h"
6 6
7 #include "ash/ash_constants.h"
8 #include "ash/frame/custom_frame_view_ash.h"
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
9 #include "ash/test/shell_test_api.h" 11 #include "ash/test/shell_test_api.h"
10 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
11 #include "ash/wm/workspace/workspace_event_handler_test_helper.h" 13 #include "ash/wm/workspace/workspace_event_handler_test_helper.h"
12 #include "ash/wm/workspace_controller.h" 14 #include "ash/wm/workspace_controller.h"
13 #include "ash/wm/workspace_controller_test_helper.h" 15 #include "ash/wm/workspace_controller_test_helper.h"
14 #include "ui/aura/test/test_window_delegate.h" 16 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
16 #include "ui/base/hit_test.h" 18 #include "ui/base/hit_test.h"
17 #include "ui/events/test/event_generator.h" 19 #include "ui/events/test/event_generator.h"
18 #include "ui/gfx/screen.h" 20 #include "ui/gfx/screen.h"
19 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
22 #include "ui/views/widget/widget_delegate.h"
20 23
21 namespace ash { 24 namespace ash {
22 25
26 namespace {
27
28 // WidgetDelegate for a resizable widget which creates a NonClientFrameView
29 // which is actually used in Ash.
30 class TestWidgetDelegate : public views::WidgetDelegateView {
31 public:
32 TestWidgetDelegate() {}
33 ~TestWidgetDelegate() override {}
34
35 bool CanResize() const override {
36 return true;
37 }
38
39 views::NonClientFrameView* CreateNonClientFrameView(
40 views::Widget* widget) override {
41 return new CustomFrameViewAsh(widget);
42 }
43
44 private:
45 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
46 };
47
48 } // namespace
49
23 class MultiWindowResizeControllerTest : public test::AshTestBase { 50 class MultiWindowResizeControllerTest : public test::AshTestBase {
24 public: 51 public:
25 MultiWindowResizeControllerTest() : resize_controller_(NULL) {} 52 MultiWindowResizeControllerTest() : resize_controller_(NULL) {}
26 ~MultiWindowResizeControllerTest() override {} 53 ~MultiWindowResizeControllerTest() override {}
27 54
28 void SetUp() override { 55 void SetUp() override {
29 test::AshTestBase::SetUp(); 56 test::AshTestBase::SetUp();
30 WorkspaceController* wc = 57 WorkspaceController* wc =
31 test::ShellTestApi(Shell::GetInstance()).workspace_controller(); 58 test::ShellTestApi(Shell::GetInstance()).workspace_controller();
32 WorkspaceEventHandler* event_handler = 59 WorkspaceEventHandler* event_handler =
(...skipping 19 matching lines...) Expand all
52 } 79 }
53 80
54 bool IsShowing() { 81 bool IsShowing() {
55 return resize_controller_->IsShowing(); 82 return resize_controller_->IsShowing();
56 } 83 }
57 84
58 bool HasPendingShow() { 85 bool HasPendingShow() {
59 return resize_controller_->show_timer_.IsRunning(); 86 return resize_controller_->show_timer_.IsRunning();
60 } 87 }
61 88
62 bool HasPendingHide() {
63 return resize_controller_->hide_timer_.IsRunning();
64 }
65
66 void Hide() { 89 void Hide() {
67 resize_controller_->Hide(); 90 resize_controller_->Hide();
68 } 91 }
69 92
70 bool HasTarget(aura::Window* window) { 93 bool HasTarget(aura::Window* window) {
71 if (!resize_controller_->windows_.is_valid()) 94 if (!resize_controller_->windows_.is_valid())
72 return false; 95 return false;
73 if ((resize_controller_->windows_.window1 == window || 96 if ((resize_controller_->windows_.window1 == window ||
74 resize_controller_->windows_.window2 == window)) 97 resize_controller_->windows_.window2 == window))
75 return true; 98 return true;
(...skipping 26 matching lines...) Expand all
102 CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100))); 125 CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100)));
103 delegate1.set_window_component(HTRIGHT); 126 delegate1.set_window_component(HTRIGHT);
104 aura::test::TestWindowDelegate delegate2; 127 aura::test::TestWindowDelegate delegate2;
105 scoped_ptr<aura::Window> w2( 128 scoped_ptr<aura::Window> w2(
106 CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100))); 129 CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100)));
107 delegate2.set_window_component(HTRIGHT); 130 delegate2.set_window_component(HTRIGHT);
108 ui::test::EventGenerator generator(w1->GetRootWindow()); 131 ui::test::EventGenerator generator(w1->GetRootWindow());
109 generator.MoveMouseTo(w1->bounds().CenterPoint()); 132 generator.MoveMouseTo(w1->bounds().CenterPoint());
110 EXPECT_TRUE(HasPendingShow()); 133 EXPECT_TRUE(HasPendingShow());
111 EXPECT_TRUE(IsShowing()); 134 EXPECT_TRUE(IsShowing());
112 EXPECT_FALSE(HasPendingHide());
113 135
114 // Force a show now. 136 // Force a show now.
115 ShowNow(); 137 ShowNow();
116 EXPECT_FALSE(HasPendingShow()); 138 EXPECT_FALSE(HasPendingShow());
117 EXPECT_TRUE(IsShowing()); 139 EXPECT_TRUE(IsShowing());
118 EXPECT_FALSE(HasPendingHide());
119 140
120 EXPECT_FALSE(IsOverWindows(gfx::Point(200, 200))); 141 EXPECT_FALSE(IsOverWindows(gfx::Point(200, 200)));
121 142
122 // Have to explicitly invoke this as MouseWatcher listens for native events. 143 // Have to explicitly invoke this as MouseWatcher listens for native events.
123 resize_controller_->MouseMovedOutOfHost(); 144 resize_controller_->MouseMovedOutOfHost();
124 EXPECT_FALSE(HasPendingShow()); 145 EXPECT_FALSE(HasPendingShow());
125 EXPECT_FALSE(IsShowing()); 146 EXPECT_FALSE(IsShowing());
126 EXPECT_FALSE(HasPendingHide()); 147 }
148
149 // Test the behavior of IsOverWindows().
150 TEST_F(MultiWindowResizeControllerTest, IsOverWindows) {
151 // Create the following layout:
152 // __________________
153 // | w1 | w2 |
154 // | |________|
155 // | | w3 |
156 // |________|________|
157 scoped_ptr<views::Widget> w1(new views::Widget);
158 views::Widget::InitParams params1;
159 params1.delegate = new TestWidgetDelegate;
160 params1.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
161 params1.bounds = gfx::Rect(100, 200);
162 params1.context = CurrentContext();
163 w1->Init(params1);
164 w1->Show();
165
166 scoped_ptr<views::Widget> w2(new views::Widget);
167 views::Widget::InitParams params2;
168 params2.delegate = new TestWidgetDelegate;
169 params2.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
170 params2.bounds = gfx::Rect(100, 0, 100, 100);
171 params2.context = CurrentContext();
172 w2->Init(params2);
173 w2->Show();
174
175 scoped_ptr<views::Widget> w3(new views::Widget);
176 views::Widget::InitParams params3;
177 params3.delegate = new TestWidgetDelegate;
178 params3.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
179 params3.bounds = gfx::Rect(100, 100, 100, 100);
180 params3.context = CurrentContext();
181 w3->Init(params3);
182 w3->Show();
183
184 ui::test::EventGenerator& generator = GetEventGenerator();
185 generator.MoveMouseTo(gfx::Point(100, 150));
186 EXPECT_TRUE(HasPendingShow());
187 EXPECT_TRUE(IsShowing());
188 ShowNow();
189 EXPECT_TRUE(IsShowing());
190
191 // Check that the multi-window resize handle does not hide while the mouse is
192 // over a window's resize area. A window's resize area extends outside the
193 // window's bounds.
194 EXPECT_TRUE(w3->IsActive());
195 ASSERT_LT(kResizeInsideBoundsSize, kResizeOutsideBoundsSize);
196
197 EXPECT_TRUE(IsOverWindows(gfx::Point(100, 150)));
198 EXPECT_TRUE(IsOverWindows(gfx::Point(100 - kResizeOutsideBoundsSize, 150)));
199 EXPECT_FALSE(
200 IsOverWindows(gfx::Point(100 - kResizeOutsideBoundsSize - 1, 150)));
201 EXPECT_TRUE(
202 IsOverWindows(gfx::Point(100 + kResizeInsideBoundsSize - 1, 150)));
203 EXPECT_FALSE(IsOverWindows(gfx::Point(100 + kResizeInsideBoundsSize, 150)));
204 EXPECT_FALSE(
205 IsOverWindows(gfx::Point(100 + kResizeOutsideBoundsSize - 1, 150)));
flackr 2014/12/01 20:19:36 This last expect is probably redundant given kResi
206
207 w1->Activate();
208 EXPECT_TRUE(IsOverWindows(gfx::Point(100, 150)));
209 EXPECT_TRUE(IsOverWindows(gfx::Point(100 - kResizeInsideBoundsSize, 150)));
210 EXPECT_FALSE(
211 IsOverWindows(gfx::Point(100 - kResizeInsideBoundsSize - 1, 150)));
212 EXPECT_FALSE(IsOverWindows(gfx::Point(100 - kResizeOutsideBoundsSize, 150)));
213 EXPECT_TRUE(
214 IsOverWindows(gfx::Point(100 + kResizeOutsideBoundsSize - 1, 150)));
215 EXPECT_FALSE(IsOverWindows(gfx::Point(100 + kResizeOutsideBoundsSize, 150)));
216
217 // Check that the multi-window resize handles eventually hide if the mouse
218 // moves between |w1| and |w2|.
219 EXPECT_FALSE(IsOverWindows(gfx::Point(100, 50)));
127 } 220 }
128 221
129 // Makes sure deleting a window hides. 222 // Makes sure deleting a window hides.
130 TEST_F(MultiWindowResizeControllerTest, DeleteWindow) { 223 TEST_F(MultiWindowResizeControllerTest, DeleteWindow) {
131 aura::test::TestWindowDelegate delegate1; 224 aura::test::TestWindowDelegate delegate1;
132 scoped_ptr<aura::Window> w1( 225 scoped_ptr<aura::Window> w1(
133 CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100))); 226 CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100)));
134 delegate1.set_window_component(HTRIGHT); 227 delegate1.set_window_component(HTRIGHT);
135 aura::test::TestWindowDelegate delegate2; 228 aura::test::TestWindowDelegate delegate2;
136 scoped_ptr<aura::Window> w2( 229 scoped_ptr<aura::Window> w2(
137 CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100))); 230 CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100)));
138 delegate2.set_window_component(HTRIGHT); 231 delegate2.set_window_component(HTRIGHT);
139 ui::test::EventGenerator generator(w1->GetRootWindow()); 232 ui::test::EventGenerator generator(w1->GetRootWindow());
140 generator.MoveMouseTo(w1->bounds().CenterPoint()); 233 generator.MoveMouseTo(w1->bounds().CenterPoint());
141 EXPECT_TRUE(HasPendingShow()); 234 EXPECT_TRUE(HasPendingShow());
142 EXPECT_TRUE(IsShowing()); 235 EXPECT_TRUE(IsShowing());
143 EXPECT_FALSE(HasPendingHide());
144 236
145 // Force a show now. 237 // Force a show now.
146 ShowNow(); 238 ShowNow();
147 EXPECT_FALSE(HasPendingShow()); 239 EXPECT_FALSE(HasPendingShow());
148 EXPECT_TRUE(IsShowing()); 240 EXPECT_TRUE(IsShowing());
149 EXPECT_FALSE(HasPendingHide());
150 241
151 // Move the mouse over the resize widget. 242 // Move the mouse over the resize widget.
152 ASSERT_TRUE(resize_widget()); 243 ASSERT_TRUE(resize_widget());
153 gfx::Rect bounds(resize_widget()->GetWindowBoundsInScreen()); 244 gfx::Rect bounds(resize_widget()->GetWindowBoundsInScreen());
154 generator.MoveMouseTo(bounds.x() + 1, bounds.y() + 1); 245 generator.MoveMouseTo(bounds.x() + 1, bounds.y() + 1);
155 EXPECT_FALSE(HasPendingShow()); 246 EXPECT_FALSE(HasPendingShow());
156 EXPECT_TRUE(IsShowing()); 247 EXPECT_TRUE(IsShowing());
157 EXPECT_FALSE(HasPendingHide());
158 248
159 // Move the resize widget 249 // Move the resize widget
160 generator.PressLeftButton(); 250 generator.PressLeftButton();
161 generator.MoveMouseTo(bounds.x() + 10, bounds.y() + 10); 251 generator.MoveMouseTo(bounds.x() + 10, bounds.y() + 10);
162 252
163 // Delete w2. 253 // Delete w2.
164 w2.reset(); 254 w2.reset();
165 EXPECT_TRUE(resize_widget() == NULL); 255 EXPECT_TRUE(resize_widget() == NULL);
166 EXPECT_FALSE(HasPendingShow()); 256 EXPECT_FALSE(HasPendingShow());
167 EXPECT_FALSE(IsShowing()); 257 EXPECT_FALSE(IsShowing());
168 EXPECT_FALSE(HasPendingHide());
169 EXPECT_FALSE(HasTarget(w1.get())); 258 EXPECT_FALSE(HasTarget(w1.get()));
170 } 259 }
171 260
172 // Tests resizing. 261 // Tests resizing.
173 TEST_F(MultiWindowResizeControllerTest, Drag) { 262 TEST_F(MultiWindowResizeControllerTest, Drag) {
174 aura::test::TestWindowDelegate delegate1; 263 aura::test::TestWindowDelegate delegate1;
175 scoped_ptr<aura::Window> w1( 264 scoped_ptr<aura::Window> w1(
176 CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100))); 265 CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100)));
177 delegate1.set_window_component(HTRIGHT); 266 delegate1.set_window_component(HTRIGHT);
178 aura::test::TestWindowDelegate delegate2; 267 aura::test::TestWindowDelegate delegate2;
179 scoped_ptr<aura::Window> w2( 268 scoped_ptr<aura::Window> w2(
180 CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100))); 269 CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100)));
181 delegate2.set_window_component(HTRIGHT); 270 delegate2.set_window_component(HTRIGHT);
182 ui::test::EventGenerator generator(w1->GetRootWindow()); 271 ui::test::EventGenerator generator(w1->GetRootWindow());
183 generator.MoveMouseTo(w1->bounds().CenterPoint()); 272 generator.MoveMouseTo(w1->bounds().CenterPoint());
184 EXPECT_TRUE(HasPendingShow()); 273 EXPECT_TRUE(HasPendingShow());
185 EXPECT_TRUE(IsShowing()); 274 EXPECT_TRUE(IsShowing());
186 EXPECT_FALSE(HasPendingHide());
187 275
188 // Force a show now. 276 // Force a show now.
189 ShowNow(); 277 ShowNow();
190 EXPECT_FALSE(HasPendingShow()); 278 EXPECT_FALSE(HasPendingShow());
191 EXPECT_TRUE(IsShowing()); 279 EXPECT_TRUE(IsShowing());
192 EXPECT_FALSE(HasPendingHide());
193 280
194 // Move the mouse over the resize widget. 281 // Move the mouse over the resize widget.
195 ASSERT_TRUE(resize_widget()); 282 ASSERT_TRUE(resize_widget());
196 gfx::Rect bounds(resize_widget()->GetWindowBoundsInScreen()); 283 gfx::Rect bounds(resize_widget()->GetWindowBoundsInScreen());
197 generator.MoveMouseTo(bounds.x() + 1, bounds.y() + 1); 284 generator.MoveMouseTo(bounds.x() + 1, bounds.y() + 1);
198 EXPECT_FALSE(HasPendingShow()); 285 EXPECT_FALSE(HasPendingShow());
199 EXPECT_TRUE(IsShowing()); 286 EXPECT_TRUE(IsShowing());
200 EXPECT_FALSE(HasPendingHide());
201 287
202 // Move the resize widget 288 // Move the resize widget
203 generator.PressLeftButton(); 289 generator.PressLeftButton();
204 generator.MoveMouseTo(bounds.x() + 11, bounds.y() + 10); 290 generator.MoveMouseTo(bounds.x() + 11, bounds.y() + 10);
205 generator.ReleaseLeftButton(); 291 generator.ReleaseLeftButton();
206 292
207 EXPECT_TRUE(resize_widget()); 293 EXPECT_TRUE(resize_widget());
208 EXPECT_FALSE(HasPendingShow()); 294 EXPECT_FALSE(HasPendingShow());
209 EXPECT_TRUE(IsShowing()); 295 EXPECT_TRUE(IsShowing());
210 EXPECT_FALSE(HasPendingHide());
211 EXPECT_EQ("0,0 110x100", w1->bounds().ToString()); 296 EXPECT_EQ("0,0 110x100", w1->bounds().ToString());
212 EXPECT_EQ("110,0 100x100", w2->bounds().ToString()); 297 EXPECT_EQ("110,0 100x100", w2->bounds().ToString());
213 } 298 }
214 299
215 // Makes sure three windows are picked up. 300 // Makes sure three windows are picked up.
216 TEST_F(MultiWindowResizeControllerTest, Three) { 301 TEST_F(MultiWindowResizeControllerTest, Three) {
217 aura::test::TestWindowDelegate delegate1; 302 aura::test::TestWindowDelegate delegate1;
218 scoped_ptr<aura::Window> w1( 303 scoped_ptr<aura::Window> w1(
219 CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100))); 304 CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100)));
220 delegate1.set_window_component(HTRIGHT); 305 delegate1.set_window_component(HTRIGHT);
221 aura::test::TestWindowDelegate delegate2; 306 aura::test::TestWindowDelegate delegate2;
222 scoped_ptr<aura::Window> w2( 307 scoped_ptr<aura::Window> w2(
223 CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100))); 308 CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100)));
224 delegate2.set_window_component(HTRIGHT); 309 delegate2.set_window_component(HTRIGHT);
225 aura::test::TestWindowDelegate delegate3; 310 aura::test::TestWindowDelegate delegate3;
226 scoped_ptr<aura::Window> w3( 311 scoped_ptr<aura::Window> w3(
227 CreateTestWindow(&delegate3, gfx::Rect(200, 0, 100, 100))); 312 CreateTestWindow(&delegate3, gfx::Rect(200, 0, 100, 100)));
228 delegate3.set_window_component(HTRIGHT); 313 delegate3.set_window_component(HTRIGHT);
229 314
230 ui::test::EventGenerator generator(w1->GetRootWindow()); 315 ui::test::EventGenerator generator(w1->GetRootWindow());
231 generator.MoveMouseTo(w1->bounds().CenterPoint()); 316 generator.MoveMouseTo(w1->bounds().CenterPoint());
232 EXPECT_TRUE(HasPendingShow()); 317 EXPECT_TRUE(HasPendingShow());
233 EXPECT_TRUE(IsShowing()); 318 EXPECT_TRUE(IsShowing());
234 EXPECT_FALSE(HasPendingHide());
235 EXPECT_FALSE(HasTarget(w3.get())); 319 EXPECT_FALSE(HasTarget(w3.get()));
236 320
237 ShowNow(); 321 ShowNow();
238 EXPECT_FALSE(HasPendingShow()); 322 EXPECT_FALSE(HasPendingShow());
239 EXPECT_TRUE(IsShowing()); 323 EXPECT_TRUE(IsShowing());
240 EXPECT_FALSE(HasPendingHide());
241 324
242 // w3 should be picked up when resize is started. 325 // w3 should be picked up when resize is started.
243 gfx::Rect bounds(resize_widget()->GetWindowBoundsInScreen()); 326 gfx::Rect bounds(resize_widget()->GetWindowBoundsInScreen());
244 generator.MoveMouseTo(bounds.x() + 1, bounds.y() + 1); 327 generator.MoveMouseTo(bounds.x() + 1, bounds.y() + 1);
245 generator.PressLeftButton(); 328 generator.PressLeftButton();
246 generator.MoveMouseTo(bounds.x() + 11, bounds.y() + 10); 329 generator.MoveMouseTo(bounds.x() + 11, bounds.y() + 10);
247 330
248 EXPECT_TRUE(HasTarget(w3.get())); 331 EXPECT_TRUE(HasTarget(w3.get()));
249 332
250 // Release the mouse. The resizer should still be visible and a subsequent 333 // Release the mouse. The resizer should still be visible and a subsequent
251 // press should not trigger a DCHECK. 334 // press should not trigger a DCHECK.
252 generator.ReleaseLeftButton(); 335 generator.ReleaseLeftButton();
253 EXPECT_TRUE(IsShowing()); 336 EXPECT_TRUE(IsShowing());
254 generator.PressLeftButton(); 337 generator.PressLeftButton();
255 } 338 }
256 339
257 } // namespace ash 340 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698