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

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

Issue 11201002: Removes worskpace 1 code. Will rename next. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove more code 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/workspace/workspace_manager.h"
6
7 #include "ash/ash_switches.h"
8 #include "ash/screen_ash.h"
9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/wm/activation_controller.h"
13 #include "ash/wm/property_util.h"
14 #include "ash/wm/shelf_layout_manager.h"
15 #include "ash/wm/window_util.h"
16 #include "ash/wm/workspace/workspace.h"
17 #include "ash/wm/workspace/workspace_layout_manager.h"
18 #include "ash/wm/workspace_controller_test_helper.h"
19 #include "base/command_line.h"
20 #include "ui/aura/client/aura_constants.h"
21 #include "ui/aura/root_window.h"
22 #include "ui/aura/test/event_generator.h"
23 #include "ui/aura/window.h"
24 #include "ui/base/ui_base_types.h"
25 #include "ui/compositor/layer.h"
26 #include "ui/gfx/screen.h"
27
28 using aura::Window;
29
30 namespace ash {
31 namespace internal {
32
33 namespace {
34
35 bool GetWindowOverlapsShelf() {
36 return Shell::GetInstance()->shelf()->window_overlaps_shelf();
37 }
38
39 } // namespace
40
41 class WorkspaceManagerTest : public test::AshTestBase {
42 public:
43 WorkspaceManagerTest() : manager_(NULL) {}
44 virtual ~WorkspaceManagerTest() {}
45
46 aura::Window* CreateTestWindowUnparented() {
47 aura::Window* window = new aura::Window(NULL);
48 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
49 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
50 window->Init(ui::LAYER_TEXTURED);
51 return window;
52 }
53
54 aura::Window* CreateTestWindow() {
55 aura::Window* window = new aura::Window(NULL);
56 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
57 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
58 window->Init(ui::LAYER_TEXTURED);
59 window->SetParent(GetViewport());
60 return window;
61 }
62
63 aura::Window* GetViewport() {
64 return Shell::GetContainer(
65 Shell::GetPrimaryRootWindow(),
66 kShellWindowId_DefaultContainer);
67 }
68
69 const std::vector<Workspace*>& workspaces() const {
70 return manager_->workspaces_;
71 }
72
73 gfx::Rect GetFullscreenBounds(aura::Window* window) {
74 return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds();
75 }
76
77 Workspace* active_workspace() {
78 return manager_->active_workspace_;
79 }
80
81 Workspace* FindBy(aura::Window* window) const {
82 return manager_->FindBy(window);
83 }
84
85 // Overridden from AshTestBase:
86 virtual void SetUp() OVERRIDE {
87 CommandLine::ForCurrentProcess()->AppendSwitch(
88 switches::kAshDisableWorkspace2);
89 test::AshTestBase::SetUp();
90 WorkspaceControllerTestHelper workspace_helper(
91 Shell::TestApi(Shell::GetInstance()).workspace_controller());
92 manager_ = workspace_helper.workspace_manager();
93 }
94 virtual void TearDown() OVERRIDE {
95 manager_ = NULL;
96 test::AshTestBase::TearDown();
97 }
98
99 protected:
100 WorkspaceManager* manager_;
101
102 private:
103 scoped_ptr<ActivationController> activation_controller_;
104
105 DISALLOW_COPY_AND_ASSIGN(WorkspaceManagerTest);
106 };
107
108 // Assertions around adding a normal window.
109 TEST_F(WorkspaceManagerTest, AddNormalWindowWhenEmpty) {
110 scoped_ptr<Window> w1(CreateTestWindow());
111 w1->SetBounds(gfx::Rect(0, 0, 250, 251));
112
113 ASSERT_TRUE(manager_->ShouldManageWindow(w1.get()));
114 EXPECT_FALSE(FindBy(w1.get()));
115
116 EXPECT_TRUE(GetRestoreBoundsInScreen(w1.get()) == NULL);
117
118 w1->Show();
119
120 EXPECT_TRUE(GetRestoreBoundsInScreen(w1.get()) == NULL);
121
122 ASSERT_TRUE(w1->layer() != NULL);
123 EXPECT_TRUE(w1->layer()->visible());
124
125 EXPECT_EQ(250, w1->bounds().width());
126 EXPECT_EQ(251, w1->bounds().height());
127
128 // Should be 1 workspace, TYPE_NORNMAL with w1.
129 ASSERT_EQ(1u, workspaces().size());
130 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
131 ASSERT_EQ(1u, workspaces()[0]->windows().size());
132 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
133 }
134
135 // Assertions around maximizing/unmaximizing.
136 TEST_F(WorkspaceManagerTest, SingleMaximizeWindow) {
137 scoped_ptr<Window> w1(CreateTestWindow());
138 w1->SetBounds(gfx::Rect(0, 0, 250, 251));
139
140 ASSERT_TRUE(manager_->ShouldManageWindow(w1.get()));
141
142 w1->Show();
143
144 ASSERT_TRUE(w1->layer() != NULL);
145 EXPECT_TRUE(w1->layer()->visible());
146
147 EXPECT_EQ(250, w1->bounds().width());
148 EXPECT_EQ(251, w1->bounds().height());
149
150 // Maximize the window.
151 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
152
153 // Should be 2 workspaces, the second TYPE_MAXIMIZED with w1.
154 ASSERT_EQ(2u, workspaces().size());
155 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
156 ASSERT_EQ(1u, workspaces()[1]->windows().size());
157 EXPECT_EQ(w1.get(), workspaces()[1]->windows()[0]);
158 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get()).width(),
159 w1->bounds().width());
160 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get()).height(),
161 w1->bounds().height());
162
163 // Restore the window.
164 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
165
166 // Should be 1 workspace, TYPE_MANAGED with w1.
167 ASSERT_EQ(1u, workspaces().size());
168 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
169 ASSERT_EQ(1u, workspaces()[0]->windows().size());
170 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
171 EXPECT_EQ(250, w1->bounds().width());
172 EXPECT_EQ(251, w1->bounds().height());
173 }
174
175 // Assertions around closing the last window in a workspace.
176 TEST_F(WorkspaceManagerTest, CloseLastWindowInWorkspace) {
177 scoped_ptr<Window> w1(CreateTestWindow());
178 scoped_ptr<Window> w2(CreateTestWindow());
179 w1->SetBounds(gfx::Rect(0, 0, 250, 251));
180 w1->Show();
181 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
182 w2->Show();
183
184 // Should be 2 workspaces, TYPE_NORMAL with w1, and TYPE_MAXIMIZED with w2.
185 ASSERT_EQ(2u, workspaces().size());
186 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
187 ASSERT_EQ(1u, workspaces()[0]->windows().size());
188 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
189 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
190 ASSERT_EQ(1u, workspaces()[1]->windows().size());
191 EXPECT_EQ(w2.get(), workspaces()[1]->windows()[0]);
192 EXPECT_FALSE(w1->layer()->visible());
193 EXPECT_TRUE(w2->layer()->visible());
194 // TYPE_MAXIMIZED workspace should be active.
195 EXPECT_EQ(workspaces()[1], active_workspace());
196
197 // Close w2.
198 w2.reset();
199
200 // Should have one workspace, TYPE_NORMAL with w1.
201 ASSERT_EQ(1u, workspaces().size());
202 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
203 ASSERT_EQ(1u, workspaces()[0]->windows().size());
204 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
205 EXPECT_TRUE(w1->layer()->visible());
206 EXPECT_EQ(workspaces()[0], active_workspace());
207 }
208
209 // Assertions around adding a maximized window when empty.
210 TEST_F(WorkspaceManagerTest, AddMaximizedWindowWhenEmpty) {
211 scoped_ptr<Window> w1(CreateTestWindow());
212 w1->SetBounds(gfx::Rect(0, 0, 250, 251));
213 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
214 w1->Show();
215
216 ASSERT_TRUE(w1->layer() != NULL);
217 EXPECT_TRUE(w1->layer()->visible());
218 gfx::Rect work_area(
219 ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get()));
220 EXPECT_EQ(work_area.width(), w1->bounds().width());
221 EXPECT_EQ(work_area.height(), w1->bounds().height());
222
223 // Should be 1 workspace, TYPE_NORNMAL with w1.
224 ASSERT_EQ(1u, workspaces().size());
225 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[0]->type());
226 ASSERT_EQ(1u, workspaces()[0]->windows().size());
227 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
228 }
229
230 // Assertions around two windows and toggling one to be maximized.
231 TEST_F(WorkspaceManagerTest, MaximizeWithNormalWindow) {
232 scoped_ptr<Window> w1(CreateTestWindow());
233 scoped_ptr<Window> w2(CreateTestWindow());
234 w1->SetBounds(gfx::Rect(0, 0, 250, 251));
235 w1->Show();
236
237 ASSERT_TRUE(w1->layer() != NULL);
238 EXPECT_TRUE(w1->layer()->visible());
239
240 w2->SetBounds(gfx::Rect(0, 0, 50, 51));
241 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
242 w2->Show();
243
244 // Should now be two workspaces.
245 ASSERT_EQ(2u, workspaces().size());
246 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
247 ASSERT_EQ(1u, workspaces()[0]->windows().size());
248 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
249 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
250 ASSERT_EQ(1u, workspaces()[1]->windows().size());
251 EXPECT_EQ(w2.get(), workspaces()[1]->windows()[0]);
252 ASSERT_TRUE(w1->layer() != NULL);
253 EXPECT_FALSE(w1->layer()->visible());
254 ASSERT_TRUE(w2->layer() != NULL);
255 EXPECT_TRUE(w2->layer()->visible());
256
257 gfx::Rect work_area(ScreenAsh::GetMaximizedWindowBoundsInParent(w1.get()));
258 EXPECT_EQ(work_area.width(), w2->bounds().width());
259 EXPECT_EQ(work_area.height(), w2->bounds().height());
260
261 // Restore w2, which should then go back to one workspace.
262 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
263 ASSERT_EQ(1u, workspaces().size());
264 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
265 ASSERT_EQ(2u, workspaces()[0]->windows().size());
266 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
267 EXPECT_EQ(w2.get(), workspaces()[0]->windows()[1]);
268 EXPECT_EQ(50, w2->bounds().width());
269 EXPECT_EQ(51, w2->bounds().height());
270 ASSERT_TRUE(w1->layer() != NULL);
271 EXPECT_TRUE(w1->layer()->visible());
272 ASSERT_TRUE(w2->layer() != NULL);
273 EXPECT_TRUE(w2->layer()->visible());
274 }
275
276 // Assertions around two maximized windows.
277 TEST_F(WorkspaceManagerTest, TwoMaximized) {
278 scoped_ptr<Window> w1(CreateTestWindow());
279 scoped_ptr<Window> w2(CreateTestWindow());
280 w1->SetBounds(gfx::Rect(0, 0, 250, 251));
281 w1->Show();
282 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
283
284 w2->SetBounds(gfx::Rect(0, 0, 50, 51));
285 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
286 w2->Show();
287
288 // Should now be three workspaces.
289 ASSERT_EQ(3u, workspaces().size());
290 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
291 ASSERT_EQ(1u, workspaces()[1]->windows().size());
292 EXPECT_EQ(w1.get(), workspaces()[1]->windows()[0]);
293 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[2]->type());
294 ASSERT_EQ(1u, workspaces()[2]->windows().size());
295 EXPECT_EQ(w2.get(), workspaces()[2]->windows()[0]);
296 ASSERT_TRUE(w1->layer() != NULL);
297 EXPECT_FALSE(w1->layer()->visible());
298 ASSERT_TRUE(w2->layer() != NULL);
299 EXPECT_TRUE(w2->layer()->visible());
300 }
301
302 // Makes sure requests to change the bounds of a normal window go through.
303 TEST_F(WorkspaceManagerTest, ChangeBoundsOfNormalWindow) {
304 scoped_ptr<Window> w1(CreateTestWindow());
305 w1->Show();
306
307 EXPECT_TRUE(manager_->ShouldManageWindow(w1.get()));
308 // Setting the bounds should go through since the window is in the normal
309 // workspace.
310 w1->SetBounds(gfx::Rect(0, 0, 200, 500));
311 EXPECT_EQ(200, w1->bounds().width());
312 EXPECT_EQ(500, w1->bounds().height());
313 }
314
315 // Assertions around grid size.
316 TEST_F(WorkspaceManagerTest, SnapToGrid) {
317 // Verify snap to grid when bounds are set before parented.
318 scoped_ptr<Window> w1(CreateTestWindowUnparented());
319 w1->SetBounds(gfx::Rect(1, 6, 25, 30));
320 w1->SetParent(GetViewport());
321 // We are not aligning this anymore this way. When the window gets shown
322 // the window is expected to be handled differently, but this cannot be
323 // tested with this test. So the result of this test should be that the
324 // bounds are exactly as passed in.
325 EXPECT_EQ(gfx::Rect(1, 6, 25, 30), w1->bounds());
326 }
327
328 // Assertions around a fullscreen window.
329 TEST_F(WorkspaceManagerTest, SingleFullscreenWindow) {
330 scoped_ptr<Window> w1(CreateTestWindow());
331 w1->SetBounds(gfx::Rect(0, 0, 250, 251));
332 // Make the window fullscreen.
333 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
334 w1->Show();
335
336 // Should be 1 workspace, TYPE_MAXIMIZED with w1.
337 ASSERT_EQ(1u, workspaces().size());
338 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[0]->type());
339 ASSERT_EQ(1u, workspaces()[0]->windows().size());
340 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
341 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width());
342 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height());
343
344 // Restore the window. Use SHOW_STATE_DEFAULT as that is what we'll end up
345 // with when using views::Widget.
346 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DEFAULT);
347 EXPECT_EQ("0,0 250x251", w1->bounds().ToString());
348
349 // Should be 1 workspace, TYPE_MANAGED with w1.
350 ASSERT_EQ(1u, workspaces().size());
351 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
352 ASSERT_EQ(1u, workspaces()[0]->windows().size());
353 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
354 EXPECT_EQ(250, w1->bounds().width());
355 EXPECT_EQ(251, w1->bounds().height());
356
357 // Back to fullscreen.
358 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
359 ASSERT_EQ(2u, workspaces().size());
360 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
361 ASSERT_EQ(1u, workspaces()[1]->windows().size());
362 EXPECT_EQ(w1.get(), workspaces()[1]->windows()[0]);
363 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width());
364 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height());
365 ASSERT_TRUE(GetRestoreBoundsInScreen(w1.get()));
366 EXPECT_EQ(gfx::Rect(0, 0, 250, 251), *GetRestoreBoundsInScreen(w1.get()));
367 }
368
369 // Makes sure switching workspaces doesn't show transient windows.
370 TEST_F(WorkspaceManagerTest, DontShowTransientsOnSwitch) {
371 scoped_ptr<Window> w1(CreateTestWindow());
372 scoped_ptr<Window> w2(CreateTestWindow());
373
374 w1->SetBounds(gfx::Rect(0, 0, 250, 251));
375 w2->SetBounds(gfx::Rect(0, 0, 250, 251));
376 w1->AddTransientChild(w2.get());
377
378 w1->Show();
379
380 scoped_ptr<Window> w3(CreateTestWindow());
381 w3->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
382 w3->Show();
383
384 EXPECT_FALSE(w1->layer()->IsDrawn());
385 EXPECT_FALSE(w2->layer()->IsDrawn());
386 EXPECT_TRUE(w3->layer()->IsDrawn());
387
388 w1->Show();
389 EXPECT_TRUE(w1->layer()->IsDrawn());
390 EXPECT_FALSE(w2->layer()->IsDrawn());
391 EXPECT_FALSE(w3->layer()->IsDrawn());
392 }
393
394 // Assertions around minimizing a single window.
395 TEST_F(WorkspaceManagerTest, MinimizeSingleWindow) {
396 scoped_ptr<Window> w1(CreateTestWindow());
397
398 w1->Show();
399 ASSERT_EQ(1u, workspaces().size());
400 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
401
402 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
403 ASSERT_EQ(1u, workspaces().size());
404 EXPECT_FALSE(w1->layer()->IsDrawn());
405
406 // Show the window.
407 w1->Show();
408 EXPECT_TRUE(wm::IsWindowNormal(w1.get()));
409 ASSERT_EQ(1u, workspaces().size());
410 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
411 EXPECT_TRUE(w1->layer()->IsDrawn());
412 }
413
414 // Assertions around minimizing a maximized window.
415 TEST_F(WorkspaceManagerTest, MinimizeMaximizedWindow) {
416 // Two windows, w1 normal, w2 maximized.
417 scoped_ptr<Window> w1(CreateTestWindow());
418 scoped_ptr<Window> w2(CreateTestWindow());
419 w1->Show();
420 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
421 w2->Show();
422 ASSERT_EQ(2u, workspaces().size());
423 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
424 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
425
426 // Minimize w2.
427 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
428 ASSERT_EQ(1u, workspaces().size());
429 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
430 EXPECT_TRUE(w1->layer()->IsDrawn());
431 EXPECT_FALSE(w2->layer()->IsDrawn());
432
433 // Show the window, which should trigger unminimizing.
434 w2->Show();
435 EXPECT_TRUE(wm::IsWindowMaximized(w2.get()));
436 ASSERT_EQ(2u, workspaces().size());
437 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
438 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
439 EXPECT_FALSE(w1->layer()->IsDrawn());
440 EXPECT_TRUE(w2->layer()->IsDrawn());
441
442 // Make it active and minimize the window, which should hide the window and
443 // activate another.
444 wm::ActivateWindow(w2.get());
445 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
446 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
447 EXPECT_FALSE(wm::IsActiveWindow(w2.get()));
448 EXPECT_FALSE(w2->layer()->IsDrawn());
449 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
450
451 // Make the window normal.
452 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
453 ASSERT_EQ(1u, workspaces().size());
454 EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
455 ASSERT_EQ(2u, workspaces()[0]->windows().size());
456 EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
457 EXPECT_EQ(w2.get(), workspaces()[0]->windows()[1]);
458 EXPECT_TRUE(w2->layer()->IsDrawn());
459 }
460
461 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly
462 // updated.
463 TEST_F(WorkspaceManagerTest, ShelfStateUpdated) {
464 // Since ShelfLayoutManager queries for mouse location, move the mouse so
465 // it isn't over the shelf.
466 aura::test::EventGenerator generator(
467 Shell::GetPrimaryRootWindow(), gfx::Point());
468 generator.MoveMouseTo(0, 0);
469
470 // Two windows, w1 normal, w2 maximized.
471 scoped_ptr<Window> w1(CreateTestWindow());
472 const gfx::Rect w1_bounds(0, 1, 101, 102);
473 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
474 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
475 const gfx::Rect touches_shelf_bounds(
476 0, shelf->GetIdealBounds().y() - 10, 101, 102);
477 // Move |w1| to overlap the shelf.
478 w1->SetBounds(touches_shelf_bounds);
479 EXPECT_FALSE(GetWindowOverlapsShelf());
480
481 // A visible ignored window should not trigger the overlap.
482 scoped_ptr<Window> w_ignored(CreateTestWindow());
483 w_ignored->SetBounds(touches_shelf_bounds);
484 SetIgnoredByShelf(&(*w_ignored), true);
485 w_ignored->Show();
486 EXPECT_FALSE(GetWindowOverlapsShelf());
487
488 // Make it visible, since visible shelf overlaps should be true.
489 w1->Show();
490 EXPECT_TRUE(GetWindowOverlapsShelf());
491
492 wm::ActivateWindow(w1.get());
493 w1->SetBounds(w1_bounds);
494 w1->Show();
495 wm::ActivateWindow(w1.get());
496
497 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
498
499 // Maximize the window.
500 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
501 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
502 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
503
504 // Restore.
505 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
506 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
507 EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
508
509 // Fullscreen.
510 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
511 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
512
513 // Normal.
514 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
515 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
516 EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
517
518 // Maximize again.
519 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
520 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
521 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
522
523 // Minimize.
524 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
525 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
526
527 // Restore.
528 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
529 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
530 EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
531
532 // Create another window, maximized.
533 scoped_ptr<Window> w2(CreateTestWindow());
534 w2->SetBounds(gfx::Rect(10, 11, 250, 251));
535 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
536 w2->Show();
537 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
538 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
539 EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
540
541 // Switch to w1.
542 w1->Show();
543 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
544 EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
545 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w2.get()).ToString(),
546 w2->bounds().ToString());
547
548 // Switch to w2.
549 w2->Show();
550 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state());
551 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
552 EXPECT_EQ("0,1 101x102", w1->bounds().ToString());
553 EXPECT_EQ(ScreenAsh::GetMaximizedWindowBoundsInParent(w2.get()).ToString(),
554 w2->bounds().ToString());
555 }
556
557 // Verifies persist across all workspaces.
558 TEST_F(WorkspaceManagerTest, PersistAcrossAllWorkspaces) {
559 // Create a maximized window.
560 scoped_ptr<Window> w1(CreateTestWindow());
561 w1->Show();
562 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
563 EXPECT_TRUE(w1->layer()->IsDrawn());
564 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, active_workspace()->type());
565
566 // Create a window that persists across all workspaces, it should be visible
567 // even while in a maximized workspace.
568 scoped_ptr<Window> w2(CreateTestWindow());
569 SetPersistsAcrossAllWorkspaces(
570 w2.get(),
571 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
572 w2->Show();
573 wm::ActivateWindow(w2.get());
574 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, active_workspace()->type());
575 EXPECT_TRUE(std::find(active_workspace()->windows().begin(),
576 active_workspace()->windows().end(), w2.get()) ==
577 active_workspace()->windows().end());
578 EXPECT_TRUE(w1->layer()->IsDrawn());
579 EXPECT_TRUE(w2->layer()->IsDrawn());
580
581 // Activate the maximized window, w1, ensure w2 is still visible.
582 wm::ActivateWindow(w1.get());
583 EXPECT_EQ(Workspace::TYPE_MAXIMIZED, active_workspace()->type());
584 EXPECT_TRUE(w1->layer()->IsDrawn());
585 EXPECT_TRUE(w2->layer()->IsDrawn());
586
587 // Create another window (normal) and show/activate it. w1 (maximized window)
588 // should hide, but w2 should still be visible since it persists across all
589 // windows.
590 scoped_ptr<Window> w3(CreateTestWindow());
591 w3->Show();
592 wm::ActivateWindow(w3.get());
593 EXPECT_EQ(Workspace::TYPE_MANAGED, active_workspace()->type());
594 EXPECT_FALSE(w1->layer()->IsDrawn());
595 EXPECT_TRUE(w2->layer()->IsDrawn());
596 EXPECT_TRUE(w3->layer()->IsDrawn());
597
598 // Activate w2 again, shouldn't switch workspaces.
599 wm::ActivateWindow(w2.get());
600 EXPECT_EQ(Workspace::TYPE_MANAGED, active_workspace()->type());
601 EXPECT_FALSE(w1->layer()->IsDrawn());
602 EXPECT_TRUE(w2->layer()->IsDrawn());
603 EXPECT_TRUE(w3->layer()->IsDrawn());
604 }
605
606 // Verifies Show()ing a minimized window that persists across all workspaces
607 // unminimizes the window.
608 TEST_F(WorkspaceManagerTest, ShowMinimizedPersistWindow) {
609 // Create a window that persists across all workspaces.
610 scoped_ptr<Window> w1(CreateTestWindow());
611 SetPersistsAcrossAllWorkspaces(
612 w1.get(),
613 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
614 w1->Show();
615 wm::ActivateWindow(w1.get());
616 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
617 EXPECT_FALSE(w1->IsVisible());
618 w1->Show();
619 EXPECT_TRUE(w1->IsVisible());
620 }
621
622 // Test that we report we're in the fullscreen state even if the fullscreen
623 // window isn't being managed by us (http://crbug.com/123931).
624 TEST_F(WorkspaceManagerTest, GetWindowStateWithUnmanagedFullscreenWindow) {
625 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
626
627 // We need to create a regular window first so there's an active workspace.
628 scoped_ptr<Window> w1(CreateTestWindow());
629 w1->Show();
630
631 scoped_ptr<Window> w2(CreateTestWindow());
632 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
633 SetPersistsAcrossAllWorkspaces(
634 w2.get(),
635 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
636 w2->Show();
637
638 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
639 ASSERT_FALSE(manager_->ShouldManageWindow(w2.get()));
640 EXPECT_EQ(WORKSPACE_WINDOW_STATE_FULL_SCREEN,
641 manager_->GetWindowState());
642
643 w2->Hide();
644 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
645
646 w2->Show();
647 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
648
649 w2.reset();
650 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
651 }
652
653 // Variant of GetWindowStateWithUnmanagedFullscreenWindow that uses a maximized
654 // window rather than a normal window.
655 TEST_F(WorkspaceManagerTest,
656 GetWindowStateWithUnmanagedFullscreenWindowWithMaximized) {
657 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
658 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
659
660 // Make the first window maximized.
661 scoped_ptr<Window> w1(CreateTestWindow());
662 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
663 w1->Show();
664
665 scoped_ptr<Window> w2(CreateTestWindow());
666 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
667 SetPersistsAcrossAllWorkspaces(
668 w2.get(),
669 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
670 w2->Show();
671
672 // Even though auto-hide behavior is NEVER full-screen windows cause the shelf
673 // to hide.
674 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
675 ASSERT_FALSE(manager_->ShouldManageWindow(w2.get()));
676 EXPECT_EQ(WORKSPACE_WINDOW_STATE_FULL_SCREEN,
677 manager_->GetWindowState());
678
679 w2->Hide();
680 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
681
682 w2->Show();
683 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state());
684 EXPECT_EQ(WORKSPACE_WINDOW_STATE_FULL_SCREEN,
685 manager_->GetWindowState());
686
687 w2.reset();
688 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state());
689 }
690
691 // Makes sure that if animations are disabled on a window they don't get reset
692 // when switching workspaces.
693 TEST_F(WorkspaceManagerTest, DontResetAnimation) {
694 scoped_ptr<Window> w1(CreateTestWindow());
695 scoped_ptr<Window> w2(CreateTestWindow());
696
697 w1->Show();
698 w1->SetProperty(aura::client::kAnimationsDisabledKey, true);
699
700 w2->Show();
701 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
702 EXPECT_TRUE(w1->GetProperty(aura::client::kAnimationsDisabledKey));
703 }
704
705 // Verifies a window marked as persisting across all workspaces ends up in its
706 // own workspace when maximized.
707 TEST_F(WorkspaceManagerTest, MaximizeDontPersistEndsUpInOwnWorkspace) {
708 scoped_ptr<Window> w1(CreateTestWindow());
709
710 SetPersistsAcrossAllWorkspaces(
711 w1.get(),
712 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
713 w1->Show();
714
715 // Shouldn't contain the window initially.
716 EXPECT_FALSE(manager_->Contains(w1.get()));
717
718 // Maximize should trigger containing the window.
719 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
720 EXPECT_TRUE(manager_->Contains(w1.get()));
721
722 // And resetting to normal should remove it.
723 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
724 EXPECT_FALSE(manager_->Contains(w1.get()));
725 }
726
727 // Verifies going from maximized to minimized sets the right state for painting
728 // the background of the launcher.
729 TEST_F(WorkspaceManagerTest, MinimizeResetsVisibility) {
730 scoped_ptr<Window> w1(CreateTestWindow());
731 w1->Show();
732 wm::ActivateWindow(w1.get());
733 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
734 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
735 EXPECT_EQ(ShelfLayoutManager::VISIBLE,
736 Shell::GetInstance()->shelf()->visibility_state());
737 EXPECT_FALSE(Shell::GetInstance()->launcher()->paints_background());
738 }
739
740 } // namespace internal
741 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698