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/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 // Make sure the unminimized window moves inside the display when | 55 // Make sure the unminimized window moves inside the display when |
56 // 2nd display is disconnected. | 56 // 2nd display is disconnected. |
57 wm::MinimizeWindow(window.get()); | 57 wm::MinimizeWindow(window.get()); |
58 UpdateDisplay("400x300"); | 58 UpdateDisplay("400x300"); |
59 wm::RestoreWindow(window.get()); | 59 wm::RestoreWindow(window.get()); |
60 EXPECT_EQ(Shell::GetPrimaryRootWindow(), window->GetRootWindow()); | 60 EXPECT_EQ(Shell::GetPrimaryRootWindow(), window->GetRootWindow()); |
61 EXPECT_TRUE( | 61 EXPECT_TRUE( |
62 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 62 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); |
63 } | 63 } |
64 | 64 |
65 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { | |
66 scoped_ptr<aura::Window> window( | |
67 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | |
68 // Maximized -> Normal transition. | |
69 wm::MaximizeWindow(window.get()); | |
70 SetRestoreBoundsInScreen(window.get(), gfx::Rect(-100, -100, 30, 40)); | |
71 wm::RestoreWindow(window.get()); | |
72 EXPECT_TRUE( | |
73 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | |
74 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); | |
75 | |
76 // Minimized -> Normal transition. | |
77 window->SetBounds(gfx::Rect(-100, -100, 30, 40)); | |
78 wm::MinimizeWindow(window.get()); | |
79 EXPECT_FALSE( | |
80 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | |
81 EXPECT_EQ("-100,-100 30x40", window->bounds().ToString()); | |
82 window->Show(); | |
83 EXPECT_TRUE( | |
84 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | |
85 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); | |
86 | |
87 // Fullscreen -> Normal transition. | |
88 window->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds. | |
89 ASSERT_EQ("0,0 30x40", window->bounds().ToString()); | |
90 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
91 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds()); | |
92 SetRestoreBoundsInScreen(window.get(), gfx::Rect(-100, -100, 30, 40)); | |
93 wm::RestoreWindow(window.get()); | |
94 EXPECT_TRUE( | |
95 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | |
96 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); | |
97 } | |
98 | |
65 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. | 99 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. |
66 // This code mirrors what BrowserFrameAura does. In particular when this code | 100 // This code mirrors what BrowserFrameAura does. In particular when this code |
67 // sees the window was maximized it changes the bounds of a secondary | 101 // sees the window was maximized it changes the bounds of a secondary |
68 // window. The secondary window mirrors the status window. | 102 // window. The secondary window mirrors the status window. |
69 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver { | 103 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver { |
70 public: | 104 public: |
71 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {} | 105 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {} |
72 | 106 |
73 void set_window(aura::Window* window) { window_ = window; } | 107 void set_window(aura::Window* window) { window_ = window; } |
74 | 108 |
(...skipping 28 matching lines...) Expand all Loading... | |
103 DontClobberRestoreBoundsWindowObserver window_observer; | 137 DontClobberRestoreBoundsWindowObserver window_observer; |
104 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 138 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
105 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 139 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
106 window->Init(ui::LAYER_TEXTURED); | 140 window->Init(ui::LAYER_TEXTURED); |
107 window->SetBounds(gfx::Rect(10, 20, 30, 40)); | 141 window->SetBounds(gfx::Rect(10, 20, 30, 40)); |
108 // NOTE: for this test to exercise the failure the observer needs to be added | 142 // NOTE: for this test to exercise the failure the observer needs to be added |
109 // before the parent set. This mimics what BrowserFrameAura does. | 143 // before the parent set. This mimics what BrowserFrameAura does. |
110 window->AddObserver(&window_observer); | 144 window->AddObserver(&window_observer); |
111 SetDefaultParentByPrimaryRootWindow(window.get()); | 145 SetDefaultParentByPrimaryRootWindow(window.get()); |
112 window->Show(); | 146 window->Show(); |
113 ash::wm::ActivateWindow(window.get()); | 147 wm::ActivateWindow(window.get()); |
114 | 148 |
115 scoped_ptr<aura::Window> window2( | 149 scoped_ptr<aura::Window> window2( |
116 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40))); | 150 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40))); |
117 window->AddTransientChild(window2.get()); | 151 window->AddTransientChild(window2.get()); |
118 window2->Show(); | 152 window2->Show(); |
119 | 153 |
120 window_observer.set_window(window2.get()); | 154 window_observer.set_window(window2.get()); |
121 wm::MaximizeWindow(window.get()); | 155 wm::MaximizeWindow(window.get()); |
122 EXPECT_EQ("10,20 30x40", GetRestoreBoundsInScreen(window.get())->ToString()); | 156 EXPECT_EQ("10,20 30x40", GetRestoreBoundsInScreen(window.get())->ToString()); |
123 window->RemoveObserver(&window_observer); | 157 window->RemoveObserver(&window_observer); |
124 } | 158 } |
125 | 159 |
126 // Verifies when a window is maximized all descendant windows have a size. | 160 // Verifies when a window is maximized all descendant windows have a size. |
127 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { | 161 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { |
128 scoped_ptr<aura::Window> window( | 162 scoped_ptr<aura::Window> window( |
129 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40))); | 163 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40))); |
130 window->Show(); | 164 window->Show(); |
131 ash::wm::ActivateWindow(window.get()); | 165 wm::ActivateWindow(window.get()); |
132 scoped_ptr<aura::Window> child_window( | 166 scoped_ptr<aura::Window> child_window( |
133 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), | 167 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), |
134 window.get())); | 168 window.get())); |
135 child_window->Show(); | 169 child_window->Show(); |
136 ash::wm::MaximizeWindow(window.get()); | 170 wm::MaximizeWindow(window.get()); |
137 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); | 171 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); |
138 } | 172 } |
139 | 173 |
140 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { | 174 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { |
141 // Normal window bounds shouldn't be changed. | 175 // Normal window bounds shouldn't be changed. |
142 gfx::Rect window_bounds(100, 100, 200, 200); | 176 gfx::Rect window_bounds(100, 100, 200, 200); |
143 scoped_ptr<aura::Window> window( | 177 scoped_ptr<aura::Window> window( |
144 CreateTestWindowInShellWithBounds(window_bounds)); | 178 CreateTestWindowInShellWithBounds(window_bounds)); |
145 EXPECT_EQ(window_bounds, window->bounds()); | 179 EXPECT_EQ(window_bounds, window->bounds()); |
146 | 180 |
147 // If the window is out of the workspace, it would be moved on screen. | 181 // If the window is out of the workspace, it would be moved on screen. |
148 gfx::Rect root_window_bounds = | 182 gfx::Rect root_window_bounds = |
149 ash::Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); | 183 Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); |
150 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); | 184 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); |
151 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); | 185 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); |
152 scoped_ptr<aura::Window> out_window( | 186 scoped_ptr<aura::Window> out_window( |
153 CreateTestWindowInShellWithBounds(window_bounds)); | 187 CreateTestWindowInShellWithBounds(window_bounds)); |
154 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); | 188 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); |
155 gfx::Rect bounds = out_window->bounds(); | 189 gfx::Rect bounds = out_window->bounds(); |
156 bounds.Intersect(root_window_bounds); | 190 bounds.Intersect(root_window_bounds); |
157 // 2/3 of the window must be visible. | 191 |
158 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.6); | 192 // 30% of the window edge must be visible. |
159 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.6); | 193 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); |
194 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | |
195 | |
196 // Make sure we always make more than 1/3 of the window edge visible even | |
197 // if the initial bounds intersects with display. | |
198 window_bounds.SetRect(-150, -150, 200, 200); | |
199 bounds = window_bounds; | |
200 bounds.Intersect(root_window_bounds); | |
201 EXPECT_LT(bounds.width(), out_window->bounds().width() * 0.29); | |
James Cook
2013/08/07 00:36:32
Should these be EXPECT_LT(..., width * 0.3) instea
oshima
2013/08/07 16:56:45
This is to make sure that the initial bounds is po
| |
202 EXPECT_LT(bounds.height(), out_window->bounds().height() * 0.29); | |
203 ASSERT_TRUE(window_bounds.Intersects(root_window_bounds)); | |
204 | |
205 scoped_ptr<aura::Window> partially_out_window( | |
206 CreateTestWindowInShellWithBounds(window_bounds)); | |
207 EXPECT_EQ(window_bounds.size(), partially_out_window->bounds().size()); | |
208 bounds = partially_out_window->bounds(); | |
209 bounds.Intersect(root_window_bounds); | |
210 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); | |
211 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | |
212 | |
213 // Make sure the window whose 30% width/height is bigger than display | |
214 // will be placed correctly. | |
215 window_bounds.SetRect(-1900, -1900, 3000, 3000); | |
216 scoped_ptr<aura::Window> window_bigger_than_display( | |
217 CreateTestWindowInShellWithBounds(window_bounds)); | |
218 EXPECT_GE(root_window_bounds.width(), | |
219 window_bigger_than_display->bounds().width()); | |
220 EXPECT_GE(root_window_bounds.height(), | |
221 window_bigger_than_display->bounds().height()); | |
222 | |
223 bounds = window_bigger_than_display->bounds(); | |
224 bounds.Intersect(root_window_bounds); | |
225 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); | |
226 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | |
160 } | 227 } |
161 | 228 |
162 // Verifies the size of a window is enforced to be smaller than the work area. | 229 // Verifies the size of a window is enforced to be smaller than the work area. |
163 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { | 230 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { |
164 // Normal window bounds shouldn't be changed. | 231 // Normal window bounds shouldn't be changed. |
165 gfx::Size work_area( | 232 gfx::Size work_area( |
166 Shell::GetScreen()->GetPrimaryDisplay().work_area().size()); | 233 Shell::GetScreen()->GetPrimaryDisplay().work_area().size()); |
167 const gfx::Rect window_bounds( | 234 const gfx::Rect window_bounds( |
168 100, 101, work_area.width() + 1, work_area.height() + 2); | 235 100, 101, work_area.width() + 1, work_area.height() + 2); |
169 scoped_ptr<aura::Window> window( | 236 scoped_ptr<aura::Window> window( |
170 CreateTestWindowInShellWithBounds(window_bounds)); | 237 CreateTestWindowInShellWithBounds(window_bounds)); |
171 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 238 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
172 window->bounds().ToString()); | 239 window->bounds().ToString()); |
173 | 240 |
174 // Directly setting the bounds triggers a slightly different code path. Verify | 241 // Directly setting the bounds triggers a slightly different code path. Verify |
175 // that too. | 242 // that too. |
176 window->SetBounds(window_bounds); | 243 window->SetBounds(window_bounds); |
177 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 244 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
178 window->bounds().ToString()); | 245 window->bounds().ToString()); |
179 } | 246 } |
180 | 247 |
181 } // namespace | 248 } // namespace |
182 } // namespace ash | 249 } // namespace ash |
OLD | NEW |