OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/wm/lock_action_handler_layout_manager.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/public/interfaces/tray_action.mojom.h" |
| 11 #include "ash/root_window_controller.h" |
| 12 #include "ash/screen_util.h" |
| 13 #include "ash/shelf/shelf_constants.h" |
| 14 #include "ash/shelf/shelf_layout_manager.h" |
| 15 #include "ash/shell.h" |
| 16 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/test/test_session_controller_client.h" |
| 18 #include "ash/tray_action/tray_action.h" |
| 19 #include "ash/wm/window_state.h" |
| 20 #include "base/command_line.h" |
| 21 #include "base/macros.h" |
| 22 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 23 #include "ui/aura/client/aura_constants.h" |
| 24 #include "ui/aura/window.h" |
| 25 #include "ui/keyboard/keyboard_controller.h" |
| 26 #include "ui/keyboard/keyboard_switches.h" |
| 27 #include "ui/keyboard/keyboard_ui.h" |
| 28 #include "ui/keyboard/keyboard_util.h" |
| 29 #include "ui/views/widget/widget.h" |
| 30 #include "ui/views/widget/widget_delegate.h" |
| 31 |
| 32 namespace ash { |
| 33 |
| 34 namespace { |
| 35 |
| 36 constexpr int kVirtualKeyboardHeight = 100; |
| 37 |
| 38 aura::Window* GetContainer(ShellWindowId container_id) { |
| 39 return Shell::GetPrimaryRootWindowController()->GetContainer(container_id); |
| 40 } |
| 41 |
| 42 class TestWindowDelegate : public views::WidgetDelegate { |
| 43 public: |
| 44 TestWindowDelegate() = default; |
| 45 ~TestWindowDelegate() override = default; |
| 46 |
| 47 // views::WidgetDelegate: |
| 48 void DeleteDelegate() override { delete this; } |
| 49 views::Widget* GetWidget() override { return widget_; } |
| 50 const views::Widget* GetWidget() const override { return widget_; } |
| 51 bool CanActivate() const override { return true; } |
| 52 bool CanResize() const override { return true; } |
| 53 bool CanMaximize() const override { return true; } |
| 54 bool ShouldAdvanceFocusToTopLevelWidget() const override { return true; } |
| 55 |
| 56 void set_widget(views::Widget* widget) { widget_ = widget; } |
| 57 |
| 58 private: |
| 59 views::Widget* widget_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); |
| 62 }; |
| 63 |
| 64 class TestTrayActionClient : public mojom::TrayActionClient { |
| 65 public: |
| 66 TestTrayActionClient() : binding_(this) {} |
| 67 |
| 68 ~TestTrayActionClient() override = default; |
| 69 |
| 70 mojom::TrayActionClientPtr CreateInterfacePtrAndBind() { |
| 71 return binding_.CreateInterfacePtrAndBind(); |
| 72 } |
| 73 |
| 74 // mojom::TrayActionClient: |
| 75 void RequestNewLockScreenNote() override {} |
| 76 |
| 77 private: |
| 78 mojo::Binding<ash::mojom::TrayActionClient> binding_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(TestTrayActionClient); |
| 81 }; |
| 82 |
| 83 } // namespace |
| 84 |
| 85 class LockActionHandlerLayoutManagerTest : public test::AshTestBase { |
| 86 public: |
| 87 LockActionHandlerLayoutManagerTest() = default; |
| 88 ~LockActionHandlerLayoutManagerTest() override = default; |
| 89 |
| 90 void SetUp() override { |
| 91 // Allow a virtual keyboard (and initialize it per default). |
| 92 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 93 keyboard::switches::kEnableVirtualKeyboard); |
| 94 AshTestBase::SetUp(); |
| 95 |
| 96 views::Widget::InitParams widget_params( |
| 97 views::Widget::InitParams::TYPE_WINDOW); |
| 98 widget_params.show_state = ui::SHOW_STATE_FULLSCREEN; |
| 99 lock_window_ = |
| 100 CreateTestingWindow(widget_params, kShellWindowId_LockScreenContainer, |
| 101 base::MakeUnique<TestWindowDelegate>()); |
| 102 } |
| 103 |
| 104 void TearDown() override { |
| 105 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( |
| 106 keyboard::KeyboardController::GetInstance()); |
| 107 lock_window_.reset(); |
| 108 AshTestBase::TearDown(); |
| 109 } |
| 110 |
| 111 std::unique_ptr<aura::Window> CreateTestingWindow( |
| 112 views::Widget::InitParams params, |
| 113 ShellWindowId parent_id, |
| 114 std::unique_ptr<TestWindowDelegate> window_delegate) { |
| 115 params.parent = GetContainer(parent_id); |
| 116 views::Widget* widget = new views::Widget; |
| 117 if (window_delegate) { |
| 118 window_delegate->set_widget(widget); |
| 119 params.delegate = window_delegate.release(); |
| 120 } |
| 121 widget->Init(params); |
| 122 widget->Show(); |
| 123 return base::WrapUnique<aura::Window>(widget->GetNativeView()); |
| 124 } |
| 125 |
| 126 // Show or hide the keyboard. |
| 127 void ShowKeyboard(bool show) { |
| 128 keyboard::KeyboardController* keyboard = |
| 129 keyboard::KeyboardController::GetInstance(); |
| 130 ASSERT_TRUE(keyboard); |
| 131 if (show == keyboard->keyboard_visible()) |
| 132 return; |
| 133 |
| 134 if (show) { |
| 135 keyboard->ShowKeyboard(true); |
| 136 keyboard->ui()->GetKeyboardWindow()->SetBounds( |
| 137 keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 138 Shell::GetPrimaryRootWindow()->bounds(), kVirtualKeyboardHeight)); |
| 139 } else { |
| 140 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); |
| 141 } |
| 142 |
| 143 DCHECK_EQ(show, keyboard->keyboard_visible()); |
| 144 } |
| 145 |
| 146 private: |
| 147 std::unique_ptr<aura::Window> lock_window_; |
| 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(LockActionHandlerLayoutManagerTest); |
| 150 }; |
| 151 |
| 152 TEST_F(LockActionHandlerLayoutManagerTest, PreserveNormalWindowBounds) { |
| 153 GetSessionControllerClient()->SetSessionState( |
| 154 session_manager::SessionState::LOCKED); |
| 155 TestTrayActionClient tray_action_client; |
| 156 Shell::Get()->tray_action()->SetClient( |
| 157 tray_action_client.CreateInterfacePtrAndBind(), |
| 158 mojom::TrayActionState::kActive); |
| 159 |
| 160 views::Widget::InitParams widget_params( |
| 161 views::Widget::InitParams::TYPE_WINDOW); |
| 162 const gfx::Rect bounds = gfx::Rect(10, 10, 300, 300); |
| 163 widget_params.bounds = bounds; |
| 164 // Note: default window delegate (used when no widget delegate is set) does |
| 165 // not allow the window to be maximized. |
| 166 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 167 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 168 nullptr /* window_delegate */); |
| 169 EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 170 |
| 171 gfx::Rect work_area = |
| 172 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); |
| 173 window->SetBounds(work_area); |
| 174 |
| 175 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
| 176 |
| 177 const gfx::Rect bounds2 = gfx::Rect(100, 100, 200, 200); |
| 178 window->SetBounds(bounds2); |
| 179 EXPECT_EQ(bounds2.ToString(), window->GetBoundsInScreen().ToString()); |
| 180 } |
| 181 |
| 182 TEST_F(LockActionHandlerLayoutManagerTest, MaximizedWindowBounds) { |
| 183 // Cange the shelf alignment before locking the session. |
| 184 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
| 185 |
| 186 // This should change the shelf alignment to bottom (temporarily for locked |
| 187 // state). |
| 188 GetSessionControllerClient()->SetSessionState( |
| 189 session_manager::SessionState::LOCKED); |
| 190 |
| 191 TestTrayActionClient tray_action_client; |
| 192 Shell::Get()->tray_action()->SetClient( |
| 193 tray_action_client.CreateInterfacePtrAndBind(), |
| 194 mojom::TrayActionState::kActive); |
| 195 |
| 196 views::Widget::InitParams widget_params( |
| 197 views::Widget::InitParams::TYPE_WINDOW); |
| 198 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 199 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 200 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 201 base::MakeUnique<TestWindowDelegate>()); |
| 202 |
| 203 // Verify that the window bounds are equal to work area for the bottom shelf |
| 204 // alignment, which matches how the shelf is aligned on the lock screen, |
| 205 gfx::Rect target_bounds = |
| 206 display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); |
| 207 target_bounds.Inset(0 /* left */, 0 /* top */, 0 /* right */, |
| 208 kShelfSize /* bottom */); |
| 209 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 210 } |
| 211 |
| 212 TEST_F(LockActionHandlerLayoutManagerTest, FullscreenWindowBounds) { |
| 213 // Cange the shelf alignment before locking the session. |
| 214 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
| 215 |
| 216 // This should change the shelf alignment to bottom (temporarily for locked |
| 217 // state). |
| 218 GetSessionControllerClient()->SetSessionState( |
| 219 session_manager::SessionState::LOCKED); |
| 220 |
| 221 TestTrayActionClient tray_action_client; |
| 222 Shell::Get()->tray_action()->SetClient( |
| 223 tray_action_client.CreateInterfacePtrAndBind(), |
| 224 mojom::TrayActionState::kActive); |
| 225 |
| 226 views::Widget::InitParams widget_params( |
| 227 views::Widget::InitParams::TYPE_WINDOW); |
| 228 widget_params.show_state = ui::SHOW_STATE_FULLSCREEN; |
| 229 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 230 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 231 base::MakeUnique<TestWindowDelegate>()); |
| 232 |
| 233 // Verify that the window bounds are equal to work area for the bottom shelf |
| 234 // alignment, which matches how the shelf is aligned on the lock screen, |
| 235 gfx::Rect target_bounds = |
| 236 display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); |
| 237 target_bounds.Inset(0 /* left */, 0 /* top */, 0 /* right */, |
| 238 kShelfSize /* bottom */); |
| 239 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 240 } |
| 241 |
| 242 TEST_F(LockActionHandlerLayoutManagerTest, MaximizeResizableWindow) { |
| 243 GetSessionControllerClient()->SetSessionState( |
| 244 session_manager::SessionState::LOCKED); |
| 245 |
| 246 TestTrayActionClient tray_action_client; |
| 247 Shell::Get()->tray_action()->SetClient( |
| 248 tray_action_client.CreateInterfacePtrAndBind(), |
| 249 mojom::TrayActionState::kActive); |
| 250 |
| 251 views::Widget::InitParams widget_params( |
| 252 views::Widget::InitParams::TYPE_WINDOW); |
| 253 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 254 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 255 base::MakeUnique<TestWindowDelegate>()); |
| 256 |
| 257 gfx::Rect target_bounds = |
| 258 display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); |
| 259 target_bounds.Inset(0 /* left */, 0 /* top */, 0 /* right */, |
| 260 kShelfSize /* bottom */); |
| 261 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 262 } |
| 263 |
| 264 TEST_F(LockActionHandlerLayoutManagerTest, KeyboardBounds) { |
| 265 GetSessionControllerClient()->SetSessionState( |
| 266 session_manager::SessionState::LOCKED); |
| 267 |
| 268 gfx::Rect initial_bounds = |
| 269 display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); |
| 270 initial_bounds.Inset(0 /* left */, 0 /* top */, 0 /* right */, |
| 271 kShelfSize /* bottom */); |
| 272 |
| 273 TestTrayActionClient tray_action_client; |
| 274 Shell::Get()->tray_action()->SetClient( |
| 275 tray_action_client.CreateInterfacePtrAndBind(), |
| 276 mojom::TrayActionState::kActive); |
| 277 |
| 278 views::Widget::InitParams widget_params( |
| 279 views::Widget::InitParams::TYPE_WINDOW); |
| 280 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 281 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 282 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 283 base::MakeUnique<TestWindowDelegate>()); |
| 284 ASSERT_EQ(initial_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 285 |
| 286 ShowKeyboard(true); |
| 287 |
| 288 gfx::Rect keyboard_bounds = |
| 289 keyboard::KeyboardController::GetInstance()->current_keyboard_bounds(); |
| 290 // Sanity check that the keyboard intersects woth original window bounds - if |
| 291 // this is not true, the window bounds would remain unchanged. |
| 292 ASSERT_TRUE(keyboard_bounds.Intersects(initial_bounds)); |
| 293 |
| 294 gfx::Rect target_bounds = |
| 295 display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); |
| 296 target_bounds.Inset(0 /* left */, 0 /* top */, 0 /* right */, |
| 297 keyboard_bounds.height() /* bottom */); |
| 298 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 299 |
| 300 // Verify that window bounds get updated when Chromevox bounds are shown (so |
| 301 // the Chromevox panel does not overlay with the action handler window). |
| 302 ash::ShelfLayoutManager* shelf_layout_manager = |
| 303 GetPrimaryShelf()->shelf_layout_manager(); |
| 304 ASSERT_TRUE(shelf_layout_manager); |
| 305 |
| 306 const int chromevox_panel_height = 45; |
| 307 shelf_layout_manager->SetChromeVoxPanelHeight(chromevox_panel_height); |
| 308 |
| 309 target_bounds.Inset(0 /* left */, chromevox_panel_height /* top */, |
| 310 0 /* right */, 0 /* bottom */); |
| 311 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 312 |
| 313 ShowKeyboard(false); |
| 314 } |
| 315 |
| 316 TEST_F(LockActionHandlerLayoutManagerTest, AddingWindowInActiveState) { |
| 317 GetSessionControllerClient()->SetSessionState( |
| 318 session_manager::SessionState::LOCKED); |
| 319 |
| 320 TestTrayActionClient tray_action_client; |
| 321 Shell::Get()->tray_action()->SetClient( |
| 322 tray_action_client.CreateInterfacePtrAndBind(), |
| 323 mojom::TrayActionState::kActive); |
| 324 |
| 325 views::Widget::InitParams widget_params( |
| 326 views::Widget::InitParams::TYPE_WINDOW); |
| 327 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 328 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 329 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 330 nullptr /* window_delegate */); |
| 331 |
| 332 EXPECT_TRUE(window->IsVisible()); |
| 333 EXPECT_TRUE(window->HasFocus()); |
| 334 } |
| 335 |
| 336 TEST_F(LockActionHandlerLayoutManagerTest, ReparentOnTrayActionStateChanges) { |
| 337 GetSessionControllerClient()->SetSessionState( |
| 338 session_manager::SessionState::LOCKED); |
| 339 |
| 340 views::Widget::InitParams widget_params( |
| 341 views::Widget::InitParams::TYPE_WINDOW); |
| 342 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 343 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 344 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 345 nullptr /* window_delegate */); |
| 346 |
| 347 // The window should not be visible if the new note action handler is not |
| 348 // active. |
| 349 EXPECT_FALSE(window->IsVisible()); |
| 350 |
| 351 TestTrayActionClient tray_action_client; |
| 352 Shell::Get()->tray_action()->SetClient( |
| 353 tray_action_client.CreateInterfacePtrAndBind(), |
| 354 mojom::TrayActionState::kActive); |
| 355 EXPECT_TRUE(window->IsVisible()); |
| 356 EXPECT_TRUE(window->HasFocus()); |
| 357 |
| 358 // When the action state changes to background, the window should remain |
| 359 // visible, but it should be reparented. |
| 360 Shell::Get()->tray_action()->UpdateLockScreenNoteState( |
| 361 mojom::TrayActionState::kBackground); |
| 362 EXPECT_TRUE(window->IsVisible()); |
| 363 |
| 364 // When the action state changes back to active, the window should be |
| 365 // reparented again. |
| 366 Shell::Get()->tray_action()->UpdateLockScreenNoteState( |
| 367 mojom::TrayActionState::kActive); |
| 368 EXPECT_EQ(GetContainer(kShellWindowId_LockActionHandlerContainer), |
| 369 window->parent()); |
| 370 EXPECT_TRUE(window->IsVisible()); |
| 371 EXPECT_TRUE(window->HasFocus()); |
| 372 |
| 373 Shell::Get()->tray_action()->UpdateLockScreenNoteState( |
| 374 mojom::TrayActionState::kNotAvailable); |
| 375 |
| 376 EXPECT_EQ(GetContainer(kShellWindowId_LockActionHandlerContainer), |
| 377 window->parent()); |
| 378 EXPECT_FALSE(window->IsVisible()); |
| 379 } |
| 380 |
| 381 TEST_F(LockActionHandlerLayoutManagerTest, AddWindowWhileInBackgroundState) { |
| 382 GetSessionControllerClient()->SetSessionState( |
| 383 session_manager::SessionState::LOCKED); |
| 384 |
| 385 TestTrayActionClient tray_action_client; |
| 386 Shell::Get()->tray_action()->SetClient( |
| 387 tray_action_client.CreateInterfacePtrAndBind(), |
| 388 mojom::TrayActionState::kBackground); |
| 389 |
| 390 views::Widget::InitParams widget_params( |
| 391 views::Widget::InitParams::TYPE_WINDOW); |
| 392 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 393 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 394 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 395 nullptr /* window_delegate */); |
| 396 |
| 397 // The window should be added to the requested container, but it should not |
| 398 // be visible while in background state. |
| 399 EXPECT_EQ(GetContainer(kShellWindowId_LockActionHandlerContainer), |
| 400 window->parent()); |
| 401 EXPECT_FALSE(window->IsVisible()); |
| 402 |
| 403 Shell::Get()->tray_action()->UpdateLockScreenNoteState( |
| 404 mojom::TrayActionState::kActive); |
| 405 |
| 406 EXPECT_EQ(GetContainer(kShellWindowId_LockActionHandlerContainer), |
| 407 window->parent()); |
| 408 EXPECT_TRUE(window->IsVisible()); |
| 409 EXPECT_TRUE(window->HasFocus()); |
| 410 } |
| 411 |
| 412 TEST_F(LockActionHandlerLayoutManagerTest, |
| 413 AddSecondaryWindowWhileInBackground) { |
| 414 GetSessionControllerClient()->SetSessionState( |
| 415 session_manager::SessionState::LOCKED); |
| 416 |
| 417 TestTrayActionClient tray_action_client; |
| 418 Shell::Get()->tray_action()->SetClient( |
| 419 tray_action_client.CreateInterfacePtrAndBind(), |
| 420 mojom::TrayActionState::kActive); |
| 421 |
| 422 views::Widget::InitParams widget_params( |
| 423 views::Widget::InitParams::TYPE_WINDOW); |
| 424 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 425 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 426 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 427 nullptr /* window_delegate */); |
| 428 |
| 429 EXPECT_EQ(GetContainer(kShellWindowId_LockActionHandlerContainer), |
| 430 window->parent()); |
| 431 EXPECT_TRUE(window->IsVisible()); |
| 432 EXPECT_TRUE(window->HasFocus()); |
| 433 |
| 434 Shell::Get()->tray_action()->UpdateLockScreenNoteState( |
| 435 mojom::TrayActionState::kBackground); |
| 436 |
| 437 EXPECT_TRUE(window->IsVisible()); |
| 438 EXPECT_FALSE(window->HasFocus()); |
| 439 |
| 440 std::unique_ptr<aura::Window> secondary_window = CreateTestingWindow( |
| 441 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 442 nullptr /* window_delegate */); |
| 443 |
| 444 EXPECT_EQ(GetContainer(kShellWindowId_LockActionHandlerContainer), |
| 445 secondary_window->parent()); |
| 446 EXPECT_FALSE(secondary_window->IsVisible()); |
| 447 EXPECT_TRUE(window->IsVisible()); |
| 448 EXPECT_FALSE(window->HasFocus()); |
| 449 |
| 450 Shell::Get()->tray_action()->UpdateLockScreenNoteState( |
| 451 mojom::TrayActionState::kActive); |
| 452 |
| 453 EXPECT_TRUE(window->IsVisible()); |
| 454 EXPECT_FALSE(window->HasFocus()); |
| 455 EXPECT_TRUE(secondary_window->IsVisible()); |
| 456 EXPECT_TRUE(secondary_window->HasFocus()); |
| 457 } |
| 458 |
| 459 TEST_F(LockActionHandlerLayoutManagerTest, FocusWindowWhileInBackground) { |
| 460 GetSessionControllerClient()->SetSessionState( |
| 461 session_manager::SessionState::LOCKED); |
| 462 |
| 463 TestTrayActionClient tray_action_client; |
| 464 Shell::Get()->tray_action()->SetClient( |
| 465 tray_action_client.CreateInterfacePtrAndBind(), |
| 466 mojom::TrayActionState::kActive); |
| 467 |
| 468 views::Widget::InitParams widget_params( |
| 469 views::Widget::InitParams::TYPE_WINDOW); |
| 470 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 471 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 472 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 473 nullptr /* window_delegate */); |
| 474 |
| 475 EXPECT_EQ(GetContainer(kShellWindowId_LockActionHandlerContainer), |
| 476 window->parent()); |
| 477 EXPECT_TRUE(window->IsVisible()); |
| 478 EXPECT_TRUE(window->HasFocus()); |
| 479 |
| 480 Shell::Get()->tray_action()->UpdateLockScreenNoteState( |
| 481 mojom::TrayActionState::kBackground); |
| 482 |
| 483 EXPECT_TRUE(window->IsVisible()); |
| 484 EXPECT_FALSE(window->HasFocus()); |
| 485 |
| 486 window->Focus(); |
| 487 |
| 488 EXPECT_TRUE(window->IsVisible()); |
| 489 EXPECT_FALSE(window->HasFocus()); |
| 490 } |
| 491 |
| 492 TEST_F(LockActionHandlerLayoutManagerTest, HideShowWindowWhileInBackground) { |
| 493 GetSessionControllerClient()->SetSessionState( |
| 494 session_manager::SessionState::LOCKED); |
| 495 |
| 496 TestTrayActionClient tray_action_client; |
| 497 Shell::Get()->tray_action()->SetClient( |
| 498 tray_action_client.CreateInterfacePtrAndBind(), |
| 499 mojom::TrayActionState::kActive); |
| 500 |
| 501 views::Widget::InitParams widget_params( |
| 502 views::Widget::InitParams::TYPE_WINDOW); |
| 503 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 504 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 505 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 506 nullptr /* window_delegate */); |
| 507 |
| 508 EXPECT_EQ(GetContainer(kShellWindowId_LockActionHandlerContainer), |
| 509 window->parent()); |
| 510 EXPECT_TRUE(window->IsVisible()); |
| 511 EXPECT_TRUE(window->HasFocus()); |
| 512 |
| 513 Shell::Get()->tray_action()->UpdateLockScreenNoteState( |
| 514 mojom::TrayActionState::kBackground); |
| 515 |
| 516 EXPECT_TRUE(window->IsVisible()); |
| 517 EXPECT_FALSE(window->HasFocus()); |
| 518 |
| 519 window->Hide(); |
| 520 |
| 521 EXPECT_FALSE(window->IsVisible()); |
| 522 EXPECT_FALSE(window->HasFocus()); |
| 523 |
| 524 window->Show(); |
| 525 |
| 526 EXPECT_FALSE(window->IsVisible()); |
| 527 EXPECT_FALSE(window->HasFocus()); |
| 528 } |
| 529 |
| 530 TEST_F(LockActionHandlerLayoutManagerTest, MultipleMonitors) { |
| 531 UpdateDisplay("300x400,400x500"); |
| 532 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 533 |
| 534 TestTrayActionClient tray_action_client; |
| 535 Shell::Get()->tray_action()->SetClient( |
| 536 tray_action_client.CreateInterfacePtrAndBind(), |
| 537 mojom::TrayActionState::kActive); |
| 538 |
| 539 views::Widget::InitParams widget_params( |
| 540 views::Widget::InitParams::TYPE_WINDOW); |
| 541 widget_params.show_state = ui::SHOW_STATE_FULLSCREEN; |
| 542 std::unique_ptr<aura::Window> window = CreateTestingWindow( |
| 543 widget_params, kShellWindowId_LockActionHandlerContainer, |
| 544 base::MakeUnique<TestWindowDelegate>()); |
| 545 |
| 546 gfx::Rect target_bounds = |
| 547 display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); |
| 548 target_bounds.Inset(0 /* left */, 0 /* top */, 0 /* right */, |
| 549 kShelfSize /* bottom */); |
| 550 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 551 |
| 552 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 553 |
| 554 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 555 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
| 556 window_state->Maximize(); |
| 557 |
| 558 // Maximize the window with as the restore bounds is inside 2nd display but |
| 559 // lock container windows are always on primary display. |
| 560 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 561 target_bounds = gfx::Rect(300, 400); |
| 562 target_bounds.Inset(0 /* left */, 0 /* top */, 0 /* right */, |
| 563 kShelfSize /* bottom */); |
| 564 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 565 |
| 566 window_state->Restore(); |
| 567 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 568 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 569 |
| 570 window_state->SetRestoreBoundsInScreen(gfx::Rect(280, 0, 30, 40)); |
| 571 window_state->Maximize(); |
| 572 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 573 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 574 |
| 575 window_state->Restore(); |
| 576 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 577 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 578 |
| 579 window->SetBoundsInScreen(gfx::Rect(0, 0, 30, 40), GetSecondaryDisplay()); |
| 580 target_bounds = gfx::Rect(400, 500); |
| 581 target_bounds.Inset(0 /* left */, 0 /* top */, 0 /* right */, |
| 582 kShelfSize /* bottom */); |
| 583 target_bounds.Offset(300, 0); |
| 584 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 585 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 586 } |
| 587 |
| 588 } // namespace ash |
OLD | NEW |