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

Side by Side Diff: ash/wm/overview/window_selector_unittest.cc

Issue 690103008: Implemented swipe to close in overview mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <algorithm> 5 #include <algorithm>
6 #include <vector>
6 7
7 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
9 #include "ash/ash_switches.h"
8 #include "ash/drag_drop/drag_drop_controller.h" 10 #include "ash/drag_drop/drag_drop_controller.h"
9 #include "ash/root_window_controller.h" 11 #include "ash/root_window_controller.h"
10 #include "ash/screen_util.h" 12 #include "ash/screen_util.h"
11 #include "ash/shelf/shelf.h" 13 #include "ash/shelf/shelf.h"
12 #include "ash/shelf/shelf_widget.h" 14 #include "ash/shelf/shelf_widget.h"
13 #include "ash/shell.h" 15 #include "ash/shell.h"
14 #include "ash/shell_window_ids.h" 16 #include "ash/shell_window_ids.h"
15 #include "ash/test/ash_test_base.h" 17 #include "ash/test/ash_test_base.h"
16 #include "ash/test/shelf_test_api.h" 18 #include "ash/test/shelf_test_api.h"
17 #include "ash/test/shelf_view_test_api.h" 19 #include "ash/test/shelf_view_test_api.h"
18 #include "ash/test/shell_test_api.h" 20 #include "ash/test/shell_test_api.h"
19 #include "ash/test/test_shelf_delegate.h" 21 #include "ash/test/test_shelf_delegate.h"
20 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 22 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
21 #include "ash/wm/mru_window_tracker.h" 23 #include "ash/wm/mru_window_tracker.h"
22 #include "ash/wm/overview/window_grid.h" 24 #include "ash/wm/overview/window_grid.h"
23 #include "ash/wm/overview/window_selector.h" 25 #include "ash/wm/overview/window_selector.h"
24 #include "ash/wm/overview/window_selector_controller.h" 26 #include "ash/wm/overview/window_selector_controller.h"
25 #include "ash/wm/overview/window_selector_item.h" 27 #include "ash/wm/overview/window_selector_item.h"
26 #include "ash/wm/panels/panel_layout_manager.h" 28 #include "ash/wm/panels/panel_layout_manager.h"
27 #include "ash/wm/window_state.h" 29 #include "ash/wm/window_state.h"
28 #include "ash/wm/window_util.h" 30 #include "ash/wm/window_util.h"
29 #include "ash/wm/wm_event.h" 31 #include "ash/wm/wm_event.h"
30 #include "base/basictypes.h" 32 #include "base/basictypes.h"
33 #include "base/command_line.h"
31 #include "base/compiler_specific.h" 34 #include "base/compiler_specific.h"
32 #include "base/memory/scoped_vector.h" 35 #include "base/memory/scoped_vector.h"
33 #include "base/run_loop.h" 36 #include "base/run_loop.h"
34 #include "base/strings/string_piece.h" 37 #include "base/strings/string_piece.h"
35 #include "base/strings/utf_string_conversions.h" 38 #include "base/strings/utf_string_conversions.h"
36 #include "ui/aura/client/aura_constants.h" 39 #include "ui/aura/client/aura_constants.h"
37 #include "ui/aura/client/cursor_client.h" 40 #include "ui/aura/client/cursor_client.h"
38 #include "ui/aura/client/focus_client.h" 41 #include "ui/aura/client/focus_client.h"
39 #include "ui/aura/test/test_window_delegate.h" 42 #include "ui/aura/test/test_window_delegate.h"
40 #include "ui/aura/test/test_windows.h" 43 #include "ui/aura/test/test_windows.h"
41 #include "ui/aura/window.h" 44 #include "ui/aura/window.h"
42 #include "ui/aura/window_event_dispatcher.h" 45 #include "ui/aura/window_event_dispatcher.h"
43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 46 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
44 #include "ui/events/test/event_generator.h" 47 #include "ui/events/test/event_generator.h"
48 #include "ui/gfx/geometry/vector2d_f.h"
45 #include "ui/gfx/rect_conversions.h" 49 #include "ui/gfx/rect_conversions.h"
46 #include "ui/gfx/transform.h" 50 #include "ui/gfx/transform.h"
47 #include "ui/views/controls/label.h" 51 #include "ui/views/controls/label.h"
48 #include "ui/views/widget/native_widget_aura.h" 52 #include "ui/views/widget/native_widget_aura.h"
49 #include "ui/views/widget/widget_delegate.h" 53 #include "ui/views/widget/widget_delegate.h"
50 #include "ui/wm/core/window_util.h" 54 #include "ui/wm/core/window_util.h"
51 #include "ui/wm/public/activation_delegate.h" 55 #include "ui/wm/public/activation_delegate.h"
52 56
53 namespace ash { 57 namespace ash {
54 namespace { 58 namespace {
55 59
60 // A short drag distance that will not cause an overview item to close.
61 const int kShortDragDistance = 10;
62
63 // A far drag distance that will cause an overview item to close.
64 const int kFarDragDistance = 200;
65
56 class NonActivatableActivationDelegate 66 class NonActivatableActivationDelegate
57 : public aura::client::ActivationDelegate { 67 : public aura::client::ActivationDelegate {
58 public: 68 public:
59 bool ShouldActivate() const override { return false; } 69 bool ShouldActivate() const override { return false; }
60 }; 70 };
61 71
62 void CancelDrag(DragDropController* controller, bool* canceled) { 72 void CancelDrag(DragDropController* controller, bool* canceled) {
63 if (controller->IsDragDropInProgress()) { 73 if (controller->IsDragDropInProgress()) {
64 *canceled = true; 74 *canceled = true;
65 controller->DragCancel(); 75 controller->DragCancel();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 views::Widget::InitParams params; 120 views::Widget::InitParams params;
111 params.bounds = bounds; 121 params.bounds = bounds;
112 params.type = views::Widget::InitParams::TYPE_PANEL; 122 params.type = views::Widget::InitParams::TYPE_PANEL;
113 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 123 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
114 widget->Init(params); 124 widget->Init(params);
115 widget->Show(); 125 widget->Show();
116 ParentWindowInPrimaryRootWindow(widget->GetNativeWindow()); 126 ParentWindowInPrimaryRootWindow(widget->GetNativeWindow());
117 return widget; 127 return widget;
118 } 128 }
119 129
130 scoped_ptr<views::Widget> CreateWindowWidget(const gfx::Rect& bounds) {
131 scoped_ptr<views::Widget> widget(new views::Widget);
132 views::Widget::InitParams params;
133 params.bounds = bounds;
134 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
135 widget->Init(params);
136 widget->Show();
137 ParentWindowInPrimaryRootWindow(widget->GetNativeWindow());
138 return widget.Pass();
139 }
140
120 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) { 141 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) {
121 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1); 142 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1);
122 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2); 143 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2);
123 return window1_bounds.Intersects(window2_bounds); 144 return window1_bounds.Intersects(window2_bounds);
124 } 145 }
125 146
126 void ToggleOverview() { 147 void ToggleOverview() {
127 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); 148 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview();
128 } 149 }
129 150
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 275 }
255 276
256 private: 277 private:
257 aura::test::TestWindowDelegate delegate_; 278 aura::test::TestWindowDelegate delegate_;
258 NonActivatableActivationDelegate non_activatable_activation_delegate_; 279 NonActivatableActivationDelegate non_activatable_activation_delegate_;
259 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_; 280 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_;
260 281
261 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); 282 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest);
262 }; 283 };
263 284
285 class WindowSelectorSwipeToCloseDisabledTest : public WindowSelectorTest {
286 public:
287 WindowSelectorSwipeToCloseDisabledTest() {}
288 virtual ~WindowSelectorSwipeToCloseDisabledTest() {}
289
290 // WindowSelectorTest:
291 virtual void SetUp() override;
292
293 private:
294 DISALLOW_COPY_AND_ASSIGN(WindowSelectorSwipeToCloseDisabledTest);
295 };
296
297 void WindowSelectorSwipeToCloseDisabledTest::SetUp() {
298 CommandLine::ForCurrentProcess()->AppendSwitch(
299 switches::kAshDisableSwipeToCloseInOverviewMode);
300 WindowSelectorTest::SetUp();
301 }
302
264 // Tests that an a11y alert is sent on entering overview mode. 303 // Tests that an a11y alert is sent on entering overview mode.
265 TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) { 304 TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) {
266 gfx::Rect bounds(0, 0, 400, 400); 305 gfx::Rect bounds(0, 0, 400, 400);
267 AccessibilityDelegate* delegate = 306 AccessibilityDelegate* delegate =
268 ash::Shell::GetInstance()->accessibility_delegate(); 307 ash::Shell::GetInstance()->accessibility_delegate();
269 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); 308 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
270 EXPECT_NE(delegate->GetLastAccessibilityAlert(), 309 EXPECT_NE(delegate->GetLastAccessibilityAlert(),
271 ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); 310 ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED);
272 ToggleOverview(); 311 ToggleOverview();
273 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), 312 EXPECT_EQ(delegate->GetLastAccessibilityAlert(),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 ui::MouseEvent event2(ui::ET_MOUSE_PRESSED, point2, point2, 426 ui::MouseEvent event2(ui::ET_MOUSE_PRESSED, point2, point2,
388 ui::EF_NONE, ui::EF_NONE); 427 ui::EF_NONE, ui::EF_NONE);
389 428
390 // Now the transparent window should be intercepting this event. 429 // Now the transparent window should be intercepting this event.
391 EXPECT_NE(window, static_cast<aura::Window*>( 430 EXPECT_NE(window, static_cast<aura::Window*>(
392 targeter->FindTargetForEvent(root_target, &event2))); 431 targeter->FindTargetForEvent(root_target, &event2)));
393 } 432 }
394 433
395 // Tests that clicking on the close button effectively closes the window. 434 // Tests that clicking on the close button effectively closes the window.
396 TEST_F(WindowSelectorTest, CloseButton) { 435 TEST_F(WindowSelectorTest, CloseButton) {
397 scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(200, 300, 250, 450)));
398
399 // We need a widget for the close button to work, a bare window will crash. 436 // We need a widget for the close button to work, a bare window will crash.
400 scoped_ptr<views::Widget> widget(new views::Widget); 437 scoped_ptr<views::Widget> widget =
401 views::Widget::InitParams params; 438 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
402 params.bounds = gfx::Rect(0, 0, 400, 400);
403 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
404 params.parent = window1->parent();
405 widget->Init(params);
406 widget->Show();
407 ToggleOverview(); 439 ToggleOverview();
408 440
409 aura::Window* window2 = widget->GetNativeWindow(); 441 aura::Window* window = widget->GetNativeWindow();
410 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window2); 442 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
411 gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1); 443 gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1);
412 ui::test::EventGenerator event_generator(window2->GetRootWindow(), point); 444 ui::test::EventGenerator event_generator(window->GetRootWindow(), point);
413 445
414 EXPECT_FALSE(widget->IsClosed()); 446 EXPECT_FALSE(widget->IsClosed());
415 event_generator.ClickLeftButton(); 447 event_generator.ClickLeftButton();
416 EXPECT_TRUE(widget->IsClosed()); 448 EXPECT_TRUE(widget->IsClosed());
417 } 449 }
418 450
419 // Tests entering overview mode with two windows and selecting one. 451 // Tests entering overview mode with two windows and selecting one.
420 TEST_F(WindowSelectorTest, FullscreenWindow) { 452 TEST_F(WindowSelectorTest, FullscreenWindow) {
421 gfx::Rect bounds(0, 0, 400, 400); 453 gfx::Rect bounds(0, 0, 400, 400);
422 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); 454 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 FilterItems(""); 1201 FilterItems("");
1170 EXPECT_FALSE(showing_filter_widget()); 1202 EXPECT_FALSE(showing_filter_widget());
1171 EXPECT_FALSE(items[0]->dimmed()); 1203 EXPECT_FALSE(items[0]->dimmed());
1172 EXPECT_FALSE(items[1]->dimmed()); 1204 EXPECT_FALSE(items[1]->dimmed());
1173 EXPECT_FALSE(items[2]->dimmed()); 1205 EXPECT_FALSE(items[2]->dimmed());
1174 } 1206 }
1175 1207
1176 // Tests selecting in the overview with dimmed and undimmed items. 1208 // Tests selecting in the overview with dimmed and undimmed items.
1177 TEST_F(WindowSelectorTest, TextFilteringSelection) { 1209 TEST_F(WindowSelectorTest, TextFilteringSelection) {
1178 gfx::Rect bounds(0, 0, 100, 100); 1210 gfx::Rect bounds(0, 0, 100, 100);
1179 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); 1211 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
1180 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); 1212 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
1181 scoped_ptr<aura::Window> window0(CreateWindow(bounds)); 1213 scoped_ptr<aura::Window> window0(CreateWindow(bounds));
1182 base::string16 window2_title = base::UTF8ToUTF16("Rock and roll"); 1214 base::string16 window2_title = base::UTF8ToUTF16("Rock and roll");
1183 base::string16 window1_title = base::UTF8ToUTF16("Rock and"); 1215 base::string16 window1_title = base::UTF8ToUTF16("Rock and");
1184 base::string16 window0_title = base::UTF8ToUTF16("Rock"); 1216 base::string16 window0_title = base::UTF8ToUTF16("Rock");
1185 window0->SetTitle(window0_title); 1217 window0->SetTitle(window0_title);
1186 window1->SetTitle(window1_title); 1218 window1->SetTitle(window1_title);
1187 window2->SetTitle(window2_title); 1219 window2->SetTitle(window2_title);
1188 ToggleOverview(); 1220 ToggleOverview();
1189 SendKey(ui::VKEY_RIGHT); 1221 SendKey(ui::VKEY_RIGHT);
1190 EXPECT_TRUE(selection_widget_active()); 1222 EXPECT_TRUE(selection_widget_active());
1191 EXPECT_EQ(GetSelectedWindow(), window0.get()); 1223 EXPECT_EQ(GetSelectedWindow(), window0.get());
1192 1224
1193 // Dim the first item, the selection should jump to the next item. 1225 // Dim the first item, the selection should jump to the next item.
1194 std::vector<WindowSelectorItem*> items = GetWindowItemsForRoot(0); 1226 std::vector<WindowSelectorItem*> items = GetWindowItemsForRoot(0);
1195 FilterItems("Rock and"); 1227 FilterItems("Rock and");
1196 EXPECT_EQ(GetSelectedWindow(), window1.get()); 1228 EXPECT_EQ(GetSelectedWindow(), window1.get());
1197 1229
1198 // Cycle the selection, the dimmed window should not be selected. 1230 // Cycle the selection, the dimmed window should not be selected.
1199 SendKey(ui::VKEY_RIGHT); 1231 SendKey(ui::VKEY_RIGHT);
1200 EXPECT_EQ(GetSelectedWindow(), window2.get()); 1232 EXPECT_EQ(GetSelectedWindow(), window2.get());
1201 SendKey(ui::VKEY_RIGHT); 1233 SendKey(ui::VKEY_RIGHT);
1202 EXPECT_EQ(GetSelectedWindow(), window1.get()); 1234 EXPECT_EQ(GetSelectedWindow(), window1.get());
1203 1235
1204 // Dimming all the items should hide the selection widget. 1236 // Dimming all the items should hide the selection widget.
1205 FilterItems("Pop"); 1237 FilterItems("Pop");
1206 EXPECT_FALSE(selection_widget_active()); 1238 EXPECT_FALSE(selection_widget_active());
1207 1239
1208 // Undimming one window should automatically select it. 1240 // Undimming one window should automatically select it.
1209 FilterItems("Rock and roll"); 1241 FilterItems("Rock and roll");
1210 EXPECT_EQ(GetSelectedWindow(), window2.get()); 1242 EXPECT_EQ(GetSelectedWindow(), window2.get());
1211 } 1243 }
1212 1244
1213 // Tests clicking on the desktop itself to cancel overview mode. 1245 // Tests clicking on the desktop itself to cancel overview mode.
1214 TEST_F(WindowSelectorTest, CancelOverviewOnMouseClick) { 1246 TEST_F(WindowSelectorTest, CancelOverviewOnMouseClick) {
1215 // Overview disabled by default. 1247 // Overview disabled by default.
1216 EXPECT_FALSE(IsSelecting()); 1248 EXPECT_FALSE(IsSelecting());
1217 1249
1218 // Point and bounds selected so that they don't intersect. This causes 1250 // Point and bounds selected so that they don't intersect. This causes
1219 // events located at the point to be passed to DesktopBackgroundController, 1251 // events located at the point to be passed to DesktopBackgroundController,
1220 // and not the window. 1252 // and not the window.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 1292
1261 // Switch to overview mode. 1293 // Switch to overview mode.
1262 ToggleOverview(); 1294 ToggleOverview();
1263 ASSERT_TRUE(IsSelecting()); 1295 ASSERT_TRUE(IsSelecting());
1264 1296
1265 // Tap should now exit overview mode. 1297 // Tap should now exit overview mode.
1266 generator.GestureTapAt(point_in_background_page); 1298 generator.GestureTapAt(point_in_background_page);
1267 EXPECT_FALSE(IsSelecting()); 1299 EXPECT_FALSE(IsSelecting());
1268 } 1300 }
1269 1301
1302 // Verify swipe to close doesn't work when swipe to close is disabled.
1303 TEST_F(WindowSelectorSwipeToCloseDisabledTest, WindowTapDragFarDistance) {
flackr 2014/11/07 19:10:52 I'm not sure testing the lack of a feature is some
bruthig 2015/01/02 16:49:17 I would argue that testing a non-existent feature/
jonross 2015/01/06 15:02:28 Could you clarify in the name+description?
1304 // We need a widget for the close button to work, a bare window will crash.
1305 scoped_ptr<views::Widget> widget =
1306 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1307
1308 ToggleOverview();
1309 ASSERT_TRUE(IsSelecting());
1310
1311 aura::Window* window = widget->GetNativeWindow();
1312 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
1313 ui::test::EventGenerator event_generator(window->GetRootWindow());
1314
1315 ASSERT_FALSE(widget->IsClosed());
1316
1317 gfx::Point start(bounds.CenterPoint());
1318 gfx::Point end(start.x() - kFarDragDistance, start.y());
1319 event_generator.GestureScrollSequence(
1320 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1321
1322 EXPECT_FALSE(widget->IsClosed());
1323
1324 RunAllPendingInMessageLoop();
1325 EXPECT_TRUE(IsSelecting());
1326 }
1327
1328 // Test dragging a window a short distance.
1329 TEST_F(WindowSelectorTest, WindowTapDragShortDistance) {
1330 // We need a widget for the close button to work, a bare window will crash.
1331 scoped_ptr<views::Widget> widget =
1332 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1333
1334 ToggleOverview();
1335
1336 aura::Window* window = widget->GetNativeWindow();
1337 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
1338 ui::test::EventGenerator event_generator(window->GetRootWindow());
1339
1340 ASSERT_FALSE(widget->IsClosed());
1341
1342 gfx::Point start(bounds.CenterPoint());
1343 gfx::Point end(start.x() - kShortDragDistance, start.y());
1344 event_generator.GestureScrollSequence(
1345 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1346
1347 EXPECT_FALSE(widget->IsClosed());
1348
1349 RunAllPendingInMessageLoop();
1350 EXPECT_TRUE(IsSelecting());
1351 }
1352
1353 // Test dragging a window a far distance.
1354 TEST_F(WindowSelectorTest, WindowTapDragFarDistance) {
1355 // We need a widget for the close button to work, a bare window will crash.
1356 scoped_ptr<views::Widget> widget =
1357 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1358
1359 ToggleOverview();
1360 ASSERT_TRUE(IsSelecting());
1361
1362 aura::Window* window = widget->GetNativeWindow();
1363 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
1364 ui::test::EventGenerator event_generator(window->GetRootWindow());
1365
1366 ASSERT_FALSE(widget->IsClosed());
1367
1368 gfx::Point start(bounds.CenterPoint());
1369 gfx::Point end(start.x() - kFarDragDistance, start.y());
1370 event_generator.GestureScrollSequence(
1371 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1372
1373 EXPECT_TRUE(widget->IsClosed());
1374
1375 RunAllPendingInMessageLoop();
1376 EXPECT_FALSE(IsSelecting());
1377 }
1378
1379 // Test dragging a window in a multi window SelectorItem a short distance.
1380 TEST_F(WindowSelectorTest, MultiWindowTapDragShortDistance) {
flackr 2014/11/07 19:10:52 Is this exercising a different code path than Wind
bruthig 2015/01/02 16:49:17 Removed.
1381 scoped_ptr<views::Widget> widget1(
1382 CreatePanelWindowWidget(gfx::Rect(0, 0, 300, 100)));
1383 scoped_ptr<views::Widget> widget2(
1384 CreatePanelWindowWidget(gfx::Rect(100, 0, 100, 100)));
1385 aura::Window* window1 = widget1->GetNativeWindow();
1386 wm::ActivateWindow(window1);
1387 ToggleOverview();
1388
1389 gfx::Rect bounds1 = ToNearestRect(GetTransformedBoundsInRootWindow(window1));
1390 ui::test::EventGenerator event_generator1(window1->GetRootWindow());
1391
1392 ASSERT_FALSE(widget1->IsClosed());
1393 ASSERT_FALSE(widget2->IsClosed());
1394
1395 gfx::Point start(bounds1.CenterPoint());
1396 gfx::Point end(start.x() - kShortDragDistance, start.y());
1397 event_generator1.GestureScrollSequence(
1398 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1399
1400 EXPECT_FALSE(widget1->IsClosed());
1401 EXPECT_FALSE(widget2->IsClosed());
1402
1403 RunAllPendingInMessageLoop();
1404 EXPECT_TRUE(IsSelecting());
1405 }
1406
1407 // Test dragging a window in a multi window SelectorItem a far distance.
1408 TEST_F(WindowSelectorTest, MultiWindowTapDragFarDistance) {
1409 scoped_ptr<views::Widget> widget1(
1410 CreatePanelWindowWidget(gfx::Rect(0, 0, 300, 100)));
1411 scoped_ptr<views::Widget> widget2(
1412 CreatePanelWindowWidget(gfx::Rect(100, 0, 100, 100)));
1413 aura::Window* window1 = widget1->GetNativeWindow();
1414 wm::ActivateWindow(window1);
1415 ToggleOverview();
1416
1417 gfx::Rect bounds1 = ToNearestRect(GetTransformedBoundsInRootWindow(window1));
1418 ui::test::EventGenerator event_generator1(window1->GetRootWindow());
1419
1420 ASSERT_FALSE(widget1->IsClosed());
1421 ASSERT_FALSE(widget2->IsClosed());
1422
1423 gfx::Point start(bounds1.CenterPoint());
1424 gfx::Point end(start.x() - kFarDragDistance, start.y());
1425 event_generator1.GestureScrollSequence(
1426 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1427
1428 EXPECT_TRUE(widget1->IsClosed());
1429 EXPECT_FALSE(widget2->IsClosed());
1430
1431 RunAllPendingInMessageLoop();
1432 EXPECT_TRUE(IsSelecting());
1433 }
1434
1435 // Test dragging all windows in a multi window SelectorItem a short distance.
1436 TEST_F(WindowSelectorTest, MultiWindowTapDragLabelShortDistance) {
1437 scoped_ptr<views::Widget> widget1(
1438 CreatePanelWindowWidget(gfx::Rect(0, 0, 300, 100)));
1439 scoped_ptr<views::Widget> widget2(
1440 CreatePanelWindowWidget(gfx::Rect(100, 0, 100, 100)));
1441 aura::Window* window1 = widget1->GetNativeWindow();
1442 wm::ActivateWindow(window1);
1443 ToggleOverview();
1444
1445 gfx::Rect bounds = GetWindowItemsForRoot(0).back()->target_bounds();
1446 ui::test::EventGenerator event_generator1(window1->GetRootWindow());
1447
1448 ASSERT_FALSE(widget1->IsClosed());
1449 ASSERT_FALSE(widget2->IsClosed());
1450
1451 gfx::Point start(bounds.CenterPoint().x(), bounds.y() + 3);
1452 gfx::Point end(start.x() - kShortDragDistance, start.y());
1453 event_generator1.GestureScrollSequence(
1454 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1455
1456 EXPECT_FALSE(widget1->IsClosed());
1457 EXPECT_FALSE(widget2->IsClosed());
1458
1459 RunAllPendingInMessageLoop();
1460
1461 RunAllPendingInMessageLoop();
1462 EXPECT_TRUE(IsSelecting());
1463 }
1464
1465 // Test dragging all windows in a multi window SelectorItem a far distance.
1466 TEST_F(WindowSelectorTest, MultiWindowTapDragLabelFarDistance) {
flackr 2014/11/07 19:10:52 Aren't these multi window drag tests a superset of
bruthig 2015/01/02 16:49:17 I will remove the MultiWindowTapDragShortDistance
1467 scoped_ptr<views::Widget> widget1(
1468 CreatePanelWindowWidget(gfx::Rect(0, 0, 300, 100)));
1469 scoped_ptr<views::Widget> widget2(
1470 CreatePanelWindowWidget(gfx::Rect(100, 0, 100, 100)));
1471 aura::Window* window1 = widget1->GetNativeWindow();
1472 wm::ActivateWindow(window1);
1473 ToggleOverview();
1474
1475 gfx::Rect bounds = GetWindowItemsForRoot(0).back()->target_bounds();
1476 ui::test::EventGenerator event_generator1(window1->GetRootWindow());
1477
1478 ASSERT_FALSE(widget1->IsClosed());
1479 ASSERT_FALSE(widget2->IsClosed());
1480
1481 gfx::Point start(bounds.CenterPoint().x(), bounds.y() + 3);
1482 gfx::Point end(start.x() - kFarDragDistance, start.y());
1483 event_generator1.GestureScrollSequence(
1484 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1485
1486 EXPECT_TRUE(widget1->IsClosed());
1487 EXPECT_TRUE(widget2->IsClosed());
1488
1489 RunAllPendingInMessageLoop();
1490 EXPECT_FALSE(IsSelecting());
1491 }
1492
1493 // Test a low velocity fling.
1494 TEST_F(WindowSelectorTest, LowVelocityFling) {
flackr 2014/11/07 19:10:52 Can probably merge this with the short distance dr
bruthig 2015/01/02 16:49:17 Unless you feel super strongly about this I would
1495 const float kFlingVelocity = 2000;
1496 const int kSmallSwipeDistance = 25;
1497
1498 // We need a widget for the close button to work, a bare window will crash.
1499 scoped_ptr<views::Widget> widget =
1500 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1501
1502 ToggleOverview();
1503
1504 aura::Window* window = widget->GetNativeWindow();
1505 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
1506 ui::test::EventGenerator event_generator(window->GetRootWindow());
1507
1508 ASSERT_FALSE(widget->IsClosed());
1509
1510 gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y());
1511 gfx::Point end(start.x() - kSmallSwipeDistance, start.y());
1512 const base::TimeDelta kScrollDuration =
1513 event_generator.CalculateDuration(start, end, kFlingVelocity, 10);
1514 event_generator.GestureScrollSequence(start, end, kScrollDuration, 10);
1515
1516 EXPECT_FALSE(widget->IsClosed());
1517
1518 RunAllPendingInMessageLoop();
1519 EXPECT_TRUE(IsSelecting());
1520 }
1521
1522 // Test a high velocity fling.
1523 TEST_F(WindowSelectorTest, HighVelocityFling) {
1524 const float kFlingVelocity = 10000;
1525 const int kSmallSwipeDistance = 25;
1526
1527 // We need a widget for the close button to work, a bare window will crash.
1528 scoped_ptr<views::Widget> widget =
1529 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1530
1531 ToggleOverview();
1532 ASSERT_TRUE(IsSelecting());
1533
1534 aura::Window* window = widget->GetNativeWindow();
1535 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
1536 ui::test::EventGenerator event_generator(window->GetRootWindow());
1537
1538 ASSERT_FALSE(widget->IsClosed());
1539
1540 gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y());
1541 gfx::Point end(start.x() - kSmallSwipeDistance, start.y());
1542 const base::TimeDelta kScrollDuration =
1543 event_generator.CalculateDuration(start, end, kFlingVelocity, 10);
1544 event_generator.GestureScrollSequence(start, end, kScrollDuration, 10);
1545
1546 EXPECT_TRUE(widget->IsClosed());
1547
1548 RunAllPendingInMessageLoop();
1549 EXPECT_FALSE(IsSelecting());
1550 }
1551
1270 } // namespace ash 1552 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698