Commit fcc50c50 authored by yusukes's avatar yusukes Committed by Commit Bot

Re-enable ARC IMEs that were auto-disabled when toggling to laptop mode

BUG=879365,845079
TEST=Enable Gboard in tablet mode, toggle to laptop mode, toggle back to
 tablet mode, verify Gboard is usable

Change-Id: I8a6094b54b93c5c246ca13adfb391450bd85b80f
Reviewed-on: https://chromium-review.googlesource.com/1199775Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Commit-Queue: Yusuke Sato <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588412}
parent b6662a7b
......@@ -426,6 +426,7 @@ void ArcInputMethodManagerService::SetArcIMEAllowed(bool allowed) {
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
......@@ -436,7 +437,15 @@ void ArcInputMethodManagerService::SetArcIMEAllowed(bool allowed) {
}
}
// TODO(yhanada): Re-enable ARC IMEs that was enabled before disallowed.
// 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()) {
......@@ -459,6 +468,11 @@ void ArcInputMethodManagerService::SetArcIMEAllowed(bool allowed) {
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);
}
void ArcInputMethodManagerService::NotifyInputMethodManagerObservers(
......
......@@ -64,6 +64,12 @@ class TestInputMethodManager : public im::MockInputMethodManager {
removed_input_method_extensions_.push_back(extension_id);
}
bool EnableInputMethod(
const std::string& new_active_input_method_id) override {
enabled_input_methods_.push_back(new_active_input_method_id);
return true;
}
void AddActiveInputMethodId(const std::string& ime_id) {
if (!std::count(active_input_method_ids_.begin(),
active_input_method_ids_.end(), ime_id)) {
......@@ -109,6 +115,7 @@ class TestInputMethodManager : public im::MockInputMethodManager {
std::vector<std::tuple<std::string, im::InputMethodDescriptors>>
added_input_method_extensions_;
std::vector<std::string> removed_input_method_extensions_;
std::vector<std::string> enabled_input_methods_;
protected:
friend base::RefCounted<InputMethodManager::State>;
......@@ -476,6 +483,14 @@ TEST_F(ArcInputMethodManagerServiceTest, AllowArcIMEsOnlyInTabletMode) {
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.
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()));
// All IMEs are allowed to use.
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(extension_ime_id));
EXPECT_TRUE(imm()->state()->IsInputMethodAllowed(component_extension_ime_id));
......@@ -490,6 +505,7 @@ TEST_F(ArcInputMethodManagerServiceTest, AllowArcIMEsOnlyInTabletMode) {
EXPECT_FALSE(imm()->state()->IsInputMethodAllowed(arc_ime_id));
// Back to tablet mode.
EXPECT_TRUE(imm()->state()->enabled_input_methods_.empty());
ToggleTabletMode(true);
// All IMEs are allowed to use.
......@@ -497,6 +513,10 @@ TEST_F(ArcInputMethodManagerServiceTest, AllowArcIMEsOnlyInTabletMode) {
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},
......
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