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