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 "ash/wm/workspace_controller.h" | 5 #include "ash/wm/workspace_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
15 #include "ash/system/status_area_widget.h" | 15 #include "ash/system/status_area_widget.h" |
16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/shell_test_api.h" | 17 #include "ash/test/shell_test_api.h" |
18 #include "ash/test/test_shelf_delegate.h" | 18 #include "ash/test/test_shelf_delegate.h" |
19 #include "ash/wm/panels/panel_layout_manager.h" | 19 #include "ash/wm/panels/panel_layout_manager.h" |
20 #include "ash/wm/window_state.h" | 20 #include "ash/wm/window_state.h" |
21 #include "ash/wm/window_util.h" | 21 #include "ash/wm/window_util.h" |
22 #include "ash/wm/workspace/workspace_window_resizer.h" | 22 #include "ash/wm/workspace/workspace_window_resizer.h" |
23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
24 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
25 #include "ui/aura/test/event_generator.h" | |
26 #include "ui/aura/test/test_window_delegate.h" | 25 #include "ui/aura/test/test_window_delegate.h" |
27 #include "ui/aura/test/test_windows.h" | 26 #include "ui/aura/test/test_windows.h" |
28 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
29 #include "ui/aura/window_event_dispatcher.h" | 28 #include "ui/aura/window_event_dispatcher.h" |
30 #include "ui/base/hit_test.h" | 29 #include "ui/base/hit_test.h" |
31 #include "ui/base/ui_base_types.h" | 30 #include "ui/base/ui_base_types.h" |
32 #include "ui/compositor/layer.h" | 31 #include "ui/compositor/layer.h" |
33 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 32 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
34 #include "ui/events/event_utils.h" | 33 #include "ui/events/event_utils.h" |
| 34 #include "ui/events/test/event_generator.h" |
35 #include "ui/gfx/screen.h" | 35 #include "ui/gfx/screen.h" |
36 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
37 #include "ui/wm/core/window_animations.h" | 37 #include "ui/wm/core/window_animations.h" |
38 #include "ui/wm/core/window_util.h" | 38 #include "ui/wm/core/window_util.h" |
39 | 39 |
40 using aura::Window; | 40 using aura::Window; |
41 | 41 |
42 namespace ash { | 42 namespace ash { |
43 | 43 |
44 // Returns a string containing the names of all the children of |window| (in | 44 // Returns a string containing the names of all the children of |window| (in |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 EXPECT_EQ(w2.get(), GetDesktop()->children()[0]); | 360 EXPECT_EQ(w2.get(), GetDesktop()->children()[0]); |
361 EXPECT_EQ(w1.get(), GetDesktop()->children()[1]); | 361 EXPECT_EQ(w1.get(), GetDesktop()->children()[1]); |
362 EXPECT_TRUE(w2->layer()->IsDrawn()); | 362 EXPECT_TRUE(w2->layer()->IsDrawn()); |
363 } | 363 } |
364 | 364 |
365 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly | 365 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly |
366 // updated. | 366 // updated. |
367 TEST_F(WorkspaceControllerTest, ShelfStateUpdated) { | 367 TEST_F(WorkspaceControllerTest, ShelfStateUpdated) { |
368 // Since ShelfLayoutManager queries for mouse location, move the mouse so | 368 // Since ShelfLayoutManager queries for mouse location, move the mouse so |
369 // it isn't over the shelf. | 369 // it isn't over the shelf. |
370 aura::test::EventGenerator generator( | 370 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
371 Shell::GetPrimaryRootWindow(), gfx::Point()); | 371 gfx::Point()); |
372 generator.MoveMouseTo(0, 0); | 372 generator.MoveMouseTo(0, 0); |
373 | 373 |
374 scoped_ptr<Window> w1(CreateTestWindow()); | 374 scoped_ptr<Window> w1(CreateTestWindow()); |
375 const gfx::Rect w1_bounds(0, 1, 101, 102); | 375 const gfx::Rect w1_bounds(0, 1, 101, 102); |
376 ShelfLayoutManager* shelf = shelf_layout_manager(); | 376 ShelfLayoutManager* shelf = shelf_layout_manager(); |
377 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 377 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
378 const gfx::Rect touches_shelf_bounds( | 378 const gfx::Rect touches_shelf_bounds( |
379 0, shelf->GetIdealBounds().y() - 10, 101, 102); | 379 0, shelf->GetIdealBounds().y() - 10, 101, 102); |
380 // Move |w1| to overlap the shelf. | 380 // Move |w1| to overlap the shelf. |
381 w1->SetBounds(touches_shelf_bounds); | 381 w1->SetBounds(touches_shelf_bounds); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 EXPECT_TRUE(w1->IsVisible()); | 568 EXPECT_TRUE(w1->IsVisible()); |
569 | 569 |
570 // Close |w2|. | 570 // Close |w2|. |
571 w2.reset(); | 571 w2.reset(); |
572 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); | 572 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); |
573 EXPECT_TRUE(w1->IsVisible()); | 573 EXPECT_TRUE(w1->IsVisible()); |
574 } | 574 } |
575 | 575 |
576 // Verifies windows that are offscreen don't move when switching workspaces. | 576 // Verifies windows that are offscreen don't move when switching workspaces. |
577 TEST_F(WorkspaceControllerTest, DontMoveOnSwitch) { | 577 TEST_F(WorkspaceControllerTest, DontMoveOnSwitch) { |
578 aura::test::EventGenerator generator( | 578 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
579 Shell::GetPrimaryRootWindow(), gfx::Point()); | 579 gfx::Point()); |
580 generator.MoveMouseTo(0, 0); | 580 generator.MoveMouseTo(0, 0); |
581 | 581 |
582 scoped_ptr<Window> w1(CreateTestWindow()); | 582 scoped_ptr<Window> w1(CreateTestWindow()); |
583 ShelfLayoutManager* shelf = shelf_layout_manager(); | 583 ShelfLayoutManager* shelf = shelf_layout_manager(); |
584 const gfx::Rect touches_shelf_bounds( | 584 const gfx::Rect touches_shelf_bounds( |
585 0, shelf->GetIdealBounds().y() - 10, 101, 102); | 585 0, shelf->GetIdealBounds().y() - 10, 101, 102); |
586 // Move |w1| to overlap the shelf. | 586 // Move |w1| to overlap the shelf. |
587 w1->SetBounds(touches_shelf_bounds); | 587 w1->SetBounds(touches_shelf_bounds); |
588 w1->Show(); | 588 w1->Show(); |
589 wm::ActivateWindow(w1.get()); | 589 wm::ActivateWindow(w1.get()); |
590 | 590 |
591 // Create another window and maximize it. | 591 // Create another window and maximize it. |
592 scoped_ptr<Window> w2(CreateTestWindow()); | 592 scoped_ptr<Window> w2(CreateTestWindow()); |
593 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); | 593 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); |
594 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 594 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
595 w2->Show(); | 595 w2->Show(); |
596 wm::ActivateWindow(w2.get()); | 596 wm::ActivateWindow(w2.get()); |
597 | 597 |
598 // Switch to w1. | 598 // Switch to w1. |
599 wm::ActivateWindow(w1.get()); | 599 wm::ActivateWindow(w1.get()); |
600 EXPECT_EQ(touches_shelf_bounds.ToString(), w1->bounds().ToString()); | 600 EXPECT_EQ(touches_shelf_bounds.ToString(), w1->bounds().ToString()); |
601 } | 601 } |
602 | 602 |
603 // Verifies that windows that are completely offscreen move when switching | 603 // Verifies that windows that are completely offscreen move when switching |
604 // workspaces. | 604 // workspaces. |
605 TEST_F(WorkspaceControllerTest, MoveOnSwitch) { | 605 TEST_F(WorkspaceControllerTest, MoveOnSwitch) { |
606 aura::test::EventGenerator generator( | 606 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
607 Shell::GetPrimaryRootWindow(), gfx::Point()); | 607 gfx::Point()); |
608 generator.MoveMouseTo(0, 0); | 608 generator.MoveMouseTo(0, 0); |
609 | 609 |
610 scoped_ptr<Window> w1(CreateTestWindow()); | 610 scoped_ptr<Window> w1(CreateTestWindow()); |
611 ShelfLayoutManager* shelf = shelf_layout_manager(); | 611 ShelfLayoutManager* shelf = shelf_layout_manager(); |
612 const gfx::Rect w1_bounds(0, shelf->GetIdealBounds().y(), 100, 200); | 612 const gfx::Rect w1_bounds(0, shelf->GetIdealBounds().y(), 100, 200); |
613 // Move |w1| so that the top edge is the same as the top edge of the shelf. | 613 // Move |w1| so that the top edge is the same as the top edge of the shelf. |
614 w1->SetBounds(w1_bounds); | 614 w1->SetBounds(w1_bounds); |
615 w1->Show(); | 615 w1->Show(); |
616 wm::ActivateWindow(w1.get()); | 616 wm::ActivateWindow(w1.get()); |
617 EXPECT_EQ(w1_bounds.ToString(), w1->bounds().ToString()); | 617 EXPECT_EQ(w1_bounds.ToString(), w1->bounds().ToString()); |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 aura::test::TestWindowDelegate delegate; | 1390 aura::test::TestWindowDelegate delegate; |
1391 delegate.set_window_component(HTCAPTION); | 1391 delegate.set_window_component(HTCAPTION); |
1392 scoped_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( | 1392 scoped_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( |
1393 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); | 1393 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); |
1394 ParentWindowInPrimaryRootWindow(w1.get()); | 1394 ParentWindowInPrimaryRootWindow(w1.get()); |
1395 | 1395 |
1396 ShelfLayoutManager* shelf = shelf_layout_manager(); | 1396 ShelfLayoutManager* shelf = shelf_layout_manager(); |
1397 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1397 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
1398 | 1398 |
1399 // Drag near the shelf. | 1399 // Drag near the shelf. |
1400 aura::test::EventGenerator generator( | 1400 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
1401 Shell::GetPrimaryRootWindow(), gfx::Point()); | 1401 gfx::Point()); |
1402 generator.MoveMouseTo(10, 10); | 1402 generator.MoveMouseTo(10, 10); |
1403 generator.PressLeftButton(); | 1403 generator.PressLeftButton(); |
1404 generator.MoveMouseTo(100, shelf->GetIdealBounds().y() - 70); | 1404 generator.MoveMouseTo(100, shelf->GetIdealBounds().y() - 70); |
1405 | 1405 |
1406 // Shelf should not be in overlapped state. | 1406 // Shelf should not be in overlapped state. |
1407 EXPECT_FALSE(GetWindowOverlapsShelf()); | 1407 EXPECT_FALSE(GetWindowOverlapsShelf()); |
1408 | 1408 |
1409 generator.MoveMouseTo(100, shelf->GetIdealBounds().y() - 20); | 1409 generator.MoveMouseTo(100, shelf->GetIdealBounds().y() - 20); |
1410 | 1410 |
1411 // Shelf should detect overlap. Overlap state stays after mouse is released. | 1411 // Shelf should detect overlap. Overlap state stays after mouse is released. |
1412 EXPECT_TRUE(GetWindowOverlapsShelf()); | 1412 EXPECT_TRUE(GetWindowOverlapsShelf()); |
1413 generator.ReleaseLeftButton(); | 1413 generator.ReleaseLeftButton(); |
1414 EXPECT_TRUE(GetWindowOverlapsShelf()); | 1414 EXPECT_TRUE(GetWindowOverlapsShelf()); |
1415 } | 1415 } |
1416 | 1416 |
1417 // Verifies that when dragging a window autohidden shelf stays hidden during | 1417 // Verifies that when dragging a window autohidden shelf stays hidden during |
1418 // and after the drag. | 1418 // and after the drag. |
1419 TEST_F(WorkspaceControllerTestDragging, DragWindowKeepsShelfAutohidden) { | 1419 TEST_F(WorkspaceControllerTestDragging, DragWindowKeepsShelfAutohidden) { |
1420 aura::test::TestWindowDelegate delegate; | 1420 aura::test::TestWindowDelegate delegate; |
1421 delegate.set_window_component(HTCAPTION); | 1421 delegate.set_window_component(HTCAPTION); |
1422 scoped_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( | 1422 scoped_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( |
1423 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); | 1423 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); |
1424 ParentWindowInPrimaryRootWindow(w1.get()); | 1424 ParentWindowInPrimaryRootWindow(w1.get()); |
1425 | 1425 |
1426 ShelfLayoutManager* shelf = shelf_layout_manager(); | 1426 ShelfLayoutManager* shelf = shelf_layout_manager(); |
1427 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1427 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
1428 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1428 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
1429 | 1429 |
1430 // Drag very little. | 1430 // Drag very little. |
1431 aura::test::EventGenerator generator( | 1431 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
1432 Shell::GetPrimaryRootWindow(), gfx::Point()); | 1432 gfx::Point()); |
1433 generator.MoveMouseTo(10, 10); | 1433 generator.MoveMouseTo(10, 10); |
1434 generator.PressLeftButton(); | 1434 generator.PressLeftButton(); |
1435 generator.MoveMouseTo(12, 12); | 1435 generator.MoveMouseTo(12, 12); |
1436 | 1436 |
1437 // Shelf should be hidden during and after the drag. | 1437 // Shelf should be hidden during and after the drag. |
1438 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1438 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
1439 generator.ReleaseLeftButton(); | 1439 generator.ReleaseLeftButton(); |
1440 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1440 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
1441 } | 1441 } |
1442 | 1442 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 ui::EventTimeForNow()); | 1609 ui::EventTimeForNow()); |
1610 target = targeter->FindTargetForEvent(root, &touch); | 1610 target = targeter->FindTargetForEvent(root, &touch); |
1611 if (points[i].is_target_hit) | 1611 if (points[i].is_target_hit) |
1612 EXPECT_EQ(window.get(), target); | 1612 EXPECT_EQ(window.get(), target); |
1613 else | 1613 else |
1614 EXPECT_NE(window.get(), target); | 1614 EXPECT_NE(window.get(), target); |
1615 } | 1615 } |
1616 } | 1616 } |
1617 | 1617 |
1618 } // namespace ash | 1618 } // namespace ash |
OLD | NEW |