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

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

Issue 11017079: Remove Shell::shelf()|status_area_widget()|launcher() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
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/workspace_manager2.h" 5 #include "ash/wm/workspace/workspace_manager2.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h"
8 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
11 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
12 #include "ash/wm/activation_controller.h" 13 #include "ash/wm/activation_controller.h"
13 #include "ash/wm/property_util.h" 14 #include "ash/wm/property_util.h"
14 #include "ash/wm/shelf_layout_manager.h" 15 #include "ash/wm/shelf_layout_manager.h"
15 #include "ash/wm/window_properties.h" 16 #include "ash/wm/window_properties.h"
16 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
17 #include "ash/wm/workspace/workspace2.h" 18 #include "ash/wm/workspace/workspace2.h"
18 #include "ash/wm/workspace_controller_test_helper.h" 19 #include "ash/wm/workspace_controller_test_helper.h"
19 #include "base/command_line.h" 20 #include "base/command_line.h"
20 #include "base/string_number_conversions.h" 21 #include "base/string_number_conversions.h"
21 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/root_window.h" 23 #include "ui/aura/root_window.h"
23 #include "ui/aura/test/event_generator.h" 24 #include "ui/aura/test/event_generator.h"
24 #include "ui/aura/test/test_window_delegate.h" 25 #include "ui/aura/test/test_window_delegate.h"
25 #include "ui/aura/test/test_windows.h" 26 #include "ui/aura/test/test_windows.h"
26 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
27 #include "ui/base/ui_base_types.h" 28 #include "ui/base/ui_base_types.h"
28 #include "ui/compositor/layer.h" 29 #include "ui/compositor/layer.h"
29 #include "ui/gfx/screen.h" 30 #include "ui/gfx/screen.h"
30 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
31 32
32 using aura::Window; 33 using aura::Window;
33 34
34 namespace ash { 35 namespace ash {
35 namespace internal { 36 namespace internal {
36 37
37 namespace {
38
39 bool GetWindowOverlapsShelf() {
40 return Shell::GetInstance()->shelf()->window_overlaps_shelf();
41 }
42
43 } // namespace
44
45 class WorkspaceManager2Test : public test::AshTestBase { 38 class WorkspaceManager2Test : public test::AshTestBase {
46 public: 39 public:
47 WorkspaceManager2Test() : manager_(NULL) {} 40 WorkspaceManager2Test() : manager_(NULL) {}
48 virtual ~WorkspaceManager2Test() {} 41 virtual ~WorkspaceManager2Test() {}
49 42
50 aura::Window* CreateTestWindowUnparented() { 43 aura::Window* CreateTestWindowUnparented() {
51 aura::Window* window = new aura::Window(NULL); 44 aura::Window* window = new aura::Window(NULL);
52 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 45 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
53 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 46 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
54 window->Init(ui::LAYER_TEXTURED); 47 window->Init(ui::LAYER_TEXTURED);
(...skipping 19 matching lines...) Expand all
74 } 67 }
75 68
76 gfx::Rect GetFullscreenBounds(aura::Window* window) { 69 gfx::Rect GetFullscreenBounds(aura::Window* window) {
77 return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds(); 70 return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds();
78 } 71 }
79 72
80 Workspace2* active_workspace() { 73 Workspace2* active_workspace() {
81 return manager_->active_workspace_; 74 return manager_->active_workspace_;
82 } 75 }
83 76
77 ShelfLayoutManager* shelf_layout_manager() {
78 return Shell::GetPrimaryRootWindowController()->shelf();
79 }
80
81 bool GetWindowOverlapsShelf() {
82 return shelf_layout_manager()->window_overlaps_shelf();
83 }
84
84 Workspace2* FindBy(aura::Window* window) const { 85 Workspace2* FindBy(aura::Window* window) const {
85 return manager_->FindBy(window); 86 return manager_->FindBy(window);
86 } 87 }
87 88
88 std::string WorkspaceStateString(Workspace2* workspace) { 89 std::string WorkspaceStateString(Workspace2* workspace) {
89 return (workspace->is_maximized() ? "M" : "") + 90 return (workspace->is_maximized() ? "M" : "") +
90 base::IntToString(static_cast<int>( 91 base::IntToString(static_cast<int>(
91 workspace->window()->children().size())); 92 workspace->window()->children().size()));
92 } 93 }
93 94
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 // updated. 454 // updated.
454 TEST_F(WorkspaceManager2Test, ShelfStateUpdated) { 455 TEST_F(WorkspaceManager2Test, ShelfStateUpdated) {
455 // Since ShelfLayoutManager queries for mouse location, move the mouse so 456 // Since ShelfLayoutManager queries for mouse location, move the mouse so
456 // it isn't over the shelf. 457 // it isn't over the shelf.
457 aura::test::EventGenerator generator( 458 aura::test::EventGenerator generator(
458 Shell::GetPrimaryRootWindow(), gfx::Point()); 459 Shell::GetPrimaryRootWindow(), gfx::Point());
459 generator.MoveMouseTo(0, 0); 460 generator.MoveMouseTo(0, 0);
460 461
461 scoped_ptr<Window> w1(CreateTestWindow()); 462 scoped_ptr<Window> w1(CreateTestWindow());
462 const gfx::Rect w1_bounds(0, 1, 101, 102); 463 const gfx::Rect w1_bounds(0, 1, 101, 102);
463 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); 464 ShelfLayoutManager* shelf = shelf_layout_manager();
464 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 465 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
465 const gfx::Rect touches_shelf_bounds( 466 const gfx::Rect touches_shelf_bounds(
466 0, shelf->GetIdealBounds().y() - 10, 101, 102); 467 0, shelf->GetIdealBounds().y() - 10, 101, 102);
467 // Move |w1| to overlap the shelf. 468 // Move |w1| to overlap the shelf.
468 w1->SetBounds(touches_shelf_bounds); 469 w1->SetBounds(touches_shelf_bounds);
469 EXPECT_FALSE(GetWindowOverlapsShelf()); 470 EXPECT_FALSE(GetWindowOverlapsShelf());
470 471
471 // A visible ignored window should not trigger the overlap. 472 // A visible ignored window should not trigger the overlap.
472 scoped_ptr<Window> w_ignored(CreateTestWindow()); 473 scoped_ptr<Window> w_ignored(CreateTestWindow());
473 w_ignored->SetBounds(touches_shelf_bounds); 474 w_ignored->SetBounds(touches_shelf_bounds);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 wm::ActivateWindow(w1.get()); 669 wm::ActivateWindow(w1.get());
669 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 670 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
670 EXPECT_FALSE(w1->IsVisible()); 671 EXPECT_FALSE(w1->IsVisible());
671 w1->Show(); 672 w1->Show();
672 EXPECT_TRUE(w1->IsVisible()); 673 EXPECT_TRUE(w1->IsVisible());
673 } 674 }
674 675
675 // Test that we report we're in the fullscreen state even if the fullscreen 676 // Test that we report we're in the fullscreen state even if the fullscreen
676 // window isn't being managed by us (http://crbug.com/123931). 677 // window isn't being managed by us (http://crbug.com/123931).
677 TEST_F(WorkspaceManager2Test, GetWindowStateWithUnmanagedFullscreenWindow) { 678 TEST_F(WorkspaceManager2Test, GetWindowStateWithUnmanagedFullscreenWindow) {
678 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); 679 ShelfLayoutManager* shelf = shelf_layout_manager();
679 680
680 // We need to create a regular window first so there's an active workspace. 681 // We need to create a regular window first so there's an active workspace.
681 scoped_ptr<Window> w1(CreateTestWindow()); 682 scoped_ptr<Window> w1(CreateTestWindow());
682 w1->Show(); 683 w1->Show();
683 684
684 scoped_ptr<Window> w2(CreateTestWindow()); 685 scoped_ptr<Window> w2(CreateTestWindow());
685 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 686 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
686 SetPersistsAcrossAllWorkspaces( 687 SetPersistsAcrossAllWorkspaces(
687 w2.get(), 688 w2.get(),
688 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); 689 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
(...skipping 22 matching lines...) Expand all
711 w2.reset(); 712 w2.reset();
712 ASSERT_EQ("1 active=0", StateString()); 713 ASSERT_EQ("1 active=0", StateString());
713 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); 714 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
714 EXPECT_EQ(WORKSPACE_WINDOW_STATE_DEFAULT, manager_->GetWindowState()); 715 EXPECT_EQ(WORKSPACE_WINDOW_STATE_DEFAULT, manager_->GetWindowState());
715 } 716 }
716 717
717 // Variant of GetWindowStateWithUnmanagedFullscreenWindow that uses a maximized 718 // Variant of GetWindowStateWithUnmanagedFullscreenWindow that uses a maximized
718 // window rather than a normal window. 719 // window rather than a normal window.
719 TEST_F(WorkspaceManager2Test, 720 TEST_F(WorkspaceManager2Test,
720 GetWindowStateWithUnmanagedFullscreenWindowWithMaximized) { 721 GetWindowStateWithUnmanagedFullscreenWindowWithMaximized) {
721 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); 722 ShelfLayoutManager* shelf = shelf_layout_manager();
722 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 723 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
723 724
724 // Make the first window maximized. 725 // Make the first window maximized.
725 scoped_ptr<Window> w1(CreateTestWindow()); 726 scoped_ptr<Window> w1(CreateTestWindow());
726 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 727 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
727 w1->Show(); 728 w1->Show();
728 729
729 scoped_ptr<Window> w2(CreateTestWindow()); 730 scoped_ptr<Window> w2(CreateTestWindow());
730 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 731 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
731 SetPersistsAcrossAllWorkspaces( 732 SetPersistsAcrossAllWorkspaces(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 777
777 // Verifies going from maximized to minimized sets the right state for painting 778 // Verifies going from maximized to minimized sets the right state for painting
778 // the background of the launcher. 779 // the background of the launcher.
779 TEST_F(WorkspaceManager2Test, MinimizeResetsVisibility) { 780 TEST_F(WorkspaceManager2Test, MinimizeResetsVisibility) {
780 scoped_ptr<Window> w1(CreateTestWindow()); 781 scoped_ptr<Window> w1(CreateTestWindow());
781 w1->Show(); 782 w1->Show();
782 wm::ActivateWindow(w1.get()); 783 wm::ActivateWindow(w1.get());
783 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 784 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
784 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 785 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
785 EXPECT_EQ(ShelfLayoutManager::VISIBLE, 786 EXPECT_EQ(ShelfLayoutManager::VISIBLE,
786 Shell::GetInstance()->shelf()->visibility_state()); 787 shelf_layout_manager()->visibility_state());
787 EXPECT_FALSE(Shell::GetInstance()->launcher()->paints_background()); 788 EXPECT_FALSE(Launcher::ForPrimaryDisplay()->paints_background());
788 } 789 }
789 790
790 // Verifies transients are moved when maximizing. 791 // Verifies transients are moved when maximizing.
791 TEST_F(WorkspaceManager2Test, MoveTransientOnMaximize) { 792 TEST_F(WorkspaceManager2Test, MoveTransientOnMaximize) {
792 scoped_ptr<Window> w1(CreateTestWindow()); 793 scoped_ptr<Window> w1(CreateTestWindow());
793 w1->Show(); 794 w1->Show();
794 scoped_ptr<Window> w2(CreateTestWindow()); 795 scoped_ptr<Window> w2(CreateTestWindow());
795 w1->AddTransientChild(w2.get()); 796 w1->AddTransientChild(w2.get());
796 w2->Show(); 797 w2->Show();
797 wm::ActivateWindow(w1.get()); 798 wm::ActivateWindow(w1.get());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 EXPECT_TRUE(w1->IsVisible()); 878 EXPECT_TRUE(w1->IsVisible());
878 } 879 }
879 880
880 // Verifies windows that are offscreen don't move when switching workspaces. 881 // Verifies windows that are offscreen don't move when switching workspaces.
881 TEST_F(WorkspaceManager2Test, DontMoveOnSwitch) { 882 TEST_F(WorkspaceManager2Test, DontMoveOnSwitch) {
882 aura::test::EventGenerator generator( 883 aura::test::EventGenerator generator(
883 Shell::GetPrimaryRootWindow(), gfx::Point()); 884 Shell::GetPrimaryRootWindow(), gfx::Point());
884 generator.MoveMouseTo(0, 0); 885 generator.MoveMouseTo(0, 0);
885 886
886 scoped_ptr<Window> w1(CreateTestWindow()); 887 scoped_ptr<Window> w1(CreateTestWindow());
887 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); 888 ShelfLayoutManager* shelf = shelf_layout_manager();
888 const gfx::Rect touches_shelf_bounds( 889 const gfx::Rect touches_shelf_bounds(
889 0, shelf->GetIdealBounds().y() - 10, 101, 102); 890 0, shelf->GetIdealBounds().y() - 10, 101, 102);
890 // Move |w1| to overlap the shelf. 891 // Move |w1| to overlap the shelf.
891 w1->SetBounds(touches_shelf_bounds); 892 w1->SetBounds(touches_shelf_bounds);
892 w1->Show(); 893 w1->Show();
893 wm::ActivateWindow(w1.get()); 894 wm::ActivateWindow(w1.get());
894 895
895 // Create another window and maximize it. 896 // Create another window and maximize it.
896 scoped_ptr<Window> w2(CreateTestWindow()); 897 scoped_ptr<Window> w2(CreateTestWindow());
897 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); 898 w2->SetBounds(gfx::Rect(10, 11, 250, 251));
898 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 899 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
899 w2->Show(); 900 w2->Show();
900 wm::ActivateWindow(w2.get()); 901 wm::ActivateWindow(w2.get());
901 902
902 // Switch to w1. 903 // Switch to w1.
903 wm::ActivateWindow(w1.get()); 904 wm::ActivateWindow(w1.get());
904 EXPECT_EQ(touches_shelf_bounds.ToString(), w1->bounds().ToString()); 905 EXPECT_EQ(touches_shelf_bounds.ToString(), w1->bounds().ToString());
905 } 906 }
906 907
907 // Verifies that windows that are completely offscreen move when switching 908 // Verifies that windows that are completely offscreen move when switching
908 // workspaces. 909 // workspaces.
909 TEST_F(WorkspaceManager2Test, MoveOnSwitch) { 910 TEST_F(WorkspaceManager2Test, MoveOnSwitch) {
910 aura::test::EventGenerator generator( 911 aura::test::EventGenerator generator(
911 Shell::GetPrimaryRootWindow(), gfx::Point()); 912 Shell::GetPrimaryRootWindow(), gfx::Point());
912 generator.MoveMouseTo(0, 0); 913 generator.MoveMouseTo(0, 0);
913 914
914 scoped_ptr<Window> w1(CreateTestWindow()); 915 scoped_ptr<Window> w1(CreateTestWindow());
915 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); 916 ShelfLayoutManager* shelf = shelf_layout_manager();
916 const gfx::Rect w1_bounds(0, shelf->GetIdealBounds().y(), 100, 200); 917 const gfx::Rect w1_bounds(0, shelf->GetIdealBounds().y(), 100, 200);
917 // Move |w1| so that the top edge is the same as the top edge of the shelf. 918 // Move |w1| so that the top edge is the same as the top edge of the shelf.
918 w1->SetBounds(w1_bounds); 919 w1->SetBounds(w1_bounds);
919 w1->Show(); 920 w1->Show();
920 wm::ActivateWindow(w1.get()); 921 wm::ActivateWindow(w1.get());
921 EXPECT_EQ(w1_bounds.ToString(), w1->bounds().ToString()); 922 EXPECT_EQ(w1_bounds.ToString(), w1->bounds().ToString());
922 923
923 // Create another window and maximize it. 924 // Create another window and maximize it.
924 scoped_ptr<Window> w2(CreateTestWindow()); 925 scoped_ptr<Window> w2(CreateTestWindow());
925 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); 926 w2->SetBounds(gfx::Rect(10, 11, 250, 251));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 986
986 } // namespace 987 } // namespace
987 988
988 // Exercises possible crash in W2. Here's the sequence: 989 // Exercises possible crash in W2. Here's the sequence:
989 // . minimize a maximized window. 990 // . minimize a maximized window.
990 // . remove the window (which happens when switching displays). 991 // . remove the window (which happens when switching displays).
991 // . add the window back. 992 // . add the window back.
992 // . show the window and during the bounds change activate it. 993 // . show the window and during the bounds change activate it.
993 TEST_F(WorkspaceManager2Test, DontCrashOnChangeAndActivate) { 994 TEST_F(WorkspaceManager2Test, DontCrashOnChangeAndActivate) {
994 // Force the shelf 995 // Force the shelf
995 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); 996 ShelfLayoutManager* shelf = shelf_layout_manager();
996 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 997 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
997 998
998 DontCrashOnChangeAndActivateDelegate delegate; 999 DontCrashOnChangeAndActivateDelegate delegate;
999 scoped_ptr<Window> w1( 1000 scoped_ptr<Window> w1(
1000 CreateTestWindowWithDelegate(&delegate, 1000, gfx::Rect(10, 11, 250, 251), 1001 CreateTestWindowWithDelegate(&delegate, 1000, gfx::Rect(10, 11, 250, 251),
1001 NULL)); 1002 NULL));
1002 w1->Show(); 1003 w1->Show();
1003 wm::ActivateWindow(w1.get()); 1004 wm::ActivateWindow(w1.get());
1004 wm::MaximizeWindow(w1.get()); 1005 wm::MaximizeWindow(w1.get());
1005 wm::MinimizeWindow(w1.get()); 1006 wm::MinimizeWindow(w1.get());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 EXPECT_EQ(w1->parent(), w2->parent()); 1101 EXPECT_EQ(w1->parent(), w2->parent());
1101 ASSERT_EQ("0 M2 active=1", StateString()); 1102 ASSERT_EQ("0 M2 active=1", StateString());
1102 1103
1103 // Activate |w1|, should result in dropping |w2| to the desktop. 1104 // Activate |w1|, should result in dropping |w2| to the desktop.
1104 wm::ActivateWindow(w1.get()); 1105 wm::ActivateWindow(w1.get());
1105 ASSERT_EQ("1 M1 active=1", StateString()); 1106 ASSERT_EQ("1 M1 active=1", StateString());
1106 } 1107 }
1107 1108
1108 } // namespace internal 1109 } // namespace internal
1109 } // namespace ash 1110 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698