OLD | NEW |
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_layout_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/property_util.h" |
11 #include "ash/wm/shelf_layout_manager.h" | 11 #include "ash/wm/shelf_layout_manager.h" |
12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 13 #include "ui/aura/client/aura_constants.h" |
13 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
14 #include "ui/aura/test/test_windows.h" | 15 #include "ui/aura/test/test_windows.h" |
15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
16 #include "ui/gfx/insets.h" | 17 #include "ui/gfx/insets.h" |
17 | 18 |
18 namespace ash { | 19 namespace ash { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 class WorkspaceLayoutManagerTest : public test::AshTestBase { | 23 typedef test::AshTestBase WorkspaceLayoutManagerTest; |
23 public: | |
24 WorkspaceLayoutManagerTest() {} | |
25 virtual ~WorkspaceLayoutManagerTest() {} | |
26 | |
27 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | |
28 return aura::test::CreateTestWindowWithBounds(bounds, NULL); | |
29 } | |
30 | |
31 private: | |
32 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerTest); | |
33 }; | |
34 | 24 |
35 // Verifies that a window containing a restore coordinate will be restored to | 25 // Verifies that a window containing a restore coordinate will be restored to |
36 // to the size prior to minimize, keeping the restore rectangle in tact (if | 26 // to the size prior to minimize, keeping the restore rectangle in tact (if |
37 // there is one). | 27 // there is one). |
38 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { | 28 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { |
39 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 29 scoped_ptr<aura::Window> window( |
| 30 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
40 gfx::Rect bounds(10, 15, 25, 35); | 31 gfx::Rect bounds(10, 15, 25, 35); |
41 window->SetBounds(bounds); | 32 window->SetBounds(bounds); |
42 SetRestoreBoundsInScreen(window.get(), gfx::Rect(0, 0, 100, 100)); | 33 SetRestoreBoundsInScreen(window.get(), gfx::Rect(0, 0, 100, 100)); |
43 wm::MinimizeWindow(window.get()); | 34 wm::MinimizeWindow(window.get()); |
44 wm::RestoreWindow(window.get()); | 35 wm::RestoreWindow(window.get()); |
45 EXPECT_EQ("0,0 100x100", GetRestoreBoundsInScreen(window.get())->ToString()); | 36 EXPECT_EQ("0,0 100x100", GetRestoreBoundsInScreen(window.get())->ToString()); |
46 EXPECT_EQ("10,15 25x35", window.get()->bounds().ToString()); | 37 EXPECT_EQ("10,15 25x35", window.get()->bounds().ToString()); |
47 } | 38 } |
48 | 39 |
49 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. | 40 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // doesn't effect the restore bounds. | 76 // doesn't effect the restore bounds. |
86 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { | 77 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { |
87 DontClobberRestoreBoundsWindowObserver window_observer; | 78 DontClobberRestoreBoundsWindowObserver window_observer; |
88 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 79 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
89 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 80 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
90 window->Init(ui::LAYER_TEXTURED); | 81 window->Init(ui::LAYER_TEXTURED); |
91 window->SetBounds(gfx::Rect(10, 20, 30, 40)); | 82 window->SetBounds(gfx::Rect(10, 20, 30, 40)); |
92 // NOTE: for this test to exercise the failure the observer needs to be added | 83 // NOTE: for this test to exercise the failure the observer needs to be added |
93 // before the parent set. This mimics what BrowserFrameAura does. | 84 // before the parent set. This mimics what BrowserFrameAura does. |
94 window->AddObserver(&window_observer); | 85 window->AddObserver(&window_observer); |
95 window->SetParent(NULL); | 86 SetDefaultParentByPrimaryRootWindow(window.get()); |
96 window->Show(); | 87 window->Show(); |
97 ash::wm::ActivateWindow(window.get()); | 88 ash::wm::ActivateWindow(window.get()); |
98 | 89 |
99 scoped_ptr<aura::Window> window2(CreateTestWindow(gfx::Rect(12, 20, 30, 40))); | 90 scoped_ptr<aura::Window> window2( |
| 91 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40))); |
100 window->AddTransientChild(window2.get()); | 92 window->AddTransientChild(window2.get()); |
101 window2->Show(); | 93 window2->Show(); |
102 | 94 |
103 window_observer.set_window(window2.get()); | 95 window_observer.set_window(window2.get()); |
104 wm::MaximizeWindow(window.get()); | 96 wm::MaximizeWindow(window.get()); |
105 EXPECT_EQ("10,20 30x40", GetRestoreBoundsInScreen(window.get())->ToString()); | 97 EXPECT_EQ("10,20 30x40", GetRestoreBoundsInScreen(window.get())->ToString()); |
106 window->RemoveObserver(&window_observer); | 98 window->RemoveObserver(&window_observer); |
107 } | 99 } |
108 | 100 |
109 // Verifies when a window is maximized all descendant windows have a size. | 101 // Verifies when a window is maximized all descendant windows have a size. |
110 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { | 102 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { |
111 scoped_ptr<aura::Window> window( | 103 scoped_ptr<aura::Window> window( |
112 CreateTestWindow(gfx::Rect(10, 20, 30, 40))); | 104 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40))); |
113 window->Show(); | 105 window->Show(); |
114 ash::wm::ActivateWindow(window.get()); | 106 ash::wm::ActivateWindow(window.get()); |
115 scoped_ptr<aura::Window> child_window( | 107 scoped_ptr<aura::Window> child_window( |
116 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), | 108 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), |
117 window.get())); | 109 window.get())); |
118 child_window->Show(); | 110 child_window->Show(); |
119 ash::wm::MaximizeWindow(window.get()); | 111 ash::wm::MaximizeWindow(window.get()); |
120 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); | 112 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); |
121 } | 113 } |
122 | 114 |
123 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { | 115 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { |
124 // Normal window bounds shouldn't be changed. | 116 // Normal window bounds shouldn't be changed. |
125 gfx::Rect window_bounds(100, 100, 200, 200); | 117 gfx::Rect window_bounds(100, 100, 200, 200); |
126 scoped_ptr<aura::Window> window(CreateTestWindow(window_bounds)); | 118 scoped_ptr<aura::Window> window( |
| 119 CreateTestWindowInShellWithBounds(window_bounds)); |
127 EXPECT_EQ(window_bounds, window->bounds()); | 120 EXPECT_EQ(window_bounds, window->bounds()); |
128 | 121 |
129 // If the window is out of the workspace, it would be moved on screen. | 122 // If the window is out of the workspace, it would be moved on screen. |
130 gfx::Rect root_window_bounds = | 123 gfx::Rect root_window_bounds = |
131 ash::Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); | 124 ash::Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); |
132 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); | 125 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); |
133 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); | 126 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); |
134 scoped_ptr<aura::Window> out_window(CreateTestWindow(window_bounds)); | 127 scoped_ptr<aura::Window> out_window( |
| 128 CreateTestWindowInShellWithBounds(window_bounds)); |
135 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); | 129 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); |
136 EXPECT_TRUE(out_window->bounds().Intersects(root_window_bounds)); | 130 EXPECT_TRUE(out_window->bounds().Intersects(root_window_bounds)); |
137 } | 131 } |
138 | 132 |
139 // Verifies the size of a window is enforced to be smaller than the work area. | 133 // Verifies the size of a window is enforced to be smaller than the work area. |
140 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { | 134 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { |
141 // Normal window bounds shouldn't be changed. | 135 // Normal window bounds shouldn't be changed. |
142 gfx::Size work_area( | 136 gfx::Size work_area( |
143 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size()); | 137 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size()); |
144 const gfx::Rect window_bounds( | 138 const gfx::Rect window_bounds( |
145 100, 101, work_area.width() + 1, work_area.height() + 2); | 139 100, 101, work_area.width() + 1, work_area.height() + 2); |
146 scoped_ptr<aura::Window> window(CreateTestWindow(window_bounds)); | 140 scoped_ptr<aura::Window> window( |
| 141 CreateTestWindowInShellWithBounds(window_bounds)); |
147 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 142 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
148 window->bounds().ToString()); | 143 window->bounds().ToString()); |
149 | 144 |
150 // Directly setting the bounds triggers a slightly different code path. Verify | 145 // Directly setting the bounds triggers a slightly different code path. Verify |
151 // that too. | 146 // that too. |
152 window->SetBounds(window_bounds); | 147 window->SetBounds(window_bounds); |
153 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 148 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
154 window->bounds().ToString()); | 149 window->bounds().ToString()); |
155 } | 150 } |
156 | 151 |
157 } // namespace | 152 } // namespace |
158 } // namespace ash | 153 } // namespace ash |
OLD | NEW |