OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/base/ime/input_method_auralinux.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/base/ime/dummy_text_input_client.h" |
| 12 #include "ui/base/ime/input_method_delegate.h" |
| 13 #include "ui/base/ime/input_method_initializer.h" |
| 14 #include "ui/base/ime/linux/fake_input_method_context.h" |
| 15 #include "ui/base/ime/linux/linux_input_method_context_factory.h" |
| 16 #include "ui/events/event.h" |
| 17 |
| 18 namespace ui { |
| 19 namespace { |
| 20 |
| 21 const base::char16 kActionCommit = L'C'; |
| 22 const base::char16 kActionCompositionStart = L'S'; |
| 23 const base::char16 kActionCompositionUpdate = L'U'; |
| 24 const base::char16 kActionCompositionEnd = L'E'; |
| 25 |
| 26 class TestResult { |
| 27 public: |
| 28 static TestResult* GetInstance() { return Singleton<TestResult>::get(); } |
| 29 |
| 30 void RecordAction(const base::string16& action) { |
| 31 recorded_actions_.push_back(action); |
| 32 } |
| 33 |
| 34 void ExpectAction(const std::string& action) { |
| 35 expected_actions_.push_back(base::ASCIIToUTF16(action)); |
| 36 } |
| 37 |
| 38 void Verify() { |
| 39 size_t len = recorded_actions_.size(); |
| 40 size_t len_exp = expected_actions_.size(); |
| 41 EXPECT_EQ(len_exp, len); |
| 42 for (size_t i = 0; i < len; i++) |
| 43 EXPECT_EQ(expected_actions_[i], recorded_actions_[i]); |
| 44 recorded_actions_.clear(); |
| 45 expected_actions_.clear(); |
| 46 } |
| 47 |
| 48 private: |
| 49 std::vector<base::string16> recorded_actions_; |
| 50 std::vector<base::string16> expected_actions_; |
| 51 }; |
| 52 |
| 53 class LinuxInputMethodContextForTesting : public LinuxInputMethodContext { |
| 54 public: |
| 55 LinuxInputMethodContextForTesting(LinuxInputMethodContextDelegate* delegate, |
| 56 bool is_simple) |
| 57 : delegate_(delegate), |
| 58 is_simple_(is_simple), |
| 59 is_sync_mode_(false), |
| 60 eat_key_(false), |
| 61 focused_(false) {} |
| 62 |
| 63 void SetSyncMode(bool is_sync_mode) { is_sync_mode_ = is_sync_mode; } |
| 64 void SetEatKey(bool eat_key) { eat_key_ = eat_key; } |
| 65 |
| 66 void AddCommitAction(const std::string& text) { |
| 67 actions_.push_back(base::ASCIIToUTF16("C:" + text)); |
| 68 } |
| 69 |
| 70 void AddCompositionUpdateAction(const std::string& text) { |
| 71 actions_.push_back(base::ASCIIToUTF16("U:" + text)); |
| 72 } |
| 73 |
| 74 void AddCompositionStartAction() { |
| 75 actions_.push_back(base::ASCIIToUTF16("S")); |
| 76 } |
| 77 |
| 78 void AddCompositionEndAction() { |
| 79 actions_.push_back(base::ASCIIToUTF16("E")); |
| 80 } |
| 81 |
| 82 protected: |
| 83 bool DispatchKeyEvent(const ui::KeyEvent& key_event) override { |
| 84 if (!is_sync_mode_) { |
| 85 actions_.clear(); |
| 86 return eat_key_; |
| 87 } |
| 88 |
| 89 for (const auto& action : actions_) { |
| 90 std::vector<base::string16> parts; |
| 91 base::SplitString(action, L':', &parts); |
| 92 base::char16 id = parts[0][0]; |
| 93 base::string16 param; |
| 94 if (parts.size() > 1) |
| 95 param = parts[1]; |
| 96 if (id == kActionCommit) { |
| 97 delegate_->OnCommit(param); |
| 98 } else if (id == kActionCompositionStart) { |
| 99 delegate_->OnPreeditStart(); |
| 100 } else if (id == kActionCompositionUpdate) { |
| 101 CompositionText comp; |
| 102 comp.text = param; |
| 103 delegate_->OnPreeditChanged(comp); |
| 104 } else if (id == kActionCompositionEnd) { |
| 105 delegate_->OnPreeditEnd(); |
| 106 } |
| 107 } |
| 108 |
| 109 actions_.clear(); |
| 110 return eat_key_; |
| 111 } |
| 112 |
| 113 void Reset() override {} |
| 114 |
| 115 void Focus() override { focused_ = true; } |
| 116 |
| 117 void Blur() override { focused_ = false; } |
| 118 |
| 119 void SetCursorLocation(const gfx::Rect& rect) override { |
| 120 cursor_position_ = rect; |
| 121 } |
| 122 |
| 123 private: |
| 124 LinuxInputMethodContextDelegate* delegate_; |
| 125 std::vector<base::string16> actions_; |
| 126 bool is_simple_; |
| 127 bool is_sync_mode_; |
| 128 bool eat_key_; |
| 129 bool focused_; |
| 130 gfx::Rect cursor_position_; |
| 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextForTesting); |
| 133 }; |
| 134 |
| 135 class LinuxInputMethodContextFactoryForTesting |
| 136 : public LinuxInputMethodContextFactory { |
| 137 public: |
| 138 LinuxInputMethodContextFactoryForTesting(){}; |
| 139 |
| 140 scoped_ptr<LinuxInputMethodContext> CreateInputMethodContext( |
| 141 LinuxInputMethodContextDelegate* delegate, |
| 142 bool is_simple) const override { |
| 143 return scoped_ptr<ui::LinuxInputMethodContext>( |
| 144 new LinuxInputMethodContextForTesting(delegate, is_simple)); |
| 145 }; |
| 146 |
| 147 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(LinuxInputMethodContextFactoryForTesting); |
| 149 }; |
| 150 |
| 151 class InputMethodDelegateForTesting : public internal::InputMethodDelegate { |
| 152 public: |
| 153 InputMethodDelegateForTesting(){}; |
| 154 ~InputMethodDelegateForTesting() override{}; |
| 155 |
| 156 bool DispatchKeyEventPostIME(const ui::KeyEvent& key_event) override { |
| 157 std::string action; |
| 158 switch (key_event.type()) { |
| 159 case ET_KEY_PRESSED: |
| 160 action = "keydown:"; |
| 161 break; |
| 162 case ET_KEY_RELEASED: |
| 163 action = "keyup:"; |
| 164 break; |
| 165 default: |
| 166 break; |
| 167 } |
| 168 std::stringstream ss; |
| 169 ss << key_event.key_code(); |
| 170 action += std::string(ss.str()); |
| 171 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16(action)); |
| 172 return false; |
| 173 } |
| 174 |
| 175 private: |
| 176 DISALLOW_COPY_AND_ASSIGN(InputMethodDelegateForTesting); |
| 177 }; |
| 178 |
| 179 class TextInputClientForTesting : public DummyTextInputClient { |
| 180 public: |
| 181 explicit TextInputClientForTesting(TextInputType text_input_type) |
| 182 : DummyTextInputClient(text_input_type){}; |
| 183 |
| 184 base::string16 composition_text; |
| 185 |
| 186 protected: |
| 187 void SetCompositionText(const CompositionText& composition) override { |
| 188 composition_text = composition.text; |
| 189 TestResult::GetInstance()->RecordAction( |
| 190 base::ASCIIToUTF16("compositionstart")); |
| 191 TestResult::GetInstance()->RecordAction( |
| 192 base::ASCIIToUTF16("compositionupdate:") + composition.text); |
| 193 } |
| 194 |
| 195 bool HasCompositionText() const override { return !composition_text.empty(); } |
| 196 |
| 197 void ConfirmCompositionText() override { |
| 198 TestResult::GetInstance()->RecordAction( |
| 199 base::ASCIIToUTF16("compositionend")); |
| 200 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") + |
| 201 composition_text); |
| 202 composition_text.clear(); |
| 203 } |
| 204 |
| 205 void ClearCompositionText() override { |
| 206 TestResult::GetInstance()->RecordAction( |
| 207 base::ASCIIToUTF16("compositionend")); |
| 208 composition_text.clear(); |
| 209 } |
| 210 |
| 211 void InsertText(const base::string16& text) override { |
| 212 if (HasCompositionText()) { |
| 213 TestResult::GetInstance()->RecordAction( |
| 214 base::ASCIIToUTF16("compositionend")); |
| 215 } |
| 216 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("textinput:") + |
| 217 text); |
| 218 composition_text.clear(); |
| 219 } |
| 220 |
| 221 void InsertChar(base::char16 ch, int flags) override { |
| 222 std::stringstream ss; |
| 223 ss << ch; |
| 224 TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("keypress:") + |
| 225 base::ASCIIToUTF16(ss.str())); |
| 226 } |
| 227 }; |
| 228 |
| 229 class InputMethodAuraLinuxTest : public testing::Test { |
| 230 protected: |
| 231 InputMethodAuraLinuxTest() |
| 232 : factory_(NULL), |
| 233 input_method_auralinux_(NULL), |
| 234 delegate_(NULL), |
| 235 context_(NULL), |
| 236 context_simple_(NULL) { |
| 237 factory_ = new LinuxInputMethodContextFactoryForTesting(); |
| 238 LinuxInputMethodContextFactory::SetInstance(factory_); |
| 239 test_result_ = TestResult::GetInstance(); |
| 240 } |
| 241 ~InputMethodAuraLinuxTest() override { |
| 242 delete factory_; |
| 243 factory_ = NULL; |
| 244 test_result_ = NULL; |
| 245 } |
| 246 |
| 247 void SetUp() override { |
| 248 delegate_ = new InputMethodDelegateForTesting(); |
| 249 input_method_auralinux_ = new InputMethodAuraLinux(delegate_); |
| 250 input_method_auralinux_->OnFocus(); |
| 251 context_ = static_cast<LinuxInputMethodContextForTesting*>( |
| 252 input_method_auralinux_->GetContextForTesting(false)); |
| 253 context_simple_ = static_cast<LinuxInputMethodContextForTesting*>( |
| 254 input_method_auralinux_->GetContextForTesting(true)); |
| 255 } |
| 256 |
| 257 void TearDown() override { |
| 258 context_->SetSyncMode(false); |
| 259 context_->SetEatKey(false); |
| 260 |
| 261 context_simple_->SetSyncMode(false); |
| 262 context_simple_->SetEatKey(false); |
| 263 |
| 264 context_ = NULL; |
| 265 context_simple_ = NULL; |
| 266 |
| 267 delete input_method_auralinux_; |
| 268 input_method_auralinux_ = NULL; |
| 269 delete delegate_; |
| 270 delegate_ = NULL; |
| 271 } |
| 272 |
| 273 LinuxInputMethodContextFactoryForTesting* factory_; |
| 274 InputMethodAuraLinux* input_method_auralinux_; |
| 275 InputMethodDelegateForTesting* delegate_; |
| 276 LinuxInputMethodContextForTesting* context_; |
| 277 LinuxInputMethodContextForTesting* context_simple_; |
| 278 TestResult* test_result_; |
| 279 |
| 280 DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinuxTest); |
| 281 }; |
| 282 |
| 283 TEST_F(InputMethodAuraLinuxTest, BasicSyncModeTest) { |
| 284 context_->SetSyncMode(true); |
| 285 context_->SetEatKey(true); |
| 286 context_->AddCommitAction("a"); |
| 287 |
| 288 scoped_ptr<TextInputClientForTesting> client( |
| 289 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 290 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 291 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 292 |
| 293 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 294 key.set_character(L'a'); |
| 295 input_method_auralinux_->DispatchKeyEvent(key); |
| 296 |
| 297 test_result_->ExpectAction("keydown:65"); |
| 298 test_result_->ExpectAction("keypress:97"); |
| 299 test_result_->Verify(); |
| 300 |
| 301 input_method_auralinux_->DetachTextInputClient(client.get()); |
| 302 client.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD)); |
| 303 context_simple_->SetSyncMode(true); |
| 304 context_simple_->SetEatKey(false); |
| 305 |
| 306 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 307 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 308 input_method_auralinux_->DispatchKeyEvent(key); |
| 309 |
| 310 test_result_->ExpectAction("keydown:65"); |
| 311 test_result_->ExpectAction("keypress:97"); |
| 312 test_result_->Verify(); |
| 313 } |
| 314 |
| 315 TEST_F(InputMethodAuraLinuxTest, BasicAsyncModeTest) { |
| 316 context_->SetSyncMode(false); |
| 317 context_->SetEatKey(true); |
| 318 |
| 319 scoped_ptr<TextInputClientForTesting> client( |
| 320 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 321 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 322 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 323 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 324 key.set_character(L'a'); |
| 325 input_method_auralinux_->DispatchKeyEvent(key); |
| 326 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("a")); |
| 327 |
| 328 test_result_->ExpectAction("keydown:229"); |
| 329 test_result_->ExpectAction("textinput:a"); |
| 330 test_result_->Verify(); |
| 331 |
| 332 input_method_auralinux_->DetachTextInputClient(client.get()); |
| 333 client.reset(new TextInputClientForTesting(TEXT_INPUT_TYPE_PASSWORD)); |
| 334 context_simple_->SetSyncMode(false); |
| 335 context_simple_->SetEatKey(false); |
| 336 |
| 337 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 338 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 339 input_method_auralinux_->DispatchKeyEvent(key); |
| 340 |
| 341 test_result_->ExpectAction("keydown:65"); |
| 342 test_result_->ExpectAction("keypress:97"); |
| 343 test_result_->Verify(); |
| 344 } |
| 345 |
| 346 TEST_F(InputMethodAuraLinuxTest, IBusUSTest) { |
| 347 context_->SetSyncMode(false); |
| 348 context_->SetEatKey(true); |
| 349 |
| 350 scoped_ptr<TextInputClientForTesting> client( |
| 351 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 352 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 353 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 354 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 355 key.set_character(L'a'); |
| 356 input_method_auralinux_->DispatchKeyEvent(key); |
| 357 |
| 358 // IBus mutes the key down. |
| 359 test_result_->Verify(); |
| 360 |
| 361 // IBus simulates a faked key down and handle it in sync mode. |
| 362 context_->SetSyncMode(true); |
| 363 context_->AddCommitAction("a"); |
| 364 input_method_auralinux_->DispatchKeyEvent(key); |
| 365 |
| 366 test_result_->ExpectAction("keydown:65"); |
| 367 test_result_->ExpectAction("keypress:97"); |
| 368 test_result_->Verify(); |
| 369 |
| 370 // IBus does NOT handle the key up. |
| 371 context_->SetEatKey(false); |
| 372 input_method_auralinux_->DispatchKeyEvent( |
| 373 KeyEvent(ET_KEY_RELEASED, VKEY_A, 0)); |
| 374 |
| 375 test_result_->ExpectAction("keyup:65"); |
| 376 test_result_->Verify(); |
| 377 } |
| 378 |
| 379 TEST_F(InputMethodAuraLinuxTest, IBusPinyinTest) { |
| 380 context_->SetSyncMode(false); |
| 381 context_->SetEatKey(true); |
| 382 |
| 383 scoped_ptr<TextInputClientForTesting> client( |
| 384 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 385 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 386 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 387 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 388 key.set_character(L'a'); |
| 389 input_method_auralinux_->DispatchKeyEvent(key); |
| 390 |
| 391 // IBus issues a standalone set_composition action. |
| 392 input_method_auralinux_->OnPreeditStart(); |
| 393 CompositionText comp; |
| 394 comp.text = base::ASCIIToUTF16("a"); |
| 395 input_method_auralinux_->OnPreeditChanged(comp); |
| 396 |
| 397 test_result_->ExpectAction("keydown:229"); |
| 398 test_result_->ExpectAction("compositionstart"); |
| 399 test_result_->ExpectAction("compositionupdate:a"); |
| 400 test_result_->Verify(); |
| 401 |
| 402 // IBus issues a commit text with composition after muting the space key down. |
| 403 input_method_auralinux_->DispatchKeyEvent( |
| 404 KeyEvent(ET_KEY_PRESSED, VKEY_SPACE, 0)); |
| 405 |
| 406 input_method_auralinux_->OnPreeditEnd(); |
| 407 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("A")); |
| 408 |
| 409 test_result_->ExpectAction("keydown:229"); |
| 410 test_result_->ExpectAction("compositionend"); |
| 411 test_result_->ExpectAction("keydown:229"); |
| 412 test_result_->ExpectAction("textinput:A"); |
| 413 test_result_->Verify(); |
| 414 } |
| 415 |
| 416 // crbug.com/463491 |
| 417 TEST_F(InputMethodAuraLinuxTest, DeadKeyTest) { |
| 418 context_simple_->SetSyncMode(true); |
| 419 context_simple_->SetEatKey(true); |
| 420 |
| 421 scoped_ptr<TextInputClientForTesting> client( |
| 422 new TextInputClientForTesting(TEXT_INPUT_TYPE_NONE)); |
| 423 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 424 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 425 |
| 426 KeyEvent dead_key(ET_KEY_PRESSED, VKEY_OEM_7, 0); |
| 427 dead_key.set_character(L'\''); |
| 428 input_method_auralinux_->DispatchKeyEvent(dead_key); |
| 429 |
| 430 // The single quote key is muted. |
| 431 test_result_->ExpectAction("keydown:222"); |
| 432 test_result_->Verify(); |
| 433 |
| 434 context_simple_->AddCommitAction("X"); |
| 435 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 436 key.set_character(L'a'); |
| 437 input_method_auralinux_->DispatchKeyEvent(key); |
| 438 |
| 439 // The following A key generates the accent key: รก. |
| 440 test_result_->ExpectAction("keydown:65"); |
| 441 test_result_->ExpectAction("keypress:88"); |
| 442 test_result_->Verify(); |
| 443 } |
| 444 |
| 445 TEST_F(InputMethodAuraLinuxTest, MultiCommitsTest) { |
| 446 context_->SetSyncMode(true); |
| 447 context_->SetEatKey(true); |
| 448 context_->AddCommitAction("a"); |
| 449 context_->AddCommitAction("b"); |
| 450 context_->AddCommitAction("c"); |
| 451 |
| 452 scoped_ptr<TextInputClientForTesting> client( |
| 453 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 454 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 455 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 456 |
| 457 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 458 key.set_character(L'a'); |
| 459 input_method_auralinux_->DispatchKeyEvent(key); |
| 460 |
| 461 test_result_->ExpectAction("keydown:229"); |
| 462 test_result_->ExpectAction("textinput:abc"); |
| 463 test_result_->Verify(); |
| 464 } |
| 465 |
| 466 TEST_F(InputMethodAuraLinuxTest, MixedCompositionAndCommitTest) { |
| 467 context_->SetSyncMode(true); |
| 468 context_->SetEatKey(true); |
| 469 context_->AddCommitAction("a"); |
| 470 context_->AddCompositionStartAction(); |
| 471 context_->AddCompositionUpdateAction("b"); |
| 472 context_->AddCommitAction("c"); |
| 473 context_->AddCompositionUpdateAction("d"); |
| 474 |
| 475 scoped_ptr<TextInputClientForTesting> client( |
| 476 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 477 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 478 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 479 |
| 480 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 481 key.set_character(L'a'); |
| 482 input_method_auralinux_->DispatchKeyEvent(key); |
| 483 |
| 484 test_result_->ExpectAction("keydown:229"); |
| 485 test_result_->ExpectAction("textinput:ac"); |
| 486 test_result_->ExpectAction("compositionstart"); |
| 487 test_result_->ExpectAction("compositionupdate:d"); |
| 488 test_result_->Verify(); |
| 489 |
| 490 context_->AddCommitAction("e"); |
| 491 input_method_auralinux_->DispatchKeyEvent(key); |
| 492 |
| 493 test_result_->ExpectAction("keydown:229"); |
| 494 test_result_->ExpectAction("compositionend"); |
| 495 test_result_->ExpectAction("textinput:e"); |
| 496 test_result_->Verify(); |
| 497 } |
| 498 |
| 499 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithoutCommitTest) { |
| 500 context_->SetSyncMode(true); |
| 501 context_->SetEatKey(true); |
| 502 context_->AddCompositionStartAction(); |
| 503 context_->AddCompositionUpdateAction("a"); |
| 504 |
| 505 scoped_ptr<TextInputClientForTesting> client( |
| 506 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 507 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 508 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 509 |
| 510 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 511 key.set_character(L'a'); |
| 512 input_method_auralinux_->DispatchKeyEvent(key); |
| 513 |
| 514 test_result_->ExpectAction("keydown:229"); |
| 515 test_result_->ExpectAction("compositionstart"); |
| 516 test_result_->ExpectAction("compositionupdate:a"); |
| 517 test_result_->Verify(); |
| 518 |
| 519 context_->AddCompositionEndAction(); |
| 520 input_method_auralinux_->DispatchKeyEvent(key); |
| 521 |
| 522 test_result_->ExpectAction("keydown:229"); |
| 523 test_result_->ExpectAction("compositionend"); |
| 524 test_result_->Verify(); |
| 525 } |
| 526 |
| 527 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithEmptyCommitTest) { |
| 528 context_->SetSyncMode(true); |
| 529 context_->SetEatKey(true); |
| 530 context_->AddCompositionStartAction(); |
| 531 context_->AddCompositionUpdateAction("a"); |
| 532 |
| 533 scoped_ptr<TextInputClientForTesting> client( |
| 534 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 535 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 536 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 537 |
| 538 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 539 key.set_character(L'a'); |
| 540 input_method_auralinux_->DispatchKeyEvent(key); |
| 541 |
| 542 test_result_->ExpectAction("keydown:229"); |
| 543 test_result_->ExpectAction("compositionstart"); |
| 544 test_result_->ExpectAction("compositionupdate:a"); |
| 545 test_result_->Verify(); |
| 546 |
| 547 context_->AddCompositionEndAction(); |
| 548 context_->AddCommitAction(""); |
| 549 input_method_auralinux_->DispatchKeyEvent(key); |
| 550 |
| 551 test_result_->ExpectAction("keydown:229"); |
| 552 test_result_->ExpectAction("compositionend"); |
| 553 test_result_->Verify(); |
| 554 } |
| 555 |
| 556 TEST_F(InputMethodAuraLinuxTest, CompositionEndWithCommitTest) { |
| 557 context_->SetSyncMode(true); |
| 558 context_->SetEatKey(true); |
| 559 context_->AddCompositionStartAction(); |
| 560 context_->AddCompositionUpdateAction("a"); |
| 561 |
| 562 scoped_ptr<TextInputClientForTesting> client( |
| 563 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 564 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 565 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 566 |
| 567 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 568 key.set_character(L'a'); |
| 569 input_method_auralinux_->DispatchKeyEvent(key); |
| 570 |
| 571 test_result_->ExpectAction("keydown:229"); |
| 572 test_result_->ExpectAction("compositionstart"); |
| 573 test_result_->ExpectAction("compositionupdate:a"); |
| 574 test_result_->Verify(); |
| 575 |
| 576 context_->AddCompositionEndAction(); |
| 577 context_->AddCommitAction("b"); |
| 578 input_method_auralinux_->DispatchKeyEvent(key); |
| 579 |
| 580 // Verifies single char commit under composition mode will call InsertText |
| 581 // intead of InsertChar. |
| 582 test_result_->ExpectAction("keydown:229"); |
| 583 test_result_->ExpectAction("compositionend"); |
| 584 test_result_->ExpectAction("textinput:b"); |
| 585 test_result_->Verify(); |
| 586 } |
| 587 |
| 588 TEST_F(InputMethodAuraLinuxTest, CompositionUpdateWithCommitTest) { |
| 589 context_->SetSyncMode(true); |
| 590 context_->SetEatKey(true); |
| 591 context_->AddCompositionStartAction(); |
| 592 context_->AddCompositionUpdateAction("a"); |
| 593 context_->AddCommitAction("b"); |
| 594 |
| 595 scoped_ptr<TextInputClientForTesting> client( |
| 596 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 597 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 598 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 599 |
| 600 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 601 key.set_character(L'a'); |
| 602 input_method_auralinux_->DispatchKeyEvent(key); |
| 603 |
| 604 test_result_->ExpectAction("keydown:229"); |
| 605 test_result_->ExpectAction("textinput:b"); |
| 606 test_result_->ExpectAction("compositionstart"); |
| 607 test_result_->ExpectAction("compositionupdate:a"); |
| 608 test_result_->Verify(); |
| 609 } |
| 610 |
| 611 TEST_F(InputMethodAuraLinuxTest, MixedAsyncAndSyncTest) { |
| 612 context_->SetSyncMode(false); |
| 613 context_->SetEatKey(true); |
| 614 |
| 615 scoped_ptr<TextInputClientForTesting> client( |
| 616 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 617 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 618 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 619 |
| 620 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 621 key.set_character(L'a'); |
| 622 input_method_auralinux_->DispatchKeyEvent(key); |
| 623 CompositionText comp; |
| 624 comp.text = base::ASCIIToUTF16("a"); |
| 625 input_method_auralinux_->OnPreeditChanged(comp); |
| 626 |
| 627 test_result_->ExpectAction("keydown:229"); |
| 628 test_result_->ExpectAction("compositionstart"); |
| 629 test_result_->ExpectAction("compositionupdate:a"); |
| 630 test_result_->Verify(); |
| 631 |
| 632 context_->SetSyncMode(true); |
| 633 context_->AddCompositionEndAction(); |
| 634 context_->AddCommitAction("b"); |
| 635 |
| 636 input_method_auralinux_->DispatchKeyEvent(key); |
| 637 |
| 638 test_result_->ExpectAction("keydown:229"); |
| 639 test_result_->ExpectAction("compositionend"); |
| 640 test_result_->ExpectAction("textinput:b"); |
| 641 test_result_->Verify(); |
| 642 } |
| 643 |
| 644 TEST_F(InputMethodAuraLinuxTest, MixedSyncAndAsyncTest) { |
| 645 context_->SetSyncMode(true); |
| 646 context_->SetEatKey(true); |
| 647 context_->AddCompositionStartAction(); |
| 648 context_->AddCompositionUpdateAction("a"); |
| 649 |
| 650 scoped_ptr<TextInputClientForTesting> client( |
| 651 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 652 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 653 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 654 |
| 655 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 656 key.set_character(L'a'); |
| 657 input_method_auralinux_->DispatchKeyEvent(key); |
| 658 |
| 659 test_result_->ExpectAction("keydown:229"); |
| 660 test_result_->ExpectAction("compositionstart"); |
| 661 test_result_->ExpectAction("compositionupdate:a"); |
| 662 test_result_->Verify(); |
| 663 |
| 664 context_->SetSyncMode(false); |
| 665 |
| 666 input_method_auralinux_->DispatchKeyEvent(key); |
| 667 input_method_auralinux_->OnCommit(base::ASCIIToUTF16("b")); |
| 668 |
| 669 test_result_->ExpectAction("keydown:229"); |
| 670 test_result_->ExpectAction("compositionend"); |
| 671 test_result_->ExpectAction("textinput:b"); |
| 672 test_result_->Verify(); |
| 673 |
| 674 context_->SetSyncMode(true); |
| 675 context_->AddCommitAction("c"); |
| 676 input_method_auralinux_->DispatchKeyEvent(key); |
| 677 |
| 678 test_result_->ExpectAction("keydown:65"); |
| 679 test_result_->ExpectAction("keypress:99"); |
| 680 test_result_->Verify(); |
| 681 } |
| 682 |
| 683 TEST_F(InputMethodAuraLinuxTest, ReleaseKeyTest) { |
| 684 context_->SetSyncMode(true); |
| 685 context_->SetEatKey(true); |
| 686 context_->AddCompositionUpdateAction("a"); |
| 687 |
| 688 scoped_ptr<TextInputClientForTesting> client( |
| 689 new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); |
| 690 input_method_auralinux_->SetFocusedTextInputClient(client.get()); |
| 691 input_method_auralinux_->OnTextInputTypeChanged(client.get()); |
| 692 |
| 693 KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); |
| 694 key.set_character(L'A'); |
| 695 input_method_auralinux_->DispatchKeyEvent(key); |
| 696 |
| 697 test_result_->ExpectAction("keydown:229"); |
| 698 test_result_->ExpectAction("compositionstart"); |
| 699 test_result_->ExpectAction("compositionupdate:a"); |
| 700 test_result_->Verify(); |
| 701 |
| 702 context_->SetEatKey(false); |
| 703 context_->AddCommitAction("b"); |
| 704 input_method_auralinux_->DispatchKeyEvent(key); |
| 705 |
| 706 test_result_->ExpectAction("compositionend"); |
| 707 test_result_->ExpectAction("textinput:b"); |
| 708 test_result_->ExpectAction("keydown:65"); |
| 709 test_result_->ExpectAction("keypress:65"); |
| 710 test_result_->Verify(); |
| 711 |
| 712 context_->AddCommitAction("c"); |
| 713 input_method_auralinux_->DispatchKeyEvent(key); |
| 714 |
| 715 test_result_->ExpectAction("textinput:c"); |
| 716 test_result_->ExpectAction("keydown:65"); |
| 717 test_result_->ExpectAction("keypress:65"); |
| 718 test_result_->Verify(); |
| 719 } |
| 720 |
| 721 } // namespace |
| 722 } // namespace ui |
OLD | NEW |