OLD | NEW |
---|---|
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 | 8 |
7 #include "ash/accessibility_delegate.h" | 9 #include "ash/accessibility_delegate.h" |
10 #include "ash/ash_switches.h" | |
8 #include "ash/drag_drop/drag_drop_controller.h" | 11 #include "ash/drag_drop/drag_drop_controller.h" |
9 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
10 #include "ash/screen_util.h" | 13 #include "ash/screen_util.h" |
11 #include "ash/shelf/shelf.h" | 14 #include "ash/shelf/shelf.h" |
12 #include "ash/shelf/shelf_widget.h" | 15 #include "ash/shelf/shelf_widget.h" |
13 #include "ash/shell.h" | 16 #include "ash/shell.h" |
14 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
15 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
16 #include "ash/test/shelf_test_api.h" | 19 #include "ash/test/shelf_test_api.h" |
17 #include "ash/test/shelf_view_test_api.h" | 20 #include "ash/test/shelf_view_test_api.h" |
18 #include "ash/test/shell_test_api.h" | 21 #include "ash/test/shell_test_api.h" |
19 #include "ash/test/test_shelf_delegate.h" | 22 #include "ash/test/test_shelf_delegate.h" |
20 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 23 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
21 #include "ash/wm/mru_window_tracker.h" | 24 #include "ash/wm/mru_window_tracker.h" |
22 #include "ash/wm/overview/window_grid.h" | 25 #include "ash/wm/overview/window_grid.h" |
23 #include "ash/wm/overview/window_selector.h" | 26 #include "ash/wm/overview/window_selector.h" |
24 #include "ash/wm/overview/window_selector_controller.h" | 27 #include "ash/wm/overview/window_selector_controller.h" |
25 #include "ash/wm/overview/window_selector_item.h" | 28 #include "ash/wm/overview/window_selector_item.h" |
26 #include "ash/wm/panels/panel_layout_manager.h" | 29 #include "ash/wm/panels/panel_layout_manager.h" |
27 #include "ash/wm/window_state.h" | 30 #include "ash/wm/window_state.h" |
28 #include "ash/wm/window_util.h" | 31 #include "ash/wm/window_util.h" |
29 #include "ash/wm/wm_event.h" | 32 #include "ash/wm/wm_event.h" |
30 #include "base/basictypes.h" | 33 #include "base/basictypes.h" |
34 #include "base/command_line.h" | |
31 #include "base/compiler_specific.h" | 35 #include "base/compiler_specific.h" |
32 #include "base/memory/scoped_vector.h" | 36 #include "base/memory/scoped_vector.h" |
33 #include "base/run_loop.h" | 37 #include "base/run_loop.h" |
34 #include "base/strings/string_piece.h" | 38 #include "base/strings/string_piece.h" |
35 #include "base/strings/utf_string_conversions.h" | 39 #include "base/strings/utf_string_conversions.h" |
36 #include "ui/aura/client/aura_constants.h" | 40 #include "ui/aura/client/aura_constants.h" |
37 #include "ui/aura/client/cursor_client.h" | 41 #include "ui/aura/client/cursor_client.h" |
38 #include "ui/aura/client/focus_client.h" | 42 #include "ui/aura/client/focus_client.h" |
39 #include "ui/aura/test/test_window_delegate.h" | 43 #include "ui/aura/test/test_window_delegate.h" |
40 #include "ui/aura/test/test_windows.h" | 44 #include "ui/aura/test/test_windows.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
61 bool ShouldActivate() const override { return false; } | 65 bool ShouldActivate() const override { return false; } |
62 }; | 66 }; |
63 | 67 |
64 void CancelDrag(DragDropController* controller, bool* canceled) { | 68 void CancelDrag(DragDropController* controller, bool* canceled) { |
65 if (controller->IsDragDropInProgress()) { | 69 if (controller->IsDragDropInProgress()) { |
66 *canceled = true; | 70 *canceled = true; |
67 controller->DragCancel(); | 71 controller->DragCancel(); |
68 } | 72 } |
69 } | 73 } |
70 | 74 |
75 // A short drag distance that will not cause an overview item to close. | |
76 const int kShortDragDistance = 10; | |
77 | |
78 // A far drag distance that will cause an overview item to close. | |
79 const int kFarDragDistance = 200; | |
80 | |
81 // A slow fling velocity that should not cause selctor items to close. | |
82 const int kSlowFlingVelocity = 2000; | |
83 | |
84 // A fast fling velocity that should cause selector items to close. | |
85 const int kFastFlingVelocity = 5000; | |
86 | |
71 } // namespace | 87 } // namespace |
72 | 88 |
73 class WindowSelectorTest : public test::AshTestBase { | 89 class WindowSelectorTest : public test::AshTestBase { |
74 public: | 90 public: |
75 WindowSelectorTest() {} | 91 WindowSelectorTest() {} |
76 ~WindowSelectorTest() override {} | 92 ~WindowSelectorTest() override {} |
77 | 93 |
78 void SetUp() override { | 94 void SetUp() override { |
79 test::AshTestBase::SetUp(); | 95 test::AshTestBase::SetUp(); |
80 ASSERT_TRUE(test::TestShelfDelegate::instance()); | 96 ASSERT_TRUE(test::TestShelfDelegate::instance()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 views::Widget::InitParams params; | 128 views::Widget::InitParams params; |
113 params.bounds = bounds; | 129 params.bounds = bounds; |
114 params.type = views::Widget::InitParams::TYPE_PANEL; | 130 params.type = views::Widget::InitParams::TYPE_PANEL; |
115 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 131 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
116 widget->Init(params); | 132 widget->Init(params); |
117 widget->Show(); | 133 widget->Show(); |
118 ParentWindowInPrimaryRootWindow(widget->GetNativeWindow()); | 134 ParentWindowInPrimaryRootWindow(widget->GetNativeWindow()); |
119 return widget; | 135 return widget; |
120 } | 136 } |
121 | 137 |
138 scoped_ptr<views::Widget> CreateWindowWidget(const gfx::Rect& bounds) { | |
139 scoped_ptr<views::Widget> widget(new views::Widget); | |
140 views::Widget::InitParams params; | |
141 params.bounds = bounds; | |
142 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
143 widget->Init(params); | |
144 widget->Show(); | |
145 ParentWindowInPrimaryRootWindow(widget->GetNativeWindow()); | |
146 return widget.Pass(); | |
147 } | |
148 | |
122 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) { | 149 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) { |
123 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1); | 150 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1); |
124 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2); | 151 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2); |
125 return window1_bounds.Intersects(window2_bounds); | 152 return window1_bounds.Intersects(window2_bounds); |
126 } | 153 } |
127 | 154 |
128 void ToggleOverview() { | 155 void ToggleOverview() { |
129 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); | 156 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); |
130 } | 157 } |
131 | 158 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 } | 276 } |
250 | 277 |
251 private: | 278 private: |
252 aura::test::TestWindowDelegate delegate_; | 279 aura::test::TestWindowDelegate delegate_; |
253 NonActivatableActivationDelegate non_activatable_activation_delegate_; | 280 NonActivatableActivationDelegate non_activatable_activation_delegate_; |
254 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_; | 281 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_; |
255 | 282 |
256 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); | 283 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); |
257 }; | 284 }; |
258 | 285 |
286 class WindowSelectorSwipeToCloseDisabledTest : public WindowSelectorTest { | |
287 public: | |
288 WindowSelectorSwipeToCloseDisabledTest() {} | |
289 ~WindowSelectorSwipeToCloseDisabledTest() override {} | |
290 | |
291 // WindowSelectorTest: | |
292 void SetUp() override; | |
293 | |
294 private: | |
295 DISALLOW_COPY_AND_ASSIGN(WindowSelectorSwipeToCloseDisabledTest); | |
296 }; | |
297 | |
298 void WindowSelectorSwipeToCloseDisabledTest::SetUp() { | |
299 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
300 switches::kAshDisableSwipeToCloseInOverviewMode); | |
301 WindowSelectorTest::SetUp(); | |
302 } | |
303 | |
259 // Tests that an a11y alert is sent on entering overview mode. | 304 // Tests that an a11y alert is sent on entering overview mode. |
260 TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) { | 305 TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) { |
261 gfx::Rect bounds(0, 0, 400, 400); | 306 gfx::Rect bounds(0, 0, 400, 400); |
262 AccessibilityDelegate* delegate = | 307 AccessibilityDelegate* delegate = |
263 ash::Shell::GetInstance()->accessibility_delegate(); | 308 ash::Shell::GetInstance()->accessibility_delegate(); |
264 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 309 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
265 EXPECT_NE(delegate->GetLastAccessibilityAlert(), | 310 EXPECT_NE(delegate->GetLastAccessibilityAlert(), |
266 ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); | 311 ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); |
267 ToggleOverview(); | 312 ToggleOverview(); |
268 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), | 313 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 | 1284 |
1240 // Switch to overview mode. | 1285 // Switch to overview mode. |
1241 ToggleOverview(); | 1286 ToggleOverview(); |
1242 ASSERT_TRUE(IsSelecting()); | 1287 ASSERT_TRUE(IsSelecting()); |
1243 | 1288 |
1244 // Tap should now exit overview mode. | 1289 // Tap should now exit overview mode. |
1245 generator.GestureTapAt(point_in_background_page); | 1290 generator.GestureTapAt(point_in_background_page); |
1246 EXPECT_FALSE(IsSelecting()); | 1291 EXPECT_FALSE(IsSelecting()); |
1247 } | 1292 } |
1248 | 1293 |
1294 // Verify swipe to close doesn't work when swipe to close is disabled. | |
1295 TEST_F(WindowSelectorSwipeToCloseDisabledTest, WindowTapDragFarDistance) { | |
1296 // We need a widget for the close button to work, a bare window will crash. | |
flackr
2015/02/10 17:49:50
Probably worth mentioning why. Is a bare window mi
bruthig
2015/02/12 18:08:55
I've moved the comment to the CreateWindowWidget m
| |
1297 scoped_ptr<views::Widget> widget = | |
1298 CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); | |
1299 | |
1300 ToggleOverview(); | |
1301 ASSERT_TRUE(IsSelecting()); | |
1302 | |
1303 aura::Window* window = widget->GetNativeWindow(); | |
1304 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window)); | |
1305 ui::test::EventGenerator event_generator(window->GetRootWindow()); | |
1306 | |
1307 ASSERT_FALSE(widget->IsClosed()); | |
1308 | |
1309 gfx::Point start(bounds.CenterPoint()); | |
1310 gfx::Point end(start.x() - kFarDragDistance, start.y()); | |
1311 event_generator.GestureScrollSequence( | |
1312 start, end, base::TimeDelta::FromMilliseconds(10), 5); | |
1313 | |
1314 EXPECT_FALSE(widget->IsClosed()); | |
1315 | |
1316 RunAllPendingInMessageLoop(); | |
1317 EXPECT_TRUE(IsSelecting()); | |
1318 } | |
1319 | |
1320 // Test dragging a window a short distance. | |
1321 TEST_F(WindowSelectorTest, WindowTapDragShortDistance) { | |
1322 // We need a widget for the close button to work, a bare window will crash. | |
1323 scoped_ptr<views::Widget> widget = | |
1324 CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); | |
1325 | |
1326 ToggleOverview(); | |
1327 | |
1328 aura::Window* window = widget->GetNativeWindow(); | |
1329 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window)); | |
1330 ui::test::EventGenerator event_generator(window->GetRootWindow()); | |
1331 | |
1332 ASSERT_FALSE(widget->IsClosed()); | |
1333 | |
1334 gfx::Point start(bounds.CenterPoint()); | |
1335 gfx::Point end(start.x() - kShortDragDistance, start.y()); | |
1336 event_generator.GestureScrollSequence( | |
1337 start, end, base::TimeDelta::FromMilliseconds(10), 5); | |
flackr
2015/02/10 17:49:50
Should probably also verify the window moves with
bruthig
2015/02/12 18:08:55
Done.
| |
1338 | |
1339 EXPECT_FALSE(widget->IsClosed()); | |
1340 | |
1341 RunAllPendingInMessageLoop(); | |
1342 EXPECT_TRUE(IsSelecting()); | |
1343 } | |
1344 | |
1345 // Test dragging a window a far distance. | |
1346 TEST_F(WindowSelectorTest, WindowTapDragFarDistance) { | |
1347 // We need a widget for the close button to work, a bare window will crash. | |
1348 scoped_ptr<views::Widget> widget = | |
1349 CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); | |
1350 | |
1351 ToggleOverview(); | |
1352 ASSERT_TRUE(IsSelecting()); | |
1353 | |
1354 aura::Window* window = widget->GetNativeWindow(); | |
1355 gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window)); | |
1356 ui::test::EventGenerator event_generator(window->GetRootWindow()); | |
1357 | |
1358 ASSERT_FALSE(widget->IsClosed()); | |
1359 | |
1360 gfx::Point start(bounds.CenterPoint()); | |
1361 gfx::Point end(start.x() - kFarDragDistance, start.y()); | |
1362 event_generator.GestureScrollSequence( | |
1363 start, end, base::TimeDelta::FromMilliseconds(10), 5); | |
1364 | |
1365 EXPECT_TRUE(widget->IsClosed()); | |
1366 | |
1367 RunAllPendingInMessageLoop(); | |
1368 EXPECT_FALSE(IsSelecting()); | |
1369 } | |
1370 | |
1371 // Test a slow velocity fling. | |
1372 TEST_F(WindowSelectorTest, SlowVelocityFling) { | |
1373 // We need a widget for the close button to work, a bare window will crash. | |
1374 scoped_ptr<views::Widget> widget = | |
1375 CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); | |
1376 | |
1377 ToggleOverview(); | |
1378 | |
1379 aura::Window* window = widget->GetNativeWindow(); | |
1380 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window); | |
1381 ui::test::EventGenerator event_generator(window->GetRootWindow()); | |
1382 | |
1383 ASSERT_FALSE(widget->IsClosed()); | |
1384 | |
1385 gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y()); | |
1386 gfx::Point end(start.x() - kShortDragDistance, start.y()); | |
1387 const base::TimeDelta kScrollDuration = | |
1388 event_generator.CalculateScrollDurationForFlingVelocity( | |
1389 start, end, kSlowFlingVelocity, 10); | |
1390 event_generator.GestureScrollSequence(start, end, kScrollDuration, 10); | |
1391 | |
1392 EXPECT_FALSE(widget->IsClosed()); | |
1393 | |
1394 RunAllPendingInMessageLoop(); | |
1395 EXPECT_TRUE(IsSelecting()); | |
1396 } | |
1397 | |
1398 // Test a fast velocity fling. | |
1399 TEST_F(WindowSelectorTest, FastVelocityFling) { | |
1400 // We need a widget for the close button to work, a bare window will crash. | |
1401 scoped_ptr<views::Widget> widget = | |
1402 CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); | |
1403 | |
1404 ToggleOverview(); | |
1405 ASSERT_TRUE(IsSelecting()); | |
1406 | |
1407 aura::Window* window = widget->GetNativeWindow(); | |
1408 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window); | |
1409 ui::test::EventGenerator event_generator(window->GetRootWindow()); | |
1410 | |
1411 ASSERT_FALSE(widget->IsClosed()); | |
1412 | |
1413 gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y()); | |
1414 gfx::Point end(start.x() - kShortDragDistance, start.y()); | |
1415 const base::TimeDelta kScrollDuration = | |
1416 event_generator.CalculateScrollDurationForFlingVelocity( | |
1417 start, end, kFastFlingVelocity, 10); | |
1418 event_generator.GestureScrollSequence(start, end, kScrollDuration, 10); | |
1419 | |
1420 EXPECT_TRUE(widget->IsClosed()); | |
1421 | |
1422 RunAllPendingInMessageLoop(); | |
1423 EXPECT_FALSE(IsSelecting()); | |
1424 } | |
1425 | |
1426 // Test a fast velocity fling. | |
1427 TEST_F(WindowSelectorTest, SlowVelocityFlingAtAFarDistance) { | |
1428 // We need a widget for the close button to work, a bare window will crash. | |
1429 scoped_ptr<views::Widget> widget = | |
1430 CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); | |
1431 | |
1432 ToggleOverview(); | |
1433 ASSERT_TRUE(IsSelecting()); | |
1434 | |
1435 aura::Window* window = widget->GetNativeWindow(); | |
1436 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window); | |
1437 ui::test::EventGenerator event_generator(window->GetRootWindow()); | |
1438 | |
1439 ASSERT_FALSE(widget->IsClosed()); | |
1440 | |
1441 gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y()); | |
1442 gfx::Point end(start.x() - kFarDragDistance, start.y()); | |
1443 const base::TimeDelta kScrollDuration = | |
1444 event_generator.CalculateScrollDurationForFlingVelocity( | |
1445 start, end, kSlowFlingVelocity, 10); | |
1446 event_generator.GestureScrollSequence(start, end, kScrollDuration, 10); | |
1447 | |
1448 EXPECT_TRUE(widget->IsClosed()); | |
1449 | |
1450 RunAllPendingInMessageLoop(); | |
1451 EXPECT_FALSE(IsSelecting()); | |
1452 } | |
1453 | |
1249 } // namespace ash | 1454 } // namespace ash |
OLD | NEW |