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