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

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

Issue 965813003: Removed the "Swipe to close in overview" feature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « ash/wm/overview/window_selector_item.cc ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map>
7 #include <vector> 6 #include <vector>
8 7
9 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
10 #include "ash/ash_switches.h"
11 #include "ash/drag_drop/drag_drop_controller.h" 9 #include "ash/drag_drop/drag_drop_controller.h"
12 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
13 #include "ash/screen_util.h" 11 #include "ash/screen_util.h"
14 #include "ash/shelf/shelf.h" 12 #include "ash/shelf/shelf.h"
15 #include "ash/shelf/shelf_widget.h" 13 #include "ash/shelf/shelf_widget.h"
16 #include "ash/shell.h" 14 #include "ash/shell.h"
17 #include "ash/shell_window_ids.h" 15 #include "ash/shell_window_ids.h"
18 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
19 #include "ash/test/shelf_test_api.h" 17 #include "ash/test/shelf_test_api.h"
20 #include "ash/test/shelf_view_test_api.h" 18 #include "ash/test/shelf_view_test_api.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 bool ShouldActivate() const override { return false; } 64 bool ShouldActivate() const override { return false; }
67 }; 65 };
68 66
69 void CancelDrag(DragDropController* controller, bool* canceled) { 67 void CancelDrag(DragDropController* controller, bool* canceled) {
70 if (controller->IsDragDropInProgress()) { 68 if (controller->IsDragDropInProgress()) {
71 *canceled = true; 69 *canceled = true;
72 controller->DragCancel(); 70 controller->DragCancel();
73 } 71 }
74 } 72 }
75 73
76 // A short drag distance that will not cause an overview item to close.
77 const int kShortDragDistance = 10;
78
79 // A far drag distance that will cause an overview item to close.
80 const int kFarDragDistance = 200;
81
82 // A slow fling velocity that should not cause selctor items to close.
83 const int kSlowFlingVelocity = 2000;
84
85 // A fast fling velocity that should cause selector items to close.
86 const int kFastFlingVelocity = 5000;
87
88 } // namespace 74 } // namespace
89 75
90 // TODO(bruthig): Move all non-simple method definitions out of class 76 // TODO(bruthig): Move all non-simple method definitions out of class
91 // declaration. 77 // declaration.
92 class WindowSelectorTest : public test::AshTestBase { 78 class WindowSelectorTest : public test::AshTestBase {
93 public: 79 public:
94 WindowSelectorTest() {} 80 WindowSelectorTest() {}
95 ~WindowSelectorTest() override {} 81 ~WindowSelectorTest() override {}
96 82
97 void SetUp() override { 83 void SetUp() override {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 258 }
273 259
274 private: 260 private:
275 aura::test::TestWindowDelegate delegate_; 261 aura::test::TestWindowDelegate delegate_;
276 NonActivatableActivationDelegate non_activatable_activation_delegate_; 262 NonActivatableActivationDelegate non_activatable_activation_delegate_;
277 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_; 263 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_;
278 264
279 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); 265 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest);
280 }; 266 };
281 267
282 class WindowSelectorSwipeToCloseEnabledTest : public WindowSelectorTest {
283 public:
284 WindowSelectorSwipeToCloseEnabledTest() {}
285 ~WindowSelectorSwipeToCloseEnabledTest() override {}
286
287 // WindowSelectorTest:
288 void SetUp() override;
289
290 private:
291 DISALLOW_COPY_AND_ASSIGN(WindowSelectorSwipeToCloseEnabledTest);
292 };
293
294 void WindowSelectorSwipeToCloseEnabledTest::SetUp() {
295 base::CommandLine::ForCurrentProcess()->AppendSwitch(
296 switches::kAshEnableSwipeToCloseInOverviewMode);
297 WindowSelectorTest::SetUp();
298 }
299
300 // Tests that an a11y alert is sent on entering overview mode. 268 // Tests that an a11y alert is sent on entering overview mode.
301 TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) { 269 TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) {
302 gfx::Rect bounds(0, 0, 400, 400); 270 gfx::Rect bounds(0, 0, 400, 400);
303 AccessibilityDelegate* delegate = 271 AccessibilityDelegate* delegate =
304 ash::Shell::GetInstance()->accessibility_delegate(); 272 ash::Shell::GetInstance()->accessibility_delegate();
305 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); 273 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
306 EXPECT_NE(delegate->GetLastAccessibilityAlert(), 274 EXPECT_NE(delegate->GetLastAccessibilityAlert(),
307 ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); 275 ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED);
308 ToggleOverview(); 276 ToggleOverview();
309 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), 277 EXPECT_EQ(delegate->GetLastAccessibilityAlert(),
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 1235
1268 // Switch to overview mode. 1236 // Switch to overview mode.
1269 ToggleOverview(); 1237 ToggleOverview();
1270 ASSERT_TRUE(IsSelecting()); 1238 ASSERT_TRUE(IsSelecting());
1271 1239
1272 // Tap should now exit overview mode. 1240 // Tap should now exit overview mode.
1273 generator.GestureTapAt(point_in_background_page); 1241 generator.GestureTapAt(point_in_background_page);
1274 EXPECT_FALSE(IsSelecting()); 1242 EXPECT_FALSE(IsSelecting());
1275 } 1243 }
1276 1244
1277 // Verify swipe to close doesn't work when swipe to close is not enabled.
1278 TEST_F(WindowSelectorTest, WindowTapDragFarDistance) {
1279 scoped_ptr<views::Widget> widget =
1280 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1281
1282 ToggleOverview();
1283 ASSERT_TRUE(IsSelecting());
1284
1285 aura::Window* window = widget->GetNativeWindow();
1286 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
1287 ui::test::EventGenerator event_generator(window->GetRootWindow());
1288
1289 ASSERT_FALSE(widget->IsClosed());
1290
1291 gfx::Point start(bounds.CenterPoint());
1292 gfx::Point end(start.x() - kFarDragDistance, start.y());
1293 event_generator.GestureScrollSequence(
1294 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1295
1296 EXPECT_FALSE(widget->IsClosed());
1297
1298 RunAllPendingInMessageLoop();
1299 EXPECT_TRUE(IsSelecting());
1300 }
1301
1302 // Verify the window moves and fades as it is dragged.
1303 TEST_F(WindowSelectorSwipeToCloseEnabledTest,
1304 VerifyWindowBehaviourDuringTapDrag) {
1305 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 400, 400)));
1306
1307 ToggleOverview();
1308
1309 gfx::Rect bounds =
1310 ToNearestRect(GetTransformedBoundsInRootWindow(window.get()));
1311 ui::test::EventGenerator event_generator(window->GetRootWindow());
1312
1313 const gfx::Point drag_start_point(bounds.CenterPoint());
1314 const gfx::Point drag_left_point(drag_start_point.x() - kFarDragDistance,
1315 drag_start_point.y());
1316 const gfx::Point drag_right_point(drag_start_point.x() + kFarDragDistance,
1317 drag_start_point.y());
1318
1319 const int drag_left_delta_x = drag_start_point.x() - drag_left_point.x();
1320 const int drag_right_delta_x = drag_start_point.x() - drag_right_point.x();
1321
1322 const gfx::Rect original_bounds = window->GetBoundsInScreen();
1323
1324 ASSERT_EQ(1.0f, window->layer()->opacity());
1325
1326 event_generator.set_current_location(drag_start_point);
1327 event_generator.PressTouch();
1328
1329 EXPECT_EQ(1.0f, window->layer()->opacity());
1330
1331 event_generator.MoveTouch(drag_left_point);
1332
1333 EXPECT_EQ(original_bounds.x() - drag_left_delta_x,
1334 window->GetBoundsInScreen().x());
1335 EXPECT_EQ(original_bounds.y(), window->GetBoundsInScreen().y());
1336
1337 EXPECT_LT(window->layer()->opacity(), 0.5f);
1338
1339 event_generator.MoveTouch(drag_start_point);
1340
1341 EXPECT_EQ(original_bounds.x(), window->GetBoundsInScreen().x());
1342 EXPECT_EQ(original_bounds.y(), window->GetBoundsInScreen().y());
1343 EXPECT_EQ(1.0f, window->layer()->opacity());
1344
1345 event_generator.MoveTouch(drag_right_point);
1346
1347 EXPECT_EQ(original_bounds.x() - drag_right_delta_x,
1348 window->GetBoundsInScreen().x());
1349 EXPECT_EQ(original_bounds.y(), window->GetBoundsInScreen().y());
1350
1351 EXPECT_LT(window->layer()->opacity(), 0.5f);
1352 }
1353
1354 // Test dragging a window a short distance.
1355 TEST_F(WindowSelectorSwipeToCloseEnabledTest, WindowTapDragShortDistance) {
1356 scoped_ptr<views::Widget> widget =
1357 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1358
1359 ToggleOverview();
1360
1361 aura::Window* window = widget->GetNativeWindow();
1362 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
1363 ui::test::EventGenerator event_generator(window->GetRootWindow());
1364
1365 ASSERT_FALSE(widget->IsClosed());
1366
1367 gfx::Point start(bounds.CenterPoint());
1368 gfx::Point end(start.x() - kShortDragDistance, start.y());
1369 event_generator.GestureScrollSequence(
1370 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1371
1372 EXPECT_FALSE(widget->IsClosed());
1373
1374 RunAllPendingInMessageLoop();
1375 EXPECT_TRUE(IsSelecting());
1376 }
1377
1378 // Test dragging a window a far distance.
1379 TEST_F(WindowSelectorSwipeToCloseEnabledTest, WindowTapDragFarDistance) {
1380 scoped_ptr<views::Widget> widget =
1381 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1382
1383 ToggleOverview();
1384 ASSERT_TRUE(IsSelecting());
1385
1386 aura::Window* window = widget->GetNativeWindow();
1387 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
1388 ui::test::EventGenerator event_generator(window->GetRootWindow());
1389
1390 ASSERT_FALSE(widget->IsClosed());
1391
1392 gfx::Point start(bounds.CenterPoint());
1393 gfx::Point end(start.x() - kFarDragDistance, start.y());
1394 event_generator.GestureScrollSequence(
1395 start, end, base::TimeDelta::FromMilliseconds(10), 5);
1396
1397 EXPECT_TRUE(widget->IsClosed());
1398
1399 RunAllPendingInMessageLoop();
1400 EXPECT_FALSE(IsSelecting());
1401 }
1402
1403 // Test a slow velocity fling.
1404 TEST_F(WindowSelectorSwipeToCloseEnabledTest, SlowVelocityFling) {
1405 scoped_ptr<views::Widget> widget =
1406 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1407
1408 ToggleOverview();
1409
1410 aura::Window* window = widget->GetNativeWindow();
1411 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
1412 ui::test::EventGenerator event_generator(window->GetRootWindow());
1413
1414 ASSERT_FALSE(widget->IsClosed());
1415
1416 gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y());
1417 gfx::Point end(start.x() - kShortDragDistance, start.y());
1418 const base::TimeDelta kScrollDuration =
1419 event_generator.CalculateScrollDurationForFlingVelocity(
1420 start, end, kSlowFlingVelocity, 10);
1421 event_generator.GestureScrollSequence(start, end, kScrollDuration, 10);
1422
1423 EXPECT_FALSE(widget->IsClosed());
1424
1425 RunAllPendingInMessageLoop();
1426 EXPECT_TRUE(IsSelecting());
1427 }
1428
1429 // Test a fast velocity fling.
1430 TEST_F(WindowSelectorSwipeToCloseEnabledTest, FastVelocityFling) {
1431 scoped_ptr<views::Widget> widget =
1432 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1433
1434 ToggleOverview();
1435 ASSERT_TRUE(IsSelecting());
1436
1437 aura::Window* window = widget->GetNativeWindow();
1438 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
1439 ui::test::EventGenerator event_generator(window->GetRootWindow());
1440
1441 ASSERT_FALSE(widget->IsClosed());
1442
1443 gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y());
1444 gfx::Point end(start.x() - kShortDragDistance, start.y());
1445 const base::TimeDelta kScrollDuration =
1446 event_generator.CalculateScrollDurationForFlingVelocity(
1447 start, end, kFastFlingVelocity, 10);
1448 event_generator.GestureScrollSequence(start, end, kScrollDuration, 10);
1449
1450 EXPECT_TRUE(widget->IsClosed());
1451
1452 RunAllPendingInMessageLoop();
1453 EXPECT_FALSE(IsSelecting());
1454 }
1455
1456 // Test a fast velocity fling.
1457 TEST_F(WindowSelectorSwipeToCloseEnabledTest, SlowVelocityFlingAtAFarDistance) {
1458 scoped_ptr<views::Widget> widget =
1459 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
1460
1461 ToggleOverview();
1462 ASSERT_TRUE(IsSelecting());
1463
1464 aura::Window* window = widget->GetNativeWindow();
1465 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
1466 ui::test::EventGenerator event_generator(window->GetRootWindow());
1467
1468 ASSERT_FALSE(widget->IsClosed());
1469
1470 gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y());
1471 gfx::Point end(start.x() - kFarDragDistance, start.y());
1472 const base::TimeDelta kScrollDuration =
1473 event_generator.CalculateScrollDurationForFlingVelocity(
1474 start, end, kSlowFlingVelocity, 10);
1475 event_generator.GestureScrollSequence(start, end, kScrollDuration, 10);
1476
1477 EXPECT_TRUE(widget->IsClosed());
1478
1479 RunAllPendingInMessageLoop();
1480 EXPECT_FALSE(IsSelecting());
1481 }
1482
1483 } // namespace ash 1245 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/overview/window_selector_item.cc ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698