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