OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura_shell/workspace_controller.h" | 5 #include "ui/aura_shell/workspace_controller.h" |
6 | 6 |
7 #include "ui/aura/test/aura_test_base.h" | 7 #include "ui/aura/test/aura_test_base.h" |
8 #include "ui/aura/test/test_stacking_client.h" | 8 #include "ui/aura/test/test_stacking_client.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/aura_shell/activation_controller.h" |
| 11 #include "ui/aura_shell/shell_window_ids.h" |
| 12 #include "ui/aura_shell/window_util.h" |
10 #include "ui/aura_shell/workspace/workspace.h" | 13 #include "ui/aura_shell/workspace/workspace.h" |
11 #include "ui/aura_shell/workspace/workspace_manager.h" | 14 #include "ui/aura_shell/workspace/workspace_manager.h" |
12 | 15 |
13 namespace aura_shell { | 16 namespace aura_shell { |
14 namespace internal { | 17 namespace internal { |
15 | 18 |
16 using aura::Window; | 19 using aura::Window; |
17 | 20 |
18 class WorkspaceControllerTest : public aura::test::AuraTestBase { | 21 class WorkspaceControllerTest : public aura::test::AuraTestBase { |
19 public: | 22 public: |
20 WorkspaceControllerTest() {} | 23 WorkspaceControllerTest() {} |
21 virtual ~WorkspaceControllerTest() {} | 24 virtual ~WorkspaceControllerTest() {} |
22 | 25 |
23 virtual void SetUp() OVERRIDE { | 26 virtual void SetUp() OVERRIDE { |
24 aura::test::AuraTestBase::SetUp(); | 27 aura::test::AuraTestBase::SetUp(); |
25 contents_view_ = GetTestStackingClient()->default_container(); | 28 contents_view_ = GetTestStackingClient()->default_container(); |
| 29 // Activatable windows need to be in a container the ActivationController |
| 30 // recognizes. |
| 31 contents_view_->set_id( |
| 32 aura_shell::internal::kShellWindowId_DefaultContainer); |
| 33 activation_controller_.reset(new ActivationController); |
| 34 activation_controller_->set_default_container_for_test(contents_view_); |
26 controller_.reset(new WorkspaceController(contents_view_)); | 35 controller_.reset(new WorkspaceController(contents_view_)); |
27 } | 36 } |
28 | 37 |
29 virtual void TearDown() OVERRIDE { | 38 virtual void TearDown() OVERRIDE { |
| 39 activation_controller_.reset(); |
30 controller_.reset(); | 40 controller_.reset(); |
31 aura::test::AuraTestBase::TearDown(); | 41 aura::test::AuraTestBase::TearDown(); |
32 } | 42 } |
33 | 43 |
34 aura::Window* CreateTestWindow() { | 44 aura::Window* CreateTestWindow() { |
35 aura::Window* window = new aura::Window(NULL); | 45 aura::Window* window = new aura::Window(NULL); |
36 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 46 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
37 contents_view()->AddChild(window); | 47 contents_view()->AddChild(window); |
38 window->Show(); | 48 window->Show(); |
39 return window; | 49 return window; |
40 } | 50 } |
41 | 51 |
42 aura::Window * contents_view() { | 52 aura::Window* contents_view() { |
43 return contents_view_; | 53 return contents_view_; |
44 } | 54 } |
45 | 55 |
46 WorkspaceManager* workspace_manager() { | 56 WorkspaceManager* workspace_manager() { |
47 return controller_->workspace_manager(); | 57 return controller_->workspace_manager(); |
48 } | 58 } |
49 | 59 |
50 scoped_ptr<WorkspaceController> controller_; | 60 scoped_ptr<WorkspaceController> controller_; |
51 | 61 |
52 private: | 62 private: |
53 aura::Window* contents_view_; | 63 aura::Window* contents_view_; |
54 | 64 |
| 65 scoped_ptr<ActivationController> activation_controller_; |
| 66 |
55 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); | 67 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); |
56 }; | 68 }; |
57 | 69 |
58 TEST_F(WorkspaceControllerTest, Overview) { | 70 TEST_F(WorkspaceControllerTest, Overview) { |
59 workspace_manager()->SetWorkspaceSize(gfx::Size(500, 300)); | 71 workspace_manager()->SetWorkspaceSize(gfx::Size(500, 300)); |
60 | 72 |
61 // Creating two workspaces, ws1 which contains window w1, | 73 // Creating two workspaces, ws1 which contains window w1, |
62 // and ws2 which contains window w2. | 74 // and ws2 which contains window w2. |
63 Workspace* ws1 = workspace_manager()->CreateWorkspace(); | 75 Workspace* ws1 = workspace_manager()->CreateWorkspace(); |
64 scoped_ptr<Window> w1(CreateTestWindow()); | 76 scoped_ptr<Window> w1(CreateTestWindow()); |
65 EXPECT_TRUE(ws1->AddWindowAfter(w1.get(), NULL)); | 77 EXPECT_TRUE(ws1->AddWindowAfter(w1.get(), NULL)); |
66 | 78 |
67 Workspace* ws2 = workspace_manager()->CreateWorkspace(); | 79 Workspace* ws2 = workspace_manager()->CreateWorkspace(); |
68 scoped_ptr<Window> w2(CreateTestWindow()); | 80 scoped_ptr<Window> w2(CreateTestWindow()); |
69 EXPECT_TRUE(ws2->AddWindowAfter(w2.get(), NULL)); | 81 EXPECT_TRUE(ws2->AddWindowAfter(w2.get(), NULL)); |
70 | 82 |
71 // Activating a window switches the active workspace. | 83 // Activating a window switches the active workspace. |
72 w2->Activate(); | 84 aura_shell::ActivateWindow(w2.get()); |
73 EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); | 85 EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); |
74 | 86 |
75 // The size of contents_view() is now ws1(500) + ws2(500) + margin(50). | 87 // The size of contents_view() is now ws1(500) + ws2(500) + margin(50). |
76 EXPECT_EQ("0,0 1050x300", contents_view()->bounds().ToString()); | 88 EXPECT_EQ("0,0 1050x300", contents_view()->bounds().ToString()); |
77 EXPECT_FALSE(workspace_manager()->is_overview()); | 89 EXPECT_FALSE(workspace_manager()->is_overview()); |
78 workspace_manager()->SetOverview(true); | 90 workspace_manager()->SetOverview(true); |
79 EXPECT_TRUE(workspace_manager()->is_overview()); | 91 EXPECT_TRUE(workspace_manager()->is_overview()); |
80 | 92 |
81 // Switching overview mode doesn't change the active workspace. | 93 // Switching overview mode doesn't change the active workspace. |
82 EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); | 94 EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); |
83 | 95 |
84 // Activating window w1 switches the active window and | 96 // Activating window w1 switches the active window and |
85 // the mode back to normal mode. | 97 // the mode back to normal mode. |
86 w1->Activate(); | 98 aura_shell::ActivateWindow(w1.get()); |
87 EXPECT_EQ(ws1, workspace_manager()->GetActiveWorkspace()); | 99 EXPECT_EQ(ws1, workspace_manager()->GetActiveWorkspace()); |
88 EXPECT_FALSE(workspace_manager()->is_overview()); | 100 EXPECT_FALSE(workspace_manager()->is_overview()); |
89 | 101 |
90 // Deleting w1 without StackingClient resets the active workspace | 102 // Deleting w1 without StackingClient resets the active workspace |
91 ws1->RemoveWindow(w1.get()); | 103 ws1->RemoveWindow(w1.get()); |
92 delete ws1; | 104 delete ws1; |
93 w1.reset(); | 105 w1.reset(); |
94 EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); | 106 EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); |
95 EXPECT_EQ("0,0 500x300", contents_view()->bounds().ToString()); | 107 EXPECT_EQ("0,0 500x300", contents_view()->bounds().ToString()); |
96 ws2->RemoveWindow(w2.get()); | 108 ws2->RemoveWindow(w2.get()); |
97 delete ws2; | 109 delete ws2; |
98 // The size of contents_view() for no workspace case must be | 110 // The size of contents_view() for no workspace case must be |
99 // same as one contents_view() case. | 111 // same as one contents_view() case. |
100 EXPECT_EQ("0,0 500x300", contents_view()->bounds().ToString()); | 112 EXPECT_EQ("0,0 500x300", contents_view()->bounds().ToString()); |
101 | 113 |
102 // Reset now before windows are destroyed. | 114 // Reset now before windows are destroyed. |
103 controller_.reset(); | 115 controller_.reset(); |
104 } | 116 } |
105 | 117 |
106 } // namespace internal | 118 } // namespace internal |
107 } // namespace aura_shell | 119 } // namespace aura_shell |
OLD | NEW |