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