| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_controller.h" | 5 #include "ash/common/wm/workspace_controller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "ash/common/session/session_controller.h" | 9 #include "ash/common/session/session_controller.h" |
| 10 #include "ash/common/shelf/shelf_layout_manager.h" | 10 #include "ash/common/shelf/shelf_layout_manager.h" |
| 11 #include "ash/common/shelf/shelf_widget.h" | 11 #include "ash/common/shelf/shelf_widget.h" |
| 12 #include "ash/common/shelf/wm_shelf.h" | 12 #include "ash/common/shelf/wm_shelf.h" |
| 13 #include "ash/common/system/status_area_widget.h" | 13 #include "ash/common/system/status_area_widget.h" |
| 14 #include "ash/common/test/test_shelf_delegate.h" | 14 #include "ash/common/test/test_shelf_delegate.h" |
| 15 #include "ash/common/wm/panels/panel_layout_manager.h" | 15 #include "ash/common/wm/panels/panel_layout_manager.h" |
| 16 #include "ash/common/wm/window_state.h" | 16 #include "ash/common/wm/window_state.h" |
| 17 #include "ash/common/wm/workspace/workspace_window_resizer.h" | 17 #include "ash/common/wm/workspace/workspace_window_resizer.h" |
| 18 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
| 19 #include "ash/common/wm_window.h" | 19 #include "ash/common/wm_window.h" |
| 20 #include "ash/public/cpp/shell_window_ids.h" | 20 #include "ash/public/cpp/shell_window_ids.h" |
| 21 #include "ash/screen_util.h" | 21 #include "ash/screen_util.h" |
| 22 #include "ash/shell.h" | 22 #include "ash/shell.h" |
| 23 #include "ash/test/ash_md_test_base.h" | 23 #include "ash/test/ash_test_base.h" |
| 24 #include "ash/test/shell_test_api.h" | 24 #include "ash/test/shell_test_api.h" |
| 25 #include "ash/wm/window_state_aura.h" | 25 #include "ash/wm/window_state_aura.h" |
| 26 #include "ash/wm/window_util.h" | 26 #include "ash/wm/window_util.h" |
| 27 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 28 #include "ui/aura/client/aura_constants.h" | 28 #include "ui/aura/client/aura_constants.h" |
| 29 #include "ui/aura/test/test_window_delegate.h" | 29 #include "ui/aura/test/test_window_delegate.h" |
| 30 #include "ui/aura/test/test_windows.h" | 30 #include "ui/aura/test/test_windows.h" |
| 31 #include "ui/aura/window.h" | 31 #include "ui/aura/window.h" |
| 32 #include "ui/aura/window_event_dispatcher.h" | 32 #include "ui/aura/window_event_dispatcher.h" |
| 33 #include "ui/base/hit_test.h" | 33 #include "ui/base/hit_test.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 LayerToWindowNameMap::iterator layer_i = window_names.find(layers[i]); | 75 LayerToWindowNameMap::iterator layer_i = window_names.find(layers[i]); |
| 76 if (layer_i != window_names.end()) { | 76 if (layer_i != window_names.end()) { |
| 77 if (!result.empty()) | 77 if (!result.empty()) |
| 78 result += " "; | 78 result += " "; |
| 79 result += layer_i->second; | 79 result += layer_i->second; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 return result; | 82 return result; |
| 83 } | 83 } |
| 84 | 84 |
| 85 class WorkspaceControllerTest : public test::AshMDTestBase { | 85 class WorkspaceControllerTest : public test::AshTestBase { |
| 86 public: | 86 public: |
| 87 WorkspaceControllerTest() {} | 87 WorkspaceControllerTest() {} |
| 88 ~WorkspaceControllerTest() override {} | 88 ~WorkspaceControllerTest() override {} |
| 89 | 89 |
| 90 aura::Window* CreateTestWindowUnparented() { | 90 aura::Window* CreateTestWindowUnparented() { |
| 91 aura::Window* window = new aura::Window(NULL); | 91 aura::Window* window = new aura::Window(NULL); |
| 92 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 92 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 93 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 93 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 94 window->Init(ui::LAYER_TEXTURED); | 94 window->Init(ui::LAYER_TEXTURED); |
| 95 return window; | 95 return window; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool GetWindowOverlapsShelf() { | 149 bool GetWindowOverlapsShelf() { |
| 150 return shelf_layout_manager()->window_overlaps_shelf(); | 150 return shelf_layout_manager()->window_overlaps_shelf(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); | 154 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 INSTANTIATE_TEST_CASE_P( | |
| 158 /* prefix intentionally left blank due to only one parameterization */, | |
| 159 WorkspaceControllerTest, | |
| 160 testing::Values(MaterialDesignController::NON_MATERIAL, | |
| 161 MaterialDesignController::MATERIAL_NORMAL, | |
| 162 MaterialDesignController::MATERIAL_EXPERIMENTAL)); | |
| 163 | |
| 164 // Assertions around adding a normal window. | 157 // Assertions around adding a normal window. |
| 165 TEST_P(WorkspaceControllerTest, AddNormalWindowWhenEmpty) { | 158 TEST_F(WorkspaceControllerTest, AddNormalWindowWhenEmpty) { |
| 166 std::unique_ptr<Window> w1(CreateTestWindow()); | 159 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 167 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | 160 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); |
| 168 | 161 |
| 169 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | 162 wm::WindowState* window_state = wm::GetWindowState(w1.get()); |
| 170 | 163 |
| 171 EXPECT_FALSE(window_state->HasRestoreBounds()); | 164 EXPECT_FALSE(window_state->HasRestoreBounds()); |
| 172 | 165 |
| 173 w1->Show(); | 166 w1->Show(); |
| 174 | 167 |
| 175 EXPECT_FALSE(window_state->HasRestoreBounds()); | 168 EXPECT_FALSE(window_state->HasRestoreBounds()); |
| 176 | 169 |
| 177 ASSERT_TRUE(w1->layer() != NULL); | 170 ASSERT_TRUE(w1->layer() != NULL); |
| 178 EXPECT_TRUE(w1->layer()->visible()); | 171 EXPECT_TRUE(w1->layer()->visible()); |
| 179 | 172 |
| 180 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); | 173 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); |
| 181 | 174 |
| 182 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 175 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
| 183 } | 176 } |
| 184 | 177 |
| 185 // Assertions around maximizing/unmaximizing. | 178 // Assertions around maximizing/unmaximizing. |
| 186 TEST_P(WorkspaceControllerTest, SingleMaximizeWindow) { | 179 TEST_F(WorkspaceControllerTest, SingleMaximizeWindow) { |
| 187 std::unique_ptr<Window> w1(CreateTestWindow()); | 180 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 188 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | 181 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); |
| 189 | 182 |
| 190 w1->Show(); | 183 w1->Show(); |
| 191 wm::ActivateWindow(w1.get()); | 184 wm::ActivateWindow(w1.get()); |
| 192 | 185 |
| 193 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 186 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 194 | 187 |
| 195 ASSERT_TRUE(w1->layer() != NULL); | 188 ASSERT_TRUE(w1->layer() != NULL); |
| 196 EXPECT_TRUE(w1->layer()->visible()); | 189 EXPECT_TRUE(w1->layer()->visible()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 209 w1->bounds().height()); | 202 w1->bounds().height()); |
| 210 | 203 |
| 211 // Restore the window. | 204 // Restore the window. |
| 212 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 205 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 213 | 206 |
| 214 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 207 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
| 215 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); | 208 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); |
| 216 } | 209 } |
| 217 | 210 |
| 218 // Assertions around two windows and toggling one to be fullscreen. | 211 // Assertions around two windows and toggling one to be fullscreen. |
| 219 TEST_P(WorkspaceControllerTest, FullscreenWithNormalWindow) { | 212 TEST_F(WorkspaceControllerTest, FullscreenWithNormalWindow) { |
| 220 std::unique_ptr<Window> w1(CreateTestWindow()); | 213 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 221 std::unique_ptr<Window> w2(CreateTestWindow()); | 214 std::unique_ptr<Window> w2(CreateTestWindow()); |
| 222 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | 215 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); |
| 223 w1->Show(); | 216 w1->Show(); |
| 224 | 217 |
| 225 ASSERT_TRUE(w1->layer() != NULL); | 218 ASSERT_TRUE(w1->layer() != NULL); |
| 226 EXPECT_TRUE(w1->layer()->visible()); | 219 EXPECT_TRUE(w1->layer()->visible()); |
| 227 | 220 |
| 228 w2->SetBounds(gfx::Rect(0, 0, 50, 51)); | 221 w2->SetBounds(gfx::Rect(0, 0, 50, 51)); |
| 229 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 222 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 230 w2->Show(); | 223 w2->Show(); |
| 231 wm::ActivateWindow(w2.get()); | 224 wm::ActivateWindow(w2.get()); |
| 232 | 225 |
| 233 // Both windows should be in the same workspace. | 226 // Both windows should be in the same workspace. |
| 234 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 227 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
| 235 EXPECT_EQ(w2.get(), GetDesktop()->children()[1]); | 228 EXPECT_EQ(w2.get(), GetDesktop()->children()[1]); |
| 236 | 229 |
| 237 gfx::Rect work_area(ScreenUtil::GetMaximizedWindowBoundsInParent(w1.get())); | 230 gfx::Rect work_area(ScreenUtil::GetMaximizedWindowBoundsInParent(w1.get())); |
| 238 EXPECT_EQ(work_area.width(), w2->bounds().width()); | 231 EXPECT_EQ(work_area.width(), w2->bounds().width()); |
| 239 EXPECT_EQ(work_area.height(), w2->bounds().height()); | 232 EXPECT_EQ(work_area.height(), w2->bounds().height()); |
| 240 | 233 |
| 241 // Restore w2, which should then go back to one workspace. | 234 // Restore w2, which should then go back to one workspace. |
| 242 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 235 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 243 EXPECT_EQ(50, w2->bounds().width()); | 236 EXPECT_EQ(50, w2->bounds().width()); |
| 244 EXPECT_EQ(51, w2->bounds().height()); | 237 EXPECT_EQ(51, w2->bounds().height()); |
| 245 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 238 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 246 } | 239 } |
| 247 | 240 |
| 248 // Makes sure requests to change the bounds of a normal window go through. | 241 // Makes sure requests to change the bounds of a normal window go through. |
| 249 TEST_P(WorkspaceControllerTest, ChangeBoundsOfNormalWindow) { | 242 TEST_F(WorkspaceControllerTest, ChangeBoundsOfNormalWindow) { |
| 250 std::unique_ptr<Window> w1(CreateTestWindow()); | 243 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 251 w1->Show(); | 244 w1->Show(); |
| 252 | 245 |
| 253 // Setting the bounds should go through since the window is in the normal | 246 // Setting the bounds should go through since the window is in the normal |
| 254 // workspace. | 247 // workspace. |
| 255 w1->SetBounds(gfx::Rect(0, 0, 200, 500)); | 248 w1->SetBounds(gfx::Rect(0, 0, 200, 500)); |
| 256 EXPECT_EQ(200, w1->bounds().width()); | 249 EXPECT_EQ(200, w1->bounds().width()); |
| 257 EXPECT_EQ(500, w1->bounds().height()); | 250 EXPECT_EQ(500, w1->bounds().height()); |
| 258 } | 251 } |
| 259 | 252 |
| 260 // Verifies the bounds is not altered when showing and grid is enabled. | 253 // Verifies the bounds is not altered when showing and grid is enabled. |
| 261 TEST_P(WorkspaceControllerTest, SnapToGrid) { | 254 TEST_F(WorkspaceControllerTest, SnapToGrid) { |
| 262 std::unique_ptr<Window> w1(CreateTestWindowUnparented()); | 255 std::unique_ptr<Window> w1(CreateTestWindowUnparented()); |
| 263 w1->SetBounds(gfx::Rect(1, 6, 25, 30)); | 256 w1->SetBounds(gfx::Rect(1, 6, 25, 30)); |
| 264 ParentWindowInPrimaryRootWindow(w1.get()); | 257 ParentWindowInPrimaryRootWindow(w1.get()); |
| 265 // We are not aligning this anymore this way. When the window gets shown | 258 // We are not aligning this anymore this way. When the window gets shown |
| 266 // the window is expected to be handled differently, but this cannot be | 259 // the window is expected to be handled differently, but this cannot be |
| 267 // tested with this test. So the result of this test should be that the | 260 // tested with this test. So the result of this test should be that the |
| 268 // bounds are exactly as passed in. | 261 // bounds are exactly as passed in. |
| 269 EXPECT_EQ("1,6 25x30", w1->bounds().ToString()); | 262 EXPECT_EQ("1,6 25x30", w1->bounds().ToString()); |
| 270 } | 263 } |
| 271 | 264 |
| 272 // Assertions around a fullscreen window. | 265 // Assertions around a fullscreen window. |
| 273 TEST_P(WorkspaceControllerTest, SingleFullscreenWindow) { | 266 TEST_F(WorkspaceControllerTest, SingleFullscreenWindow) { |
| 274 std::unique_ptr<Window> w1(CreateTestWindow()); | 267 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 275 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | 268 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); |
| 276 // Make the window fullscreen. | 269 // Make the window fullscreen. |
| 277 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 270 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 278 w1->Show(); | 271 w1->Show(); |
| 279 wm::ActivateWindow(w1.get()); | 272 wm::ActivateWindow(w1.get()); |
| 280 | 273 |
| 281 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 274 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
| 282 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); | 275 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); |
| 283 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); | 276 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 296 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 289 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
| 297 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); | 290 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); |
| 298 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); | 291 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); |
| 299 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | 292 wm::WindowState* window_state = wm::GetWindowState(w1.get()); |
| 300 | 293 |
| 301 ASSERT_TRUE(window_state->HasRestoreBounds()); | 294 ASSERT_TRUE(window_state->HasRestoreBounds()); |
| 302 EXPECT_EQ("0,0 250x251", window_state->GetRestoreBoundsInScreen().ToString()); | 295 EXPECT_EQ("0,0 250x251", window_state->GetRestoreBoundsInScreen().ToString()); |
| 303 } | 296 } |
| 304 | 297 |
| 305 // Assertions around minimizing a single window. | 298 // Assertions around minimizing a single window. |
| 306 TEST_P(WorkspaceControllerTest, MinimizeSingleWindow) { | 299 TEST_F(WorkspaceControllerTest, MinimizeSingleWindow) { |
| 307 std::unique_ptr<Window> w1(CreateTestWindow()); | 300 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 308 | 301 |
| 309 w1->Show(); | 302 w1->Show(); |
| 310 | 303 |
| 311 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 304 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 312 EXPECT_FALSE(w1->layer()->IsDrawn()); | 305 EXPECT_FALSE(w1->layer()->IsDrawn()); |
| 313 EXPECT_TRUE(w1->layer()->GetTargetTransform().IsIdentity()); | 306 EXPECT_TRUE(w1->layer()->GetTargetTransform().IsIdentity()); |
| 314 | 307 |
| 315 // Show the window. | 308 // Show the window. |
| 316 w1->Show(); | 309 w1->Show(); |
| 317 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsNormalStateType()); | 310 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsNormalStateType()); |
| 318 EXPECT_TRUE(w1->layer()->IsDrawn()); | 311 EXPECT_TRUE(w1->layer()->IsDrawn()); |
| 319 } | 312 } |
| 320 | 313 |
| 321 // Assertions around minimizing a fullscreen window. | 314 // Assertions around minimizing a fullscreen window. |
| 322 TEST_P(WorkspaceControllerTest, MinimizeFullscreenWindow) { | 315 TEST_F(WorkspaceControllerTest, MinimizeFullscreenWindow) { |
| 323 // Two windows, w1 normal, w2 fullscreen. | 316 // Two windows, w1 normal, w2 fullscreen. |
| 324 std::unique_ptr<Window> w1(CreateTestWindow()); | 317 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 325 std::unique_ptr<Window> w2(CreateTestWindow()); | 318 std::unique_ptr<Window> w2(CreateTestWindow()); |
| 326 w1->Show(); | 319 w1->Show(); |
| 327 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 320 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 328 w2->Show(); | 321 w2->Show(); |
| 329 | 322 |
| 330 wm::WindowState* w1_state = wm::GetWindowState(w1.get()); | 323 wm::WindowState* w1_state = wm::GetWindowState(w1.get()); |
| 331 wm::WindowState* w2_state = wm::GetWindowState(w2.get()); | 324 wm::WindowState* w2_state = wm::GetWindowState(w2.get()); |
| 332 | 325 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 359 // Setting back to normal doesn't change the activation. | 352 // Setting back to normal doesn't change the activation. |
| 360 EXPECT_FALSE(w2_state->IsActive()); | 353 EXPECT_FALSE(w2_state->IsActive()); |
| 361 EXPECT_TRUE(w1_state->IsActive()); | 354 EXPECT_TRUE(w1_state->IsActive()); |
| 362 EXPECT_EQ(w2.get(), GetDesktop()->children()[0]); | 355 EXPECT_EQ(w2.get(), GetDesktop()->children()[0]); |
| 363 EXPECT_EQ(w1.get(), GetDesktop()->children()[1]); | 356 EXPECT_EQ(w1.get(), GetDesktop()->children()[1]); |
| 364 EXPECT_TRUE(w2->layer()->IsDrawn()); | 357 EXPECT_TRUE(w2->layer()->IsDrawn()); |
| 365 } | 358 } |
| 366 | 359 |
| 367 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly | 360 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly |
| 368 // updated. | 361 // updated. |
| 369 TEST_P(WorkspaceControllerTest, ShelfStateUpdated) { | 362 TEST_F(WorkspaceControllerTest, ShelfStateUpdated) { |
| 370 // Since ShelfLayoutManager queries for mouse location, move the mouse so | 363 // Since ShelfLayoutManager queries for mouse location, move the mouse so |
| 371 // it isn't over the shelf. | 364 // it isn't over the shelf. |
| 372 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 365 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 373 gfx::Point()); | 366 gfx::Point()); |
| 374 generator.MoveMouseTo(0, 0); | 367 generator.MoveMouseTo(0, 0); |
| 375 | 368 |
| 376 std::unique_ptr<Window> w1(CreateTestWindow()); | 369 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 377 const gfx::Rect w1_bounds(0, 1, 101, 102); | 370 const gfx::Rect w1_bounds(0, 1, 101, 102); |
| 378 WmShelf* shelf = GetPrimaryShelf(); | 371 WmShelf* shelf = GetPrimaryShelf(); |
| 379 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 372 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // Minimize. | 430 // Minimize. |
| 438 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 431 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 439 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 432 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
| 440 | 433 |
| 441 // Since the restore from minimize will restore to the pre-minimize | 434 // Since the restore from minimize will restore to the pre-minimize |
| 442 // state (tested elsewhere), we abandon the current size and restore | 435 // state (tested elsewhere), we abandon the current size and restore |
| 443 // rect and set them to the window. | 436 // rect and set them to the window. |
| 444 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | 437 wm::WindowState* window_state = wm::GetWindowState(w1.get()); |
| 445 | 438 |
| 446 gfx::Rect restore = window_state->GetRestoreBoundsInScreen(); | 439 gfx::Rect restore = window_state->GetRestoreBoundsInScreen(); |
| 447 EXPECT_EQ( | 440 EXPECT_EQ(gfx::Rect(0, 0, 800, 600).ToString(), w1->bounds().ToString()); |
| 448 gfx::Rect(0, 0, 800, 597 + GetMdAutoHiddenShelfHeightOffset()).ToString(), | |
| 449 w1->bounds().ToString()); | |
| 450 EXPECT_EQ("0,1 101x102", restore.ToString()); | 441 EXPECT_EQ("0,1 101x102", restore.ToString()); |
| 451 window_state->ClearRestoreBounds(); | 442 window_state->ClearRestoreBounds(); |
| 452 w1->SetBounds(restore); | 443 w1->SetBounds(restore); |
| 453 | 444 |
| 454 // Restore. | 445 // Restore. |
| 455 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 446 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 456 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 447 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
| 457 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 448 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
| 458 | 449 |
| 459 // Create another window, maximized. | 450 // Create another window, maximized. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 wm::ActivateWindow(w1.get()); | 491 wm::ActivateWindow(w1.get()); |
| 501 EXPECT_FALSE(GetWindowOverlapsShelf()); | 492 EXPECT_FALSE(GetWindowOverlapsShelf()); |
| 502 | 493 |
| 503 // Restore w2. | 494 // Restore w2. |
| 504 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 495 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 505 EXPECT_TRUE(GetWindowOverlapsShelf()); | 496 EXPECT_TRUE(GetWindowOverlapsShelf()); |
| 506 } | 497 } |
| 507 | 498 |
| 508 // Verifies going from maximized to minimized sets the right state for painting | 499 // Verifies going from maximized to minimized sets the right state for painting |
| 509 // the background of the launcher. | 500 // the background of the launcher. |
| 510 TEST_P(WorkspaceControllerTest, MinimizeResetsVisibility) { | 501 TEST_F(WorkspaceControllerTest, MinimizeResetsVisibility) { |
| 511 // TODO(bruthig|xiyuan): Move SessionState setup into AshTestBase or | 502 // TODO(bruthig|xiyuan): Move SessionState setup into AshTestBase or |
| 512 // AshTestHelper. | 503 // AshTestHelper. |
| 513 mojom::SessionInfoPtr info = mojom::SessionInfo::New(); | 504 mojom::SessionInfoPtr info = mojom::SessionInfo::New(); |
| 514 info->state = session_manager::SessionState::ACTIVE; | 505 info->state = session_manager::SessionState::ACTIVE; |
| 515 ash::WmShell::Get()->session_controller()->SetSessionInfo(std::move(info)); | 506 ash::WmShell::Get()->session_controller()->SetSessionInfo(std::move(info)); |
| 516 | 507 |
| 517 std::unique_ptr<Window> w1(CreateTestWindow()); | 508 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 518 w1->Show(); | 509 w1->Show(); |
| 519 wm::ActivateWindow(w1.get()); | 510 wm::ActivateWindow(w1.get()); |
| 520 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 511 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 521 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, shelf_widget()->GetBackgroundType()); | 512 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, shelf_widget()->GetBackgroundType()); |
| 522 | 513 |
| 523 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 514 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 524 EXPECT_EQ(SHELF_VISIBLE, GetPrimaryShelf()->GetVisibilityState()); | 515 EXPECT_EQ(SHELF_VISIBLE, GetPrimaryShelf()->GetVisibilityState()); |
| 525 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, shelf_widget()->GetBackgroundType()); | 516 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, shelf_widget()->GetBackgroundType()); |
| 526 } | 517 } |
| 527 | 518 |
| 528 // Verifies window visibility during various workspace changes. | 519 // Verifies window visibility during various workspace changes. |
| 529 TEST_P(WorkspaceControllerTest, VisibilityTests) { | 520 TEST_F(WorkspaceControllerTest, VisibilityTests) { |
| 530 std::unique_ptr<Window> w1(CreateTestWindow()); | 521 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 531 w1->Show(); | 522 w1->Show(); |
| 532 EXPECT_TRUE(w1->IsVisible()); | 523 EXPECT_TRUE(w1->IsVisible()); |
| 533 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); | 524 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); |
| 534 | 525 |
| 535 // Create another window, activate it and make it fullscreen. | 526 // Create another window, activate it and make it fullscreen. |
| 536 std::unique_ptr<Window> w2(CreateTestWindow()); | 527 std::unique_ptr<Window> w2(CreateTestWindow()); |
| 537 w2->Show(); | 528 w2->Show(); |
| 538 wm::ActivateWindow(w2.get()); | 529 wm::ActivateWindow(w2.get()); |
| 539 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 530 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity()); | 567 EXPECT_EQ(1.0f, w2->layer()->GetCombinedOpacity()); |
| 577 EXPECT_TRUE(w1->IsVisible()); | 568 EXPECT_TRUE(w1->IsVisible()); |
| 578 | 569 |
| 579 // Close |w2|. | 570 // Close |w2|. |
| 580 w2.reset(); | 571 w2.reset(); |
| 581 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); | 572 EXPECT_EQ(1.0f, w1->layer()->GetCombinedOpacity()); |
| 582 EXPECT_TRUE(w1->IsVisible()); | 573 EXPECT_TRUE(w1->IsVisible()); |
| 583 } | 574 } |
| 584 | 575 |
| 585 // Verifies windows that are offscreen don't move when switching workspaces. | 576 // Verifies windows that are offscreen don't move when switching workspaces. |
| 586 TEST_P(WorkspaceControllerTest, DontMoveOnSwitch) { | 577 TEST_F(WorkspaceControllerTest, DontMoveOnSwitch) { |
| 587 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 578 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 588 gfx::Point()); | 579 gfx::Point()); |
| 589 generator.MoveMouseTo(0, 0); | 580 generator.MoveMouseTo(0, 0); |
| 590 | 581 |
| 591 std::unique_ptr<Window> w1(CreateTestWindow()); | 582 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 592 const gfx::Rect touches_shelf_bounds( | 583 const gfx::Rect touches_shelf_bounds( |
| 593 0, shelf_layout_manager()->GetIdealBounds().y() - 10, 101, 102); | 584 0, shelf_layout_manager()->GetIdealBounds().y() - 10, 101, 102); |
| 594 // Move |w1| to overlap the shelf. | 585 // Move |w1| to overlap the shelf. |
| 595 w1->SetBounds(touches_shelf_bounds); | 586 w1->SetBounds(touches_shelf_bounds); |
| 596 w1->Show(); | 587 w1->Show(); |
| 597 wm::ActivateWindow(w1.get()); | 588 wm::ActivateWindow(w1.get()); |
| 598 | 589 |
| 599 // Create another window and maximize it. | 590 // Create another window and maximize it. |
| 600 std::unique_ptr<Window> w2(CreateTestWindow()); | 591 std::unique_ptr<Window> w2(CreateTestWindow()); |
| 601 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); | 592 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); |
| 602 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 593 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 603 w2->Show(); | 594 w2->Show(); |
| 604 wm::ActivateWindow(w2.get()); | 595 wm::ActivateWindow(w2.get()); |
| 605 | 596 |
| 606 // Switch to w1. | 597 // Switch to w1. |
| 607 wm::ActivateWindow(w1.get()); | 598 wm::ActivateWindow(w1.get()); |
| 608 EXPECT_EQ(touches_shelf_bounds.ToString(), w1->bounds().ToString()); | 599 EXPECT_EQ(touches_shelf_bounds.ToString(), w1->bounds().ToString()); |
| 609 } | 600 } |
| 610 | 601 |
| 611 // Verifies that windows that are completely offscreen move when switching | 602 // Verifies that windows that are completely offscreen move when switching |
| 612 // workspaces. | 603 // workspaces. |
| 613 TEST_P(WorkspaceControllerTest, MoveOnSwitch) { | 604 TEST_F(WorkspaceControllerTest, MoveOnSwitch) { |
| 614 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 605 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 615 gfx::Point()); | 606 gfx::Point()); |
| 616 generator.MoveMouseTo(0, 0); | 607 generator.MoveMouseTo(0, 0); |
| 617 | 608 |
| 618 std::unique_ptr<Window> w1(CreateTestWindow()); | 609 std::unique_ptr<Window> w1(CreateTestWindow()); |
| 619 const gfx::Rect w1_bounds(0, shelf_layout_manager()->GetIdealBounds().y(), | 610 const gfx::Rect w1_bounds(0, shelf_layout_manager()->GetIdealBounds().y(), |
| 620 100, 200); | 611 100, 200); |
| 621 // Move |w1| so that the top edge is the same as the top edge of the shelf. | 612 // Move |w1| so that the top edge is the same as the top edge of the shelf. |
| 622 w1->SetBounds(w1_bounds); | 613 w1->SetBounds(w1_bounds); |
| 623 w1->Show(); | 614 w1->Show(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 DISALLOW_COPY_AND_ASSIGN(DontCrashOnChangeAndActivateDelegate); | 659 DISALLOW_COPY_AND_ASSIGN(DontCrashOnChangeAndActivateDelegate); |
| 669 }; | 660 }; |
| 670 | 661 |
| 671 } // namespace | 662 } // namespace |
| 672 | 663 |
| 673 // Exercises possible crash in W2. Here's the sequence: | 664 // Exercises possible crash in W2. Here's the sequence: |
| 674 // . minimize a maximized window. | 665 // . minimize a maximized window. |
| 675 // . remove the window (which happens when switching displays). | 666 // . remove the window (which happens when switching displays). |
| 676 // . add the window back. | 667 // . add the window back. |
| 677 // . show the window and during the bounds change activate it. | 668 // . show the window and during the bounds change activate it. |
| 678 TEST_P(WorkspaceControllerTest, DontCrashOnChangeAndActivate) { | 669 TEST_F(WorkspaceControllerTest, DontCrashOnChangeAndActivate) { |
| 679 // Force the shelf | 670 // Force the shelf |
| 680 WmShelf* shelf = GetPrimaryShelf(); | 671 WmShelf* shelf = GetPrimaryShelf(); |
| 681 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 672 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 682 | 673 |
| 683 DontCrashOnChangeAndActivateDelegate delegate; | 674 DontCrashOnChangeAndActivateDelegate delegate; |
| 684 std::unique_ptr<Window> w1(CreateTestWindowInShellWithDelegate( | 675 std::unique_ptr<Window> w1(CreateTestWindowInShellWithDelegate( |
| 685 &delegate, 1000, gfx::Rect(10, 11, 250, 251))); | 676 &delegate, 1000, gfx::Rect(10, 11, 250, 251))); |
| 686 | 677 |
| 687 w1->Show(); | 678 w1->Show(); |
| 688 wm::WindowState* w1_state = wm::GetWindowState(w1.get()); | 679 wm::WindowState* w1_state = wm::GetWindowState(w1.get()); |
| 689 w1_state->Activate(); | 680 w1_state->Activate(); |
| 690 w1_state->Maximize(); | 681 w1_state->Maximize(); |
| 691 w1_state->Minimize(); | 682 w1_state->Minimize(); |
| 692 | 683 |
| 693 w1->parent()->RemoveChild(w1.get()); | 684 w1->parent()->RemoveChild(w1.get()); |
| 694 | 685 |
| 695 // Do this so that when we Show() the window a resize occurs and we make the | 686 // Do this so that when we Show() the window a resize occurs and we make the |
| 696 // window active. | 687 // window active. |
| 697 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 688 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 698 | 689 |
| 699 ParentWindowInPrimaryRootWindow(w1.get()); | 690 ParentWindowInPrimaryRootWindow(w1.get()); |
| 700 delegate.set_window(w1.get()); | 691 delegate.set_window(w1.get()); |
| 701 w1->Show(); | 692 w1->Show(); |
| 702 } | 693 } |
| 703 | 694 |
| 704 // Verifies a window with a transient parent not managed by workspace works. | 695 // Verifies a window with a transient parent not managed by workspace works. |
| 705 TEST_P(WorkspaceControllerTest, TransientParent) { | 696 TEST_F(WorkspaceControllerTest, TransientParent) { |
| 706 // Normal window with no transient parent. | 697 // Normal window with no transient parent. |
| 707 std::unique_ptr<Window> w2(CreateTestWindow()); | 698 std::unique_ptr<Window> w2(CreateTestWindow()); |
| 708 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); | 699 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); |
| 709 w2->Show(); | 700 w2->Show(); |
| 710 wm::ActivateWindow(w2.get()); | 701 wm::ActivateWindow(w2.get()); |
| 711 | 702 |
| 712 // Window with a transient parent. We set the transient parent to the root, | 703 // Window with a transient parent. We set the transient parent to the root, |
| 713 // which would never happen but is enough to exercise the bug. | 704 // which would never happen but is enough to exercise the bug. |
| 714 std::unique_ptr<Window> w1(CreateTestWindowUnparented()); | 705 std::unique_ptr<Window> w1(CreateTestWindowUnparented()); |
| 715 ::wm::AddTransientChild(Shell::GetInstance()->GetPrimaryRootWindow(), | 706 ::wm::AddTransientChild(Shell::GetInstance()->GetPrimaryRootWindow(), |
| 716 w1.get()); | 707 w1.get()); |
| 717 w1->SetBounds(gfx::Rect(10, 11, 250, 251)); | 708 w1->SetBounds(gfx::Rect(10, 11, 250, 251)); |
| 718 ParentWindowInPrimaryRootWindow(w1.get()); | 709 ParentWindowInPrimaryRootWindow(w1.get()); |
| 719 w1->Show(); | 710 w1->Show(); |
| 720 wm::ActivateWindow(w1.get()); | 711 wm::ActivateWindow(w1.get()); |
| 721 | 712 |
| 722 // The window with the transient parent should get added to the same parent as | 713 // The window with the transient parent should get added to the same parent as |
| 723 // the normal window. | 714 // the normal window. |
| 724 EXPECT_EQ(w2->parent(), w1->parent()); | 715 EXPECT_EQ(w2->parent(), w1->parent()); |
| 725 } | 716 } |
| 726 | 717 |
| 727 // Test the placement of newly created windows. | 718 // Test the placement of newly created windows. |
| 728 TEST_P(WorkspaceControllerTest, BasicAutoPlacingOnCreate) { | 719 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnCreate) { |
| 729 UpdateDisplay("1600x1200"); | 720 UpdateDisplay("1600x1200"); |
| 730 // Creating a popup handler here to make sure it does not interfere with the | 721 // Creating a popup handler here to make sure it does not interfere with the |
| 731 // existing windows. | 722 // existing windows. |
| 732 gfx::Rect source_browser_bounds(16, 32, 640, 320); | 723 gfx::Rect source_browser_bounds(16, 32, 640, 320); |
| 733 std::unique_ptr<aura::Window> browser_window( | 724 std::unique_ptr<aura::Window> browser_window( |
| 734 CreateBrowserLikeWindow(source_browser_bounds)); | 725 CreateBrowserLikeWindow(source_browser_bounds)); |
| 735 | 726 |
| 736 // Creating a popup to make sure it does not interfere with the positioning. | 727 // Creating a popup to make sure it does not interfere with the positioning. |
| 737 std::unique_ptr<aura::Window> browser_popup( | 728 std::unique_ptr<aura::Window> browser_popup( |
| 738 CreatePopupLikeWindow(gfx::Rect(16, 32, 128, 256))); | 729 CreatePopupLikeWindow(gfx::Rect(16, 32, 128, 256))); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 browser_window->Hide(); | 763 browser_window->Hide(); |
| 773 { // If a window is there but not shown the default should be centered. | 764 { // If a window is there but not shown the default should be centered. |
| 774 std::unique_ptr<aura::Window> new_browser_window( | 765 std::unique_ptr<aura::Window> new_browser_window( |
| 775 CreateBrowserLikeWindow(gfx::Rect(50, 100, 300, 150))); | 766 CreateBrowserLikeWindow(gfx::Rect(50, 100, 300, 150))); |
| 776 EXPECT_EQ("650,100 300x150", new_browser_window->bounds().ToString()); | 767 EXPECT_EQ("650,100 300x150", new_browser_window->bounds().ToString()); |
| 777 } | 768 } |
| 778 } | 769 } |
| 779 | 770 |
| 780 // Test that adding a second window shifts both the first window and its | 771 // Test that adding a second window shifts both the first window and its |
| 781 // transient child. | 772 // transient child. |
| 782 TEST_P(WorkspaceControllerTest, AutoPlacingMovesTransientChild) { | 773 TEST_F(WorkspaceControllerTest, AutoPlacingMovesTransientChild) { |
| 783 // Create an auto-positioned window. | 774 // Create an auto-positioned window. |
| 784 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 775 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 785 gfx::Rect desktop_area = window1->parent()->bounds(); | 776 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 786 wm::GetWindowState(window1.get())->set_window_position_managed(true); | 777 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
| 787 // Hide and then show |window1| to trigger auto-positioning logic. | 778 // Hide and then show |window1| to trigger auto-positioning logic. |
| 788 window1->Hide(); | 779 window1->Hide(); |
| 789 window1->SetBounds(gfx::Rect(16, 32, 300, 300)); | 780 window1->SetBounds(gfx::Rect(16, 32, 300, 300)); |
| 790 window1->Show(); | 781 window1->Show(); |
| 791 | 782 |
| 792 // |window1| should be horizontally centered. | 783 // |window1| should be horizontally centered. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 820 EXPECT_EQ("0,32 300x300", window1->bounds().ToString()); | 811 EXPECT_EQ("0,32 300x300", window1->bounds().ToString()); |
| 821 int x = x_child - x_window1; | 812 int x = x_child - x_window1; |
| 822 EXPECT_EQ(base::IntToString(x) + ",20 200x200", child->bounds().ToString()); | 813 EXPECT_EQ(base::IntToString(x) + ",20 200x200", child->bounds().ToString()); |
| 823 // Check that |window2| has moved right. | 814 // Check that |window2| has moved right. |
| 824 x = desktop_area.width() - window2->bounds().width(); | 815 x = desktop_area.width() - window2->bounds().width(); |
| 825 EXPECT_EQ(base::IntToString(x) + ",48 250x250", window2->bounds().ToString()); | 816 EXPECT_EQ(base::IntToString(x) + ",48 250x250", window2->bounds().ToString()); |
| 826 } | 817 } |
| 827 | 818 |
| 828 // Test the basic auto placement of one and or two windows in a "simulated | 819 // Test the basic auto placement of one and or two windows in a "simulated |
| 829 // session" of sequential window operations. | 820 // session" of sequential window operations. |
| 830 TEST_P(WorkspaceControllerTest, BasicAutoPlacingOnShowHide) { | 821 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnShowHide) { |
| 831 // Test 1: In case there is no manageable window, no window should shift. | 822 // Test 1: In case there is no manageable window, no window should shift. |
| 832 | 823 |
| 833 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 824 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 834 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 825 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 835 gfx::Rect desktop_area = window1->parent()->bounds(); | 826 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 836 | 827 |
| 837 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 828 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
| 838 // Trigger the auto window placement function by making it visible. | 829 // Trigger the auto window placement function by making it visible. |
| 839 // Note that the bounds are getting changed while it is invisible. | 830 // Note that the bounds are getting changed while it is invisible. |
| 840 window2->Hide(); | 831 window2->Hide(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 window1->Hide(); | 889 window1->Hide(); |
| 899 window1->Show(); | 890 window1->Show(); |
| 900 // |window1| should be centered. | 891 // |window1| should be centered. |
| 901 EXPECT_EQ(base::IntToString( | 892 EXPECT_EQ(base::IntToString( |
| 902 (desktop_area.width() - window1->bounds().width()) / 2) + | 893 (desktop_area.width() - window1->bounds().width()) / 2) + |
| 903 ",32 640x320", | 894 ",32 640x320", |
| 904 window1->bounds().ToString()); | 895 window1->bounds().ToString()); |
| 905 } | 896 } |
| 906 | 897 |
| 907 // Test the proper usage of user window movement interaction. | 898 // Test the proper usage of user window movement interaction. |
| 908 TEST_P(WorkspaceControllerTest, TestUserMovedWindowRepositioning) { | 899 TEST_F(WorkspaceControllerTest, TestUserMovedWindowRepositioning) { |
| 909 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 900 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 910 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 901 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 911 gfx::Rect desktop_area = window1->parent()->bounds(); | 902 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 912 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 903 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
| 913 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 904 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 914 window1->Hide(); | 905 window1->Hide(); |
| 915 window2->Hide(); | 906 window2->Hide(); |
| 916 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 907 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 917 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | 908 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
| 918 | 909 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 945 EXPECT_FALSE(window2_state->bounds_changed_by_user()); | 936 EXPECT_FALSE(window2_state->bounds_changed_by_user()); |
| 946 | 937 |
| 947 // Going back to one shown window should keep the state. | 938 // Going back to one shown window should keep the state. |
| 948 window1_state->set_bounds_changed_by_user(true); | 939 window1_state->set_bounds_changed_by_user(true); |
| 949 window2->Hide(); | 940 window2->Hide(); |
| 950 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); | 941 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); |
| 951 EXPECT_TRUE(window1_state->bounds_changed_by_user()); | 942 EXPECT_TRUE(window1_state->bounds_changed_by_user()); |
| 952 } | 943 } |
| 953 | 944 |
| 954 // Test if the single window will be restored at original position. | 945 // Test if the single window will be restored at original position. |
| 955 TEST_P(WorkspaceControllerTest, TestSingleWindowsRestoredBounds) { | 946 TEST_F(WorkspaceControllerTest, TestSingleWindowsRestoredBounds) { |
| 956 std::unique_ptr<aura::Window> window1( | 947 std::unique_ptr<aura::Window> window1( |
| 957 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 948 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
| 958 std::unique_ptr<aura::Window> window2( | 949 std::unique_ptr<aura::Window> window2( |
| 959 CreateTestWindowInShellWithBounds(gfx::Rect(110, 110, 100, 100))); | 950 CreateTestWindowInShellWithBounds(gfx::Rect(110, 110, 100, 100))); |
| 960 std::unique_ptr<aura::Window> window3( | 951 std::unique_ptr<aura::Window> window3( |
| 961 CreateTestWindowInShellWithBounds(gfx::Rect(120, 120, 100, 100))); | 952 CreateTestWindowInShellWithBounds(gfx::Rect(120, 120, 100, 100))); |
| 962 window1->Hide(); | 953 window1->Hide(); |
| 963 window2->Hide(); | 954 window2->Hide(); |
| 964 window3->Hide(); | 955 window3->Hide(); |
| 965 wm::GetWindowState(window1.get())->set_window_position_managed(true); | 956 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 994 EXPECT_EQ(window3->GetRootWindow()->bounds().right(), | 985 EXPECT_EQ(window3->GetRootWindow()->bounds().right(), |
| 995 window3->bounds().right()); | 986 window3->bounds().right()); |
| 996 | 987 |
| 997 // Being a single window will retore the original location. | 988 // Being a single window will retore the original location. |
| 998 window2->Hide(); | 989 window2->Hide(); |
| 999 EXPECT_EQ("120,120 100x100", window3->bounds().ToString()); | 990 EXPECT_EQ("120,120 100x100", window3->bounds().ToString()); |
| 1000 } | 991 } |
| 1001 | 992 |
| 1002 // Test that user placed windows go back to their user placement after the user | 993 // Test that user placed windows go back to their user placement after the user |
| 1003 // closes all other windows. | 994 // closes all other windows. |
| 1004 TEST_P(WorkspaceControllerTest, TestUserHandledWindowRestore) { | 995 TEST_F(WorkspaceControllerTest, TestUserHandledWindowRestore) { |
| 1005 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 996 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 1006 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320); | 997 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320); |
| 1007 window1->SetBounds(user_pos); | 998 window1->SetBounds(user_pos); |
| 1008 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 999 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 1009 | 1000 |
| 1010 window1_state->SetPreAutoManageWindowBounds(user_pos); | 1001 window1_state->SetPreAutoManageWindowBounds(user_pos); |
| 1011 gfx::Rect desktop_area = window1->parent()->bounds(); | 1002 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1012 | 1003 |
| 1013 // Create a second window to let the auto manager kick in. | 1004 // Create a second window to let the auto manager kick in. |
| 1014 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1005 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1032 | 1023 |
| 1033 // After the other window get hidden the window has to move back to the | 1024 // After the other window get hidden the window has to move back to the |
| 1034 // previous position and the bounds should still be set and unchanged. | 1025 // previous position and the bounds should still be set and unchanged. |
| 1035 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); | 1026 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); |
| 1036 ASSERT_TRUE(window1_state->pre_auto_manage_window_bounds()); | 1027 ASSERT_TRUE(window1_state->pre_auto_manage_window_bounds()); |
| 1037 EXPECT_EQ(user_pos.ToString(), | 1028 EXPECT_EQ(user_pos.ToString(), |
| 1038 window1_state->pre_auto_manage_window_bounds()->ToString()); | 1029 window1_state->pre_auto_manage_window_bounds()->ToString()); |
| 1039 } | 1030 } |
| 1040 | 1031 |
| 1041 // Solo window should be restored to the bounds where a user moved to. | 1032 // Solo window should be restored to the bounds where a user moved to. |
| 1042 TEST_P(WorkspaceControllerTest, TestRestoreToUserModifiedBounds) { | 1033 TEST_F(WorkspaceControllerTest, TestRestoreToUserModifiedBounds) { |
| 1043 UpdateDisplay("400x300"); | 1034 UpdateDisplay("400x300"); |
| 1044 gfx::Rect default_bounds(10, 0, 100, 100); | 1035 gfx::Rect default_bounds(10, 0, 100, 100); |
| 1045 std::unique_ptr<aura::Window> window1( | 1036 std::unique_ptr<aura::Window> window1( |
| 1046 CreateTestWindowInShellWithBounds(default_bounds)); | 1037 CreateTestWindowInShellWithBounds(default_bounds)); |
| 1047 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 1038 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 1048 window1->Hide(); | 1039 window1->Hide(); |
| 1049 window1_state->set_window_position_managed(true); | 1040 window1_state->set_window_position_managed(true); |
| 1050 window1->Show(); | 1041 window1->Show(); |
| 1051 // First window is centered. | 1042 // First window is centered. |
| 1052 EXPECT_EQ("150,0 100x100", window1->bounds().ToString()); | 1043 EXPECT_EQ("150,0 100x100", window1->bounds().ToString()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1081 window2->Show(); | 1072 window2->Show(); |
| 1082 EXPECT_EQ("0,0 100x100", window1->bounds().ToString()); | 1073 EXPECT_EQ("0,0 100x100", window1->bounds().ToString()); |
| 1083 EXPECT_EQ("300,0 100x100", window2->bounds().ToString()); | 1074 EXPECT_EQ("300,0 100x100", window2->bounds().ToString()); |
| 1084 | 1075 |
| 1085 // Window 1 should be restored to the user modified bounds. | 1076 // Window 1 should be restored to the user modified bounds. |
| 1086 window2->Hide(); | 1077 window2->Hide(); |
| 1087 EXPECT_EQ("100,0 100x100", window1->bounds().ToString()); | 1078 EXPECT_EQ("100,0 100x100", window1->bounds().ToString()); |
| 1088 } | 1079 } |
| 1089 | 1080 |
| 1090 // Test that a window from normal to minimize will repos the remaining. | 1081 // Test that a window from normal to minimize will repos the remaining. |
| 1091 TEST_P(WorkspaceControllerTest, ToMinimizeRepositionsRemaining) { | 1082 TEST_F(WorkspaceControllerTest, ToMinimizeRepositionsRemaining) { |
| 1092 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1083 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 1093 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 1084 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 1094 window1_state->set_window_position_managed(true); | 1085 window1_state->set_window_position_managed(true); |
| 1095 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1086 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1096 gfx::Rect desktop_area = window1->parent()->bounds(); | 1087 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1097 | 1088 |
| 1098 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1089 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
| 1099 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | 1090 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
| 1100 window2_state->set_window_position_managed(true); | 1091 window2_state->set_window_position_managed(true); |
| 1101 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1092 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1113 window1_state->Restore(); | 1104 window1_state->Restore(); |
| 1114 // |window1| should be flush right and |window3| flush left. | 1105 // |window1| should be flush right and |window3| flush left. |
| 1115 EXPECT_EQ( | 1106 EXPECT_EQ( |
| 1116 base::IntToString(desktop_area.width() - window1->bounds().width()) + | 1107 base::IntToString(desktop_area.width() - window1->bounds().width()) + |
| 1117 ",32 640x320", | 1108 ",32 640x320", |
| 1118 window1->bounds().ToString()); | 1109 window1->bounds().ToString()); |
| 1119 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); | 1110 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
| 1120 } | 1111 } |
| 1121 | 1112 |
| 1122 // Test that minimizing an initially maximized window will repos the remaining. | 1113 // Test that minimizing an initially maximized window will repos the remaining. |
| 1123 TEST_P(WorkspaceControllerTest, MaxToMinRepositionsRemaining) { | 1114 TEST_F(WorkspaceControllerTest, MaxToMinRepositionsRemaining) { |
| 1124 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1115 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 1125 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 1116 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 1126 window1_state->set_window_position_managed(true); | 1117 window1_state->set_window_position_managed(true); |
| 1127 gfx::Rect desktop_area = window1->parent()->bounds(); | 1118 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1128 | 1119 |
| 1129 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1120 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
| 1130 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | 1121 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
| 1131 window2_state->set_window_position_managed(true); | 1122 window2_state->set_window_position_managed(true); |
| 1132 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1123 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1133 | 1124 |
| 1134 window1_state->Maximize(); | 1125 window1_state->Maximize(); |
| 1135 window1_state->Minimize(); | 1126 window1_state->Minimize(); |
| 1136 | 1127 |
| 1137 // |window2| should be centered now. | 1128 // |window2| should be centered now. |
| 1138 EXPECT_TRUE(window2->IsVisible()); | 1129 EXPECT_TRUE(window2->IsVisible()); |
| 1139 EXPECT_TRUE(window2_state->IsNormalStateType()); | 1130 EXPECT_TRUE(window2_state->IsNormalStateType()); |
| 1140 EXPECT_EQ(base::IntToString( | 1131 EXPECT_EQ(base::IntToString( |
| 1141 (desktop_area.width() - window2->bounds().width()) / 2) + | 1132 (desktop_area.width() - window2->bounds().width()) / 2) + |
| 1142 ",48 256x512", | 1133 ",48 256x512", |
| 1143 window2->bounds().ToString()); | 1134 window2->bounds().ToString()); |
| 1144 } | 1135 } |
| 1145 | 1136 |
| 1146 // Test that nomral, maximize, minimizing will repos the remaining. | 1137 // Test that nomral, maximize, minimizing will repos the remaining. |
| 1147 TEST_P(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) { | 1138 TEST_F(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) { |
| 1148 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1139 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 1149 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1140 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1150 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 1141 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 1151 window1_state->set_window_position_managed(true); | 1142 window1_state->set_window_position_managed(true); |
| 1152 gfx::Rect desktop_area = window1->parent()->bounds(); | 1143 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1153 | 1144 |
| 1154 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1145 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
| 1155 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | 1146 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
| 1156 window2_state->set_window_position_managed(true); | 1147 window2_state->set_window_position_managed(true); |
| 1157 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); | 1148 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1173 // |window2| should be centered now. | 1164 // |window2| should be centered now. |
| 1174 EXPECT_TRUE(window2->IsVisible()); | 1165 EXPECT_TRUE(window2->IsVisible()); |
| 1175 EXPECT_TRUE(window2_state->IsNormalStateType()); | 1166 EXPECT_TRUE(window2_state->IsNormalStateType()); |
| 1176 EXPECT_EQ(base::IntToString( | 1167 EXPECT_EQ(base::IntToString( |
| 1177 (desktop_area.width() - window2->bounds().width()) / 2) + | 1168 (desktop_area.width() - window2->bounds().width()) / 2) + |
| 1178 ",40 256x512", | 1169 ",40 256x512", |
| 1179 window2->bounds().ToString()); | 1170 window2->bounds().ToString()); |
| 1180 } | 1171 } |
| 1181 | 1172 |
| 1182 // Test that nomral, maximize, normal will repos the remaining. | 1173 // Test that nomral, maximize, normal will repos the remaining. |
| 1183 TEST_P(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) { | 1174 TEST_F(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) { |
| 1184 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1175 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 1185 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1176 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1186 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 1177 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 1187 window1_state->set_window_position_managed(true); | 1178 window1_state->set_window_position_managed(true); |
| 1188 gfx::Rect desktop_area = window1->parent()->bounds(); | 1179 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1189 | 1180 |
| 1190 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1181 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
| 1191 wm::GetWindowState(window2.get())->set_window_position_managed(true); | 1182 wm::GetWindowState(window2.get())->set_window_position_managed(true); |
| 1192 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); | 1183 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); |
| 1193 | 1184 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1207 | 1198 |
| 1208 // |window1| should be flush right and |window2| flush left. | 1199 // |window1| should be flush right and |window2| flush left. |
| 1209 EXPECT_EQ( | 1200 EXPECT_EQ( |
| 1210 base::IntToString(desktop_area.width() - window1->bounds().width()) + | 1201 base::IntToString(desktop_area.width() - window1->bounds().width()) + |
| 1211 ",32 640x320", | 1202 ",32 640x320", |
| 1212 window1->bounds().ToString()); | 1203 window1->bounds().ToString()); |
| 1213 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); | 1204 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); |
| 1214 } | 1205 } |
| 1215 | 1206 |
| 1216 // Test that animations are triggered. | 1207 // Test that animations are triggered. |
| 1217 TEST_P(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) { | 1208 TEST_F(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) { |
| 1218 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 1209 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 1219 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 1210 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 1220 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1211 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
| 1221 window1->Hide(); | 1212 window1->Hide(); |
| 1222 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1213 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1223 gfx::Rect desktop_area = window1->parent()->bounds(); | 1214 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1224 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1215 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
| 1225 window2->Hide(); | 1216 window2->Hide(); |
| 1226 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1217 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1227 | 1218 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1249 ",32 640x320", | 1240 ",32 640x320", |
| 1250 window1->bounds().ToString()); | 1241 window1->bounds().ToString()); |
| 1251 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); | 1242 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
| 1252 } | 1243 } |
| 1253 | 1244 |
| 1254 // This tests simulates a browser and an app and verifies the ordering of the | 1245 // This tests simulates a browser and an app and verifies the ordering of the |
| 1255 // windows and layers doesn't get out of sync as various operations occur. Its | 1246 // windows and layers doesn't get out of sync as various operations occur. Its |
| 1256 // really testing code in FocusController, but easier to simulate here. Just as | 1247 // really testing code in FocusController, but easier to simulate here. Just as |
| 1257 // with a real browser the browser here has a transient child window | 1248 // with a real browser the browser here has a transient child window |
| 1258 // (corresponds to the status bubble). | 1249 // (corresponds to the status bubble). |
| 1259 TEST_P(WorkspaceControllerTest, VerifyLayerOrdering) { | 1250 TEST_F(WorkspaceControllerTest, VerifyLayerOrdering) { |
| 1260 std::unique_ptr<Window> browser(aura::test::CreateTestWindowWithDelegate( | 1251 std::unique_ptr<Window> browser(aura::test::CreateTestWindowWithDelegate( |
| 1261 NULL, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 6, 7, 8), NULL)); | 1252 NULL, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 6, 7, 8), NULL)); |
| 1262 browser->SetName("browser"); | 1253 browser->SetName("browser"); |
| 1263 ParentWindowInPrimaryRootWindow(browser.get()); | 1254 ParentWindowInPrimaryRootWindow(browser.get()); |
| 1264 browser->Show(); | 1255 browser->Show(); |
| 1265 wm::ActivateWindow(browser.get()); | 1256 wm::ActivateWindow(browser.get()); |
| 1266 | 1257 |
| 1267 // |status_bubble| is made a transient child of |browser| and as a result | 1258 // |status_bubble| is made a transient child of |browser| and as a result |
| 1268 // owned by |browser|. | 1259 // owned by |browser|. |
| 1269 aura::test::TestWindowDelegate* status_bubble_delegate = | 1260 aura::test::TestWindowDelegate* status_bubble_delegate = |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 aura::Window* window_; | 1342 aura::Window* window_; |
| 1352 | 1343 |
| 1353 DISALLOW_COPY_AND_ASSIGN(DragMaximizedNonTrackedWindowObserver); | 1344 DISALLOW_COPY_AND_ASSIGN(DragMaximizedNonTrackedWindowObserver); |
| 1354 }; | 1345 }; |
| 1355 | 1346 |
| 1356 } // namespace | 1347 } // namespace |
| 1357 | 1348 |
| 1358 // Verifies that a new maximized window becomes visible after its activation | 1349 // Verifies that a new maximized window becomes visible after its activation |
| 1359 // is requested, even though it does not become activated because a system | 1350 // is requested, even though it does not become activated because a system |
| 1360 // modal window is active. | 1351 // modal window is active. |
| 1361 TEST_P(WorkspaceControllerTest, SwitchFromModal) { | 1352 TEST_F(WorkspaceControllerTest, SwitchFromModal) { |
| 1362 std::unique_ptr<Window> modal_window(CreateTestWindowUnparented()); | 1353 std::unique_ptr<Window> modal_window(CreateTestWindowUnparented()); |
| 1363 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22)); | 1354 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22)); |
| 1364 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | 1355 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); |
| 1365 ParentWindowInPrimaryRootWindow(modal_window.get()); | 1356 ParentWindowInPrimaryRootWindow(modal_window.get()); |
| 1366 modal_window->Show(); | 1357 modal_window->Show(); |
| 1367 wm::ActivateWindow(modal_window.get()); | 1358 wm::ActivateWindow(modal_window.get()); |
| 1368 | 1359 |
| 1369 std::unique_ptr<Window> maximized_window(CreateTestWindow()); | 1360 std::unique_ptr<Window> maximized_window(CreateTestWindow()); |
| 1370 maximized_window->SetProperty(aura::client::kShowStateKey, | 1361 maximized_window->SetProperty(aura::client::kShowStateKey, |
| 1371 ui::SHOW_STATE_MAXIMIZED); | 1362 ui::SHOW_STATE_MAXIMIZED); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1384 ~WorkspaceControllerTestDragging() override {} | 1375 ~WorkspaceControllerTestDragging() override {} |
| 1385 | 1376 |
| 1386 private: | 1377 private: |
| 1387 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTestDragging); | 1378 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTestDragging); |
| 1388 }; | 1379 }; |
| 1389 | 1380 |
| 1390 } // namespace | 1381 } // namespace |
| 1391 | 1382 |
| 1392 // Verifies that when dragging a window over the shelf overlap is detected | 1383 // Verifies that when dragging a window over the shelf overlap is detected |
| 1393 // during and after the drag. | 1384 // during and after the drag. |
| 1394 TEST_P(WorkspaceControllerTestDragging, DragWindowOverlapShelf) { | 1385 TEST_F(WorkspaceControllerTestDragging, DragWindowOverlapShelf) { |
| 1395 aura::test::TestWindowDelegate delegate; | 1386 aura::test::TestWindowDelegate delegate; |
| 1396 delegate.set_window_component(HTCAPTION); | 1387 delegate.set_window_component(HTCAPTION); |
| 1397 std::unique_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( | 1388 std::unique_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( |
| 1398 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); | 1389 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); |
| 1399 ParentWindowInPrimaryRootWindow(w1.get()); | 1390 ParentWindowInPrimaryRootWindow(w1.get()); |
| 1400 | 1391 |
| 1401 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1392 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 1402 | 1393 |
| 1403 // Drag near the shelf. | 1394 // Drag near the shelf. |
| 1404 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1395 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1405 gfx::Point()); | 1396 gfx::Point()); |
| 1406 generator.MoveMouseTo(10, 10); | 1397 generator.MoveMouseTo(10, 10); |
| 1407 generator.PressLeftButton(); | 1398 generator.PressLeftButton(); |
| 1408 generator.MoveMouseTo(100, shelf_layout_manager()->GetIdealBounds().y() - 70); | 1399 generator.MoveMouseTo(100, shelf_layout_manager()->GetIdealBounds().y() - 70); |
| 1409 | 1400 |
| 1410 // Shelf should not be in overlapped state. | 1401 // Shelf should not be in overlapped state. |
| 1411 EXPECT_FALSE(GetWindowOverlapsShelf()); | 1402 EXPECT_FALSE(GetWindowOverlapsShelf()); |
| 1412 | 1403 |
| 1413 generator.MoveMouseTo(100, shelf_layout_manager()->GetIdealBounds().y() - 20); | 1404 generator.MoveMouseTo(100, shelf_layout_manager()->GetIdealBounds().y() - 20); |
| 1414 | 1405 |
| 1415 // Shelf should detect overlap. Overlap state stays after mouse is released. | 1406 // Shelf should detect overlap. Overlap state stays after mouse is released. |
| 1416 EXPECT_TRUE(GetWindowOverlapsShelf()); | 1407 EXPECT_TRUE(GetWindowOverlapsShelf()); |
| 1417 generator.ReleaseLeftButton(); | 1408 generator.ReleaseLeftButton(); |
| 1418 EXPECT_TRUE(GetWindowOverlapsShelf()); | 1409 EXPECT_TRUE(GetWindowOverlapsShelf()); |
| 1419 } | 1410 } |
| 1420 | 1411 |
| 1421 // Verifies that when dragging a window autohidden shelf stays hidden during | 1412 // Verifies that when dragging a window autohidden shelf stays hidden during |
| 1422 // and after the drag. | 1413 // and after the drag. |
| 1423 TEST_P(WorkspaceControllerTestDragging, DragWindowKeepsShelfAutohidden) { | 1414 TEST_F(WorkspaceControllerTestDragging, DragWindowKeepsShelfAutohidden) { |
| 1424 aura::test::TestWindowDelegate delegate; | 1415 aura::test::TestWindowDelegate delegate; |
| 1425 delegate.set_window_component(HTCAPTION); | 1416 delegate.set_window_component(HTCAPTION); |
| 1426 std::unique_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( | 1417 std::unique_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( |
| 1427 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); | 1418 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); |
| 1428 ParentWindowInPrimaryRootWindow(w1.get()); | 1419 ParentWindowInPrimaryRootWindow(w1.get()); |
| 1429 | 1420 |
| 1430 WmShelf* shelf = GetPrimaryShelf(); | 1421 WmShelf* shelf = GetPrimaryShelf(); |
| 1431 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1422 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 1432 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 1423 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 1433 | 1424 |
| 1434 // Drag very little. | 1425 // Drag very little. |
| 1435 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1426 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1436 gfx::Point()); | 1427 gfx::Point()); |
| 1437 generator.MoveMouseTo(10, 10); | 1428 generator.MoveMouseTo(10, 10); |
| 1438 generator.PressLeftButton(); | 1429 generator.PressLeftButton(); |
| 1439 generator.MoveMouseTo(12, 12); | 1430 generator.MoveMouseTo(12, 12); |
| 1440 | 1431 |
| 1441 // Shelf should be hidden during and after the drag. | 1432 // Shelf should be hidden during and after the drag. |
| 1442 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 1433 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 1443 generator.ReleaseLeftButton(); | 1434 generator.ReleaseLeftButton(); |
| 1444 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 1435 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 1445 } | 1436 } |
| 1446 | 1437 |
| 1447 // Verifies that events are targeted properly just outside the window edges. | 1438 // Verifies that events are targeted properly just outside the window edges. |
| 1448 TEST_P(WorkspaceControllerTest, WindowEdgeHitTest) { | 1439 TEST_F(WorkspaceControllerTest, WindowEdgeHitTest) { |
| 1449 aura::test::TestWindowDelegate d_first, d_second; | 1440 aura::test::TestWindowDelegate d_first, d_second; |
| 1450 std::unique_ptr<Window> first(aura::test::CreateTestWindowWithDelegate( | 1441 std::unique_ptr<Window> first(aura::test::CreateTestWindowWithDelegate( |
| 1451 &d_first, 123, gfx::Rect(20, 10, 100, 50), NULL)); | 1442 &d_first, 123, gfx::Rect(20, 10, 100, 50), NULL)); |
| 1452 ParentWindowInPrimaryRootWindow(first.get()); | 1443 ParentWindowInPrimaryRootWindow(first.get()); |
| 1453 first->Show(); | 1444 first->Show(); |
| 1454 | 1445 |
| 1455 std::unique_ptr<Window> second(aura::test::CreateTestWindowWithDelegate( | 1446 std::unique_ptr<Window> second(aura::test::CreateTestWindowWithDelegate( |
| 1456 &d_second, 234, gfx::Rect(30, 40, 40, 10), NULL)); | 1447 &d_second, 234, gfx::Rect(30, 40, 40, 10), NULL)); |
| 1457 ParentWindowInPrimaryRootWindow(second.get()); | 1448 ParentWindowInPrimaryRootWindow(second.get()); |
| 1458 second->Show(); | 1449 second->Show(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 } | 1486 } |
| 1496 // Apply a transform on |second|. After the transform is applied, the window | 1487 // Apply a transform on |second|. After the transform is applied, the window |
| 1497 // should no longer be targeted. | 1488 // should no longer be targeted. |
| 1498 gfx::Transform transform; | 1489 gfx::Transform transform; |
| 1499 transform.Translate(70, 40); | 1490 transform.Translate(70, 40); |
| 1500 second->SetTransform(transform); | 1491 second->SetTransform(transform); |
| 1501 } | 1492 } |
| 1502 } | 1493 } |
| 1503 | 1494 |
| 1504 // Verifies mouse event targeting just outside the window edges for panels. | 1495 // Verifies mouse event targeting just outside the window edges for panels. |
| 1505 TEST_P(WorkspaceControllerTest, WindowEdgeMouseHitTestPanel) { | 1496 TEST_F(WorkspaceControllerTest, WindowEdgeMouseHitTestPanel) { |
| 1506 aura::test::TestWindowDelegate delegate; | 1497 aura::test::TestWindowDelegate delegate; |
| 1507 std::unique_ptr<Window> window( | 1498 std::unique_ptr<Window> window( |
| 1508 CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50))); | 1499 CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50))); |
| 1509 ui::EventTarget* root = window->GetRootWindow(); | 1500 ui::EventTarget* root = window->GetRootWindow(); |
| 1510 ui::EventTargeter* targeter = root->GetEventTargeter(); | 1501 ui::EventTargeter* targeter = root->GetEventTargeter(); |
| 1511 const gfx::Rect bounds = window->bounds(); | 1502 const gfx::Rect bounds = window->bounds(); |
| 1512 const int kNumPoints = 5; | 1503 const int kNumPoints = 5; |
| 1513 struct { | 1504 struct { |
| 1514 const char* direction; | 1505 const char* direction; |
| 1515 gfx::Point location; | 1506 gfx::Point location; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1531 EXPECT_EQ(window.get(), target); | 1522 EXPECT_EQ(window.get(), target); |
| 1532 else | 1523 else |
| 1533 EXPECT_NE(window.get(), target); | 1524 EXPECT_NE(window.get(), target); |
| 1534 } | 1525 } |
| 1535 } | 1526 } |
| 1536 | 1527 |
| 1537 // Verifies touch event targeting just outside the window edges for panels. | 1528 // Verifies touch event targeting just outside the window edges for panels. |
| 1538 // The shelf is aligned to the bottom by default, and so touches just below | 1529 // The shelf is aligned to the bottom by default, and so touches just below |
| 1539 // the bottom edge of the panel should not target the panel itself because | 1530 // the bottom edge of the panel should not target the panel itself because |
| 1540 // an AttachedPanelWindowTargeter is installed on the panel container. | 1531 // an AttachedPanelWindowTargeter is installed on the panel container. |
| 1541 TEST_P(WorkspaceControllerTest, WindowEdgeTouchHitTestPanel) { | 1532 TEST_F(WorkspaceControllerTest, WindowEdgeTouchHitTestPanel) { |
| 1542 aura::test::TestWindowDelegate delegate; | 1533 aura::test::TestWindowDelegate delegate; |
| 1543 std::unique_ptr<Window> window( | 1534 std::unique_ptr<Window> window( |
| 1544 CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50))); | 1535 CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50))); |
| 1545 ui::EventTarget* root = window->GetRootWindow(); | 1536 ui::EventTarget* root = window->GetRootWindow(); |
| 1546 ui::EventTargeter* targeter = root->GetEventTargeter(); | 1537 ui::EventTargeter* targeter = root->GetEventTargeter(); |
| 1547 const gfx::Rect bounds = window->bounds(); | 1538 const gfx::Rect bounds = window->bounds(); |
| 1548 const int kNumPoints = 5; | 1539 const int kNumPoints = 5; |
| 1549 struct { | 1540 struct { |
| 1550 const char* direction; | 1541 const char* direction; |
| 1551 gfx::Point location; | 1542 gfx::Point location; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1564 ui::EventTimeForNow()); | 1555 ui::EventTimeForNow()); |
| 1565 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); | 1556 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); |
| 1566 if (points[i].is_target_hit) | 1557 if (points[i].is_target_hit) |
| 1567 EXPECT_EQ(window.get(), target); | 1558 EXPECT_EQ(window.get(), target); |
| 1568 else | 1559 else |
| 1569 EXPECT_NE(window.get(), target); | 1560 EXPECT_NE(window.get(), target); |
| 1570 } | 1561 } |
| 1571 } | 1562 } |
| 1572 | 1563 |
| 1573 // Verifies events targeting just outside the window edges for docked windows. | 1564 // Verifies events targeting just outside the window edges for docked windows. |
| 1574 TEST_P(WorkspaceControllerTest, WindowEdgeHitTestDocked) { | 1565 TEST_F(WorkspaceControllerTest, WindowEdgeHitTestDocked) { |
| 1575 aura::test::TestWindowDelegate delegate; | 1566 aura::test::TestWindowDelegate delegate; |
| 1576 // Make window smaller than the minimum docked area so that the window edges | 1567 // Make window smaller than the minimum docked area so that the window edges |
| 1577 // are exposed. | 1568 // are exposed. |
| 1578 delegate.set_maximum_size(gfx::Size(180, 200)); | 1569 delegate.set_maximum_size(gfx::Size(180, 200)); |
| 1579 std::unique_ptr<Window> window(aura::test::CreateTestWindowWithDelegate( | 1570 std::unique_ptr<Window> window(aura::test::CreateTestWindowWithDelegate( |
| 1580 &delegate, 123, gfx::Rect(20, 10, 100, 50), NULL)); | 1571 &delegate, 123, gfx::Rect(20, 10, 100, 50), NULL)); |
| 1581 ParentWindowInPrimaryRootWindow(window.get()); | 1572 ParentWindowInPrimaryRootWindow(window.get()); |
| 1582 aura::Window* docked_container = Shell::GetContainer( | 1573 aura::Window* docked_container = Shell::GetContainer( |
| 1583 window->GetRootWindow(), kShellWindowId_DockedContainer); | 1574 window->GetRootWindow(), kShellWindowId_DockedContainer); |
| 1584 docked_container->AddChild(window.get()); | 1575 docked_container->AddChild(window.get()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1613 ui::EventTimeForNow()); | 1604 ui::EventTimeForNow()); |
| 1614 target = targeter->FindTargetForEvent(root, &touch); | 1605 target = targeter->FindTargetForEvent(root, &touch); |
| 1615 if (points[i].is_target_hit) | 1606 if (points[i].is_target_hit) |
| 1616 EXPECT_EQ(window.get(), target); | 1607 EXPECT_EQ(window.get(), target); |
| 1617 else | 1608 else |
| 1618 EXPECT_NE(window.get(), target); | 1609 EXPECT_NE(window.get(), target); |
| 1619 } | 1610 } |
| 1620 } | 1611 } |
| 1621 | 1612 |
| 1622 } // namespace ash | 1613 } // namespace ash |
| OLD | NEW |