Commit c6b7409c authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

Add lock screen test to verify IME states

Checks that correct IME is loaded on different users unlocking

Fixed: 1024563
Change-Id: Icbe8217c830e27aba421c08a4f460aff66c503ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142252Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758952}
parent 069a4050
......@@ -58,6 +58,8 @@ void BrowserStateMonitor::OnSessionStateChanged() {
SetUiSessionState(InputMethodManager::STATE_BROWSER_SCREEN);
} else if (session_state == session_manager::SessionState::LOCKED) {
SetUiSessionState(InputMethodManager::STATE_LOCK_SCREEN);
} else if (session_state == session_manager::SessionState::LOGIN_SECONDARY) {
SetUiSessionState(InputMethodManager::STATE_SECONDARY_LOGIN_SCREEN);
}
}
......
......@@ -939,13 +939,11 @@ InputMethodManagerImpl::InputMethodManagerImpl(
const InputMethodDescriptors& descriptors =
component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor();
util_.ResetInputMethods(descriptors);
chromeos::UserAddingScreen::Get()->AddObserver(this);
}
InputMethodManagerImpl::~InputMethodManagerImpl() {
if (candidate_window_controller_.get())
candidate_window_controller_->RemoveObserver(this);
chromeos::UserAddingScreen::Get()->RemoveObserver(this);
}
void InputMethodManagerImpl::RecordInputMethodUsage(
......@@ -1007,16 +1005,6 @@ void InputMethodManagerImpl::SetUISessionState(UISessionState new_ui_session) {
}
}
void InputMethodManagerImpl::OnUserAddingStarted() {
if (ui_session_ == STATE_BROWSER_SCREEN)
SetUISessionState(STATE_SECONDARY_LOGIN_SCREEN);
}
void InputMethodManagerImpl::OnUserAddingFinished() {
if (ui_session_ == STATE_SECONDARY_LOGIN_SCREEN)
SetUISessionState(STATE_BROWSER_SCREEN);
}
std::unique_ptr<InputMethodDescriptors>
InputMethodManagerImpl::GetSupportedInputMethods() const {
return std::unique_ptr<InputMethodDescriptors>(new InputMethodDescriptors);
......
......@@ -18,7 +18,6 @@
#include "chrome/browser/chromeos/input_method/candidate_window_controller.h"
#include "chrome/browser/chromeos/input_method/ime_service_connector.h"
#include "chrome/browser/chromeos/input_method/suggestion_window_controller.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/profiles/profile.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/ime/chromeos/input_method_util.h"
......@@ -37,8 +36,7 @@ class ImeKeyboard;
// The implementation of InputMethodManager.
class InputMethodManagerImpl : public InputMethodManager,
public CandidateWindowController::Observer,
public UserAddingScreen::Observer {
public CandidateWindowController::Observer {
public:
class StateImpl : public InputMethodManager::State {
public:
......@@ -219,10 +217,6 @@ class InputMethodManagerImpl : public InputMethodManager,
void NotifyInputMethodExtensionRemoved(
const std::string& extension_id) override;
// chromeos::UserAddingScreen:
void OnUserAddingStarted() override;
void OnUserAddingFinished() override;
ImeKeyboard* GetImeKeyboard() override;
InputMethodUtil* GetInputMethodUtil() override;
ComponentExtensionIMEManager* GetComponentExtensionIMEManager() override;
......
......@@ -8,6 +8,7 @@
#include "base/system/sys_info.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/language_preferences.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
......@@ -121,6 +122,12 @@ void InputMethodPersistence::InputMethodChanged(InputMethodManager* manager,
Profile* profile,
bool show_message) {
DCHECK_EQ(input_method_manager_, manager);
// We might get here during the locking process. When locker is already
// created but session state has not changed yet.
if (ScreenLocker::default_screen_locker()) {
// We use a special set of input methods on the lock screen. Do not update.
return;
}
const std::string current_input_method =
manager->GetActiveIMEState()->GetCurrentInputMethod().id();
// Save the new input method id depending on the current browser state.
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/public/cpp/login_screen_test_api.h"
#include "chrome/browser/chromeos/login/lock/screen_locker_tester.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "components/user_manager/user_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
namespace chromeos {
namespace {
class LockScreenTest : public LoginManagerTest {
public:
LockScreenTest() { login_manager_.AppendRegularUsers(2); }
void SetUpOnMainThread() override {
LoginManagerTest::SetUpOnMainThread();
user_input_methods_.push_back("xkb:fr::fra");
user_input_methods_.push_back("xkb:de::ger");
chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods(
&user_input_methods_);
}
~LockScreenTest() override = default;
protected:
std::vector<std::string> user_input_methods_;
LoginManagerMixin login_manager_{&mixin_host_};
};
IN_PROC_BROWSER_TEST_F(LockScreenTest, CheckIMESwitches) {
const auto& users = login_manager_.users();
LoginUser(users[0].account_id);
scoped_refptr<input_method::InputMethodManager::State> ime_states[2] = {
nullptr, nullptr};
input_method::InputMethodManager* input_manager =
input_method::InputMethodManager::Get();
ime_states[0] = input_manager->GetActiveIMEState();
ASSERT_TRUE(ime_states[0]->EnableInputMethod(user_input_methods_[0]));
ime_states[0]->ChangeInputMethod(user_input_methods_[0], false);
EXPECT_EQ(ime_states[0]->GetCurrentInputMethod().id(),
user_input_methods_[0]);
UserAddingScreen::Get()->Start();
AddUser(users[1].account_id);
EXPECT_EQ(users[1].account_id,
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId());
ime_states[1] = input_manager->GetActiveIMEState();
ASSERT_TRUE(ime_states[1]->EnableInputMethod(user_input_methods_[1]));
ime_states[1]->ChangeInputMethod(user_input_methods_[1], false);
EXPECT_EQ(ime_states[1]->GetCurrentInputMethod().id(),
user_input_methods_[1]);
ASSERT_NE(ime_states[0], ime_states[1]);
ScreenLockerTester locker_tester;
locker_tester.Lock();
EXPECT_EQ(2, ash::LoginScreenTestApi::GetUsersCount());
// IME state should be lock screen specific.
EXPECT_NE(ime_states[0], input_manager->GetActiveIMEState());
EXPECT_NE(ime_states[1], input_manager->GetActiveIMEState());
EXPECT_EQ(users[0].account_id, ash::LoginScreenTestApi::GetFocusedUser());
EXPECT_EQ(input_manager->GetActiveIMEState()->GetCurrentInputMethod().id(),
user_input_methods_[0]);
locker_tester.UnlockWithPassword(users[0].account_id, "password");
locker_tester.WaitForUnlock();
EXPECT_EQ(users[0].account_id,
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId());
EXPECT_EQ(ime_states[0], input_manager->GetActiveIMEState());
EXPECT_EQ(ime_states[0]->GetCurrentInputMethod().id(),
user_input_methods_[0]);
locker_tester.Lock();
EXPECT_EQ(2, ash::LoginScreenTestApi::GetUsersCount());
// IME state should be lock screen specific.
EXPECT_NE(ime_states[0], input_manager->GetActiveIMEState());
EXPECT_NE(ime_states[1], input_manager->GetActiveIMEState());
EXPECT_EQ(users[0].account_id, ash::LoginScreenTestApi::GetFocusedUser());
EXPECT_EQ(input_manager->GetActiveIMEState()->GetCurrentInputMethod().id(),
user_input_methods_[0]);
EXPECT_TRUE(ash::LoginScreenTestApi::FocusUser(users[1].account_id));
EXPECT_EQ(input_manager->GetActiveIMEState()->GetCurrentInputMethod().id(),
user_input_methods_[1]);
locker_tester.UnlockWithPassword(users[1].account_id, "password");
EXPECT_EQ(users[1].account_id,
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId());
EXPECT_EQ(ime_states[1], input_manager->GetActiveIMEState());
EXPECT_EQ(ime_states[1]->GetCurrentInputMethod().id(),
user_input_methods_[1]);
}
} // namespace
} // namespace chromeos
......@@ -96,6 +96,17 @@ void ScreenLockerTester::Lock() {
base::RunLoop().RunUntilIdle();
}
void ScreenLockerTester::WaitForUnlock() {
content::WindowedNotificationObserver lock_state_observer(
chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
content::NotificationService::AllSources());
if (IsLocked())
lock_state_observer.Wait();
ASSERT_TRUE(!IsLocked());
ASSERT_EQ(session_manager::SessionState::ACTIVE,
session_manager::SessionManager::Get()->session_state());
}
void ScreenLockerTester::SetUnlockPassword(const AccountId& account_id,
const std::string& password) {
UserContext user_context(user_manager::UserType::USER_TYPE_REGULAR,
......
......@@ -22,6 +22,8 @@ class ScreenLockerTester {
// Synchronously lock the device.
void Lock();
void WaitForUnlock();
// Injects authenticators that only authenticate with the given password.
void SetUnlockPassword(const AccountId& account_id,
const std::string& password);
......
......@@ -10,11 +10,13 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/input_method/input_method_persistence.h"
#include "chrome/browser/chromeos/language_preferences.h"
#include "chrome/browser/chromeos/login/lock_screen_utils.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/settings/scoped_testing_cros_settings.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
......@@ -34,6 +36,11 @@ constexpr char kTestUser2GaiaId[] = "2222222222";
constexpr char kTestUser3[] = "test-user3@gmail.com";
constexpr char kTestUser3GaiaId[] = "3333333333";
void Append_en_US_InputMethod(std::vector<std::string>* out) {
out->push_back("xkb:us::eng");
chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods(out);
}
void Append_en_US_InputMethods(std::vector<std::string>* out) {
out->push_back("xkb:us::eng");
out->push_back("xkb:us:intl:eng");
......@@ -87,6 +94,70 @@ class LoginUIKeyboardTest : public chromeos::LoginManagerTest {
std::vector<AccountId> test_users_;
};
class LoginUIUserAddingKeyboardTest : public LoginUIKeyboardTest {
public:
LoginUIUserAddingKeyboardTest() {
test_users_.push_back(
AccountId::FromUserEmailGaiaId(kTestUser3, kTestUser3GaiaId));
}
protected:
void FocusUserPod(const AccountId& account_id) {
test::ExecuteOobeJS(
base::StringPrintf(R"($('pod-row').focusPod($('pod-row'))"
R"(.getPodWithUsername_('%s'), true))",
account_id.Serialize().c_str()));
}
};
IN_PROC_BROWSER_TEST_F(LoginUIUserAddingKeyboardTest, PRE_CheckPODSwitches) {
RegisterUser(test_users_[0]);
RegisterUser(test_users_[1]);
RegisterUser(test_users_[2]);
InitUserLastInputMethod();
StartupUtils::MarkOobeCompleted();
}
IN_PROC_BROWSER_TEST_F(LoginUIUserAddingKeyboardTest, CheckPODSwitches) {
EXPECT_EQ(
lock_screen_utils::GetUserLastInputMethod(test_users_[2].GetUserEmail()),
std::string());
LoginUser(test_users_[2]);
UserAddingScreen::Get()->Start();
OobeScreenWaiter(OobeScreen::SCREEN_ACCOUNT_PICKER).Wait();
std::vector<std::string> expected_input_methods;
expected_input_methods.push_back(user_input_methods[0]);
// Append just one.
Append_en_US_InputMethod(&expected_input_methods);
EXPECT_EQ(expected_input_methods, input_method::InputMethodManager::Get()
->GetActiveIMEState()
->GetActiveInputMethodIds());
EXPECT_EQ(user_input_methods[0], input_method::InputMethodManager::Get()
->GetActiveIMEState()
->GetCurrentInputMethod()
.id());
FocusUserPod(test_users_[1]);
EXPECT_EQ(user_input_methods[1], input_method::InputMethodManager::Get()
->GetActiveIMEState()
->GetCurrentInputMethod()
.id());
FocusUserPod(test_users_[0]);
EXPECT_EQ(user_input_methods[0], input_method::InputMethodManager::Get()
->GetActiveIMEState()
->GetCurrentInputMethod()
.id());
// Check that logged in user settings did not change.
EXPECT_EQ(
lock_screen_utils::GetUserLastInputMethod(test_users_[2].GetUserEmail()),
std::string());
}
IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, PRE_CheckPODScreenDefault) {
RegisterUser(test_users_[0]);
RegisterUser(test_users_[1]);
......@@ -141,6 +212,13 @@ IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, CheckPODScreenWithUsers) {
->GetActiveIMEState()
->GetCurrentInputMethod()
.id());
EXPECT_TRUE(ash::LoginScreenTestApi::FocusUser(test_users_[0]));
EXPECT_EQ(user_input_methods[0], input_method::InputMethodManager::Get()
->GetActiveIMEState()
->GetCurrentInputMethod()
.id());
}
class LoginUIKeyboardTestWithUsersAndOwner : public chromeos::LoginManagerTest {
......
......@@ -2195,6 +2195,7 @@ if (!is_android) {
"../browser/chromeos/login/hid_detection_browsertest.cc",
"../browser/chromeos/login/kiosk_browsertest.cc",
"../browser/chromeos/login/lock/fingerprint_unlock_browsertest.cc",
"../browser/chromeos/login/lock/lock_screen_browsertest.cc",
"../browser/chromeos/login/lock/screen_locker_browsertest.cc",
"../browser/chromeos/login/lock/screen_locker_tester.cc",
"../browser/chromeos/login/lock/screen_locker_tester.h",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment