Commit e8c18c76 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

rule-based: Delete unused ProcessText code in InputEngine.

As of cl/258693469, our code no longer uses ProcessText API, which has
been deprecated.

We delete the unused code.

Bug: 1009903
Change-Id: I4d920d6b147df086c01fb4d5e3c18f31b5ed2f5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1833018Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704471}
parent eac70600
...@@ -29,11 +29,6 @@ void ConnectCallback(bool* success, bool result) { ...@@ -29,11 +29,6 @@ void ConnectCallback(bool* success, bool result) {
*success = result; *success = result;
} }
void TestProcessTextCallback(std::string* res_out,
const std::string& response) {
*res_out = response;
}
void TestProcessKeypressForRulebasedCallback( void TestProcessKeypressForRulebasedCallback(
mojom::KeypressResponseForRulebased* res_out, mojom::KeypressResponseForRulebased* res_out,
mojom::KeypressResponseForRulebasedPtr response) { mojom::KeypressResponseForRulebasedPtr response) {
...@@ -115,182 +110,6 @@ TEST_F(ImeServiceTest, ConnectInvalidImeEngine) { ...@@ -115,182 +110,6 @@ TEST_F(ImeServiceTest, ConnectInvalidImeEngine) {
EXPECT_FALSE(success); EXPECT_FALSE(success);
} }
TEST_F(ImeServiceTest, MultipleClients) {
bool success = false;
TestClientChannel test_channel_1;
TestClientChannel test_channel_2;
mojo::Remote<mojom::InputChannel> remote_engine_1;
mojo::Remote<mojom::InputChannel> remote_engine_2;
remote_manager_->ConnectToImeEngine(
"m17n:ar", remote_engine_1.BindNewPipeAndPassReceiver(),
test_channel_1.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success));
remote_manager_.FlushForTesting();
remote_manager_->ConnectToImeEngine(
"m17n:ar", remote_engine_2.BindNewPipeAndPassReceiver(),
test_channel_2.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success));
remote_manager_.FlushForTesting();
std::string response;
std::string process_text_key =
"{\"method\":\"keyEvent\",\"type\":\"keydown\""
",\"code\":\"KeyA\",\"shift\":true,\"altgr\":false,\"caps\":false}";
remote_engine_1->ProcessText(
process_text_key, base::BindOnce(&TestProcessTextCallback, &response));
remote_engine_1.FlushForTesting();
remote_engine_2->ProcessText(
process_text_key, base::BindOnce(&TestProcessTextCallback, &response));
remote_engine_2.FlushForTesting();
std::string process_text_key_count = "{\"method\":\"countKey\"}";
remote_engine_1->ProcessText(
process_text_key_count,
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine_1.FlushForTesting();
EXPECT_EQ("1", response);
remote_engine_2->ProcessText(
process_text_key_count,
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine_2.FlushForTesting();
EXPECT_EQ("1", response);
}
// Tests that the rule-based Arabic keyboard can work correctly.
TEST_F(ImeServiceTest, RuleBasedArabic) {
bool success = false;
TestClientChannel test_channel;
mojo::Remote<mojom::InputChannel> remote_engine;
remote_manager_->ConnectToImeEngine(
"m17n:ar", remote_engine.BindNewPipeAndPassReceiver(),
test_channel.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success));
remote_manager_.FlushForTesting();
EXPECT_TRUE(success);
// Test Shift+KeyA.
std::string response;
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyA\","
"\"shift\":true,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
const wchar_t* expected_response =
L"{\"result\":true,\"operations\":[{\"method\":\"commitText\","
L"\"arguments\":[\"\u0650\"]}]}";
EXPECT_EQ(base::WideToUTF8(expected_response), response);
// Test KeyB.
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyB\","
"\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
expected_response =
L"{\"result\":true,\"operations\":[{\"method\":\"commitText\","
L"\"arguments\":[\"\u0644\u0627\"]}]}";
EXPECT_EQ(base::WideToUTF8(expected_response), response);
// Test unhandled key.
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Enter\","
"\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
EXPECT_EQ("{\"result\":false}", response);
// Test keyup.
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keyup\",\"code\":\"Enter\","
"\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
EXPECT_EQ("{\"result\":false}", response);
// Test reset.
remote_engine->ProcessText(
"{\"method\":\"reset\"}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
EXPECT_EQ("{\"result\":true}", response);
// Test invalid request.
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\"}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
EXPECT_EQ("{\"result\":false}", response);
}
// Tests that the rule-based DevaPhone keyboard can work correctly.
TEST_F(ImeServiceTest, RuleBasedDevaPhone) {
bool success = false;
TestClientChannel test_channel;
mojo::Remote<mojom::InputChannel> remote_engine;
remote_manager_->ConnectToImeEngine(
"m17n:deva_phone", remote_engine.BindNewPipeAndPassReceiver(),
test_channel.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success));
remote_manager_.FlushForTesting();
EXPECT_TRUE(success);
std::string response;
// KeyN.
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyN\","
"\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
const char* expected_response =
u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\","
u8"\"arguments\":[\"\u0928\"]}]}";
EXPECT_EQ(expected_response, response);
// Backspace.
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Backspace\","
"\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
expected_response =
u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\","
u8"\"arguments\":[\"\"]}]}";
EXPECT_EQ(expected_response, response);
// KeyN + KeyC.
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyN\","
"\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyC\","
"\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
expected_response =
u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\","
u8"\"arguments\":[\"\u091e\u094d\u091a\"]}]}";
EXPECT_EQ(expected_response, response);
// Space.
remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Space\","
"\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response));
remote_engine.FlushForTesting();
expected_response =
u8"{\"result\":true,\"operations\":[{\"method\":\"commitText\","
u8"\"arguments\":[\"\u091e\u094d\u091a \"]}]}";
EXPECT_EQ(expected_response, response);
}
TEST_F(ImeServiceTest, MultipleClientsRulebased) { TEST_F(ImeServiceTest, MultipleClientsRulebased) {
bool success = false; bool success = false;
TestClientChannel test_channel_1; TestClientChannel test_channel_1;
...@@ -339,7 +158,7 @@ TEST_F(ImeServiceTest, MultipleClientsRulebased) { ...@@ -339,7 +158,7 @@ TEST_F(ImeServiceTest, MultipleClientsRulebased) {
} }
// Tests that the rule-based Arabic keyboard can work correctly. // Tests that the rule-based Arabic keyboard can work correctly.
TEST_F(ImeServiceTest, RuleBasedArabicKeypress) { TEST_F(ImeServiceTest, RuleBasedArabic) {
bool success = false; bool success = false;
TestClientChannel test_channel; TestClientChannel test_channel;
mojom::InputChannelPtr to_engine_ptr; mojom::InputChannelPtr to_engine_ptr;
...@@ -408,7 +227,7 @@ TEST_F(ImeServiceTest, RuleBasedArabicKeypress) { ...@@ -408,7 +227,7 @@ TEST_F(ImeServiceTest, RuleBasedArabicKeypress) {
} }
// Tests that the rule-based DevaPhone keyboard can work correctly. // Tests that the rule-based DevaPhone keyboard can work correctly.
TEST_F(ImeServiceTest, RuleBasedDevaPhoneKeypress) { TEST_F(ImeServiceTest, RuleBasedDevaPhone) {
bool success = false; bool success = false;
TestClientChannel test_channel; TestClientChannel test_channel;
mojom::InputChannelPtr to_engine_ptr; mojom::InputChannelPtr to_engine_ptr;
......
...@@ -100,9 +100,7 @@ bool InputEngine::IsImeSupportedByRulebased(const std::string& ime_spec) { ...@@ -100,9 +100,7 @@ bool InputEngine::IsImeSupportedByRulebased(const std::string& ime_spec) {
void InputEngine::ProcessText(const std::string& message, void InputEngine::ProcessText(const std::string& message,
ProcessTextCallback callback) { ProcessTextCallback callback) {
auto& context = channel_receivers_.current_context(); NOTIMPLEMENTED(); // Text message not used in the rulebased engine.
std::string result = Process(message, context.get());
std::move(callback).Run(result);
} }
void InputEngine::ProcessMessage(const std::vector<uint8_t>& message, void InputEngine::ProcessMessage(const std::vector<uint8_t>& message,
...@@ -110,118 +108,6 @@ void InputEngine::ProcessMessage(const std::vector<uint8_t>& message, ...@@ -110,118 +108,6 @@ void InputEngine::ProcessMessage(const std::vector<uint8_t>& message,
NOTIMPLEMENTED(); // Protobuf message is not used in the rulebased engine. NOTIMPLEMENTED(); // Protobuf message is not used in the rulebased engine.
} }
std::string InputEngine::Process(const std::string& message,
const InputEngineContext* context) {
auto& engine = context->engine;
if (!engine)
return std::string();
const char kFalseResponse[] = "{\"result\":false}";
// The request message is in JSON format as:
// {
// 'method': <string>, // 'reset' or 'keyEvent'
// 'type': <string>, // 'keydown' or 'keyup'
// 'code': <string>, // e.g. 'KeyA', 'Backspace', etc.
// 'shift': <boolean>,
// 'altgr': <boolean>,
// 'caps': <boolean>,
// 'ctrl': <boolean>,
// 'alt': <boolean>
// }
// TODO(shuchen): make parser/writer util class for the JSON-based protocol.
int error_code;
std::string error_string;
std::unique_ptr<base::Value> message_value =
base::JSONReader::ReadAndReturnErrorDeprecated(
message, base::JSON_PARSE_RFC, &error_code, &error_string);
if (!message_value) {
LOG(ERROR) << "Read message error: " << error_code << "; " << error_string;
return kFalseResponse;
}
base::Value* method = message_value->FindKey("method");
if (!method)
return kFalseResponse;
const std::string& method_str = method->GetString();
if (method_str == "countKey") {
return std::to_string(engine->process_key_count());
}
if (method_str == "reset") {
engine->Reset();
return "{\"result\":true}";
}
if (method_str == "keyEvent") {
base::Value* type = message_value->FindKey("type");
if (!type || type->GetString() != "keydown")
return kFalseResponse;
}
base::Value* code = message_value->FindKey("code");
base::Value* shift = message_value->FindKey("shift");
base::Value* altgr = message_value->FindKey("altgr");
base::Value* caps = message_value->FindKey("caps");
if (!code || !shift || !altgr || !caps)
return kFalseResponse;
uint8_t modifiers = 0;
if (shift->GetBool())
modifiers |= rulebased::MODIFIER_SHIFT;
if (altgr->GetBool())
modifiers |= rulebased::MODIFIER_ALTGR;
if (caps->GetBool())
modifiers |= rulebased::MODIFIER_CAPSLOCK;
rulebased::ProcessKeyResult res =
engine->ProcessKey(code->GetString(), modifiers);
// The response message is in JSON format as:
// {
// 'result': <boolean>,
// 'operations': [
// {
// 'method': 'commitText|setComposition',
// 'arguments': <string>
// }
// ]
// }
std::string response_str = "{\"result\":";
response_str += (res.key_handled ? "true" : "false");
std::vector<std::string> ops;
if (!res.commit_text.empty()) {
std::string commit_text;
base::EscapeJSONString(res.commit_text, false, &commit_text);
ops.push_back("{\"method\":\"commitText\",\"arguments\":[\"" + commit_text +
"\"]}");
}
// Need to add the setComposition operation to the result when the key is
// handled and commit_text and composition_text are both empty.
// That is the case of using Backspace to delete the last character in
// composition.
if (!res.composition_text.empty() ||
(res.key_handled && res.commit_text.empty())) {
std::string composition_text;
base::EscapeJSONString(res.composition_text, false, &composition_text);
ops.push_back("{\"method\":\"setComposition\",\"arguments\":[\"" +
composition_text + "\"]}");
}
if (ops.empty()) {
response_str += "}";
} else {
response_str += ",\"operations\":[";
for (size_t i = 0; i < ops.size(); ++i) {
if (i > 0)
response_str += ",";
response_str += ops[i];
}
response_str += "]}";
}
return response_str;
}
void InputEngine::ProcessKeypressForRulebased( void InputEngine::ProcessKeypressForRulebased(
mojom::KeypressInfoForRulebasedPtr keypress_info, mojom::KeypressInfoForRulebasedPtr keypress_info,
ProcessKeypressForRulebasedCallback callback) { ProcessKeypressForRulebasedCallback callback) {
......
...@@ -60,9 +60,6 @@ class InputEngine : public mojom::InputChannel { ...@@ -60,9 +60,6 @@ class InputEngine : public mojom::InputChannel {
// Returns whether the given ime_spec is supported by rulebased engine. // Returns whether the given ime_spec is supported by rulebased engine.
bool IsImeSupportedByRulebased(const std::string& ime_spec); bool IsImeSupportedByRulebased(const std::string& ime_spec);
std::string Process(const std::string& message,
const InputEngineContext* context);
mojo::ReceiverSet<mojom::InputChannel, std::unique_ptr<InputEngineContext>> mojo::ReceiverSet<mojom::InputChannel, std::unique_ptr<InputEngineContext>>
channel_receivers_; channel_receivers_;
......
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