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