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/common/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/aura/wm_window_aura.h" | 10 #include "ash/aura/wm_window_aura.h" |
11 #include "ash/common/session/session_state_delegate.h" | 11 #include "ash/common/session/session_state_delegate.h" |
12 #include "ash/common/shelf/shelf_constants.h" | 12 #include "ash/common/shelf/shelf_constants.h" |
13 #include "ash/common/shelf/shelf_layout_manager.h" | 13 #include "ash/common/shelf/shelf_layout_manager.h" |
14 #include "ash/common/shelf/wm_shelf.h" | 14 #include "ash/common/shelf/wm_shelf.h" |
15 #include "ash/common/shell_observer.h" | 15 #include "ash/common/shell_observer.h" |
16 #include "ash/common/shell_window_ids.h" | 16 #include "ash/common/shell_window_ids.h" |
| 17 #include "ash/common/test/ash_test.h" |
| 18 #include "ash/common/wm/fullscreen_window_finder.h" |
17 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h" | 19 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h" |
18 #include "ash/common/wm/window_state.h" | 20 #include "ash/common/wm/window_state.h" |
19 #include "ash/common/wm/wm_event.h" | 21 #include "ash/common/wm/wm_event.h" |
| 22 #include "ash/common/wm/wm_screen_util.h" |
20 #include "ash/common/wm/workspace/workspace_window_resizer.h" | 23 #include "ash/common/wm/workspace/workspace_window_resizer.h" |
| 24 #include "ash/common/wm_lookup.h" |
| 25 #include "ash/common/wm_root_window_controller.h" |
21 #include "ash/common/wm_shell.h" | 26 #include "ash/common/wm_shell.h" |
22 #include "ash/display/display_manager.h" | 27 #include "ash/display/display_manager.h" |
23 #include "ash/root_window_controller.h" | 28 #include "ash/root_window_controller.h" |
24 #include "ash/screen_util.h" | 29 #include "ash/screen_util.h" |
25 #include "ash/shell.h" | 30 #include "ash/shell.h" |
26 #include "ash/test/ash_test_base.h" | 31 #include "ash/test/ash_test_base.h" |
27 #include "ash/test/display_manager_test_api.h" | 32 #include "ash/test/display_manager_test_api.h" |
| 33 #include "ash/test/test_session_state_delegate.h" |
28 #include "ash/wm/window_state_aura.h" | 34 #include "ash/wm/window_state_aura.h" |
29 #include "ash/wm/window_util.h" | 35 #include "ash/wm/window_util.h" |
30 #include "base/command_line.h" | 36 #include "base/command_line.h" |
31 #include "base/compiler_specific.h" | 37 #include "base/compiler_specific.h" |
32 #include "base/run_loop.h" | 38 #include "base/run_loop.h" |
33 #include "ui/aura/client/aura_constants.h" | |
34 #include "ui/aura/test/test_windows.h" | |
35 #include "ui/aura/window.h" | |
36 #include "ui/aura/window_event_dispatcher.h" | |
37 #include "ui/base/ui_base_switches.h" | 39 #include "ui/base/ui_base_switches.h" |
38 #include "ui/base/ui_base_types.h" | 40 #include "ui/base/ui_base_types.h" |
39 #include "ui/display/manager/display_layout.h" | 41 #include "ui/display/manager/display_layout.h" |
40 #include "ui/display/screen.h" | 42 #include "ui/display/screen.h" |
41 #include "ui/gfx/geometry/insets.h" | 43 #include "ui/gfx/geometry/insets.h" |
42 #include "ui/keyboard/keyboard_controller.h" | 44 #include "ui/keyboard/keyboard_controller.h" |
43 #include "ui/keyboard/keyboard_ui.h" | 45 #include "ui/keyboard/keyboard_ui.h" |
44 #include "ui/keyboard/keyboard_util.h" | 46 #include "ui/keyboard/keyboard_util.h" |
45 #include "ui/views/widget/widget.h" | 47 #include "ui/views/widget/widget.h" |
46 #include "ui/views/widget/widget_delegate.h" | 48 #include "ui/views/widget/widget_delegate.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 91 |
90 private: | 92 private: |
91 int call_count_; | 93 int call_count_; |
92 bool is_fullscreen_; | 94 bool is_fullscreen_; |
93 | 95 |
94 DISALLOW_COPY_AND_ASSIGN(TestShellObserver); | 96 DISALLOW_COPY_AND_ASSIGN(TestShellObserver); |
95 }; | 97 }; |
96 | 98 |
97 } // namespace | 99 } // namespace |
98 | 100 |
99 typedef test::AshTestBase WorkspaceLayoutManagerTest; | 101 using WorkspaceLayoutManagerTest = AshTest; |
100 | 102 |
101 // Verifies that a window containing a restore coordinate will be restored to | 103 // Verifies that a window containing a restore coordinate will be restored to |
102 // to the size prior to minimize, keeping the restore rectangle in tact (if | 104 // to the size prior to minimize, keeping the restore rectangle in tact (if |
103 // there is one). | 105 // there is one). |
104 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { | 106 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { |
105 std::unique_ptr<aura::Window> window( | 107 std::unique_ptr<WindowOwner> window_owner( |
106 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 108 CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 109 WmWindow* window = window_owner->window(); |
107 gfx::Rect bounds(10, 15, 25, 35); | 110 gfx::Rect bounds(10, 15, 25, 35); |
108 window->SetBounds(bounds); | 111 window->SetBounds(bounds); |
109 | 112 |
110 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 113 wm::WindowState* window_state = window->GetWindowState(); |
111 | 114 |
112 // This will not be used for un-minimizing window. | 115 // This will not be used for un-minimizing window. |
113 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); | 116 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); |
114 window_state->Minimize(); | 117 window_state->Minimize(); |
115 window_state->Restore(); | 118 window_state->Restore(); |
116 EXPECT_EQ("0,0 100x100", window_state->GetRestoreBoundsInScreen().ToString()); | 119 EXPECT_EQ("0,0 100x100", window_state->GetRestoreBoundsInScreen().ToString()); |
117 EXPECT_EQ("10,15 25x35", window.get()->bounds().ToString()); | 120 EXPECT_EQ("10,15 25x35", window->GetBounds().ToString()); |
118 | 121 |
119 if (!SupportsMultipleDisplays()) | 122 if (!SupportsMultipleDisplays()) |
120 return; | 123 return; |
121 | 124 |
122 UpdateDisplay("400x300,500x400"); | 125 UpdateDisplay("400x300,500x400"); |
123 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), | 126 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), GetSecondaryDisplay()); |
124 display_manager()->GetSecondaryDisplay()); | 127 EXPECT_EQ(WmShell::Get()->GetAllRootWindows()[1], window->GetRootWindow()); |
125 EXPECT_EQ(Shell::GetAllRootWindows()[1], window->GetRootWindow()); | |
126 window_state->Minimize(); | 128 window_state->Minimize(); |
127 // This will not be used for un-minimizing window. | 129 // This will not be used for un-minimizing window. |
128 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); | 130 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); |
129 window_state->Restore(); | 131 window_state->Restore(); |
130 EXPECT_EQ("600,0 100x100", window->GetBoundsInScreen().ToString()); | 132 EXPECT_EQ("600,0 100x100", window->GetBoundsInScreen().ToString()); |
131 | 133 |
132 // Make sure the unminimized window moves inside the display when | 134 // Make sure the unminimized window moves inside the display when |
133 // 2nd display is disconnected. | 135 // 2nd display is disconnected. |
134 window_state->Minimize(); | 136 window_state->Minimize(); |
135 UpdateDisplay("400x300"); | 137 UpdateDisplay("400x300"); |
136 window_state->Restore(); | 138 window_state->Restore(); |
137 EXPECT_EQ(Shell::GetPrimaryRootWindow(), window->GetRootWindow()); | 139 EXPECT_EQ(WmShell::Get()->GetPrimaryRootWindow(), window->GetRootWindow()); |
138 EXPECT_TRUE( | 140 EXPECT_TRUE(WmShell::Get()->GetPrimaryRootWindow()->GetBounds().Intersects( |
139 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 141 window->GetBounds())); |
140 } | 142 } |
141 | 143 |
142 TEST_F(WorkspaceLayoutManagerTest, KeepMinimumVisibilityInDisplays) { | 144 TEST_F(WorkspaceLayoutManagerTest, KeepMinimumVisibilityInDisplays) { |
143 if (!SupportsMultipleDisplays()) | 145 if (!SupportsMultipleDisplays()) |
144 return; | 146 return; |
145 | 147 |
146 UpdateDisplay("300x400,400x500"); | 148 UpdateDisplay("300x400,400x500"); |
147 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 149 WmWindow::Windows root_windows = WmShell::Get()->GetAllRootWindows(); |
148 | 150 |
149 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( | 151 if (!SetSecondaryDisplayPlacement(display::DisplayPlacement::TOP, 0)) |
150 test::CreateDisplayLayout(display_manager(), | 152 return; |
151 display::DisplayPlacement::TOP, 0)); | 153 |
152 EXPECT_EQ("0,-500 400x500", root_windows[1]->GetBoundsInScreen().ToString()); | 154 EXPECT_EQ("0,-500 400x500", root_windows[1]->GetBoundsInScreen().ToString()); |
153 | 155 |
154 std::unique_ptr<aura::Window> window1( | 156 std::unique_ptr<WindowOwner> window1_owner( |
155 CreateTestWindowInShellWithBounds(gfx::Rect(10, -400, 200, 200))); | 157 CreateTestWindow(gfx::Rect(10, -400, 200, 200))); |
156 EXPECT_EQ("10,-400 200x200", window1->GetBoundsInScreen().ToString()); | 158 EXPECT_EQ("10,-400 200x200", |
| 159 window1_owner->window()->GetBoundsInScreen().ToString()); |
157 | 160 |
158 // Make sure the caption is visible. | 161 // Make sure the caption is visible. |
159 std::unique_ptr<aura::Window> window2( | 162 std::unique_ptr<WindowOwner> window2_owner( |
160 CreateTestWindowInShellWithBounds(gfx::Rect(10, -600, 200, 200))); | 163 CreateTestWindow(gfx::Rect(10, -600, 200, 200))); |
161 EXPECT_EQ("10,-500 200x200", window2->GetBoundsInScreen().ToString()); | 164 EXPECT_EQ("10,-500 200x200", |
| 165 window2_owner->window()->GetBoundsInScreen().ToString()); |
162 } | 166 } |
163 | 167 |
164 TEST_F(WorkspaceLayoutManagerTest, NoMinimumVisibilityForPopupWindows) { | 168 TEST_F(WorkspaceLayoutManagerTest, NoMinimumVisibilityForPopupWindows) { |
165 UpdateDisplay("300x400"); | 169 UpdateDisplay("300x400"); |
166 | 170 |
167 // Create a popup window out of display boundaries and make sure it is not | 171 // Create a popup window out of display boundaries and make sure it is not |
168 // moved to have minimum visibility. | 172 // moved to have minimum visibility. |
169 std::unique_ptr<aura::Window> window( | 173 std::unique_ptr<WindowOwner> window_owner( |
170 CreateTestWindowInShellWithDelegateAndType( | 174 CreateTestWindow(gfx::Rect(400, 100, 50, 50), ui::wm::WINDOW_TYPE_POPUP)); |
171 nullptr, ui::wm::WINDOW_TYPE_POPUP, 0, gfx::Rect(400, 100, 50, 50))); | 175 EXPECT_EQ("400,100 50x50", |
172 EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString()); | 176 window_owner->window()->GetBoundsInScreen().ToString()); |
173 } | 177 } |
174 | 178 |
175 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { | 179 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { |
176 std::unique_ptr<aura::Window> window( | 180 std::unique_ptr<WindowOwner> window_owner( |
177 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 181 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
178 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 182 WmWindow* window = window_owner->window(); |
| 183 wm::WindowState* window_state = window->GetWindowState(); |
179 | 184 |
180 // Maximized -> Normal transition. | 185 // Maximized -> Normal transition. |
181 window_state->Maximize(); | 186 window_state->Maximize(); |
182 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); | 187 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); |
183 window_state->Restore(); | 188 window_state->Restore(); |
184 EXPECT_TRUE( | 189 EXPECT_TRUE(WmShell::Get()->GetPrimaryRootWindow()->GetBounds().Intersects( |
185 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 190 window->GetBounds())); |
186 // Y bounds should not be negative. | 191 // Y bounds should not be negative. |
187 EXPECT_EQ("-5,0 30x40", window->bounds().ToString()); | 192 EXPECT_EQ("-5,0 30x40", window->GetBounds().ToString()); |
188 | 193 |
189 // Minimized -> Normal transition. | 194 // Minimized -> Normal transition. |
190 window->SetBounds(gfx::Rect(-100, -100, 30, 40)); | 195 window->SetBounds(gfx::Rect(-100, -100, 30, 40)); |
191 window_state->Minimize(); | 196 window_state->Minimize(); |
192 EXPECT_FALSE( | 197 EXPECT_FALSE(WmShell::Get()->GetPrimaryRootWindow()->GetBounds().Intersects( |
193 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 198 window->GetBounds())); |
194 EXPECT_EQ("-100,-100 30x40", window->bounds().ToString()); | 199 EXPECT_EQ("-100,-100 30x40", window->GetBounds().ToString()); |
195 window->Show(); | 200 window->Show(); |
196 EXPECT_TRUE( | 201 EXPECT_TRUE(WmShell::Get()->GetPrimaryRootWindow()->GetBounds().Intersects( |
197 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 202 window->GetBounds())); |
198 // Y bounds should not be negative. | 203 // Y bounds should not be negative. |
199 EXPECT_EQ("-5,0 30x40", window->bounds().ToString()); | 204 EXPECT_EQ("-5,0 30x40", window->GetBounds().ToString()); |
200 | 205 |
201 // Fullscreen -> Normal transition. | 206 // Fullscreen -> Normal transition. |
202 window->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds. | 207 window->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds. |
203 ASSERT_EQ("0,0 30x40", window->bounds().ToString()); | 208 ASSERT_EQ("0,0 30x40", window->GetBounds().ToString()); |
204 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 209 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
205 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds()); | 210 EXPECT_EQ(window->GetBounds(), window->GetRootWindow()->GetBounds()); |
206 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); | 211 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); |
207 window_state->Restore(); | 212 window_state->Restore(); |
208 EXPECT_TRUE( | 213 EXPECT_TRUE(WmShell::Get()->GetPrimaryRootWindow()->GetBounds().Intersects( |
209 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 214 window->GetBounds())); |
210 // Y bounds should not be negative. | 215 // Y bounds should not be negative. |
211 EXPECT_EQ("-5,0 30x40", window->bounds().ToString()); | 216 EXPECT_EQ("-5,0 30x40", window->GetBounds().ToString()); |
212 } | 217 } |
213 | 218 |
214 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) { | 219 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) { |
215 if (!SupportsMultipleDisplays()) | 220 if (!SupportsMultipleDisplays()) |
216 return; | 221 return; |
217 UpdateDisplay("300x400,400x500"); | 222 UpdateDisplay("300x400,400x500"); |
218 | 223 |
219 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 224 WmWindow::Windows root_windows = WmShell::Get()->GetAllRootWindows(); |
220 | 225 |
221 std::unique_ptr<aura::Window> window( | 226 std::unique_ptr<WindowOwner> window_owner( |
222 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 227 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
| 228 WmWindow* window = window_owner->window(); |
223 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 229 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
224 | 230 |
225 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 231 wm::WindowState* window_state = window->GetWindowState(); |
226 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); | 232 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
227 // Maximize the window in 2nd display as the restore bounds | 233 // Maximize the window in 2nd display as the restore bounds |
228 // is inside 2nd display. | 234 // is inside 2nd display. |
229 window_state->Maximize(); | 235 window_state->Maximize(); |
230 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 236 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
231 EXPECT_EQ( | 237 EXPECT_EQ( |
232 gfx::Rect(300, 0, 400, 500 - GetShelfConstant(SHELF_SIZE)).ToString(), | 238 gfx::Rect(300, 0, 400, 500 - GetShelfConstant(SHELF_SIZE)).ToString(), |
233 window->GetBoundsInScreen().ToString()); | 239 window->GetBoundsInScreen().ToString()); |
234 | 240 |
235 window_state->Restore(); | 241 window_state->Restore(); |
(...skipping 11 matching lines...) Expand all Loading... |
247 | 253 |
248 window_state->Restore(); | 254 window_state->Restore(); |
249 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 255 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
250 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString()); | 256 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString()); |
251 | 257 |
252 // Restoring widget state. | 258 // Restoring widget state. |
253 std::unique_ptr<views::Widget> w1(new views::Widget); | 259 std::unique_ptr<views::Widget> w1(new views::Widget); |
254 views::Widget::InitParams params; | 260 views::Widget::InitParams params; |
255 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 261 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
256 params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40)); | 262 params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40)); |
257 params.context = root_windows[0]; | 263 ConfigureWidgetInitParamsForDisplay(root_windows[0], ¶ms); |
258 w1->Init(params); | 264 w1->Init(params); |
| 265 WmLookup* wm_lookup = WmLookup::Get(); |
| 266 EXPECT_EQ(root_windows[0], |
| 267 wm_lookup->GetWindowForWidget(w1.get())->GetRootWindow()); |
259 w1->Show(); | 268 w1->Show(); |
260 EXPECT_TRUE(w1->IsMaximized()); | 269 EXPECT_TRUE(w1->IsMaximized()); |
261 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); | 270 EXPECT_EQ(root_windows[1], |
| 271 wm_lookup->GetWindowForWidget(w1.get())->GetRootWindow()); |
262 EXPECT_EQ( | 272 EXPECT_EQ( |
263 gfx::Rect(300, 0, 400, 500 - GetShelfConstant(SHELF_SIZE)).ToString(), | 273 gfx::Rect(300, 0, 400, 500 - GetShelfConstant(SHELF_SIZE)).ToString(), |
264 w1->GetWindowBoundsInScreen().ToString()); | 274 w1->GetWindowBoundsInScreen().ToString()); |
265 w1->Restore(); | 275 w1->Restore(); |
266 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); | 276 EXPECT_EQ(root_windows[1], |
| 277 wm_lookup->GetWindowForWidget(w1.get())->GetRootWindow()); |
267 EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString()); | 278 EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString()); |
268 } | 279 } |
269 | 280 |
270 TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) { | 281 TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) { |
271 if (!SupportsMultipleDisplays()) | 282 if (!SupportsMultipleDisplays()) |
272 return; | 283 return; |
273 UpdateDisplay("300x400,400x500"); | 284 UpdateDisplay("300x400,400x500"); |
274 | 285 |
275 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 286 WmWindow::Windows root_windows = WmShell::Get()->GetAllRootWindows(); |
276 | 287 |
277 std::unique_ptr<aura::Window> window( | 288 std::unique_ptr<WindowOwner> window_owner( |
278 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 289 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
| 290 WmWindow* window = window_owner->window(); |
279 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 291 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
280 | 292 |
281 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 293 wm::WindowState* window_state = window->GetWindowState(); |
282 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); | 294 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
283 // Maximize the window in 2nd display as the restore bounds | 295 // Maximize the window in 2nd display as the restore bounds |
284 // is inside 2nd display. | 296 // is inside 2nd display. |
285 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 297 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
286 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 298 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
287 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); | 299 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); |
288 | 300 |
289 window_state->Restore(); | 301 window_state->Restore(); |
290 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 302 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
291 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString()); | 303 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString()); |
292 | 304 |
293 // If the restore bounds intersects with the current display, | 305 // If the restore bounds intersects with the current display, |
294 // don't move. | 306 // don't move. |
295 window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40)); | 307 window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40)); |
296 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 308 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
297 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 309 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
298 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); | 310 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); |
299 | 311 |
300 window_state->Restore(); | 312 window_state->Restore(); |
301 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 313 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
302 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString()); | 314 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString()); |
303 } | 315 } |
304 | 316 |
305 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. | 317 // WmWindowObserver implementation used by |
306 // This code mirrors what BrowserFrameAsh does. In particular when this code | 318 // DontClobberRestoreBoundsWindowObserver. This code mirrors what |
307 // sees the window was maximized it changes the bounds of a secondary | 319 // BrowserFrameAsh does. In particular when this code sees the window was |
308 // window. The secondary window mirrors the status window. | 320 // maximized it changes the bounds of a secondary window. The secondary window |
309 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver { | 321 // mirrors the status window. |
| 322 class DontClobberRestoreBoundsWindowObserver : public WmWindowObserver { |
310 public: | 323 public: |
311 DontClobberRestoreBoundsWindowObserver() : window_(nullptr) {} | 324 DontClobberRestoreBoundsWindowObserver() : window_(nullptr) {} |
312 | 325 |
313 void set_window(aura::Window* window) { window_ = window; } | 326 void set_window(WmWindow* window) { window_ = window; } |
314 | 327 |
315 // aura::WindowObserver: | 328 // WmWindowObserver: |
316 void OnWindowPropertyChanged(aura::Window* window, | 329 void OnWindowPropertyChanged(WmWindow* window, |
317 const void* key, | 330 WmWindowProperty property) override { |
318 intptr_t old) override { | |
319 if (!window_) | 331 if (!window_) |
320 return; | 332 return; |
321 | 333 |
322 if (wm::GetWindowState(window)->IsMaximized()) { | 334 if (window->GetWindowState()->IsMaximized()) { |
323 aura::Window* w = window_; | 335 WmWindow* w = window_; |
324 window_ = nullptr; | 336 window_ = nullptr; |
325 | 337 |
326 gfx::Rect shelf_bounds( | 338 gfx::Rect shelf_bounds(AshTest::GetPrimaryShelf()->GetIdealBounds()); |
327 test::AshTestBase::GetPrimaryShelf()->GetIdealBounds()); | 339 const gfx::Rect& window_bounds(w->GetBounds()); |
328 const gfx::Rect& window_bounds(w->bounds()); | |
329 w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1, | 340 w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1, |
330 window_bounds.width(), window_bounds.height())); | 341 window_bounds.width(), window_bounds.height())); |
331 } | 342 } |
332 } | 343 } |
333 | 344 |
334 private: | 345 private: |
335 aura::Window* window_; | 346 WmWindow* window_; |
336 | 347 |
337 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver); | 348 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver); |
338 }; | 349 }; |
339 | 350 |
340 // Creates a window, maximized the window and from within the maximized | 351 // Creates a window, maximized the window and from within the maximized |
341 // notification sets the bounds of a window to overlap the shelf. Verifies this | 352 // notification sets the bounds of a window to overlap the shelf. Verifies this |
342 // doesn't effect the restore bounds. | 353 // doesn't effect the restore bounds. |
343 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { | 354 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { |
344 DontClobberRestoreBoundsWindowObserver window_observer; | 355 DontClobberRestoreBoundsWindowObserver window_observer; |
345 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); | 356 WindowOwner window_owner(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, |
346 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 357 ui::LAYER_TEXTURED)); |
347 window->Init(ui::LAYER_TEXTURED); | 358 WmWindow* window = window_owner.window(); |
348 window->SetBounds(gfx::Rect(10, 20, 30, 40)); | 359 window->SetBounds(gfx::Rect(10, 20, 30, 40)); |
349 // NOTE: for this test to exercise the failure the observer needs to be added | 360 // NOTE: for this test to exercise the failure the observer needs to be added |
350 // before the parent set. This mimics what BrowserFrameAsh does. | 361 // before the parent set. This mimics what BrowserFrameAsh does. |
351 window->AddObserver(&window_observer); | 362 window->AddObserver(&window_observer); |
352 ParentWindowInPrimaryRootWindow(window.get()); | 363 ParentWindowInPrimaryRootWindow(window); |
353 window->Show(); | 364 window->Show(); |
354 | 365 |
355 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 366 wm::WindowState* window_state = window->GetWindowState(); |
356 window_state->Activate(); | 367 window_state->Activate(); |
357 | 368 |
358 std::unique_ptr<aura::Window> window2( | 369 std::unique_ptr<WindowOwner> window2_owner( |
359 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40))); | 370 CreateTestWindow(gfx::Rect(12, 20, 30, 40))); |
360 ::wm::AddTransientChild(window.get(), window2.get()); | 371 WmWindow* window2 = window2_owner->window(); |
| 372 AddTransientChild(window, window2); |
361 window2->Show(); | 373 window2->Show(); |
362 | 374 |
363 window_observer.set_window(window2.get()); | 375 window_observer.set_window(window2); |
364 window_state->Maximize(); | 376 window_state->Maximize(); |
365 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInScreen().ToString()); | 377 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInScreen().ToString()); |
366 window->RemoveObserver(&window_observer); | 378 window->RemoveObserver(&window_observer); |
367 } | 379 } |
368 | 380 |
369 // Verifies when a window is maximized all descendant windows have a size. | 381 // Verifies when a window is maximized all descendant windows have a size. |
370 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { | 382 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { |
371 std::unique_ptr<aura::Window> window( | 383 std::unique_ptr<WindowOwner> window_owner( |
372 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40))); | 384 CreateTestWindow(gfx::Rect(10, 20, 30, 40))); |
| 385 WmWindow* window = window_owner->window(); |
373 window->Show(); | 386 window->Show(); |
374 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 387 wm::WindowState* window_state = window->GetWindowState(); |
375 window_state->Activate(); | 388 window_state->Activate(); |
376 std::unique_ptr<aura::Window> child_window( | 389 std::unique_ptr<WindowOwner> child_window_owner( |
377 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), | 390 CreateChildWindow(window, gfx::Rect(5, 6, 7, 8))); |
378 window.get())); | 391 WmWindow* child_window = child_window_owner->window(); |
379 child_window->Show(); | |
380 window_state->Maximize(); | 392 window_state->Maximize(); |
381 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); | 393 EXPECT_EQ("5,6 7x8", child_window->GetBounds().ToString()); |
382 } | 394 } |
383 | 395 |
384 // Verifies a window created with maximized state has the maximized | 396 // Verifies a window created with maximized state has the maximized |
385 // bounds. | 397 // bounds. |
386 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { | 398 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { |
387 std::unique_ptr<aura::Window> window( | 399 WindowOwner window_owner(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, |
388 aura::test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 0, 0), nullptr)); | 400 ui::LAYER_TEXTURED)); |
389 wm::GetWindowState(window.get())->Maximize(); | 401 WmWindow* window = window_owner.window(); |
390 aura::Window* default_container = Shell::GetContainer( | 402 window->GetWindowState()->Maximize(); |
391 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); | 403 WmWindow* default_container = |
392 default_container->AddChild(window.get()); | 404 WmShell::Get()->GetPrimaryRootWindowController()->GetContainer( |
| 405 kShellWindowId_DefaultContainer); |
| 406 default_container->AddChild(window); |
393 window->Show(); | 407 window->Show(); |
394 gfx::Rect work_area( | 408 gfx::Rect work_area( |
395 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 409 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
396 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); | 410 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
397 } | 411 } |
398 | 412 |
399 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { | 413 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { |
400 // Normal window bounds shouldn't be changed. | 414 // Normal window bounds shouldn't be changed. |
401 gfx::Rect window_bounds(100, 100, 200, 200); | 415 gfx::Rect window_bounds(100, 100, 200, 200); |
402 std::unique_ptr<aura::Window> window( | 416 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(window_bounds)); |
403 CreateTestWindowInShellWithBounds(window_bounds)); | 417 WmWindow* window = window_owner->window(); |
404 EXPECT_EQ(window_bounds, window->bounds()); | 418 EXPECT_EQ(window_bounds, window->GetBounds()); |
405 | 419 |
406 // If the window is out of the workspace, it would be moved on screen. | 420 // If the window is out of the workspace, it would be moved on screen. |
407 gfx::Rect root_window_bounds = | 421 gfx::Rect root_window_bounds = |
408 Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); | 422 WmShell::Get()->GetPrimaryRootWindow()->GetBounds(); |
409 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); | 423 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); |
410 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); | 424 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); |
411 std::unique_ptr<aura::Window> out_window( | 425 std::unique_ptr<WindowOwner> out_window_owner( |
412 CreateTestWindowInShellWithBounds(window_bounds)); | 426 CreateTestWindow(window_bounds)); |
413 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); | 427 WmWindow* out_window = out_window_owner->window(); |
414 gfx::Rect bounds = out_window->bounds(); | 428 EXPECT_EQ(window_bounds.size(), out_window->GetBounds().size()); |
| 429 gfx::Rect bounds = out_window->GetBounds(); |
415 bounds.Intersect(root_window_bounds); | 430 bounds.Intersect(root_window_bounds); |
416 | 431 |
417 // 30% of the window edge must be visible. | 432 // 30% of the window edge must be visible. |
418 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); | 433 EXPECT_GT(bounds.width(), out_window->GetBounds().width() * 0.29); |
419 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | 434 EXPECT_GT(bounds.height(), out_window->GetBounds().height() * 0.29); |
420 | 435 |
421 aura::Window* parent = out_window->parent(); | 436 WmWindow* parent = out_window->GetParent(); |
422 parent->RemoveChild(out_window.get()); | 437 parent->RemoveChild(out_window); |
423 out_window->SetBounds(gfx::Rect(-200, -200, 200, 200)); | 438 out_window->SetBounds(gfx::Rect(-200, -200, 200, 200)); |
424 // UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior. | 439 // UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior. |
425 wm::GetWindowState(window.get())->set_bounds_changed_by_user(true); | 440 window->GetWindowState()->set_bounds_changed_by_user(true); |
426 parent->AddChild(out_window.get()); | 441 parent->AddChild(out_window); |
427 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); | 442 EXPECT_GT(bounds.width(), out_window->GetBounds().width() * 0.29); |
428 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | 443 EXPECT_GT(bounds.height(), out_window->GetBounds().height() * 0.29); |
429 | 444 |
430 // Make sure we always make more than 1/3 of the window edge visible even | 445 // Make sure we always make more than 1/3 of the window edge visible even |
431 // if the initial bounds intersects with display. | 446 // if the initial bounds intersects with display. |
432 window_bounds.SetRect(-150, -150, 200, 200); | 447 window_bounds.SetRect(-150, -150, 200, 200); |
433 bounds = window_bounds; | 448 bounds = window_bounds; |
434 bounds.Intersect(root_window_bounds); | 449 bounds.Intersect(root_window_bounds); |
435 | 450 |
436 // Make sure that the initial bounds' visible area is less than 26% | 451 // Make sure that the initial bounds' visible area is less than 26% |
437 // so that the auto adjustment logic kicks in. | 452 // so that the auto adjustment logic kicks in. |
438 ASSERT_LT(bounds.width(), out_window->bounds().width() * 0.26); | 453 ASSERT_LT(bounds.width(), out_window->GetBounds().width() * 0.26); |
439 ASSERT_LT(bounds.height(), out_window->bounds().height() * 0.26); | 454 ASSERT_LT(bounds.height(), out_window->GetBounds().height() * 0.26); |
440 ASSERT_TRUE(window_bounds.Intersects(root_window_bounds)); | 455 ASSERT_TRUE(window_bounds.Intersects(root_window_bounds)); |
441 | 456 |
442 std::unique_ptr<aura::Window> partially_out_window( | 457 std::unique_ptr<WindowOwner> partially_out_window_owner( |
443 CreateTestWindowInShellWithBounds(window_bounds)); | 458 CreateTestWindow(window_bounds)); |
444 EXPECT_EQ(window_bounds.size(), partially_out_window->bounds().size()); | 459 WmWindow* partially_out_window = partially_out_window_owner->window(); |
445 bounds = partially_out_window->bounds(); | 460 EXPECT_EQ(window_bounds.size(), partially_out_window->GetBounds().size()); |
| 461 bounds = partially_out_window->GetBounds(); |
446 bounds.Intersect(root_window_bounds); | 462 bounds.Intersect(root_window_bounds); |
447 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); | 463 EXPECT_GT(bounds.width(), out_window->GetBounds().width() * 0.29); |
448 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | 464 EXPECT_GT(bounds.height(), out_window->GetBounds().height() * 0.29); |
449 | 465 |
450 // Make sure the window whose 30% width/height is bigger than display | 466 // Make sure the window whose 30% width/height is bigger than display |
451 // will be placed correctly. | 467 // will be placed correctly. |
452 window_bounds.SetRect(-1900, -1900, 3000, 3000); | 468 window_bounds.SetRect(-1900, -1900, 3000, 3000); |
453 std::unique_ptr<aura::Window> window_bigger_than_display( | 469 std::unique_ptr<WindowOwner> window_bigger_than_display_owner( |
454 CreateTestWindowInShellWithBounds(window_bounds)); | 470 CreateTestWindow(window_bounds)); |
| 471 WmWindow* window_bigger_than_display = |
| 472 window_bigger_than_display_owner->window(); |
455 EXPECT_GE(root_window_bounds.width(), | 473 EXPECT_GE(root_window_bounds.width(), |
456 window_bigger_than_display->bounds().width()); | 474 window_bigger_than_display->GetBounds().width()); |
457 EXPECT_GE(root_window_bounds.height(), | 475 EXPECT_GE(root_window_bounds.height(), |
458 window_bigger_than_display->bounds().height()); | 476 window_bigger_than_display->GetBounds().height()); |
459 | 477 |
460 bounds = window_bigger_than_display->bounds(); | 478 bounds = window_bigger_than_display->GetBounds(); |
461 bounds.Intersect(root_window_bounds); | 479 bounds.Intersect(root_window_bounds); |
462 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); | 480 EXPECT_GT(bounds.width(), out_window->GetBounds().width() * 0.29); |
463 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | 481 EXPECT_GT(bounds.height(), out_window->GetBounds().height() * 0.29); |
464 } | 482 } |
465 | 483 |
466 // Verifies the size of a window is enforced to be smaller than the work area. | 484 // Verifies the size of a window is enforced to be smaller than the work area. |
467 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { | 485 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { |
468 // Normal window bounds shouldn't be changed. | 486 // Normal window bounds shouldn't be changed. |
469 gfx::Size work_area( | 487 gfx::Size work_area( |
470 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size()); | 488 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size()); |
471 const gfx::Rect window_bounds(100, 101, work_area.width() + 1, | 489 const gfx::Rect window_bounds(100, 101, work_area.width() + 1, |
472 work_area.height() + 2); | 490 work_area.height() + 2); |
473 std::unique_ptr<aura::Window> window( | 491 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(window_bounds)); |
474 CreateTestWindowInShellWithBounds(window_bounds)); | 492 WmWindow* window = window_owner->window(); |
475 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 493 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
476 window->bounds().ToString()); | 494 window->GetBounds().ToString()); |
477 | 495 |
478 // Directly setting the bounds triggers a slightly different code path. Verify | 496 // Directly setting the bounds triggers a slightly different code path. Verify |
479 // that too. | 497 // that too. |
480 window->SetBounds(window_bounds); | 498 window->SetBounds(window_bounds); |
481 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 499 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
482 window->bounds().ToString()); | 500 window->GetBounds().ToString()); |
483 } | 501 } |
484 | 502 |
485 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) { | 503 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) { |
486 TestShellObserver observer; | 504 TestShellObserver observer; |
487 std::unique_ptr<aura::Window> window1( | 505 std::unique_ptr<WindowOwner> window1_owner( |
488 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 506 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
489 std::unique_ptr<aura::Window> window2( | 507 WmWindow* window1 = window1_owner->window(); |
490 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 508 std::unique_ptr<WindowOwner> window2_owner( |
491 wm::WindowState* window_state1 = wm::GetWindowState(window1.get()); | 509 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
492 wm::WindowState* window_state2 = wm::GetWindowState(window2.get()); | 510 WmWindow* window2 = window2_owner->window(); |
| 511 wm::WindowState* window_state1 = window1->GetWindowState(); |
| 512 wm::WindowState* window_state2 = window2->GetWindowState(); |
493 window_state2->Activate(); | 513 window_state2->Activate(); |
494 | 514 |
495 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 515 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
496 window_state2->OnWMEvent(&toggle_fullscreen_event); | 516 window_state2->OnWMEvent(&toggle_fullscreen_event); |
497 EXPECT_EQ(1, observer.call_count()); | 517 EXPECT_EQ(1, observer.call_count()); |
498 EXPECT_TRUE(observer.is_fullscreen()); | 518 EXPECT_TRUE(observer.is_fullscreen()); |
499 | 519 |
500 // When window1 moves to the front the fullscreen state should change. | 520 // When window1 moves to the front the fullscreen state should change. |
501 window_state1->Activate(); | 521 window_state1->Activate(); |
502 EXPECT_EQ(2, observer.call_count()); | 522 EXPECT_EQ(2, observer.call_count()); |
503 EXPECT_FALSE(observer.is_fullscreen()); | 523 EXPECT_FALSE(observer.is_fullscreen()); |
504 | 524 |
505 // It should change back if window2 becomes active again. | 525 // It should change back if window2 becomes active again. |
506 window_state2->Activate(); | 526 window_state2->Activate(); |
507 EXPECT_EQ(3, observer.call_count()); | 527 EXPECT_EQ(3, observer.call_count()); |
508 EXPECT_TRUE(observer.is_fullscreen()); | 528 EXPECT_TRUE(observer.is_fullscreen()); |
509 | 529 |
510 window_state2->OnWMEvent(&toggle_fullscreen_event); | 530 window_state2->OnWMEvent(&toggle_fullscreen_event); |
511 EXPECT_EQ(4, observer.call_count()); | 531 EXPECT_EQ(4, observer.call_count()); |
512 EXPECT_FALSE(observer.is_fullscreen()); | 532 EXPECT_FALSE(observer.is_fullscreen()); |
513 | 533 |
514 window_state2->OnWMEvent(&toggle_fullscreen_event); | 534 window_state2->OnWMEvent(&toggle_fullscreen_event); |
515 EXPECT_EQ(5, observer.call_count()); | 535 EXPECT_EQ(5, observer.call_count()); |
516 EXPECT_TRUE(observer.is_fullscreen()); | 536 EXPECT_TRUE(observer.is_fullscreen()); |
517 | 537 |
518 // Closing the window should change the fullscreen state. | 538 // Closing the window should change the fullscreen state. |
519 window2.reset(); | 539 window2_owner.reset(); |
520 EXPECT_EQ(6, observer.call_count()); | 540 EXPECT_EQ(6, observer.call_count()); |
521 EXPECT_FALSE(observer.is_fullscreen()); | 541 EXPECT_FALSE(observer.is_fullscreen()); |
522 } | 542 } |
523 | 543 |
524 // Following "Solo" tests were originally written for BaseLayoutManager. | 544 // Following "Solo" tests were originally written for BaseLayoutManager. |
525 namespace { | 545 using WorkspaceLayoutManagerSoloTest = AshTest; |
526 | |
527 class WorkspaceLayoutManagerSoloTest : public test::AshTestBase { | |
528 public: | |
529 WorkspaceLayoutManagerSoloTest() {} | |
530 ~WorkspaceLayoutManagerSoloTest() override {} | |
531 | |
532 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | |
533 return CreateTestWindowInShellWithBounds(bounds); | |
534 } | |
535 | |
536 private: | |
537 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerSoloTest); | |
538 }; | |
539 | |
540 } // namespace | |
541 | 546 |
542 // Tests normal->maximize->normal. | 547 // Tests normal->maximize->normal. |
543 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { | 548 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { |
544 gfx::Rect bounds(100, 100, 200, 200); | 549 gfx::Rect bounds(100, 100, 200, 200); |
545 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 550 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds)); |
546 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 551 WmWindow* window = window_owner->window(); |
| 552 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
547 // Maximized window fills the work area, not the whole display. | 553 // Maximized window fills the work area, not the whole display. |
548 EXPECT_EQ( | 554 EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(), |
549 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), | 555 window->GetBounds().ToString()); |
550 window->bounds().ToString()); | 556 window->SetShowState(ui::SHOW_STATE_NORMAL); |
551 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 557 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString()); |
552 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); | |
553 } | 558 } |
554 | 559 |
555 // Tests normal->minimize->normal. | 560 // Tests normal->minimize->normal. |
556 TEST_F(WorkspaceLayoutManagerSoloTest, Minimize) { | 561 TEST_F(WorkspaceLayoutManagerSoloTest, Minimize) { |
557 gfx::Rect bounds(100, 100, 200, 200); | 562 gfx::Rect bounds(100, 100, 200, 200); |
558 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 563 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds)); |
559 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 564 WmWindow* window = window_owner->window(); |
| 565 window->SetShowState(ui::SHOW_STATE_MINIMIZED); |
560 // Note: Currently minimize doesn't do anything except set the state. | 566 // Note: Currently minimize doesn't do anything except set the state. |
561 // See crbug.com/104571. | 567 // See crbug.com/104571. |
562 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); | 568 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString()); |
563 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 569 window->SetShowState(ui::SHOW_STATE_NORMAL); |
564 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); | 570 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString()); |
565 } | 571 } |
566 | 572 |
567 // A WindowDelegate which sets the focus when the window | 573 // A WmWindowObserver which sets the focus when the window becomes visible. |
568 // becomes visible. | 574 class FocusDuringUnminimizeWindowObserver : public WmWindowObserver { |
569 class FocusDelegate : public aura::test::TestWindowDelegate { | |
570 public: | 575 public: |
571 FocusDelegate() : window_(nullptr), show_state_(ui::SHOW_STATE_END) {} | 576 FocusDuringUnminimizeWindowObserver() |
572 ~FocusDelegate() override {} | 577 : window_(nullptr), show_state_(ui::SHOW_STATE_END) {} |
| 578 ~FocusDuringUnminimizeWindowObserver() override { SetWindow(nullptr); } |
573 | 579 |
574 void set_window(aura::Window* window) { window_ = window; } | 580 void SetWindow(WmWindow* window) { |
| 581 if (window_) |
| 582 window_->RemoveObserver(this); |
| 583 window_ = window; |
| 584 if (window_) |
| 585 window_->AddObserver(this); |
| 586 } |
575 | 587 |
576 // aura::test::TestWindowDelegate overrides: | 588 // WmWindowObserver: |
577 void OnWindowTargetVisibilityChanged(bool visible) override { | 589 void OnWindowVisibilityChanged(WmWindow* window, bool visible) override { |
578 if (window_) { | 590 if (window_) { |
579 if (visible) | 591 if (visible) |
580 window_->Focus(); | 592 window_->SetFocused(); |
581 show_state_ = window_->GetProperty(aura::client::kShowStateKey); | 593 show_state_ = window_->GetShowState(); |
582 } | 594 } |
583 } | 595 } |
584 | 596 |
585 ui::WindowShowState GetShowStateAndReset() { | 597 ui::WindowShowState GetShowStateAndReset() { |
586 ui::WindowShowState ret = show_state_; | 598 ui::WindowShowState ret = show_state_; |
587 show_state_ = ui::SHOW_STATE_END; | 599 show_state_ = ui::SHOW_STATE_END; |
588 return ret; | 600 return ret; |
589 } | 601 } |
590 | 602 |
591 private: | 603 private: |
592 aura::Window* window_; | 604 WmWindow* window_; |
593 ui::WindowShowState show_state_; | 605 ui::WindowShowState show_state_; |
594 | 606 |
595 DISALLOW_COPY_AND_ASSIGN(FocusDelegate); | 607 DISALLOW_COPY_AND_ASSIGN(FocusDuringUnminimizeWindowObserver); |
596 }; | 608 }; |
597 | 609 |
598 // Make sure that the window's show state is correct in | 610 // Make sure that the window's show state is correct in |
599 // |WindowDelegate::OnWindowTargetVisibilityChanged|, and setting | 611 // WindowObserver::OnWindowTargetVisibilityChanged(), and setting focus in this |
600 // focus in this callback doesn't cause DCHECK error. See | 612 // callback doesn't cause DCHECK error. See crbug.com/168383. |
601 // crbug.com/168383. | |
602 TEST_F(WorkspaceLayoutManagerSoloTest, FocusDuringUnminimize) { | 613 TEST_F(WorkspaceLayoutManagerSoloTest, FocusDuringUnminimize) { |
603 FocusDelegate delegate; | 614 FocusDuringUnminimizeWindowObserver observer; |
604 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 615 std::unique_ptr<WindowOwner> window_owner( |
605 &delegate, 0, gfx::Rect(100, 100, 100, 100))); | 616 CreateTestWindow(gfx::Rect(100, 100, 100, 100))); |
606 delegate.set_window(window.get()); | 617 WmWindow* window = window_owner->window(); |
607 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 618 observer.SetWindow(window); |
| 619 window->SetShowState(ui::SHOW_STATE_MINIMIZED); |
608 EXPECT_FALSE(window->IsVisible()); | 620 EXPECT_FALSE(window->IsVisible()); |
609 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, delegate.GetShowStateAndReset()); | 621 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, observer.GetShowStateAndReset()); |
610 window->Show(); | 622 window->Show(); |
611 EXPECT_TRUE(window->IsVisible()); | 623 EXPECT_TRUE(window->IsVisible()); |
612 EXPECT_EQ(ui::SHOW_STATE_NORMAL, delegate.GetShowStateAndReset()); | 624 EXPECT_EQ(ui::SHOW_STATE_NORMAL, observer.GetShowStateAndReset()); |
| 625 observer.SetWindow(nullptr); |
613 } | 626 } |
614 | 627 |
615 // Tests maximized window size during root window resize. | 628 // Tests maximized window size during root window resize. |
616 #if defined(OS_WIN) && !defined(USE_ASH) | 629 #if defined(OS_WIN) && !defined(USE_ASH) |
617 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 630 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
618 #define MAYBE_MaximizeRootWindowResize DISABLED_MaximizeRootWindowResize | 631 #define MAYBE_MaximizeRootWindowResize DISABLED_MaximizeRootWindowResize |
619 #else | 632 #else |
620 #define MAYBE_MaximizeRootWindowResize MaximizeRootWindowResize | 633 #define MAYBE_MaximizeRootWindowResize MaximizeRootWindowResize |
621 #endif | 634 #endif |
622 TEST_F(WorkspaceLayoutManagerSoloTest, MAYBE_MaximizeRootWindowResize) { | 635 TEST_F(WorkspaceLayoutManagerSoloTest, MAYBE_MaximizeRootWindowResize) { |
623 gfx::Rect bounds(100, 100, 200, 200); | 636 gfx::Rect bounds(100, 100, 200, 200); |
624 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 637 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds)); |
625 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 638 WmWindow* window = window_owner->window(); |
| 639 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
626 gfx::Rect initial_work_area_bounds = | 640 gfx::Rect initial_work_area_bounds = |
627 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()); | 641 wm::GetMaximizedWindowBoundsInParent(window); |
628 EXPECT_EQ(initial_work_area_bounds.ToString(), window->bounds().ToString()); | 642 EXPECT_EQ(initial_work_area_bounds.ToString(), |
| 643 window->GetBounds().ToString()); |
629 // Enlarge the root window. We should still match the work area size. | 644 // Enlarge the root window. We should still match the work area size. |
630 UpdateDisplay("900x700"); | 645 UpdateDisplay("900x700"); |
631 EXPECT_EQ( | 646 EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(), |
632 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), | 647 window->GetBounds().ToString()); |
633 window->bounds().ToString()); | 648 EXPECT_NE(initial_work_area_bounds.ToString(), |
634 EXPECT_NE( | 649 wm::GetMaximizedWindowBoundsInParent(window).ToString()); |
635 initial_work_area_bounds.ToString(), | |
636 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString()); | |
637 } | 650 } |
638 | 651 |
639 // Tests normal->fullscreen->normal. | 652 // Tests normal->fullscreen->normal. |
640 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) { | 653 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) { |
641 gfx::Rect bounds(100, 100, 200, 200); | 654 gfx::Rect bounds(100, 100, 200, 200); |
642 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 655 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds)); |
643 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 656 WmWindow* window = window_owner->window(); |
| 657 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
644 // Fullscreen window fills the whole display. | 658 // Fullscreen window fills the whole display. |
645 EXPECT_EQ(display::Screen::GetScreen() | 659 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), |
646 ->GetDisplayNearestWindow(window.get()) | 660 window->GetBounds().ToString()); |
647 .bounds() | 661 window->SetShowState(ui::SHOW_STATE_NORMAL); |
648 .ToString(), | 662 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString()); |
649 window->bounds().ToString()); | |
650 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
651 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); | |
652 } | 663 } |
653 | 664 |
654 // Tests that fullscreen window causes always_on_top windows to stack below. | 665 // Tests that fullscreen window causes always_on_top windows to stack below. |
655 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) { | 666 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) { |
656 gfx::Rect bounds(100, 100, 200, 200); | 667 gfx::Rect bounds(100, 100, 200, 200); |
657 std::unique_ptr<aura::Window> fullscreen_window(CreateTestWindow(bounds)); | 668 std::unique_ptr<WindowOwner> fullscreen_window_owner( |
658 std::unique_ptr<aura::Window> always_on_top_window1(CreateTestWindow(bounds)); | 669 CreateTestWindow(bounds)); |
659 std::unique_ptr<aura::Window> always_on_top_window2(CreateTestWindow(bounds)); | 670 WmWindow* fullscreen_window = fullscreen_window_owner->window(); |
660 always_on_top_window1->SetProperty(aura::client::kAlwaysOnTopKey, true); | 671 std::unique_ptr<WindowOwner> always_on_top_window1_owner( |
661 always_on_top_window2->SetProperty(aura::client::kAlwaysOnTopKey, true); | 672 CreateTestWindow(bounds)); |
| 673 WmWindow* always_on_top_window1 = always_on_top_window1_owner->window(); |
| 674 std::unique_ptr<WindowOwner> always_on_top_window2_owner( |
| 675 CreateTestWindow(bounds)); |
| 676 WmWindow* always_on_top_window2 = always_on_top_window2_owner->window(); |
| 677 always_on_top_window1->SetAlwaysOnTop(true); |
| 678 always_on_top_window2->SetAlwaysOnTop(true); |
662 // Making a window fullscreen temporarily suspends always on top state. | 679 // Making a window fullscreen temporarily suspends always on top state. |
663 fullscreen_window->SetProperty(aura::client::kShowStateKey, | 680 fullscreen_window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
664 ui::SHOW_STATE_FULLSCREEN); | 681 EXPECT_FALSE(always_on_top_window1->IsAlwaysOnTop()); |
665 EXPECT_FALSE( | 682 EXPECT_FALSE(always_on_top_window2->IsAlwaysOnTop()); |
666 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey)); | 683 EXPECT_NE(nullptr, wm::GetWindowForFullscreenMode(fullscreen_window)); |
667 EXPECT_FALSE( | |
668 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey)); | |
669 EXPECT_NE(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow()) | |
670 ->GetWindowForFullscreenMode()); | |
671 | 684 |
672 // Adding a new always-on-top window is not affected by fullscreen. | 685 // Adding a new always-on-top window is not affected by fullscreen. |
673 std::unique_ptr<aura::Window> always_on_top_window3(CreateTestWindow(bounds)); | 686 std::unique_ptr<WindowOwner> always_on_top_window3_owner( |
674 always_on_top_window3->SetProperty(aura::client::kAlwaysOnTopKey, true); | 687 CreateTestWindow(bounds)); |
675 EXPECT_TRUE( | 688 WmWindow* always_on_top_window3 = always_on_top_window3_owner->window(); |
676 always_on_top_window3->GetProperty(aura::client::kAlwaysOnTopKey)); | 689 always_on_top_window3->SetAlwaysOnTop(true); |
| 690 EXPECT_TRUE(always_on_top_window3->IsAlwaysOnTop()); |
677 | 691 |
678 // Making fullscreen window normal restores always on top windows. | 692 // Making fullscreen window normal restores always on top windows. |
679 fullscreen_window->SetProperty(aura::client::kShowStateKey, | 693 fullscreen_window->SetShowState(ui::SHOW_STATE_NORMAL); |
680 ui::SHOW_STATE_NORMAL); | 694 EXPECT_TRUE(always_on_top_window1->IsAlwaysOnTop()); |
681 EXPECT_TRUE( | 695 EXPECT_TRUE(always_on_top_window2->IsAlwaysOnTop()); |
682 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey)); | 696 EXPECT_TRUE(always_on_top_window3->IsAlwaysOnTop()); |
683 EXPECT_TRUE( | 697 EXPECT_EQ(nullptr, wm::GetWindowForFullscreenMode(fullscreen_window)); |
684 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey)); | |
685 EXPECT_TRUE( | |
686 always_on_top_window3->GetProperty(aura::client::kAlwaysOnTopKey)); | |
687 EXPECT_EQ(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow()) | |
688 ->GetWindowForFullscreenMode()); | |
689 } | 698 } |
690 | 699 |
691 // Similary, pinned window causes always_on_top_ windows to stack below. | 700 // Similary, pinned window causes always_on_top_ windows to stack below. |
692 TEST_F(WorkspaceLayoutManagerSoloTest, PinnedSuspendsAlwaysOnTop) { | 701 TEST_F(WorkspaceLayoutManagerSoloTest, PinnedSuspendsAlwaysOnTop) { |
| 702 // TODO: mash doesn't support pinning yet http://crbug.com/622486. |
| 703 if (WmShell::Get()->IsRunningInMash()) |
| 704 return; |
| 705 |
693 gfx::Rect bounds(100, 100, 200, 200); | 706 gfx::Rect bounds(100, 100, 200, 200); |
694 std::unique_ptr<aura::Window> pinned_window(CreateTestWindow(bounds)); | 707 std::unique_ptr<WindowOwner> pinned_window_owner(CreateTestWindow(bounds)); |
695 std::unique_ptr<aura::Window> always_on_top_window1(CreateTestWindow(bounds)); | 708 WmWindow* pinned_window = pinned_window_owner->window(); |
696 std::unique_ptr<aura::Window> always_on_top_window2(CreateTestWindow(bounds)); | 709 std::unique_ptr<WindowOwner> always_on_top_window1_owner( |
697 always_on_top_window1->SetProperty(aura::client::kAlwaysOnTopKey, true); | 710 CreateTestWindow(bounds)); |
698 always_on_top_window2->SetProperty(aura::client::kAlwaysOnTopKey, true); | 711 WmWindow* always_on_top_window1 = always_on_top_window1_owner->window(); |
| 712 std::unique_ptr<WindowOwner> always_on_top_window2_owner( |
| 713 CreateTestWindow(bounds)); |
| 714 WmWindow* always_on_top_window2 = always_on_top_window2_owner->window(); |
| 715 always_on_top_window1->SetAlwaysOnTop(true); |
| 716 always_on_top_window2->SetAlwaysOnTop(true); |
699 | 717 |
700 // Making a window pinned temporarily suspends always on top state. | 718 // Making a window pinned temporarily suspends always on top state. |
701 wm::PinWindow(pinned_window.get(), /* trusted */ false); | 719 const bool trusted = false; |
702 EXPECT_FALSE( | 720 pinned_window->SetPinned(trusted); |
703 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey)); | 721 EXPECT_FALSE(always_on_top_window1->IsAlwaysOnTop()); |
704 EXPECT_FALSE( | 722 EXPECT_FALSE(always_on_top_window2->IsAlwaysOnTop()); |
705 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey)); | |
706 | 723 |
707 // Adding a new always-on-top window also is affected by pinned mode. | 724 // Adding a new always-on-top window also is affected by pinned mode. |
708 std::unique_ptr<aura::Window> always_on_top_window3(CreateTestWindow(bounds)); | 725 std::unique_ptr<WindowOwner> always_on_top_window3_owner( |
709 always_on_top_window3->SetProperty(aura::client::kAlwaysOnTopKey, true); | 726 CreateTestWindow(bounds)); |
710 EXPECT_FALSE( | 727 WmWindow* always_on_top_window3 = always_on_top_window3_owner->window(); |
711 always_on_top_window3->GetProperty(aura::client::kAlwaysOnTopKey)); | 728 always_on_top_window3->SetAlwaysOnTop(true); |
| 729 EXPECT_FALSE(always_on_top_window3->IsAlwaysOnTop()); |
712 | 730 |
713 // Making pinned window normal restores always on top windows. | 731 // Making pinned window normal restores always on top windows. |
714 WmWindowAura::Get(pinned_window.get())->GetWindowState()->Restore(); | 732 pinned_window->GetWindowState()->Restore(); |
715 EXPECT_TRUE( | 733 EXPECT_TRUE(always_on_top_window1->IsAlwaysOnTop()); |
716 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey)); | 734 EXPECT_TRUE(always_on_top_window2->IsAlwaysOnTop()); |
717 EXPECT_TRUE( | 735 EXPECT_TRUE(always_on_top_window3->IsAlwaysOnTop()); |
718 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey)); | |
719 EXPECT_TRUE( | |
720 always_on_top_window3->GetProperty(aura::client::kAlwaysOnTopKey)); | |
721 } | 736 } |
722 | 737 |
723 // Tests fullscreen window size during root window resize. | 738 // Tests fullscreen window size during root window resize. |
724 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) { | 739 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) { |
725 gfx::Rect bounds(100, 100, 200, 200); | 740 gfx::Rect bounds(100, 100, 200, 200); |
726 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 741 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds)); |
| 742 WmWindow* window = window_owner->window(); |
727 // Fullscreen window fills the whole display. | 743 // Fullscreen window fills the whole display. |
728 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 744 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
729 EXPECT_EQ(display::Screen::GetScreen() | 745 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), |
730 ->GetDisplayNearestWindow(window.get()) | 746 window->GetBounds().ToString()); |
731 .bounds() | |
732 .ToString(), | |
733 window->bounds().ToString()); | |
734 // Enlarge the root window. We should still match the display size. | 747 // Enlarge the root window. We should still match the display size. |
735 UpdateDisplay("800x600"); | 748 UpdateDisplay("800x600"); |
736 EXPECT_EQ(display::Screen::GetScreen() | 749 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), |
737 ->GetDisplayNearestWindow(window.get()) | 750 window->GetBounds().ToString()); |
738 .bounds() | |
739 .ToString(), | |
740 window->bounds().ToString()); | |
741 } | 751 } |
742 | 752 |
743 // Tests that when the screen gets smaller the windows aren't bigger than | 753 // Tests that when the screen gets smaller the windows aren't bigger than |
744 // the screen. | 754 // the screen. |
745 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) { | 755 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) { |
746 std::unique_ptr<aura::Window> window( | 756 std::unique_ptr<WindowOwner> window_owner( |
747 CreateTestWindow(gfx::Rect(10, 20, 500, 400))); | 757 CreateTestWindow(gfx::Rect(10, 20, 500, 400))); |
748 gfx::Rect work_area = display::Screen::GetScreen() | 758 WmWindow* window = window_owner->window(); |
749 ->GetDisplayNearestWindow(window.get()) | 759 gfx::Rect work_area = window->GetDisplayNearestWindow().work_area(); |
750 .work_area(); | |
751 // Invariant: Window is smaller than work area. | 760 // Invariant: Window is smaller than work area. |
752 EXPECT_LE(window->bounds().width(), work_area.width()); | 761 EXPECT_LE(window->GetBounds().width(), work_area.width()); |
753 EXPECT_LE(window->bounds().height(), work_area.height()); | 762 EXPECT_LE(window->GetBounds().height(), work_area.height()); |
754 | 763 |
755 // Make the root window narrower than our window. | 764 // Make the root window narrower than our window. |
756 UpdateDisplay("300x400"); | 765 UpdateDisplay("300x400"); |
757 work_area = display::Screen::GetScreen() | 766 work_area = window->GetDisplayNearestWindow().work_area(); |
758 ->GetDisplayNearestWindow(window.get()) | 767 EXPECT_LE(window->GetBounds().width(), work_area.width()); |
759 .work_area(); | 768 EXPECT_LE(window->GetBounds().height(), work_area.height()); |
760 EXPECT_LE(window->bounds().width(), work_area.width()); | |
761 EXPECT_LE(window->bounds().height(), work_area.height()); | |
762 | 769 |
763 // Make the root window shorter than our window. | 770 // Make the root window shorter than our window. |
764 UpdateDisplay("300x200"); | 771 UpdateDisplay("300x200"); |
765 work_area = display::Screen::GetScreen() | 772 work_area = window->GetDisplayNearestWindow().work_area(); |
766 ->GetDisplayNearestWindow(window.get()) | 773 EXPECT_LE(window->GetBounds().width(), work_area.width()); |
767 .work_area(); | 774 EXPECT_LE(window->GetBounds().height(), work_area.height()); |
768 EXPECT_LE(window->bounds().width(), work_area.width()); | |
769 EXPECT_LE(window->bounds().height(), work_area.height()); | |
770 | 775 |
771 // Enlarging the root window does not change the window bounds. | 776 // Enlarging the root window does not change the window bounds. |
772 gfx::Rect old_bounds = window->bounds(); | 777 gfx::Rect old_bounds = window->GetBounds(); |
773 UpdateDisplay("800x600"); | 778 UpdateDisplay("800x600"); |
774 EXPECT_EQ(old_bounds.width(), window->bounds().width()); | 779 EXPECT_EQ(old_bounds.width(), window->GetBounds().width()); |
775 EXPECT_EQ(old_bounds.height(), window->bounds().height()); | 780 EXPECT_EQ(old_bounds.height(), window->GetBounds().height()); |
776 } | 781 } |
777 | 782 |
778 // Verifies maximizing sets the restore bounds, and restoring | 783 // Verifies maximizing sets the restore bounds, and restoring |
779 // restores the bounds. | 784 // restores the bounds. |
780 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) { | 785 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) { |
781 std::unique_ptr<aura::Window> window( | 786 std::unique_ptr<WindowOwner> window_owner( |
782 CreateTestWindow(gfx::Rect(10, 20, 30, 40))); | 787 CreateTestWindow(gfx::Rect(10, 20, 30, 40))); |
783 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 788 WmWindow* window = window_owner->window(); |
| 789 wm::WindowState* window_state = window->GetWindowState(); |
784 | 790 |
785 // Maximize it, which will keep the previous restore bounds. | 791 // Maximize it, which will keep the previous restore bounds. |
786 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 792 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
787 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString()); | 793 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString()); |
788 | 794 |
789 // Restore it, which should restore bounds and reset restore bounds. | 795 // Restore it, which should restore bounds and reset restore bounds. |
790 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 796 window->SetShowState(ui::SHOW_STATE_NORMAL); |
791 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); | 797 EXPECT_EQ("10,20 30x40", window->GetBounds().ToString()); |
792 EXPECT_FALSE(window_state->HasRestoreBounds()); | 798 EXPECT_FALSE(window_state->HasRestoreBounds()); |
793 } | 799 } |
794 | 800 |
795 // Verifies maximizing keeps the restore bounds if set. | 801 // Verifies maximizing keeps the restore bounds if set. |
796 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeResetsRestoreBounds) { | 802 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeResetsRestoreBounds) { |
797 std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 803 std::unique_ptr<WindowOwner> window_owner( |
798 | 804 CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
799 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 805 WmWindow* window = window_owner->window(); |
| 806 wm::WindowState* window_state = window->GetWindowState(); |
800 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13)); | 807 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13)); |
801 | 808 |
802 // Maximize it, which will keep the previous restore bounds. | 809 // Maximize it, which will keep the previous restore bounds. |
803 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 810 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
804 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString()); | 811 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString()); |
805 } | 812 } |
806 | 813 |
807 // Verifies that the restore bounds do not get reset when restoring to a | 814 // Verifies that the restore bounds do not get reset when restoring to a |
808 // maximzied state from a minimized state. | 815 // maximzied state from a minimized state. |
809 TEST_F(WorkspaceLayoutManagerSoloTest, | 816 TEST_F(WorkspaceLayoutManagerSoloTest, |
810 BoundsAfterRestoringToMaximizeFromMinimize) { | 817 BoundsAfterRestoringToMaximizeFromMinimize) { |
811 std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 818 std::unique_ptr<WindowOwner> window_owner( |
| 819 CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 820 WmWindow* window = window_owner->window(); |
812 gfx::Rect bounds(10, 15, 25, 35); | 821 gfx::Rect bounds(10, 15, 25, 35); |
813 window->SetBounds(bounds); | 822 window->SetBounds(bounds); |
814 | 823 |
815 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 824 wm::WindowState* window_state = window->GetWindowState(); |
816 // Maximize it, which should reset restore bounds. | 825 // Maximize it, which should reset restore bounds. |
817 window_state->Maximize(); | 826 window_state->Maximize(); |
818 EXPECT_EQ(bounds.ToString(), | 827 EXPECT_EQ(bounds.ToString(), |
819 window_state->GetRestoreBoundsInParent().ToString()); | 828 window_state->GetRestoreBoundsInParent().ToString()); |
820 // Minimize the window. The restore bounds should not change. | 829 // Minimize the window. The restore bounds should not change. |
821 window_state->Minimize(); | 830 window_state->Minimize(); |
822 EXPECT_EQ(bounds.ToString(), | 831 EXPECT_EQ(bounds.ToString(), |
823 window_state->GetRestoreBoundsInParent().ToString()); | 832 window_state->GetRestoreBoundsInParent().ToString()); |
824 | 833 |
825 // Show the window again. The window should be maximized, and the restore | 834 // Show the window again. The window should be maximized, and the restore |
826 // bounds should not change. | 835 // bounds should not change. |
827 window->Show(); | 836 window->Show(); |
828 EXPECT_EQ(bounds.ToString(), | 837 EXPECT_EQ(bounds.ToString(), |
829 window_state->GetRestoreBoundsInParent().ToString()); | 838 window_state->GetRestoreBoundsInParent().ToString()); |
830 EXPECT_TRUE(window_state->IsMaximized()); | 839 EXPECT_TRUE(window_state->IsMaximized()); |
831 | 840 |
832 window_state->Restore(); | 841 window_state->Restore(); |
833 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); | 842 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString()); |
834 } | 843 } |
835 | 844 |
836 // Verify if the window is not resized during screen lock. See: crbug.com/173127 | 845 // Verify if the window is not resized during screen lock. See: crbug.com/173127 |
837 TEST_F(WorkspaceLayoutManagerSoloTest, NotResizeWhenScreenIsLocked) { | 846 TEST_F(WorkspaceLayoutManagerSoloTest, NotResizeWhenScreenIsLocked) { |
838 SetCanLockScreen(true); | 847 test::TestSessionStateDelegate::SetCanLockScreen(true); |
839 std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 848 std::unique_ptr<WindowOwner> window_owner( |
| 849 CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 850 WmWindow* window = window_owner->window(); |
840 // window with AlwaysOnTop will be managed by BaseLayoutManager. | 851 // window with AlwaysOnTop will be managed by BaseLayoutManager. |
841 window->SetProperty(aura::client::kAlwaysOnTopKey, true); | 852 window->SetAlwaysOnTop(true); |
842 window->Show(); | 853 window->Show(); |
843 | 854 |
844 WmShelf* shelf = GetPrimaryShelf(); | 855 WmShelf* shelf = GetPrimaryShelf(); |
845 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 856 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
846 | 857 |
847 window->SetBounds(ScreenUtil::GetMaximizedWindowBoundsInParent(window.get())); | 858 window->SetBounds(wm::GetMaximizedWindowBoundsInParent(window)); |
848 gfx::Rect window_bounds = window->bounds(); | 859 gfx::Rect window_bounds = window->GetBounds(); |
849 EXPECT_EQ( | 860 EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(), |
850 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), | 861 window_bounds.ToString()); |
851 window_bounds.ToString()); | |
852 | 862 |
853 // The window size should not get touched while we are in lock screen. | 863 // The window size should not get touched while we are in lock screen. |
854 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); | 864 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); |
855 ShelfLayoutManager* shelf_layout_manager = shelf->shelf_layout_manager(); | 865 ShelfLayoutManager* shelf_layout_manager = shelf->shelf_layout_manager(); |
856 shelf_layout_manager->UpdateVisibilityState(); | 866 shelf_layout_manager->UpdateVisibilityState(); |
857 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); | 867 EXPECT_EQ(window_bounds.ToString(), window->GetBounds().ToString()); |
858 | 868 |
859 // Coming out of the lock screen the window size should still remain. | 869 // Coming out of the lock screen the window size should still remain. |
860 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen(); | 870 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen(); |
861 shelf_layout_manager->UpdateVisibilityState(); | 871 shelf_layout_manager->UpdateVisibilityState(); |
862 EXPECT_EQ( | 872 EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(), |
863 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), | 873 window_bounds.ToString()); |
864 window_bounds.ToString()); | 874 EXPECT_EQ(window_bounds.ToString(), window->GetBounds().ToString()); |
865 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); | |
866 } | 875 } |
867 | 876 |
868 // Following tests are written to test the backdrop functionality. | 877 // Following tests are written to test the backdrop functionality. |
869 | 878 |
870 namespace { | 879 namespace { |
871 | 880 |
872 WorkspaceLayoutManager* GetWorkspaceLayoutManager(aura::Window* container) { | 881 WorkspaceLayoutManager* GetWorkspaceLayoutManager(WmWindow* container) { |
873 return static_cast<WorkspaceLayoutManager*>( | 882 return static_cast<WorkspaceLayoutManager*>(container->GetLayoutManager()); |
874 WmWindowAura::Get(container)->GetLayoutManager()); | |
875 } | 883 } |
876 | 884 |
877 class WorkspaceLayoutManagerBackdropTest : public test::AshTestBase { | 885 class WorkspaceLayoutManagerBackdropTest : public AshTest { |
878 public: | 886 public: |
879 WorkspaceLayoutManagerBackdropTest() : default_container_(nullptr) {} | 887 WorkspaceLayoutManagerBackdropTest() : default_container_(nullptr) {} |
880 ~WorkspaceLayoutManagerBackdropTest() override {} | 888 ~WorkspaceLayoutManagerBackdropTest() override {} |
881 | 889 |
882 void SetUp() override { | 890 void SetUp() override { |
883 test::AshTestBase::SetUp(); | 891 AshTest::SetUp(); |
884 UpdateDisplay("800x600"); | 892 UpdateDisplay("800x600"); |
885 default_container_ = Shell::GetContainer(Shell::GetPrimaryRootWindow(), | 893 default_container_ = |
886 kShellWindowId_DefaultContainer); | 894 WmShell::Get()->GetPrimaryRootWindowController()->GetContainer( |
887 } | 895 kShellWindowId_DefaultContainer); |
888 | |
889 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | |
890 aura::Window* window = CreateTestWindowInShellWithBounds(bounds); | |
891 return window; | |
892 } | 896 } |
893 | 897 |
894 // Turn the top window back drop on / off. | 898 // Turn the top window back drop on / off. |
895 void ShowTopWindowBackdrop(bool show) { | 899 void ShowTopWindowBackdrop(bool show) { |
896 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> backdrop; | 900 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> backdrop; |
897 if (show) { | 901 if (show) |
898 backdrop.reset(new WorkspaceBackdropDelegate( | 902 backdrop.reset(new WorkspaceBackdropDelegate(default_container_)); |
899 WmWindowAura::Get(default_container_))); | |
900 } | |
901 GetWorkspaceLayoutManager(default_container_) | 903 GetWorkspaceLayoutManager(default_container_) |
902 ->SetMaximizeBackdropDelegate(std::move(backdrop)); | 904 ->SetMaximizeBackdropDelegate(std::move(backdrop)); |
903 // Closing and / or opening can be a delayed operation. | 905 // Closing and / or opening can be a delayed operation. |
904 base::RunLoop().RunUntilIdle(); | 906 base::RunLoop().RunUntilIdle(); |
905 } | 907 } |
906 | 908 |
907 // Return the default container. | 909 // Return the default container. |
908 aura::Window* default_container() { return default_container_; } | 910 WmWindow* default_container() { return default_container_; } |
909 | 911 |
910 // Return the order of windows (top most first) as they are in the default | 912 // Return the order of windows (top most first) as they are in the default |
911 // container. If the window is visible it will be a big letter, otherwise a | 913 // container. If the window is visible it will be a big letter, otherwise a |
912 // small one. The backdrop will be an X and unknown windows will be shown as | 914 // small one. The backdrop will be an X and unknown windows will be shown as |
913 // '!'. | 915 // '!'. |
914 std::string GetWindowOrderAsString(aura::Window* backdrop, | 916 std::string GetWindowOrderAsString(WmWindow* backdrop, |
915 aura::Window* wa, | 917 WmWindow* wa, |
916 aura::Window* wb, | 918 WmWindow* wb, |
917 aura::Window* wc) { | 919 WmWindow* wc) { |
918 std::string result; | 920 std::string result; |
919 for (int i = static_cast<int>(default_container()->children().size()) - 1; | 921 WmWindow::Windows children = default_container()->GetChildren(); |
920 i >= 0; --i) { | 922 for (int i = static_cast<int>(children.size()) - 1; i >= 0; --i) { |
921 if (!result.empty()) | 923 if (!result.empty()) |
922 result += ","; | 924 result += ","; |
923 if (default_container()->children()[i] == wa) | 925 if (children[i] == wa) |
924 result += default_container()->children()[i]->IsVisible() ? "A" : "a"; | 926 result += children[i]->IsVisible() ? "A" : "a"; |
925 else if (default_container()->children()[i] == wb) | 927 else if (children[i] == wb) |
926 result += default_container()->children()[i]->IsVisible() ? "B" : "b"; | 928 result += children[i]->IsVisible() ? "B" : "b"; |
927 else if (default_container()->children()[i] == wc) | 929 else if (children[i] == wc) |
928 result += default_container()->children()[i]->IsVisible() ? "C" : "c"; | 930 result += children[i]->IsVisible() ? "C" : "c"; |
929 else if (default_container()->children()[i] == backdrop) | 931 else if (children[i] == backdrop) |
930 result += default_container()->children()[i]->IsVisible() ? "X" : "x"; | 932 result += children[i]->IsVisible() ? "X" : "x"; |
931 else | 933 else |
932 result += "!"; | 934 result += "!"; |
933 } | 935 } |
934 return result; | 936 return result; |
935 } | 937 } |
936 | 938 |
937 private: | 939 private: |
938 // The default container. | 940 // The default container. |
939 aura::Window* default_container_; | 941 WmWindow* default_container_; |
940 | 942 |
941 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerBackdropTest); | 943 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerBackdropTest); |
942 }; | 944 }; |
943 | 945 |
944 } // namespace | 946 } // namespace |
945 | 947 |
946 // Check that creating the BackDrop without destroying it does not lead into | 948 // Check that creating the BackDrop without destroying it does not lead into |
947 // a crash. | 949 // a crash. |
948 TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropCrashTest) { | 950 TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropCrashTest) { |
| 951 // TODO: Triggers crash in mash: http://crbug.com/652871. |
| 952 if (WmShell::Get()->IsRunningInMash()) |
| 953 return; |
| 954 |
949 ShowTopWindowBackdrop(true); | 955 ShowTopWindowBackdrop(true); |
950 } | 956 } |
951 | 957 |
952 // Verify basic assumptions about the backdrop. | 958 // Verify basic assumptions about the backdrop. |
953 TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) { | 959 TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) { |
| 960 // TODO: Triggers crash in mash: http://crbug.com/652871. |
| 961 if (WmShell::Get()->IsRunningInMash()) |
| 962 return; |
| 963 |
954 // Create a backdrop and see that there is one window (the backdrop) and | 964 // Create a backdrop and see that there is one window (the backdrop) and |
955 // that the size is the same as the default container as well as that it is | 965 // that the size is the same as the default container as well as that it is |
956 // not visible. | 966 // not visible. |
957 ShowTopWindowBackdrop(true); | 967 ShowTopWindowBackdrop(true); |
958 ASSERT_EQ(1U, default_container()->children().size()); | 968 ASSERT_EQ(1U, default_container()->GetChildren().size()); |
959 EXPECT_FALSE(default_container()->children()[0]->IsVisible()); | 969 EXPECT_FALSE(default_container()->GetChildren()[0]->IsVisible()); |
960 | 970 |
961 { | 971 { |
962 // Add a window and make sure that the backdrop is the second child. | 972 // Add a window and make sure that the backdrop is the second child. |
963 std::unique_ptr<aura::Window> window( | 973 std::unique_ptr<WindowOwner> window_owner( |
964 CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 974 CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 975 WmWindow* window = window_owner->window(); |
965 window->Show(); | 976 window->Show(); |
966 ASSERT_EQ(2U, default_container()->children().size()); | 977 ASSERT_EQ(2U, default_container()->GetChildren().size()); |
967 EXPECT_TRUE(default_container()->children()[0]->IsVisible()); | 978 EXPECT_TRUE(default_container()->GetChildren()[0]->IsVisible()); |
968 EXPECT_TRUE(default_container()->children()[1]->IsVisible()); | 979 EXPECT_TRUE(default_container()->GetChildren()[1]->IsVisible()); |
969 EXPECT_EQ(window.get(), default_container()->children()[1]); | 980 EXPECT_EQ(window, default_container()->GetChildren()[1]); |
970 EXPECT_EQ(default_container()->bounds().ToString(), | 981 EXPECT_EQ(default_container()->GetBounds().ToString(), |
971 default_container()->children()[0]->bounds().ToString()); | 982 default_container()->GetChildren()[0]->GetBounds().ToString()); |
972 } | 983 } |
973 | 984 |
974 // With the window gone the backdrop should be invisible again. | 985 // With the window gone the backdrop should be invisible again. |
975 ASSERT_EQ(1U, default_container()->children().size()); | 986 ASSERT_EQ(1U, default_container()->GetChildren().size()); |
976 EXPECT_FALSE(default_container()->children()[0]->IsVisible()); | 987 EXPECT_FALSE(default_container()->GetChildren()[0]->IsVisible()); |
977 | 988 |
978 // Destroying the Backdrop should empty the container. | 989 // Destroying the Backdrop should empty the container. |
979 ShowTopWindowBackdrop(false); | 990 ShowTopWindowBackdrop(false); |
980 ASSERT_EQ(0U, default_container()->children().size()); | 991 ASSERT_EQ(0U, default_container()->GetChildren().size()); |
981 } | 992 } |
982 | 993 |
983 // Verify that the backdrop gets properly created and placed. | 994 // Verify that the backdrop gets properly created and placed. |
984 TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) { | 995 TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) { |
985 std::unique_ptr<aura::Window> window1( | 996 // TODO: Triggers crash in mash: http://crbug.com/652871. |
| 997 if (WmShell::Get()->IsRunningInMash()) |
| 998 return; |
| 999 |
| 1000 std::unique_ptr<WindowOwner> window1_owner( |
986 CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 1001 CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 1002 WmWindow* window1 = window1_owner->window(); |
987 window1->Show(); | 1003 window1->Show(); |
988 | 1004 |
989 // Get the default container and check that only a single window is in there. | 1005 // Get the default container and check that only a single window is in there. |
990 ASSERT_EQ(1U, default_container()->children().size()); | 1006 ASSERT_EQ(1U, default_container()->GetChildren().size()); |
991 EXPECT_EQ(window1.get(), default_container()->children()[0]); | 1007 EXPECT_EQ(window1, default_container()->GetChildren()[0]); |
992 EXPECT_EQ("A", | 1008 EXPECT_EQ("A", GetWindowOrderAsString(nullptr, window1, nullptr, nullptr)); |
993 GetWindowOrderAsString(nullptr, window1.get(), nullptr, nullptr)); | |
994 | 1009 |
995 // Create 2 more windows and check that they are also in the container. | 1010 // Create 2 more windows and check that they are also in the container. |
996 std::unique_ptr<aura::Window> window2( | 1011 std::unique_ptr<WindowOwner> window2_owner( |
997 CreateTestWindow(gfx::Rect(10, 2, 3, 4))); | 1012 CreateTestWindow(gfx::Rect(10, 2, 3, 4))); |
998 std::unique_ptr<aura::Window> window3( | 1013 WmWindow* window2 = window2_owner->window(); |
| 1014 std::unique_ptr<WindowOwner> window3_owner( |
999 CreateTestWindow(gfx::Rect(20, 2, 3, 4))); | 1015 CreateTestWindow(gfx::Rect(20, 2, 3, 4))); |
| 1016 WmWindow* window3 = window3_owner->window(); |
1000 window2->Show(); | 1017 window2->Show(); |
1001 window3->Show(); | 1018 window3->Show(); |
1002 | 1019 |
1003 aura::Window* backdrop = nullptr; | 1020 WmWindow* backdrop = nullptr; |
1004 EXPECT_EQ("C,B,A", GetWindowOrderAsString(backdrop, window1.get(), | 1021 EXPECT_EQ("C,B,A", |
1005 window2.get(), window3.get())); | 1022 GetWindowOrderAsString(backdrop, window1, window2, window3)); |
1006 | 1023 |
1007 // Turn on the backdrop mode and check that the window shows up where it | 1024 // Turn on the backdrop mode and check that the window shows up where it |
1008 // should be (second highest number). | 1025 // should be (second highest number). |
1009 ShowTopWindowBackdrop(true); | 1026 ShowTopWindowBackdrop(true); |
1010 backdrop = default_container()->children()[2]; | 1027 backdrop = default_container()->GetChildren()[2]; |
1011 EXPECT_EQ("C,X,B,A", GetWindowOrderAsString(backdrop, window1.get(), | 1028 EXPECT_EQ("C,X,B,A", |
1012 window2.get(), window3.get())); | 1029 GetWindowOrderAsString(backdrop, window1, window2, window3)); |
1013 | 1030 |
1014 // Switch the order of windows and check that it still remains in that | 1031 // Switch the order of windows and check that it still remains in that |
1015 // location. | 1032 // location. |
1016 default_container()->StackChildAtTop(window2.get()); | 1033 default_container()->StackChildAtTop(window2); |
1017 EXPECT_EQ("B,X,C,A", GetWindowOrderAsString(backdrop, window1.get(), | 1034 EXPECT_EQ("B,X,C,A", |
1018 window2.get(), window3.get())); | 1035 GetWindowOrderAsString(backdrop, window1, window2, window3)); |
1019 | 1036 |
1020 // Make the top window invisible and check. | 1037 // Make the top window invisible and check. |
1021 window2.get()->Hide(); | 1038 window2->Hide(); |
1022 EXPECT_EQ("b,C,X,A", GetWindowOrderAsString(backdrop, window1.get(), | 1039 EXPECT_EQ("b,C,X,A", |
1023 window2.get(), window3.get())); | 1040 GetWindowOrderAsString(backdrop, window1, window2, window3)); |
1024 // Then delete window after window and see that everything is in order. | 1041 // Then delete window after window and see that everything is in order. |
1025 window1.reset(); | 1042 window1_owner.reset(); |
1026 EXPECT_EQ("b,C,X", GetWindowOrderAsString(backdrop, window1.get(), | 1043 EXPECT_EQ("b,C,X", |
1027 window2.get(), window3.get())); | 1044 GetWindowOrderAsString(backdrop, window1, window2, window3)); |
1028 window3.reset(); | 1045 window3_owner.reset(); |
1029 EXPECT_EQ("b,x", GetWindowOrderAsString(backdrop, window1.get(), | 1046 EXPECT_EQ("b,x", GetWindowOrderAsString(backdrop, window1, window2, window3)); |
1030 window2.get(), window3.get())); | |
1031 ShowTopWindowBackdrop(false); | 1047 ShowTopWindowBackdrop(false); |
1032 EXPECT_EQ("b", GetWindowOrderAsString(nullptr, window1.get(), window2.get(), | 1048 EXPECT_EQ("b", GetWindowOrderAsString(nullptr, window1, window2, window3)); |
1033 window3.get())); | |
1034 } | 1049 } |
1035 | 1050 |
1036 // Tests that when hidding the shelf, that the backdrop resizes to fill the | 1051 // Tests that when hidding the shelf, that the backdrop resizes to fill the |
1037 // entire workspace area. | 1052 // entire workspace area. |
1038 TEST_F(WorkspaceLayoutManagerBackdropTest, ShelfVisibilityChangesBounds) { | 1053 TEST_F(WorkspaceLayoutManagerBackdropTest, ShelfVisibilityChangesBounds) { |
| 1054 // TODO: Triggers crash in mash: http://crbug.com/652871. |
| 1055 if (WmShell::Get()->IsRunningInMash()) |
| 1056 return; |
| 1057 |
1039 WmShelf* shelf = GetPrimaryShelf(); | 1058 WmShelf* shelf = GetPrimaryShelf(); |
1040 ShelfLayoutManager* shelf_layout_manager = shelf->shelf_layout_manager(); | 1059 ShelfLayoutManager* shelf_layout_manager = shelf->shelf_layout_manager(); |
1041 ShowTopWindowBackdrop(true); | 1060 ShowTopWindowBackdrop(true); |
1042 RunAllPendingInMessageLoop(); | 1061 RunAllPendingInMessageLoop(); |
1043 | 1062 |
1044 ASSERT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state()); | 1063 ASSERT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state()); |
1045 gfx::Rect initial_bounds = default_container()->children()[0]->bounds(); | 1064 gfx::Rect initial_bounds = default_container()->GetChildren()[0]->GetBounds(); |
1046 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1065 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
1047 shelf_layout_manager->UpdateVisibilityState(); | 1066 shelf_layout_manager->UpdateVisibilityState(); |
1048 | 1067 |
1049 // When the shelf is re-shown WorkspaceLayoutManager shrinks all children | 1068 // When the shelf is re-shown WorkspaceLayoutManager shrinks all children |
1050 // including the backdrop. | 1069 // including the backdrop. |
1051 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1070 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
1052 shelf_layout_manager->UpdateVisibilityState(); | 1071 shelf_layout_manager->UpdateVisibilityState(); |
1053 gfx::Rect reduced_bounds = default_container()->children()[0]->bounds(); | 1072 gfx::Rect reduced_bounds = default_container()->GetChildren()[0]->GetBounds(); |
1054 EXPECT_LT(reduced_bounds.height(), initial_bounds.height()); | 1073 EXPECT_LT(reduced_bounds.height(), initial_bounds.height()); |
1055 | 1074 |
1056 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1075 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
1057 shelf_layout_manager->UpdateVisibilityState(); | 1076 shelf_layout_manager->UpdateVisibilityState(); |
1058 | 1077 |
1059 EXPECT_GT(default_container()->children()[0]->bounds().height(), | 1078 EXPECT_GT(default_container()->GetChildren()[0]->GetBounds().height(), |
1060 reduced_bounds.height()); | 1079 reduced_bounds.height()); |
1061 } | 1080 } |
1062 | 1081 |
1063 class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase { | 1082 class WorkspaceLayoutManagerKeyboardTest : public AshTest { |
1064 public: | 1083 public: |
1065 WorkspaceLayoutManagerKeyboardTest() : layout_manager_(nullptr) {} | 1084 WorkspaceLayoutManagerKeyboardTest() : layout_manager_(nullptr) {} |
1066 ~WorkspaceLayoutManagerKeyboardTest() override {} | 1085 ~WorkspaceLayoutManagerKeyboardTest() override {} |
1067 | 1086 |
1068 void SetUp() override { | 1087 void SetUp() override { |
1069 test::AshTestBase::SetUp(); | 1088 AshTest::SetUp(); |
1070 UpdateDisplay("800x600"); | 1089 UpdateDisplay("800x600"); |
1071 aura::Window* default_container = Shell::GetContainer( | 1090 WmWindow* default_container = |
1072 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); | 1091 WmShell::Get()->GetPrimaryRootWindowController()->GetContainer( |
| 1092 kShellWindowId_DefaultContainer); |
1073 layout_manager_ = GetWorkspaceLayoutManager(default_container); | 1093 layout_manager_ = GetWorkspaceLayoutManager(default_container); |
1074 } | 1094 } |
1075 | 1095 |
1076 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | |
1077 return CreateTestWindowInShellWithBounds(bounds); | |
1078 } | |
1079 | |
1080 void ShowKeyboard() { | 1096 void ShowKeyboard() { |
1081 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_); | 1097 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_); |
1082 restore_work_area_insets_ = | 1098 restore_work_area_insets_ = |
1083 display::Screen::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets(); | 1099 display::Screen::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets(); |
1084 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 1100 WmShell::Get()->SetDisplayWorkAreaInsets( |
1085 Shell::GetPrimaryRootWindow(), | 1101 WmShell::Get()->GetPrimaryRootWindow(), |
1086 gfx::Insets(0, 0, keyboard_bounds_.height(), 0)); | 1102 gfx::Insets(0, 0, keyboard_bounds_.height(), 0)); |
1087 } | 1103 } |
1088 | 1104 |
1089 void HideKeyboard() { | 1105 void HideKeyboard() { |
1090 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 1106 WmShell::Get()->SetDisplayWorkAreaInsets( |
1091 Shell::GetPrimaryRootWindow(), restore_work_area_insets_); | 1107 WmShell::Get()->GetPrimaryRootWindow(), restore_work_area_insets_); |
1092 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); | 1108 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); |
1093 } | 1109 } |
1094 | 1110 |
1095 // Initializes the keyboard bounds using the bottom half of the work area. | 1111 // Initializes the keyboard bounds using the bottom half of the work area. |
1096 void InitKeyboardBounds() { | 1112 void InitKeyboardBounds() { |
1097 gfx::Rect work_area( | 1113 gfx::Rect work_area( |
1098 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1114 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
1099 keyboard_bounds_.SetRect(work_area.x(), | 1115 keyboard_bounds_.SetRect(work_area.x(), |
1100 work_area.y() + work_area.height() / 2, | 1116 work_area.y() + work_area.height() / 2, |
1101 work_area.width(), work_area.height() / 2); | 1117 work_area.width(), work_area.height() / 2); |
(...skipping 16 matching lines...) Expand all Loading... |
1118 }; | 1134 }; |
1119 | 1135 |
1120 // Tests that when a child window gains focus the top level window containing it | 1136 // Tests that when a child window gains focus the top level window containing it |
1121 // is resized to fit the remaining workspace area. | 1137 // is resized to fit the remaining workspace area. |
1122 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) { | 1138 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) { |
1123 InitKeyboardBounds(); | 1139 InitKeyboardBounds(); |
1124 | 1140 |
1125 gfx::Rect work_area( | 1141 gfx::Rect work_area( |
1126 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1142 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
1127 | 1143 |
1128 aura::test::TestWindowDelegate delegate1; | 1144 std::unique_ptr<WindowOwner> parent_window_owner( |
1129 std::unique_ptr<aura::Window> parent_window( | 1145 CreateToplevelTestWindow(work_area)); |
1130 CreateTestWindowInShellWithDelegate(&delegate1, -1, work_area)); | 1146 WmWindow* parent_window = parent_window_owner->window(); |
1131 aura::test::TestWindowDelegate delegate2; | 1147 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(work_area)); |
1132 std::unique_ptr<aura::Window> window( | 1148 WmWindow* window = window_owner->window(); |
1133 CreateTestWindowInShellWithDelegate(&delegate2, -1, work_area)); | 1149 parent_window->AddChild(window); |
1134 parent_window->AddChild(window.get()); | |
1135 | 1150 |
1136 wm::ActivateWindow(window.get()); | 1151 window->Activate(); |
1137 | 1152 |
1138 int available_height = | 1153 int available_height = |
1139 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() - | 1154 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() - |
1140 keyboard_bounds().height(); | 1155 keyboard_bounds().height(); |
1141 | 1156 |
1142 gfx::Rect initial_window_bounds(50, 50, 100, 500); | 1157 gfx::Rect initial_window_bounds(50, 50, 100, 500); |
1143 parent_window->SetBounds(initial_window_bounds); | 1158 parent_window->SetBounds(initial_window_bounds); |
1144 EXPECT_EQ(initial_window_bounds.ToString(), | 1159 EXPECT_EQ(initial_window_bounds.ToString(), |
1145 parent_window->bounds().ToString()); | 1160 parent_window->GetBounds().ToString()); |
1146 ShowKeyboard(); | 1161 ShowKeyboard(); |
1147 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), | 1162 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), |
1148 parent_window->bounds().ToString()); | 1163 parent_window->GetBounds().ToString()); |
1149 HideKeyboard(); | 1164 HideKeyboard(); |
1150 EXPECT_EQ(initial_window_bounds.ToString(), | 1165 EXPECT_EQ(initial_window_bounds.ToString(), |
1151 parent_window->bounds().ToString()); | 1166 parent_window->GetBounds().ToString()); |
1152 } | 1167 } |
1153 | 1168 |
1154 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { | 1169 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { |
1155 InitKeyboardBounds(); | 1170 InitKeyboardBounds(); |
1156 gfx::Rect work_area( | 1171 gfx::Rect work_area( |
1157 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1172 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
1158 | 1173 |
1159 aura::test::TestWindowDelegate delegate; | 1174 std::unique_ptr<WindowOwner> window_owner( |
1160 std::unique_ptr<aura::Window> window( | 1175 CreateToplevelTestWindow(work_area)); |
1161 CreateTestWindowInShellWithDelegate(&delegate, -1, work_area)); | 1176 WmWindow* window = window_owner->window(); |
1162 | 1177 |
1163 int available_height = | 1178 int available_height = |
1164 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() - | 1179 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() - |
1165 keyboard_bounds().height(); | 1180 keyboard_bounds().height(); |
1166 | 1181 |
1167 wm::ActivateWindow(window.get()); | 1182 window->Activate(); |
1168 | 1183 |
1169 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); | 1184 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->GetBounds().ToString()); |
1170 ShowKeyboard(); | 1185 ShowKeyboard(); |
1171 EXPECT_EQ(gfx::Rect(work_area.origin(), | 1186 EXPECT_EQ(gfx::Rect(work_area.origin(), |
1172 gfx::Size(work_area.width(), available_height)) | 1187 gfx::Size(work_area.width(), available_height)) |
1173 .ToString(), | 1188 .ToString(), |
1174 window->bounds().ToString()); | 1189 window->GetBounds().ToString()); |
1175 HideKeyboard(); | 1190 HideKeyboard(); |
1176 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); | 1191 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->GetBounds().ToString()); |
1177 | 1192 |
1178 gfx::Rect small_window_bound(50, 50, 100, 500); | 1193 gfx::Rect small_window_bound(50, 50, 100, 500); |
1179 window->SetBounds(small_window_bound); | 1194 window->SetBounds(small_window_bound); |
1180 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString()); | 1195 EXPECT_EQ(small_window_bound.ToString(), window->GetBounds().ToString()); |
1181 ShowKeyboard(); | 1196 ShowKeyboard(); |
1182 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), | 1197 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), |
1183 window->bounds().ToString()); | 1198 window->GetBounds().ToString()); |
1184 HideKeyboard(); | 1199 HideKeyboard(); |
1185 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString()); | 1200 EXPECT_EQ(small_window_bound.ToString(), window->GetBounds().ToString()); |
1186 | 1201 |
1187 gfx::Rect occluded_window_bounds( | 1202 gfx::Rect occluded_window_bounds( |
1188 50, keyboard_bounds().y() + keyboard_bounds().height() / 2, 50, | 1203 50, keyboard_bounds().y() + keyboard_bounds().height() / 2, 50, |
1189 keyboard_bounds().height() / 2); | 1204 keyboard_bounds().height() / 2); |
1190 window->SetBounds(occluded_window_bounds); | 1205 window->SetBounds(occluded_window_bounds); |
1191 EXPECT_EQ(occluded_window_bounds.ToString(), | 1206 EXPECT_EQ(occluded_window_bounds.ToString(), |
1192 occluded_window_bounds.ToString()); | 1207 occluded_window_bounds.ToString()); |
1193 ShowKeyboard(); | 1208 ShowKeyboard(); |
1194 EXPECT_EQ( | 1209 EXPECT_EQ( |
1195 gfx::Rect(50, keyboard_bounds().y() - keyboard_bounds().height() / 2, | 1210 gfx::Rect(50, keyboard_bounds().y() - keyboard_bounds().height() / 2, |
1196 occluded_window_bounds.width(), occluded_window_bounds.height()) | 1211 occluded_window_bounds.width(), occluded_window_bounds.height()) |
1197 .ToString(), | 1212 .ToString(), |
1198 window->bounds().ToString()); | 1213 window->GetBounds().ToString()); |
1199 HideKeyboard(); | 1214 HideKeyboard(); |
1200 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString()); | 1215 EXPECT_EQ(occluded_window_bounds.ToString(), window->GetBounds().ToString()); |
1201 } | 1216 } |
1202 | 1217 |
1203 TEST_F(WorkspaceLayoutManagerKeyboardTest, IgnoreKeyboardBoundsChagne) { | 1218 TEST_F(WorkspaceLayoutManagerKeyboardTest, IgnoreKeyboardBoundsChange) { |
1204 InitKeyboardBounds(); | 1219 InitKeyboardBounds(); |
1205 | 1220 |
1206 aura::test::TestWindowDelegate delegate2; | 1221 std::unique_ptr<WindowOwner> window_owner( |
1207 std::unique_ptr<aura::Window> window( | 1222 CreateTestWindow(keyboard_bounds())); |
1208 CreateTestWindowInShellWithDelegate(&delegate2, -1, keyboard_bounds())); | 1223 WmWindow* window = window_owner->window(); |
1209 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true); | 1224 window->GetWindowState()->set_ignore_keyboard_bounds_change(true); |
1210 wm::ActivateWindow(window.get()); | 1225 window->Activate(); |
1211 | 1226 |
1212 EXPECT_EQ(keyboard_bounds(), window->bounds()); | 1227 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); |
1213 ShowKeyboard(); | 1228 ShowKeyboard(); |
1214 EXPECT_EQ(keyboard_bounds(), window->bounds()); | 1229 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); |
1215 } | 1230 } |
1216 | 1231 |
1217 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChangeWorkAreaInNonStickyMode) { | 1232 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChangeWorkAreaInNonStickyMode) { |
1218 keyboard::SetAccessibilityKeyboardEnabled(true); | 1233 keyboard::SetAccessibilityKeyboardEnabled(true); |
1219 InitKeyboardBounds(); | 1234 InitKeyboardBounds(); |
1220 Shell::GetInstance()->CreateKeyboard(); | 1235 Shell::GetInstance()->CreateKeyboard(); |
1221 keyboard::KeyboardController* kb_controller = | 1236 keyboard::KeyboardController* kb_controller = |
1222 keyboard::KeyboardController::GetInstance(); | 1237 keyboard::KeyboardController::GetInstance(); |
1223 | 1238 |
1224 gfx::Rect work_area( | 1239 gfx::Rect work_area( |
1225 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1240 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
1226 | 1241 |
1227 aura::test::TestWindowDelegate delegate; | |
1228 gfx::Rect orig_window_bounds(0, 100, work_area.width(), | 1242 gfx::Rect orig_window_bounds(0, 100, work_area.width(), |
1229 work_area.height() - 100); | 1243 work_area.height() - 100); |
1230 std::unique_ptr<aura::Window> window( | 1244 std::unique_ptr<WindowOwner> window_owner( |
1231 CreateTestWindowInShellWithDelegate(&delegate, -1, orig_window_bounds)); | 1245 CreateToplevelTestWindow(orig_window_bounds)); |
| 1246 WmWindow* window = window_owner->window(); |
1232 | 1247 |
1233 wm::ActivateWindow(window.get()); | 1248 window->Activate(); |
1234 EXPECT_EQ(orig_window_bounds, window->bounds()); | 1249 EXPECT_EQ(orig_window_bounds, window->GetBounds()); |
1235 | 1250 |
1236 // Open keyboard in non-sticky mode. | 1251 // Open keyboard in non-sticky mode. |
1237 kb_controller->ShowKeyboard(false); | 1252 kb_controller->ShowKeyboard(false); |
1238 kb_controller->ui()->GetKeyboardWindow()->SetBounds( | 1253 kb_controller->ui()->GetKeyboardWindow()->SetBounds( |
1239 keyboard::FullWidthKeyboardBoundsFromRootBounds( | 1254 keyboard::FullWidthKeyboardBoundsFromRootBounds( |
1240 Shell::GetPrimaryRootWindow()->bounds(), 100)); | 1255 WmShell::Get()->GetPrimaryRootWindow()->GetBounds(), 100)); |
1241 | 1256 |
1242 int shift = | 1257 int shift = |
1243 work_area.height() - kb_controller->GetContainerWindow()->bounds().y(); | 1258 work_area.height() - kb_controller->GetContainerWindow()->bounds().y(); |
1244 gfx::Rect changed_window_bounds(orig_window_bounds); | 1259 gfx::Rect changed_window_bounds(orig_window_bounds); |
1245 changed_window_bounds.Offset(0, -shift); | 1260 changed_window_bounds.Offset(0, -shift); |
1246 // Window should be shifted up. | 1261 // Window should be shifted up. |
1247 EXPECT_EQ(changed_window_bounds, window->bounds()); | 1262 EXPECT_EQ(changed_window_bounds, window->GetBounds()); |
1248 | 1263 |
1249 kb_controller->HideKeyboard( | 1264 kb_controller->HideKeyboard( |
1250 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | 1265 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); |
1251 EXPECT_EQ(orig_window_bounds, window->bounds()); | 1266 EXPECT_EQ(orig_window_bounds, window->GetBounds()); |
1252 | 1267 |
1253 // Open keyboard in sticky mode. | 1268 // Open keyboard in sticky mode. |
1254 kb_controller->ShowKeyboard(true); | 1269 kb_controller->ShowKeyboard(true); |
1255 | 1270 |
1256 // Window should be shifted up. | 1271 // Window should be shifted up. |
1257 EXPECT_EQ(changed_window_bounds, window->bounds()); | 1272 EXPECT_EQ(changed_window_bounds, window->GetBounds()); |
1258 | 1273 |
1259 kb_controller->HideKeyboard( | 1274 kb_controller->HideKeyboard( |
1260 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | 1275 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); |
1261 EXPECT_EQ(orig_window_bounds, window->bounds()); | 1276 EXPECT_EQ(orig_window_bounds, window->GetBounds()); |
1262 } | 1277 } |
1263 | 1278 |
1264 // When kAshUseNewVKWindowBehavior flag enabled, do not change accessibility | 1279 // When kAshUseNewVKWindowBehavior flag enabled, do not change accessibility |
1265 // keyboard work area in non-sticky mode. | 1280 // keyboard work area in non-sticky mode. |
1266 TEST_F(WorkspaceLayoutManagerKeyboardTest, | 1281 TEST_F(WorkspaceLayoutManagerKeyboardTest, |
1267 IgnoreWorkAreaChangeinNonStickyMode) { | 1282 IgnoreWorkAreaChangeinNonStickyMode) { |
1268 // Append flag to ignore work area change in non-sticky mode. | 1283 // Append flag to ignore work area change in non-sticky mode. |
1269 EnableNewVKMode(); | 1284 EnableNewVKMode(); |
1270 | 1285 |
1271 keyboard::SetAccessibilityKeyboardEnabled(true); | 1286 keyboard::SetAccessibilityKeyboardEnabled(true); |
1272 InitKeyboardBounds(); | 1287 InitKeyboardBounds(); |
1273 Shell::GetInstance()->CreateKeyboard(); | 1288 Shell::GetInstance()->CreateKeyboard(); |
1274 keyboard::KeyboardController* kb_controller = | 1289 keyboard::KeyboardController* kb_controller = |
1275 keyboard::KeyboardController::GetInstance(); | 1290 keyboard::KeyboardController::GetInstance(); |
1276 | 1291 |
1277 gfx::Rect work_area( | 1292 gfx::Rect work_area( |
1278 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1293 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
1279 | 1294 |
1280 aura::test::TestWindowDelegate delegate; | |
1281 gfx::Rect orig_window_bounds(0, 100, work_area.width(), | 1295 gfx::Rect orig_window_bounds(0, 100, work_area.width(), |
1282 work_area.height() - 100); | 1296 work_area.height() - 100); |
1283 std::unique_ptr<aura::Window> window( | 1297 std::unique_ptr<WindowOwner> window_owner( |
1284 CreateTestWindowInShellWithDelegate(&delegate, -1, orig_window_bounds)); | 1298 CreateToplevelTestWindow(orig_window_bounds)); |
| 1299 WmWindow* window = window_owner->window(); |
1285 | 1300 |
1286 wm::ActivateWindow(window.get()); | 1301 window->Activate(); |
1287 EXPECT_EQ(orig_window_bounds, window->bounds()); | 1302 EXPECT_EQ(orig_window_bounds, window->GetBounds()); |
1288 | 1303 |
1289 // Open keyboard in non-sticky mode. | 1304 // Open keyboard in non-sticky mode. |
1290 kb_controller->ShowKeyboard(false); | 1305 kb_controller->ShowKeyboard(false); |
1291 kb_controller->ui()->GetKeyboardWindow()->SetBounds( | 1306 kb_controller->ui()->GetKeyboardWindow()->SetBounds( |
1292 keyboard::FullWidthKeyboardBoundsFromRootBounds( | 1307 keyboard::FullWidthKeyboardBoundsFromRootBounds( |
1293 Shell::GetPrimaryRootWindow()->bounds(), 100)); | 1308 WmShell::Get()->GetPrimaryRootWindow()->GetBounds(), 100)); |
1294 | 1309 |
1295 // Window should not be shifted up. | 1310 // Window should not be shifted up. |
1296 EXPECT_EQ(orig_window_bounds, window->bounds()); | 1311 EXPECT_EQ(orig_window_bounds, window->GetBounds()); |
1297 | 1312 |
1298 kb_controller->HideKeyboard( | 1313 kb_controller->HideKeyboard( |
1299 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | 1314 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); |
1300 EXPECT_EQ(orig_window_bounds, window->bounds()); | 1315 EXPECT_EQ(orig_window_bounds, window->GetBounds()); |
1301 | 1316 |
1302 // Open keyboard in sticky mode. | 1317 // Open keyboard in sticky mode. |
1303 kb_controller->ShowKeyboard(true); | 1318 kb_controller->ShowKeyboard(true); |
1304 | 1319 |
1305 int shift = | 1320 int shift = |
1306 work_area.height() - kb_controller->GetContainerWindow()->bounds().y(); | 1321 work_area.height() - kb_controller->GetContainerWindow()->bounds().y(); |
1307 gfx::Rect changed_window_bounds(orig_window_bounds); | 1322 gfx::Rect changed_window_bounds(orig_window_bounds); |
1308 changed_window_bounds.Offset(0, -shift); | 1323 changed_window_bounds.Offset(0, -shift); |
1309 // Window should be shifted up. | 1324 // Window should be shifted up. |
1310 EXPECT_EQ(changed_window_bounds, window->bounds()); | 1325 EXPECT_EQ(changed_window_bounds, window->GetBounds()); |
1311 | 1326 |
1312 kb_controller->HideKeyboard( | 1327 kb_controller->HideKeyboard( |
1313 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | 1328 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); |
1314 EXPECT_EQ(orig_window_bounds, window->bounds()); | 1329 EXPECT_EQ(orig_window_bounds, window->GetBounds()); |
1315 } | 1330 } |
1316 | 1331 |
1317 } // namespace ash | 1332 } // namespace ash |
OLD | NEW |