Commit 2aee8ef9 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Commit Bot

Don't use AllowedInputMethod list for ARC IMEs.

Some UI elements assume that InputMethodManager's allowed input method
list is used for the policy enforcement exclusively.
Using that mechanism to restrict ARC IMEs in clamshell mode breaks them.
This CL stops using it for ARC IMEs and uninstalls the fake input method
entry from InputMethodManager instead of disallowing it if no ARC IME is
allowed.

Bug: 1139332
Test: unit_tests
Change-Id: I9952b1f99a8215d5f3a0ee0165d143e4ac62557f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485651Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818786}
parent 084a0c64
......@@ -239,7 +239,7 @@ class ArcInputMethodManagerService::TabletModeObserver
private:
void OnTabletModeToggled(bool enabled) {
owner_->UpdateArcIMEAllowed();
owner_->OnTabletModeToggled(enabled);
owner_->NotifyInputMethodManagerObservers(enabled);
}
......@@ -389,6 +389,13 @@ void ArcInputMethodManagerService::OnImeDisabled(const std::string& ime_id) {
void ArcInputMethodManagerService::OnImeInfoChanged(
std::vector<mojom::ImeInfoPtr> ime_info_array) {
latest_ime_info_ = std::move(ime_info_array);
UpdateInputMethodEntryWithImeInfo();
}
void ArcInputMethodManagerService::UpdateInputMethodEntryWithImeInfo() {
using chromeos::extension_ime_util::GetArcInputMethodID;
using chromeos::input_method::InputMethodDescriptor;
using chromeos::input_method::InputMethodDescriptors;
using chromeos::input_method::InputMethodManager;
......@@ -410,7 +417,7 @@ void ArcInputMethodManagerService::OnImeInfoChanged(
InputMethodDescriptors descriptors;
std::vector<std::string> enabled_input_method_ids;
ime_ids_allowed_in_clamshell_mode_.clear();
for (const auto& ime_info : ime_info_array) {
for (const auto& ime_info : latest_ime_info_) {
const InputMethodDescriptor& descriptor =
BuildInputMethodDescriptor(ime_info.get());
descriptors.push_back(descriptor);
......@@ -424,6 +431,11 @@ void ArcInputMethodManagerService::OnImeInfoChanged(
RemoveArcIMEFromPrefs();
return;
}
if (!ShouldArcIMEAllowed() && ime_ids_allowed_in_clamshell_mode_.empty()) {
// ARC IME is disallowed, remove ARC IME entry from preferences.
RemoveArcIMEFromPrefs();
return;
}
// Add the proxy IME entry to InputMethodManager if any ARC IME is installed.
state->AddInputMethodExtension(proxy_ime_extension_id_, descriptors,
proxy_ime_engine_.get());
......@@ -436,8 +448,11 @@ void ArcInputMethodManagerService::OnImeInfoChanged(
// TODO(crbug.com/845079): We should keep the order of the IMEs as same as in
// chrome://settings
for (const auto& input_method_id : enabled_input_method_ids) {
if (!base::Contains(active_ime_list, input_method_id))
if (!base::Contains(active_ime_list, input_method_id) &&
(ShouldArcIMEAllowed() ||
ime_ids_allowed_in_clamshell_mode_.count(input_method_id))) {
active_ime_list.push_back(input_method_id);
}
}
// Disable IMEs that are already disable in the container.
base::EraseIf(active_ime_list, [&enabled_input_method_ids](const auto& id) {
......@@ -447,11 +462,14 @@ void ArcInputMethodManagerService::OnImeInfoChanged(
profile_->GetPrefs()->SetString(prefs::kLanguageEnabledImes,
base::JoinString(active_ime_list, ","));
// Refresh allowed IME list.
UpdateArcIMEAllowed();
for (const auto& input_method_id : enabled_input_method_ids) {
if (ShouldArcIMEAllowed() ||
ime_ids_allowed_in_clamshell_mode_.count(input_method_id)) {
state->EnableInputMethod(input_method_id);
}
}
InputMethodManager::Get()->GetActiveIMEState()->ChangeInputMethod(
active_ime_id, false);
state->ChangeInputMethod(active_ime_id, false);
is_updating_imm_entry_ = false;
// Call ImeMenuListChanged() here to notify the latest state.
......@@ -588,7 +606,7 @@ void ArcInputMethodManagerService::OnAccessibilityStatusChanged(
return;
}
UpdateArcIMEAllowed();
UpdateInputMethodEntryWithImeInfo();
}
void ArcInputMethodManagerService::OnArcInputMethodBoundsChanged(
......@@ -708,87 +726,6 @@ void ArcInputMethodManagerService::RemoveArcIMEFromPref(const char* pref_name) {
base::JoinString(ime_id_list, ","));
}
void ArcInputMethodManagerService::UpdateArcIMEAllowed() {
const bool allowed = ShouldArcIMEAllowed();
auto* manager = chromeos::input_method::InputMethodManager::Get();
std::set<std::string> allowed_method_ids_set;
{
std::vector<std::string> allowed_method_ids =
manager->GetActiveIMEState()->GetAllowedInputMethods();
allowed_method_ids_set = std::set<std::string>(allowed_method_ids.begin(),
allowed_method_ids.end());
}
chromeos::input_method::InputMethodDescriptors installed_imes;
if (manager->GetComponentExtensionIMEManager()) {
installed_imes = manager->GetComponentExtensionIMEManager()
->GetAllIMEAsInputMethodDescriptor();
}
{
chromeos::input_method::InputMethodDescriptors installed_extensions;
manager->GetActiveIMEState()->GetInputMethodExtensions(
&installed_extensions);
installed_imes.insert(installed_imes.end(), installed_extensions.begin(),
installed_extensions.end());
}
std::vector<std::string> ime_ids_to_enable;
if (allowed) {
if (!allowed_method_ids_set.empty()) {
// Some IMEs are not allowed now. Add ARC IMEs to
// |allowed_method_ids_set|.
for (const auto& desc : installed_imes) {
if (chromeos::extension_ime_util::IsArcIME(desc.id()))
allowed_method_ids_set.insert(desc.id());
}
}
// Re-enable ARC IMEs that were auto-disabled when toggling to laptop mode.
const std::string active_ime_ids =
profile_->GetPrefs()->GetString(prefs::kLanguageEnabledImes);
std::vector<base::StringPiece> active_ime_list = base::SplitStringPiece(
active_ime_ids, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
for (const auto& id : active_ime_list) {
if (chromeos::extension_ime_util::IsArcIME(id.as_string()))
ime_ids_to_enable.push_back(id.as_string());
}
} else {
// Disallow Arc IMEs.
if (allowed_method_ids_set.empty()) {
// Currently there is no restriction. Add all IMEs except ARC IMEs to
// |allowed_method_ids_set|.
for (const auto& desc : installed_imes) {
if (!chromeos::extension_ime_util::IsArcIME(desc.id()) ||
ime_ids_allowed_in_clamshell_mode_.count(desc.id())) {
allowed_method_ids_set.insert(desc.id());
}
}
} else {
// Remove ARC IMEs from |allowed_method_ids_set|.
base::EraseIf(allowed_method_ids_set, [this](const std::string& id) {
return chromeos::extension_ime_util::IsArcIME(id) &&
!ime_ids_allowed_in_clamshell_mode_.count(id);
});
// Add back IMEs allowed in clamshell mode.
for (const auto& ime_id : ime_ids_allowed_in_clamshell_mode_)
allowed_method_ids_set.insert(ime_id);
}
DCHECK(!allowed_method_ids_set.empty());
}
manager->GetActiveIMEState()->SetAllowedInputMethods(
std::vector<std::string>(allowed_method_ids_set.begin(),
allowed_method_ids_set.end()),
false /* enable_allowed_input_methods */);
// This has to be called after SetAllowedInputMethods() because enabling an
// IME that is disallowed always fails.
for (const auto& id : ime_ids_to_enable)
manager->GetActiveIMEState()->EnableInputMethod(id);
}
bool ArcInputMethodManagerService::ShouldArcIMEAllowed() const {
const bool is_command_line_flag_enabled =
base::CommandLine::ForCurrentProcess()->HasSwitch(
......@@ -800,6 +737,10 @@ bool ArcInputMethodManagerService::ShouldArcIMEAllowed() const {
return is_command_line_flag_enabled || is_normal_vk_enabled;
}
void ArcInputMethodManagerService::OnTabletModeToggled(bool /* enabled */) {
UpdateInputMethodEntryWithImeInfo();
}
void ArcInputMethodManagerService::NotifyInputMethodManagerObservers(
bool is_tablet_mode) {
// Togging the mode may enable or disable all the ARC IMEs. To dynamically
......
......@@ -120,13 +120,16 @@ class ArcInputMethodManagerService
void RemoveArcIMEFromPrefs();
void RemoveArcIMEFromPref(const char* pref_name);
// Calls InputMethodManager.SetAllowedInputMethods according to the return
// value of ShouldArcImeAllowed().
void UpdateArcIMEAllowed();
// Returns whether ARC IMEs should be allowed now or not.
// It depends on tablet mode state and a11y keyboard option.
bool ShouldArcIMEAllowed() const;
void OnTabletModeToggled(bool enabled);
// Update the descriptors in IMM and the prefs according to
// |latest_ime_info_|.
void UpdateInputMethodEntryWithImeInfo();
// Notifies InputMethodManager's observers of possible ARC IME state changes.
void NotifyInputMethodManagerObservers(bool is_tablet_mode);
......@@ -140,6 +143,7 @@ class ArcInputMethodManagerService
std::unique_ptr<ArcInputMethodManagerBridge> imm_bridge_;
std::set<std::string> active_arc_ime_ids_;
std::set<std::string> ime_ids_allowed_in_clamshell_mode_;
std::vector<mojom::ImeInfoPtr> latest_ime_info_;
bool is_virtual_keyboard_shown_;
// This flag is set to true while updating ARC IMEs entries in IMM to avoid
// exposing incomplete state.
......
......@@ -29,6 +29,7 @@
#include "components/arc/test/test_browser_context.h"
#include "components/crx_file/id_util.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/chromeos/extension_ime_util.h"
#include "ui/base/ime/chromeos/ime_bridge.h"
......@@ -170,20 +171,10 @@ class TestInputMethodManager : public im::MockInputMethodManager {
}
}
bool SetAllowedInputMethods(
const std::vector<std::string>& new_allowed_input_method_ids,
bool enable_allowed_input_methods) override {
allowed_input_methods_ = new_allowed_input_method_ids;
return true;
}
const std::vector<std::string>& GetAllowedInputMethods() override {
return allowed_input_methods_;
}
bool IsInputMethodAllowed(const std::string& ime_id) {
return allowed_input_methods_.empty() ||
base::Contains(allowed_input_methods_, ime_id);
void Reset() {
added_input_method_extensions_.clear();
removed_input_method_extensions_.clear();
enabled_input_methods_.clear();
}
std::vector<std::tuple<std::string,
......@@ -200,7 +191,6 @@ class TestInputMethodManager : public im::MockInputMethodManager {
private:
std::vector<std::string> active_input_method_ids_;
std::string active_ime_id_;
std::vector<std::string> allowed_input_methods_;
};
TestInputMethodManager() {
......@@ -255,6 +245,12 @@ class ArcInputMethodManagerServiceTest : public testing::Test {
input_method_bounds_tracker_->NotifyArcInputMethodBoundsChanged(bounds);
}
std::vector<std::string> GetEnabledInputMethodIds() {
return base::SplitString(
profile()->GetPrefs()->GetString(prefs::kLanguageEnabledImes), ",",
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
}
void SetUp() override {
ui::IMEBridge::Initialize();
input_method_manager_ = new TestInputMethodManager();
......@@ -564,129 +560,172 @@ TEST_F(ArcInputMethodManagerServiceTest, OnImeInfoChanged) {
}
}
TEST_F(ArcInputMethodManagerServiceTest, AllowArcIMEsOnlyInTabletMode) {
TEST_F(ArcInputMethodManagerServiceTest, EnableArcIMEsOnlyInTabletMode) {
namespace ceiu = chromeos::extension_ime_util;
using crx_file::id_util::GenerateId;
constexpr char kArcIMEProxyExtensionName[] =
"org.chromium.arc.inputmethod.proxy";
const std::string extension_ime_id =
ceiu::GetInputMethodID(GenerateId("test.extension.ime"), "us");
const std::string component_extension_ime_id =
ceiu::GetComponentInputMethodID(
GenerateId("test.component.extension.ime"), "us");
const std::string proxy_ime_extension_id =
crx_file::id_util::GenerateId(kArcIMEProxyExtensionName);
const std::string android_ime_id = "test.arc.ime";
const std::string arc_ime_id =
ceiu::GetArcInputMethodID(GenerateId("test.arc.ime"), "us");
ceiu::GetArcInputMethodID(proxy_ime_extension_id, android_ime_id);
// Start from tablet mode.
ToggleTabletMode(true);
// Activate 3 IMEs.
// Activate the extension IME and the component extension IME.
imm()->state()->AddActiveInputMethodId(extension_ime_id);
imm()->state()->AddActiveInputMethodId(component_extension_ime_id);
imm()->state()->AddActiveInputMethodId(arc_ime_id);
// Update the prefs because the testee checks them. Note that toggling the
// mode never changes the prefs.
// Update the prefs because the testee checks them.
profile()->GetPrefs()->SetString(
prefs::kLanguageEnabledImes,
base::StringPrintf("%s,%s,%s", extension_ime_id.c_str(),
component_extension_ime_id.c_str(),
arc_ime_id.c_str()));
base::StringPrintf("%s,%s", extension_ime_id.c_str(),
component_extension_ime_id.c_str()));
service()->ImeMenuListChanged();
// All IMEs are allowed to use.
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
imm()->state()->Reset();
// Enable the ARC IME.
{
mojom::ImeInfoPtr info = mojom::ImeInfo::New();
info->ime_id = android_ime_id;
info->enabled = true;
std::vector<mojom::ImeInfoPtr> info_array{};
info_array.emplace_back(info.Clone());
service()->OnImeInfoChanged(std::move(info_array));
}
// IMM should get the newly enabled IME id.
EXPECT_EQ(1u, imm()->state()->added_input_method_extensions_.size());
EXPECT_EQ(1u, imm()->state()->enabled_input_methods_.size());
EXPECT_EQ(arc_ime_id, imm()->state()->enabled_input_methods_.at(0));
imm()->state()->enabled_input_methods_.clear();
{
// Pref should get updated.
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(3u, enabled_ime_in_pref.size());
EXPECT_EQ(arc_ime_id, enabled_ime_in_pref.at(2));
}
imm()->state()->Reset();
// Change to laptop mode.
ToggleTabletMode(false);
// ARC IME is not allowed in laptop mode.
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
// The fake IME extension is uninstalled.
EXPECT_EQ(1u, imm()->state()->removed_input_method_extensions_.size());
EXPECT_TRUE(imm()->state()->enabled_input_methods_.empty());
{
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(2u, enabled_ime_in_pref.size());
}
imm()->state()->Reset();
// Back to tablet mode.
EXPECT_TRUE(imm()->state()->enabled_input_methods_.empty());
ToggleTabletMode(true);
// All IMEs are allowed to use.
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
// Verify they appear in the CrOS IME menu.
ASSERT_EQ(1u, imm()->state()->enabled_input_methods_.size());
EXPECT_EQ(arc_ime_id, imm()->state()->enabled_input_methods_[0]);
// Do the same tests again, but with |extension_ime_id| disabled.
imm()->state()->SetAllowedInputMethods(
{component_extension_ime_id, arc_ime_id},
false /* enable_allowed_input_methods */);
ToggleTabletMode(false);
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
ToggleTabletMode(true);
EXPECT_EQ(1u, imm()->state()->added_input_method_extensions_.size());
EXPECT_EQ(1u, imm()->state()->enabled_input_methods_.size());
EXPECT_EQ(arc_ime_id, imm()->state()->enabled_input_methods_.at(0));
imm()->state()->enabled_input_methods_.clear();
{
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(3u, enabled_ime_in_pref.size());
EXPECT_EQ(arc_ime_id, enabled_ime_in_pref.at(2));
}
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
imm()->state()->Reset();
// Confirm that entering the same mode twice in a row is no-op.
ToggleTabletMode(true);
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
EXPECT_TRUE(imm()->state()->removed_input_method_extensions_.empty());
EXPECT_TRUE(imm()->state()->added_input_method_extensions_.empty());
EXPECT_TRUE(imm()->state()->enabled_input_methods_.empty());
ToggleTabletMode(false);
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
EXPECT_EQ(1u, imm()->state()->removed_input_method_extensions_.size());
EXPECT_TRUE(imm()->state()->enabled_input_methods_.empty());
{
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(2u, enabled_ime_in_pref.size());
}
ToggleTabletMode(false);
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
EXPECT_EQ(1u, imm()->state()->removed_input_method_extensions_.size());
EXPECT_TRUE(imm()->state()->enabled_input_methods_.empty());
{
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(2u, enabled_ime_in_pref.size());
}
}
TEST_F(ArcInputMethodManagerServiceTest,
DisallowArcIMEsWhenAccessibilityKeyboardEnabled) {
RemoveArcIMEsWhenAccessibilityKeyboardEnabled) {
namespace ceiu = chromeos::extension_ime_util;
using crx_file::id_util::GenerateId;
constexpr char kArcIMEProxyExtensionName[] =
"org.chromium.arc.inputmethod.proxy";
const std::string extension_ime_id =
ceiu::GetInputMethodID(GenerateId("test.extension.ime"), "us");
const std::string component_extension_ime_id =
ceiu::GetComponentInputMethodID(
GenerateId("test.component.extension.ime"), "us");
const std::string proxy_ime_extension_id =
crx_file::id_util::GenerateId(kArcIMEProxyExtensionName);
const std::string android_ime_id = "test.arc.ime";
const std::string arc_ime_id =
ceiu::GetArcInputMethodID(GenerateId("test.arc.ime"), "us");
ceiu::GetArcInputMethodID(proxy_ime_extension_id, android_ime_id);
// Start from tablet mode.
ToggleTabletMode(true);
// Activate 3 IMEs.
// Activate the extension IME and the component extension IME.
imm()->state()->AddActiveInputMethodId(extension_ime_id);
imm()->state()->AddActiveInputMethodId(component_extension_ime_id);
imm()->state()->AddActiveInputMethodId(arc_ime_id);
// Update the prefs because the testee checks them. Note that toggling the
// mode never changes the prefs.
// Update the prefs because the testee checks them.
profile()->GetPrefs()->SetString(
prefs::kLanguageEnabledImes,
base::StringPrintf("%s,%s,%s", extension_ime_id.c_str(),
component_extension_ime_id.c_str(),
arc_ime_id.c_str()));
base::StringPrintf("%s,%s", extension_ime_id.c_str(),
component_extension_ime_id.c_str()));
service()->ImeMenuListChanged();
imm()->state()->Reset();
// All IMEs are allowed to use.
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
// Enable the ARC IME.
{
mojom::ImeInfoPtr info = mojom::ImeInfo::New();
info->ime_id = android_ime_id;
info->enabled = true;
std::vector<mojom::ImeInfoPtr> info_array{};
info_array.emplace_back(info.Clone());
service()->OnImeInfoChanged(std::move(info_array));
}
// IMM should get the newly enabled IME id.
EXPECT_EQ(1u, imm()->state()->added_input_method_extensions_.size());
EXPECT_EQ(1u, imm()->state()->enabled_input_methods_.size());
EXPECT_EQ(arc_ime_id, imm()->state()->enabled_input_methods_.at(0));
imm()->state()->enabled_input_methods_.clear();
{
// Pref should get updated.
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(3u, enabled_ime_in_pref.size());
EXPECT_EQ(arc_ime_id, enabled_ime_in_pref.at(2));
}
imm()->state()->Reset();
// Enable a11y keyboard option.
profile()->GetPrefs()->SetBoolean(
......@@ -695,10 +734,17 @@ TEST_F(ArcInputMethodManagerServiceTest,
service()->OnAccessibilityStatusChanged(
{chromeos::ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD, true});
// ARC IME is not allowed.
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
// ARC IME is not allowed when a11y keyboard is enabled.
EXPECT_EQ(1u, imm()->state()->removed_input_method_extensions_.size());
EXPECT_TRUE(imm()->state()->enabled_input_methods_.empty());
{
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(2u, enabled_ime_in_pref.size());
}
imm()->state()->removed_input_method_extensions_.clear();
imm()->state()->added_input_method_extensions_.clear();
imm()->state()->enabled_input_methods_.clear();
// Disable a11y keyboard option.
profile()->GetPrefs()->SetBoolean(
......@@ -707,9 +753,17 @@ TEST_F(ArcInputMethodManagerServiceTest,
service()->OnAccessibilityStatusChanged(
{chromeos::ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD, false});
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
// ARC IME can be enabled.
EXPECT_EQ(1u, imm()->state()->added_input_method_extensions_.size());
EXPECT_EQ(1u, imm()->state()->enabled_input_methods_.size());
EXPECT_EQ(arc_ime_id, imm()->state()->enabled_input_methods_.at(0));
imm()->state()->enabled_input_methods_.clear();
{
// Pref should get updated.
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(3u, enabled_ime_in_pref.size());
EXPECT_EQ(arc_ime_id, enabled_ime_in_pref.at(2));
}
}
TEST_F(ArcInputMethodManagerServiceTest,
......@@ -717,13 +771,19 @@ TEST_F(ArcInputMethodManagerServiceTest,
namespace ceiu = chromeos::extension_ime_util;
using crx_file::id_util::GenerateId;
constexpr char kArcIMEProxyExtensionName[] =
"org.chromium.arc.inputmethod.proxy";
const std::string extension_ime_id =
ceiu::GetInputMethodID(GenerateId("test.extension.ime"), "us");
const std::string component_extension_ime_id =
ceiu::GetComponentInputMethodID(
GenerateId("test.component.extension.ime"), "us");
const std::string proxy_ime_extension_id =
crx_file::id_util::GenerateId(kArcIMEProxyExtensionName);
const std::string android_ime_id = "test.arc.ime";
const std::string arc_ime_id =
ceiu::GetArcInputMethodID(GenerateId("test.arc.ime"), "us");
ceiu::GetArcInputMethodID(proxy_ime_extension_id, android_ime_id);
// Add '--enable-virtual-keyboard' flag.
base::test::ScopedCommandLine scoped_command_line;
......@@ -733,23 +793,56 @@ TEST_F(ArcInputMethodManagerServiceTest,
// Start from tablet mode.
ToggleTabletMode(true);
// Activate 3 IMEs.
// Activate the extension IME and the component extension IME.
imm()->state()->AddActiveInputMethodId(extension_ime_id);
imm()->state()->AddActiveInputMethodId(component_extension_ime_id);
imm()->state()->AddActiveInputMethodId(arc_ime_id);
// Update the prefs because the testee checks them.
profile()->GetPrefs()->SetString(
prefs::kLanguageEnabledImes,
base::StringPrintf("%s,%s", extension_ime_id.c_str(),
component_extension_ime_id.c_str()));
service()->ImeMenuListChanged();
// All IMEs are allowed to use.
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
imm()->state()->removed_input_method_extensions_.clear();
imm()->state()->added_input_method_extensions_.clear();
imm()->state()->enabled_input_methods_.clear();
// Enable the ARC IME.
{
mojom::ImeInfoPtr info = mojom::ImeInfo::New();
info->ime_id = android_ime_id;
info->enabled = true;
std::vector<mojom::ImeInfoPtr> info_array{};
info_array.emplace_back(info.Clone());
service()->OnImeInfoChanged(std::move(info_array));
}
// IMM should get the newly enabled IME id.
EXPECT_EQ(1u, imm()->state()->added_input_method_extensions_.size());
EXPECT_EQ(1u, imm()->state()->enabled_input_methods_.size());
EXPECT_EQ(arc_ime_id, imm()->state()->enabled_input_methods_.at(0));
{
// Pref should get updated.
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(3u, enabled_ime_in_pref.size());
EXPECT_EQ(arc_ime_id, enabled_ime_in_pref.at(2));
}
imm()->state()->removed_input_method_extensions_.clear();
imm()->state()->added_input_method_extensions_.clear();
imm()->state()->enabled_input_methods_.clear();
// Change to laptop mode.
ToggleTabletMode(false);
// All IMEs are allowed to use even in laptop mode if the flag is set.
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
EXPECT_EQ(1u, imm()->state()->added_input_method_extensions_.size());
EXPECT_EQ(1u, imm()->state()->enabled_input_methods_.size());
EXPECT_EQ(arc_ime_id, imm()->state()->enabled_input_methods_.at(0));
{
const auto enabled_ime_in_pref = GetEnabledInputMethodIds();
EXPECT_EQ(3u, enabled_ime_in_pref.size());
EXPECT_EQ(arc_ime_id, enabled_ime_in_pref.at(2));
}
}
TEST_F(ArcInputMethodManagerServiceTest, FocusAndBlur) {
......
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