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