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