1 // Copyright 2018 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/login/ui/login_keyboard_test_base.h"
6 
7 #include "ash/keyboard/keyboard_controller_impl.h"
8 #include "ash/keyboard/ui/keyboard_ui.h"
9 #include "ash/keyboard/ui/keyboard_ui_controller.h"
10 #include "ash/keyboard/ui/test/keyboard_test_util.h"
11 #include "ash/login/mock_login_screen_client.h"
12 #include "ash/login/ui/lock_screen.h"
13 #include "ash/login/ui/login_test_utils.h"
14 #include "ash/public/cpp/keyboard/keyboard_switches.h"
15 #include "ash/root_window_controller.h"
16 #include "ash/session/test_session_controller_client.h"
17 #include "ash/shell.h"
18 #include "base/command_line.h"
19 #include "base/strings/strcat.h"
20 
21 namespace ash {
22 
23 LoginKeyboardTestBase::LoginKeyboardTestBase() = default;
24 
25 LoginKeyboardTestBase::~LoginKeyboardTestBase() = default;
26 
SetUp()27 void LoginKeyboardTestBase::SetUp() {
28   base::CommandLine::ForCurrentProcess()->AppendSwitch(
29       keyboard::switches::kEnableVirtualKeyboard);
30   LoginTestBase::SetUp();
31 }
32 
ShowKeyboard()33 void LoginKeyboardTestBase::ShowKeyboard() {
34   auto* keyboard_controller = keyboard::KeyboardUIController::Get();
35   keyboard_controller->ShowKeyboard(false);
36   // Set keyboard height to half of the root window - this should overlap with
37   // lock/login layout.
38   int height = Shell::GetPrimaryRootWindow()->bounds().height() / 2;
39   keyboard_controller->GetKeyboardWindow()->SetBounds(
40       keyboard::KeyboardBoundsFromRootBounds(
41           Shell::GetPrimaryRootWindow()->bounds(), height));
42   ASSERT_TRUE(keyboard::WaitUntilShown());
43 }
44 
HideKeyboard()45 void LoginKeyboardTestBase::HideKeyboard() {
46   auto* keyboard_controller = keyboard::KeyboardUIController::Get();
47   keyboard_controller->HideKeyboardByUser();
48   ASSERT_FALSE(keyboard_controller->IsKeyboardVisible());
49 }
50 
GetKeyboardBoundsInScreen() const51 gfx::Rect LoginKeyboardTestBase::GetKeyboardBoundsInScreen() const {
52   return keyboard::KeyboardUIController::Get()
53       ->GetKeyboardWindow()
54       ->GetBoundsInScreen();
55 }
56 
57 }  // namespace ash
58