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

Side by Side Diff: ui/aura_shell/workspace/workspace_manager_unittest.cc

Issue 8381015: Add workspace to desktop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: temporarily exlucde tests failing on win Created 9 years, 1 month 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
« no previous file with comments | « ui/aura_shell/workspace/workspace_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/workspace_manager.h" 5 #include "ui/aura_shell/workspace/workspace_manager.h"
6 #include "ui/aura_shell/workspace/workspace.h" 6 #include "ui/aura_shell/workspace/workspace.h"
7 7
8 #include "ui/aura/test/aura_test_base.h" 8 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/test/test_desktop_delegate.h"
10 #include "ui/aura/desktop.h"
11 #include "ui/aura/screen_aura.h"
9 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
10 13
11 namespace { 14 namespace {
12 15
13 class WorkspaceManagerTestBase : public aura::test::AuraTestBase { 16 class WorkspaceManagerTestBase : public aura::test::AuraTestBase {
14 public: 17 public:
15 aura::Window* CreateTestWindow() { 18 aura::Window* CreateTestWindow() {
16 aura::Window* window = new aura::Window(NULL); 19 aura::Window* window = new aura::Window(NULL);
17 window->Init(); 20 window->Init();
18 return window; 21 return window;
19 } 22 }
23
24 aura::Window* viewport() {
25 return GetTestDesktopDelegate()->default_container();
26 }
20 }; 27 };
21 28
22 } // namespace 29 } // namespace
23 30
24 namespace aura_shell { 31 namespace aura_shell {
25 32
26 using aura::Window; 33 using aura::Window;
27 using aura_shell::Workspace; 34 using aura_shell::Workspace;
35 using aura_shell::WorkspaceManager;
28 36
29 class WorkspaceManagerTest : public WorkspaceManagerTestBase { 37 class WorkspaceManagerTest : public WorkspaceManagerTestBase {
30 }; 38 };
31 39
32 TEST_F(WorkspaceManagerTest, WorkspaceManagerBaic) { 40 TEST_F(WorkspaceManagerTest, WorkspaceManagerCreateAddFind) {
33 WorkspaceManager manager; 41 WorkspaceManager manager(viewport());
34 scoped_ptr<Window> w1(CreateTestWindow()); 42 scoped_ptr<Window> w1(CreateTestWindow());
35 scoped_ptr<Window> w2(CreateTestWindow()); 43 scoped_ptr<Window> w2(CreateTestWindow());
36 44
37 Workspace* ws1 = manager.CreateWorkspace(); 45 Workspace* ws1 = manager.CreateWorkspace();
38 ws1->AddWindowAfter(w1.get(), NULL); 46 ws1->AddWindowAfter(w1.get(), NULL);
39 // w2 is not a part of any workspace yet. 47 // w2 is not a part of any workspace yet.
40 EXPECT_EQ(NULL, manager.FindBy(w2.get())); 48 EXPECT_EQ(NULL, manager.FindBy(w2.get()));
41 49
42 // w2 is in ws2 workspace. 50 // w2 is in ws2 workspace.
43 Workspace* ws2 = manager.CreateWorkspace(); 51 Workspace* ws2 = manager.CreateWorkspace();
44 ws2->AddWindowAfter(w2.get(), NULL); 52 ws2->AddWindowAfter(w2.get(), NULL);
45 EXPECT_EQ(ws2, manager.FindBy(w2.get())); 53 EXPECT_EQ(ws2, manager.FindBy(w2.get()));
46 54
47 // Make sure |FindBy(w1.get())| still returns 55 // Make sure |FindBy(w1.get())| still returns
48 // correct workspace. 56 // correct workspace.
49 EXPECT_EQ(ws1, manager.FindBy(w1.get())); 57 EXPECT_EQ(ws1, manager.FindBy(w1.get()));
50 58
51 // once workspace is gone, w2 shouldn't match 59 // once workspace is gone, w2 shouldn't match
52 // any workspace. 60 // any workspace.
53 delete ws2; 61 delete ws2;
54 EXPECT_EQ(NULL, manager.FindBy(w2.get())); 62 EXPECT_EQ(NULL, manager.FindBy(w2.get()));
55 } 63 }
56 64
57 TEST_F(WorkspaceManagerTest, WorkspaceManagerLayout) { 65 TEST_F(WorkspaceManagerTest, LayoutWorkspaces) {
58 WorkspaceManager manager; 66 WorkspaceManager manager(viewport());
59 manager.set_workspace_size(gfx::Size(100, 100)); 67 manager.workspace_size_ = gfx::Size(100, 100);
60 EXPECT_EQ(0, manager.GetTotalWidth()); 68 manager.LayoutWorkspaces();
69 EXPECT_EQ("0,0 100x100", viewport()->bounds().ToString());
61 70
62 Workspace* ws1 = manager.CreateWorkspace(); 71 Workspace* ws1 = manager.CreateWorkspace();
63 manager.Layout(); 72 manager.LayoutWorkspaces();
73
64 // ws1 is laied out in left most position. 74 // ws1 is laied out in left most position.
65 EXPECT_EQ(100, manager.GetTotalWidth()); 75 EXPECT_EQ(100, viewport()->bounds().width());
66 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); 76 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString());
67 77
68 // ws2 is laied out next to ws1, with 50 margin. 78 // ws2 is laied out next to ws1, with 50 margin.
69 Workspace* ws2 = manager.CreateWorkspace(); 79 Workspace* ws2 = manager.CreateWorkspace();
70 manager.Layout(); 80 manager.LayoutWorkspaces();
71 EXPECT_EQ(250, manager.GetTotalWidth()); 81
82 EXPECT_EQ(250, viewport()->bounds().width());
72 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); 83 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString());
73 EXPECT_EQ("150,0 100x100", ws2->bounds().ToString()); 84 EXPECT_EQ("150,0 100x100", ws2->bounds().ToString());
74 } 85 }
75 86
87 TEST_F(WorkspaceManagerTest, WorkspaceManagerDragArea) {
88 aura::Desktop::GetInstance()->screen()->set_work_area_insets(
89 gfx::Insets(10, 10, 10, 10));
90
91 WorkspaceManager manager(viewport());
92 viewport()->SetBounds(gfx::Rect(0, 0, 200, 200));
93 EXPECT_EQ("10,10 180x180", manager.GetDragAreaBounds().ToString());
94 }
95
96 TEST_F(WorkspaceManagerTest, Overview) {
97 WorkspaceManager manager(viewport());
98 manager.workspace_size_ = gfx::Size(500, 300);
99
100 // Creating two workspaces, ws1 which contains window w1,
101 // and ws2 which contains window w2.
102 Workspace* ws1 = manager.CreateWorkspace();
103 scoped_ptr<Window> w1(CreateTestWindow());
104 viewport()->AddChild(w1.get());
105 EXPECT_TRUE(ws1->AddWindowAfter(w1.get(), NULL));
106
107 Workspace* ws2 = manager.CreateWorkspace();
108 scoped_ptr<Window> w2(CreateTestWindow());
109 viewport()->AddChild(w2.get());
110 EXPECT_TRUE(ws2->AddWindowAfter(w2.get(), NULL));
111
112 // Activating a window switches the active workspace.
113 w2->Activate();
114 EXPECT_EQ(ws2, manager.GetActiveWorkspace());
115
116 // The size of viewport() is now ws1(500) + ws2(500) + margin(50).
117 EXPECT_EQ("0,0 1050x300", viewport()->bounds().ToString());
118 EXPECT_FALSE(manager.is_overview());
119 manager.SetOverview(true);
120 EXPECT_TRUE(manager.is_overview());
121
122 // Switching overview mode doesn't change the active workspace.
123 EXPECT_EQ(ws2, manager.GetActiveWorkspace());
124
125 // Activaing window w1 switches the active window and
126 // the mode back to normal mode.
127 w1->Activate();
128 EXPECT_EQ(ws1, manager.GetActiveWorkspace());
129 EXPECT_FALSE(manager.is_overview());
130
131 // Deleting w1 without DesktopDelegate resets the active workspace
132 ws1->RemoveWindow(w1.get());
133 delete ws1;
134 w1.reset();
135 EXPECT_EQ(NULL, manager.GetActiveWorkspace());
136
137 EXPECT_EQ("0,0 500x300", viewport()->bounds().ToString());
138 ws2->RemoveWindow(w2.get());
139 delete ws2;
140 // The size of viewport() for no workspace case must be
141 // same as one viewport() case.
142 EXPECT_EQ("0,0 500x300", viewport()->bounds().ToString());
143 }
144
76 TEST_F(WorkspaceManagerTest, WorkspaceManagerActivate) { 145 TEST_F(WorkspaceManagerTest, WorkspaceManagerActivate) {
77 WorkspaceManager manager; 146 WorkspaceManager manager(viewport());
78 Workspace* ws1 = manager.CreateWorkspace(); 147 Workspace* ws1 = manager.CreateWorkspace();
79 Workspace* ws2 = manager.CreateWorkspace(); 148 Workspace* ws2 = manager.CreateWorkspace();
80 EXPECT_EQ(NULL, manager.GetActiveWorkspace()); 149 EXPECT_EQ(NULL, manager.GetActiveWorkspace());
81 150
82 // Activate ws1. 151 // Activate ws1.
83 ws1->Activate(); 152 ws1->Activate();
84 EXPECT_EQ(ws1, manager.GetActiveWorkspace()); 153 EXPECT_EQ(ws1, manager.GetActiveWorkspace());
85 154
86 // Activate ws2. 155 // Activate ws2.
87 ws2->Activate(); 156 ws2->Activate();
88 EXPECT_EQ(ws2, manager.GetActiveWorkspace()); 157 EXPECT_EQ(ws2, manager.GetActiveWorkspace());
89 158
90 // Deleting active workspace sets active workspace to NULL. 159 // Deleting active workspace sets active workspace to NULL.
91 delete ws2; 160 delete ws2;
92 EXPECT_EQ(NULL, manager.GetActiveWorkspace()); 161 EXPECT_EQ(NULL, manager.GetActiveWorkspace());
93 } 162 }
94 163
95 class WorkspaceTest : public WorkspaceManagerTestBase { 164 class WorkspaceTest : public WorkspaceManagerTestBase {
96 }; 165 };
97 166
98 TEST_F(WorkspaceTest, WorkspaceBasic) { 167 TEST_F(WorkspaceTest, WorkspaceBasic) {
99 WorkspaceManager manager; 168 WorkspaceManager manager(viewport());
100 169
101 Workspace* ws = manager.CreateWorkspace(); 170 Workspace* ws = manager.CreateWorkspace();
102 // Sanity check 171 // Sanity check
103 EXPECT_TRUE(ws->is_empty()); 172 EXPECT_TRUE(ws->is_empty());
104 173
105 scoped_ptr<Window> w1(CreateTestWindow()); 174 scoped_ptr<Window> w1(CreateTestWindow());
106 scoped_ptr<Window> w2(CreateTestWindow()); 175 scoped_ptr<Window> w2(CreateTestWindow());
107 scoped_ptr<Window> w3(CreateTestWindow()); 176 scoped_ptr<Window> w3(CreateTestWindow());
108 w1->Init(); 177 w1->Init();
109 w2->Init(); 178 w2->Init();
(...skipping 27 matching lines...) Expand all
137 EXPECT_EQ(0, ws->GetIndexOf(w2.get())); 206 EXPECT_EQ(0, ws->GetIndexOf(w2.get()));
138 EXPECT_FALSE(ws->Contains(w1.get())); 207 EXPECT_FALSE(ws->Contains(w1.get()));
139 208
140 // Add w1 back. w1 now has index = 1. 209 // Add w1 back. w1 now has index = 1.
141 EXPECT_TRUE(ws->AddWindowAfter(w1.get(), w2.get())); 210 EXPECT_TRUE(ws->AddWindowAfter(w1.get(), w2.get()));
142 EXPECT_EQ(0, ws->GetIndexOf(w2.get())); 211 EXPECT_EQ(0, ws->GetIndexOf(w2.get()));
143 EXPECT_EQ(1, ws->GetIndexOf(w1.get())); 212 EXPECT_EQ(1, ws->GetIndexOf(w1.get()));
144 } 213 }
145 214
146 } // namespace aura_shell 215 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/workspace/workspace_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698