summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-03 00:38:17 +0000
committernona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-03 00:38:17 +0000
commit561c37211b16fe1566c7b93d908903d121008d4b (patch)
tree2cdabf11753f83b00f9d009aa8a233872141e8f9
parenta4180a032e389c40d1cd954073e9a69d23ce85ad (diff)
downloadchromium_src-561c37211b16fe1566c7b93d908903d121008d4b.zip
chromium_src-561c37211b16fe1566c7b93d908903d121008d4b.tar.gz
chromium_src-561c37211b16fe1566c7b93d908903d121008d4b.tar.bz2
Introduce component extension specific id format.
Component Extension IME should be treated as default install input method. Thus it should not have same format of id with normal extension ime. BUG=164377 TEST=None Review URL: https://chromiumcodereview.appspot.com/13451003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191949 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chromeos/ime/component_extension_ime_manager.cc56
-rw-r--r--chromeos/ime/component_extension_ime_manager.h27
-rw-r--r--chromeos/ime/component_extension_ime_manager_unittest.cc67
3 files changed, 125 insertions, 25 deletions
diff --git a/chromeos/ime/component_extension_ime_manager.cc b/chromeos/ime/component_extension_ime_manager.cc
index f004846..e5af80d 100644
--- a/chromeos/ime/component_extension_ime_manager.cc
+++ b/chromeos/ime/component_extension_ime_manager.cc
@@ -3,10 +3,13 @@
// found in the LICENSE file.
#include "base/logging.h"
+#include "base/string_util.h"
#include "chromeos/ime/component_extension_ime_manager.h"
-#include "chromeos/ime/extension_ime_util.h"
namespace chromeos {
+namespace {
+const char* kComponentExtensionIMEPrefix = "_comp_ime_";
+} // namespace
ComponentExtensionIME::ComponentExtensionIME() {
}
@@ -57,9 +60,45 @@ bool ComponentExtensionIMEManager::UnloadComponentExtensionIME(
return false;
}
+// static
+std::string ComponentExtensionIMEManager::GetComponentExtensionIMEId(
+ const std::string& extension_id,
+ const std::string& engine_id) {
+ return kComponentExtensionIMEPrefix + extension_id + engine_id;
+}
+
+// static
bool ComponentExtensionIMEManager::IsComponentExtensionIMEId(
const std::string& input_method_id) {
- return FindEngineEntry(input_method_id, NULL, NULL);
+ return StartsWithASCII(input_method_id,
+ kComponentExtensionIMEPrefix,
+ true); // Case sensitive.
+}
+
+bool ComponentExtensionIMEManager::IsWhitelisted(
+ const std::string& input_method_id) {
+ return IsComponentExtensionIMEId(input_method_id) &&
+ FindEngineEntry(input_method_id, NULL, NULL);
+}
+
+bool ComponentExtensionIMEManager::IsWhitelistedExtension(
+ const std::string& extension_id) {
+ for (size_t i = 0; i < component_extension_imes_.size(); ++i) {
+ if (component_extension_imes_[i].id == extension_id)
+ return true;
+ }
+ return false;
+}
+
+std::string ComponentExtensionIMEManager::GetId(
+ const std::string& extension_id,
+ const std::string& engine_id) {
+ IBusComponent::EngineDescription engine;
+ const std::string& input_method_id =
+ GetComponentExtensionIMEId(extension_id, engine_id);
+ if (!FindEngineEntry(input_method_id, NULL, &engine))
+ return "";
+ return input_method_id;
}
std::string ComponentExtensionIMEManager::GetName(
@@ -85,7 +124,7 @@ std::vector<std::string> ComponentExtensionIMEManager::ListIMEByLanguage(
for (size_t j = 0; j < component_extension_imes_[i].engines.size(); ++j) {
if (component_extension_imes_[i].engines[j].language_code == language)
result.push_back(
- extension_ime_util::GetInputMethodID(
+ GetComponentExtensionIMEId(
component_extension_imes_[i].id,
component_extension_imes_[i].engines[j].engine_id));
}
@@ -100,7 +139,7 @@ input_method::InputMethodDescriptors
for (size_t j = 0; j < component_extension_imes_[i].engines.size(); ++j) {
result.push_back(
input_method::InputMethodDescriptor(
- extension_ime_util::GetInputMethodID(
+ GetComponentExtensionIMEId(
component_extension_imes_[i].id,
component_extension_imes_[i].engines[j].engine_id),
component_extension_imes_[i].engines[j].display_name,
@@ -124,19 +163,16 @@ bool ComponentExtensionIMEManager::FindEngineEntry(
const std::string& input_method_id,
ComponentExtensionIME* out_extension,
IBusComponent::EngineDescription* out_engine) {
- if (!extension_ime_util::IsExtensionIME(input_method_id))
+ if (!IsComponentExtensionIMEId(input_method_id))
return false;
for (size_t i = 0; i < component_extension_imes_.size(); ++i) {
const std::string extension_id = component_extension_imes_[i].id;
- if (!extension_ime_util::IsMemberOfExtension(input_method_id, extension_id))
- continue;
const std::vector<IBusComponent::EngineDescription>& engines =
component_extension_imes_[i].engines;
for (size_t j = 0; j < engines.size(); ++j) {
- const std::string trial_ime_id =
- extension_ime_util::GetInputMethodID(extension_id,
- engines[j].engine_id);
+ const std::string trial_ime_id = GetComponentExtensionIMEId(
+ extension_id, engines[j].engine_id);
if (trial_ime_id != input_method_id)
continue;
diff --git a/chromeos/ime/component_extension_ime_manager.h b/chromeos/ime/component_extension_ime_manager.h
index 683e008..bf83bde 100644
--- a/chromeos/ime/component_extension_ime_manager.h
+++ b/chromeos/ime/component_extension_ime_manager.h
@@ -76,8 +76,23 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManager {
// false if already corresponding component extension is unloaded.
bool UnloadComponentExtensionIME(const std::string& input_method_id);
- // Returns true if |input_method_id| is component extension ime id.
- bool IsComponentExtensionIMEId(const std::string& input_method_id);
+ // Returns true if |input_method_id| is component extension ime id. Note that
+ // this function does not check the |input_method_id| is really whitelisted
+ // one or not. If you want to check |input_method_id| is whitelisted component
+ // extension ime, please use IsWhitelisted instead.
+ static bool IsComponentExtensionIMEId(const std::string& input_method_id);
+
+ // Returns true if |input_method_id| is whitelisted component extension input
+ // method.
+ bool IsWhitelisted(const std::string& input_method_id);
+
+ // Returns true if |extension_id| is whitelisted component extension.
+ bool IsWhitelistedExtension(const std::string& extension_id);
+
+ // Returns InputMethodId. This function returns empty string if |extension_id|
+ // and |engine_id| is not a whitelisted component extention IME.
+ std::string GetId(const std::string& extension_id,
+ const std::string& engine_id);
// Returns localized name of |input_method_id|.
std::string GetName(const std::string& input_method_id);
@@ -94,6 +109,14 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManager {
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
+ protected:
+ // Returns InputMethodId for |engine_id| in |extension_id|. This function does
+ // not check |extension_id| is component one or |engine_id| is really a member
+ // of |extension_id|. Do not use this function outside from this class, just
+ // for protected for unit testing.
+ static std::string GetComponentExtensionIMEId(const std::string& extension_id,
+ const std::string& engine_id);
+
private:
// Finds ComponentExtensionIME and EngineDescription associated with
// |input_method_id|. This function retruns true if it is found, otherwise
diff --git a/chromeos/ime/component_extension_ime_manager_unittest.cc b/chromeos/ime/component_extension_ime_manager_unittest.cc
index 9695cff..ba6a665 100644
--- a/chromeos/ime/component_extension_ime_manager_unittest.cc
+++ b/chromeos/ime/component_extension_ime_manager_unittest.cc
@@ -70,6 +70,12 @@ class MockComponentExtensionIMEManagerDelegate
DISALLOW_COPY_AND_ASSIGN(MockComponentExtensionIMEManagerDelegate);
};
+class TestableComponentExtensionIMEManager
+ : public ComponentExtensionIMEManager {
+ public:
+ using ComponentExtensionIMEManager::GetComponentExtensionIMEId;
+};
+
class ComponentExtensionIMEManagerTest :
public testing::Test,
public ComponentExtensionIMEManager::Observer {
@@ -202,7 +208,7 @@ TEST_F(ComponentExtensionIMEManagerTest, LoadComponentExtensionIMETest) {
for (size_t i = 0; i < ime_list_.size(); ++i) {
for (size_t j = 0; j < ime_list_[i].engines.size(); ++j) {
const std::string input_method_id =
- extension_ime_util::GetInputMethodID(
+ TestableComponentExtensionIMEManager::GetComponentExtensionIMEId(
ime_list_[i].id,
ime_list_[i].engines[j].engine_id);
component_ext_mgr_->LoadComponentExtensionIME(input_method_id);
@@ -216,7 +222,7 @@ TEST_F(ComponentExtensionIMEManagerTest, UnloadComponentExtensionIMETest) {
for (size_t i = 0; i < ime_list_.size(); ++i) {
for (size_t j = 0; j < ime_list_[i].engines.size(); ++j) {
const std::string input_method_id =
- extension_ime_util::GetInputMethodID(
+ TestableComponentExtensionIMEManager::GetComponentExtensionIMEId(
ime_list_[i].id,
ime_list_[i].engines[j].engine_id);
component_ext_mgr_->UnloadComponentExtensionIME(input_method_id);
@@ -226,14 +232,28 @@ TEST_F(ComponentExtensionIMEManagerTest, UnloadComponentExtensionIMETest) {
EXPECT_EQ(9, mock_delegate_->unload_call_count());
}
-TEST_F(ComponentExtensionIMEManagerTest, IsComponentExtensionIMEIdTest) {
- EXPECT_TRUE(component_ext_mgr_->IsComponentExtensionIMEId(
+TEST_F(ComponentExtensionIMEManagerTest, IsWhitelistedTest) {
+ EXPECT_TRUE(component_ext_mgr_->IsWhitelisted(
+ TestableComponentExtensionIMEManager::GetComponentExtensionIMEId(
+ ime_list_[0].id,
+ ime_list_[0].engines[0].engine_id)));
+ EXPECT_FALSE(component_ext_mgr_->IsWhitelisted(
extension_ime_util::GetInputMethodID(
ime_list_[0].id,
ime_list_[0].engines[0].engine_id)));
- EXPECT_FALSE(component_ext_mgr_->IsComponentExtensionIMEId("mozc"));
- EXPECT_FALSE(component_ext_mgr_->IsComponentExtensionIMEId(
+ EXPECT_FALSE(component_ext_mgr_->IsWhitelisted("mozc"));
+ EXPECT_FALSE(component_ext_mgr_->IsWhitelisted(
extension_ime_util::GetInputMethodID("AAAA", "012345")));
+ EXPECT_FALSE(component_ext_mgr_->IsWhitelisted(
+ TestableComponentExtensionIMEManager::GetComponentExtensionIMEId(
+ "AAAA", "012345")));
+}
+
+TEST_F(ComponentExtensionIMEManagerTest, IsWhitelistedExtensionTest) {
+ EXPECT_TRUE(component_ext_mgr_->IsWhitelistedExtension(ime_list_[0].id));
+ EXPECT_TRUE(component_ext_mgr_->IsWhitelistedExtension(ime_list_[1].id));
+ EXPECT_FALSE(component_ext_mgr_->IsWhitelistedExtension("dummy"));
+ EXPECT_FALSE(component_ext_mgr_->IsWhitelistedExtension(""));
}
TEST_F(ComponentExtensionIMEManagerTest, GetNameDescriptionTest) {
@@ -242,10 +262,13 @@ TEST_F(ComponentExtensionIMEManagerTest, GetNameDescriptionTest) {
const IBusComponent::EngineDescription& engine
= ime_list_[i].engines[j];
- const std::string input_method_id = extension_ime_util::GetInputMethodID(
- ime_list_[i].id,
- engine.engine_id);
+ const std::string input_method_id =
+ TestableComponentExtensionIMEManager::GetComponentExtensionIMEId(
+ ime_list_[i].id,
+ engine.engine_id);
+ EXPECT_EQ(input_method_id,
+ component_ext_mgr_->GetId(ime_list_[i].id, engine.engine_id));
EXPECT_EQ(engine.display_name,
component_ext_mgr_->GetName(input_method_id));
EXPECT_EQ(engine.description,
@@ -256,11 +279,11 @@ TEST_F(ComponentExtensionIMEManagerTest, GetNameDescriptionTest) {
TEST_F(ComponentExtensionIMEManagerTest, ListIMEByLanguageTest) {
const std::string hindi_layout1 =
- extension_ime_util::GetInputMethodID(ime_list_[1].id,
- ime_list_[1].engines[1].engine_id);
+ TestableComponentExtensionIMEManager::GetComponentExtensionIMEId(
+ ime_list_[1].id, ime_list_[1].engines[1].engine_id);
const std::string hindi_layout2 =
- extension_ime_util::GetInputMethodID(ime_list_[2].id,
- ime_list_[2].engines[0].engine_id);
+ TestableComponentExtensionIMEManager::GetComponentExtensionIMEId(
+ ime_list_[2].id, ime_list_[2].engines[0].engine_id);
std::vector<std::string> hindi_list
= component_ext_mgr_->ListIMEByLanguage("hi");
@@ -285,6 +308,24 @@ TEST_F(ComponentExtensionIMEManagerTest, GetAllIMEAsInputMethodDescriptor) {
EXPECT_EQ(total_ime_size, descriptors.size());
}
+TEST_F(ComponentExtensionIMEManagerTest, GetComponentExtensionIMEId) {
+ const char kExtensionID[] = "extension_id";
+ const char kEngineID[] = "engine_id";
+ const std::string ime_id =
+ TestableComponentExtensionIMEManager::GetComponentExtensionIMEId(
+ kExtensionID, kEngineID);
+
+ EXPECT_TRUE(ComponentExtensionIMEManager::IsComponentExtensionIMEId(
+ ime_id));
+ EXPECT_FALSE(ComponentExtensionIMEManager::IsComponentExtensionIMEId("mozc"));
+ EXPECT_FALSE(ComponentExtensionIMEManager::IsComponentExtensionIMEId(
+ extension_ime_util::GetInputMethodID(kExtensionID, kEngineID)));
+ EXPECT_FALSE(ComponentExtensionIMEManager::IsComponentExtensionIMEId(
+ extension_ime_util::GetInputMethodID(kExtensionID, "mozc")));
+ EXPECT_FALSE(ComponentExtensionIMEManager::IsComponentExtensionIMEId(
+ extension_ime_util::GetInputMethodID("ext-id", kEngineID)));
+}
+
} // namespace
} // namespace input_method