Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc

Issue 309623005: Remove the flag g_use_wrapped_extension_keyboard_layouts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ime/input_method_menu_item.h" 9 #include "ash/ime/input_method_menu_item.h"
10 #include "ash/ime/input_method_menu_manager.h" 10 #include "ash/ime/input_method_menu_manager.h"
(...skipping 20 matching lines...) Expand all
31 #include "ui/base/accelerators/accelerator.h" 31 #include "ui/base/accelerators/accelerator.h"
32 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" 32 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h"
33 #include "ui/base/ime/input_method_initializer.h" 33 #include "ui/base/ime/input_method_initializer.h"
34 #include "ui/events/keycodes/keyboard_codes.h" 34 #include "ui/events/keycodes/keyboard_codes.h"
35 35
36 namespace chromeos { 36 namespace chromeos {
37 37
38 namespace input_method { 38 namespace input_method {
39 namespace { 39 namespace {
40 40
41 const char kNaclMozcUsId[] = 41 const char kNaclMozcUsId[] = "nacl_mozc_us";
42 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_us"; 42 const char kNaclMozcJpId[] = "nacl_mozc_jp";
43 const char kNaclMozcJpId[] = 43 const char kExt2Engine1Id[] = "ext2_engine1-t-i0-engine_id";
44 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_jp"; 44 const char kExt2Engine2Id[] = "ext2_engine2-t-i0-engine_id";
45 const char kExt2Engine1Id[] = 45 const char kPinyinImeId[] = "zh-t-i0-pinyin";
46 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopext2_engine1_engine_id";
47 const char kExt2Engine2Id[] =
48 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopext2_engine2_engine_id";
49 const char kXkbExtId[] =
50 #if defined(OFFICIAL_BUILD)
51 "jkghodnilhceideoidjikpgommlajknk";
52 #else
53 "fgoepimhcoialccpbmpnnblemnepkkao";
54 #endif
55 46
56 // Returns true if |descriptors| contain |target|. 47 // Returns true if |descriptors| contain |target|.
57 bool Contain(const InputMethodDescriptors& descriptors, 48 bool Contain(const InputMethodDescriptors& descriptors,
58 const InputMethodDescriptor& target) { 49 const InputMethodDescriptor& target) {
59 for (size_t i = 0; i < descriptors.size(); ++i) { 50 for (size_t i = 0; i < descriptors.size(); ++i) {
60 if (descriptors[i].id() == target.id()) 51 if (descriptors[i].id() == target.id())
61 return true; 52 return true;
62 } 53 }
63 return false; 54 return false;
64 } 55 }
65 56
66 std::string XkbId(const std::string& id) { 57 std::string ImeIdFromEngineId(const std::string& id) {
67 return extension_ime_util::GetInputMethodIDByKeyboardLayout(id); 58 return extension_ime_util::GetInputMethodIDByEngineID(id);
68 } 59 }
69 60
70 class InputMethodManagerImplTest : public BrowserWithTestWindowTest { 61 class InputMethodManagerImplTest : public BrowserWithTestWindowTest {
71 public: 62 public:
72 InputMethodManagerImplTest() 63 InputMethodManagerImplTest()
73 : delegate_(NULL), 64 : delegate_(NULL),
74 candidate_window_controller_(NULL), 65 candidate_window_controller_(NULL),
75 keyboard_(NULL) { 66 keyboard_(NULL) {
76 } 67 }
77 virtual ~InputMethodManagerImplTest() {} 68 virtual ~InputMethodManagerImplTest() {}
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 protected: 110 protected:
120 // Helper function to initialize component extension stuff for testing. 111 // Helper function to initialize component extension stuff for testing.
121 void InitComponentExtension() { 112 void InitComponentExtension() {
122 mock_delegate_ = new MockComponentExtIMEManagerDelegate(); 113 mock_delegate_ = new MockComponentExtIMEManagerDelegate();
123 mock_delegate_->set_ime_list(ime_list_); 114 mock_delegate_->set_ime_list(ime_list_);
124 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); 115 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_);
125 116
126 // Note, for production, these SetEngineHandler are called when 117 // Note, for production, these SetEngineHandler are called when
127 // IMEEngineHandlerInterface is initialized via 118 // IMEEngineHandlerInterface is initialized via
128 // InitializeComponentextension. 119 // InitializeComponentextension.
129 manager_->AddInputMethodExtension(kNaclMozcUsId, 120 manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcUsId),
130 mock_engine_handler_.get()); 121 mock_engine_handler_.get());
131 manager_->AddInputMethodExtension(kNaclMozcJpId, 122 manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcJpId),
132 mock_engine_handler_.get()); 123 mock_engine_handler_.get());
133 manager_->AddInputMethodExtension(kExt2Engine1Id, 124 manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine1Id),
134 mock_engine_handler_.get()); 125 mock_engine_handler_.get());
135 manager_->AddInputMethodExtension(kExt2Engine2Id, 126 manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine2Id),
136 mock_engine_handler_.get()); 127 mock_engine_handler_.get());
137 manager_->InitializeComponentExtensionForTesting(delegate.Pass()); 128 manager_->InitializeComponentExtensionForTesting(delegate.Pass());
138 } 129 }
139 130
140 void InitImeList() { 131 void InitImeList() {
141 ime_list_.clear(); 132 ime_list_.clear();
142 133
143 ComponentExtensionIME ext_xkb; 134 ComponentExtensionIME ext_xkb;
144 ext_xkb.id = kXkbExtId; 135 ext_xkb.id = extension_ime_util::kXkbExtensionId;
145 ext_xkb.description = "ext_xkb_description"; 136 ext_xkb.description = "ext_xkb_description";
146 ext_xkb.path = base::FilePath("ext_xkb_file_path"); 137 ext_xkb.path = base::FilePath("ext_xkb_file_path");
147 138
148 ComponentExtensionEngine ext_xkb_engine_us; 139 ComponentExtensionEngine ext_xkb_engine_us;
149 ext_xkb_engine_us.engine_id = "xkb:us::eng"; 140 ext_xkb_engine_us.engine_id = "xkb:us::eng";
150 ext_xkb_engine_us.display_name = "xkb:us::eng"; 141 ext_xkb_engine_us.display_name = "xkb:us::eng";
151 ext_xkb_engine_us.language_codes.push_back("en-US"); 142 ext_xkb_engine_us.language_codes.push_back("en-US");
152 ext_xkb_engine_us.layouts.push_back("us"); 143 ext_xkb_engine_us.layouts.push_back("us");
153 ext_xkb.engines.push_back(ext_xkb_engine_us); 144 ext_xkb.engines.push_back(ext_xkb_engine_us);
154 145
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 ComponentExtensionEngine ext_xkb_engine_hu; 202 ComponentExtensionEngine ext_xkb_engine_hu;
212 ext_xkb_engine_hu.engine_id = "xkb:hu::hun"; 203 ext_xkb_engine_hu.engine_id = "xkb:hu::hun";
213 ext_xkb_engine_hu.display_name = "xkb:hu::hun"; 204 ext_xkb_engine_hu.display_name = "xkb:hu::hun";
214 ext_xkb_engine_hu.language_codes.push_back("hu"); 205 ext_xkb_engine_hu.language_codes.push_back("hu");
215 ext_xkb_engine_hu.layouts.push_back("hu"); 206 ext_xkb_engine_hu.layouts.push_back("hu");
216 ext_xkb.engines.push_back(ext_xkb_engine_hu); 207 ext_xkb.engines.push_back(ext_xkb_engine_hu);
217 208
218 ime_list_.push_back(ext_xkb); 209 ime_list_.push_back(ext_xkb);
219 210
220 ComponentExtensionIME ext1; 211 ComponentExtensionIME ext1;
221 ext1.id = "gjaehgfemfahhmlgpdfknkhdnemmolop"; 212 ext1.id = extension_ime_util::kMozcExtensionId;
222 ext1.description = "ext1_description"; 213 ext1.description = "ext1_description";
223 ext1.path = base::FilePath("ext1_file_path"); 214 ext1.path = base::FilePath("ext1_file_path");
224 215
225 ComponentExtensionEngine ext1_engine1; 216 ComponentExtensionEngine ext1_engine1;
226 ext1_engine1.engine_id = "nacl_mozc_us"; 217 ext1_engine1.engine_id = "nacl_mozc_us";
227 ext1_engine1.display_name = "ext1_engine_1_display_name"; 218 ext1_engine1.display_name = "ext1_engine_1_display_name";
228 ext1_engine1.language_codes.push_back("ja"); 219 ext1_engine1.language_codes.push_back("ja");
229 ext1_engine1.layouts.push_back("us"); 220 ext1_engine1.layouts.push_back("us");
230 ext1.engines.push_back(ext1_engine1); 221 ext1.engines.push_back(ext1_engine1);
231 222
232 ComponentExtensionEngine ext1_engine2; 223 ComponentExtensionEngine ext1_engine2;
233 ext1_engine2.engine_id = "nacl_mozc_jp"; 224 ext1_engine2.engine_id = "nacl_mozc_jp";
234 ext1_engine2.display_name = "ext1_engine_1_display_name"; 225 ext1_engine2.display_name = "ext1_engine_1_display_name";
235 ext1_engine2.language_codes.push_back("ja"); 226 ext1_engine2.language_codes.push_back("ja");
236 ext1_engine2.layouts.push_back("jp"); 227 ext1_engine2.layouts.push_back("jp");
237 ext1.engines.push_back(ext1_engine2); 228 ext1.engines.push_back(ext1_engine2);
238 229
239 ime_list_.push_back(ext1); 230 ime_list_.push_back(ext1);
240 231
241 ComponentExtensionIME ext2; 232 ComponentExtensionIME ext2;
242 ext2.id = "gjaehgfemfahhmlgpdfknkhdnemmolop"; 233 ext2.id = extension_ime_util::kT13nExtensionId;
243 ext2.description = "ext2_description"; 234 ext2.description = "ext2_description";
244 ext2.path = base::FilePath("ext2_file_path"); 235 ext2.path = base::FilePath("ext2_file_path");
245 236
246 ComponentExtensionEngine ext2_engine1; 237 ComponentExtensionEngine ext2_engine1;
247 ext2_engine1.engine_id = "ext2_engine1_engine_id"; 238 ext2_engine1.engine_id = kExt2Engine1Id;
248 ext2_engine1.display_name = "ext2_engine_1_display_name"; 239 ext2_engine1.display_name = "ext2_engine_1_display_name";
249 ext2_engine1.language_codes.push_back("en"); 240 ext2_engine1.language_codes.push_back("en");
250 ext2_engine1.layouts.push_back("us"); 241 ext2_engine1.layouts.push_back("us");
251 ext2.engines.push_back(ext2_engine1); 242 ext2.engines.push_back(ext2_engine1);
252 243
253 ComponentExtensionEngine ext2_engine2; 244 ComponentExtensionEngine ext2_engine2;
254 ext2_engine2.engine_id = "ext2_engine2_engine_id"; 245 ext2_engine2.engine_id = kExt2Engine2Id;
255 ext2_engine2.display_name = "ext2_engine_2_display_name"; 246 ext2_engine2.display_name = "ext2_engine_2_display_name";
256 ext2_engine2.language_codes.push_back("en"); 247 ext2_engine2.language_codes.push_back("en");
257 ext2_engine2.layouts.push_back("us(dvorak)"); 248 ext2_engine2.layouts.push_back("us(dvorak)");
258 ext2.engines.push_back(ext2_engine2); 249 ext2.engines.push_back(ext2_engine2);
259 250
260 ime_list_.push_back(ext2); 251 ime_list_.push_back(ext2);
261 } 252 }
262 253
263 TestingBrowserProcess* GetBrowserProcess() { 254 TestingBrowserProcess* GetBrowserProcess() {
264 return TestingBrowserProcess::GetGlobal(); 255 return TestingBrowserProcess::GetGlobal();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 350
360 TestObserver observer; 351 TestObserver observer;
361 InitComponentExtension(); 352 InitComponentExtension();
362 manager_->AddObserver(&observer); 353 manager_->AddObserver(&observer);
363 menu_manager_->AddObserver(&observer); 354 menu_manager_->AddObserver(&observer);
364 EXPECT_EQ(0, observer.input_method_changed_count_); 355 EXPECT_EQ(0, observer.input_method_changed_count_);
365 manager_->EnableLoginLayouts("en-US", keyboard_layouts); 356 manager_->EnableLoginLayouts("en-US", keyboard_layouts);
366 EXPECT_EQ(5U, manager_->GetActiveInputMethods()->size()); 357 EXPECT_EQ(5U, manager_->GetActiveInputMethods()->size());
367 EXPECT_EQ(1, observer.input_method_changed_count_); 358 EXPECT_EQ(1, observer.input_method_changed_count_);
368 EXPECT_EQ(1, observer.input_method_menu_item_changed_count_); 359 EXPECT_EQ(1, observer.input_method_menu_item_changed_count_);
369 manager_->ChangeInputMethod(XkbId("xkb:us:dvorak:eng")); 360 manager_->ChangeInputMethod(ImeIdFromEngineId("xkb:us:dvorak:eng"));
370 EXPECT_FALSE(observer.last_show_message_); 361 EXPECT_FALSE(observer.last_show_message_);
371 EXPECT_EQ(2, observer.input_method_changed_count_); 362 EXPECT_EQ(2, observer.input_method_changed_count_);
372 EXPECT_EQ(2, observer.input_method_menu_item_changed_count_); 363 EXPECT_EQ(2, observer.input_method_menu_item_changed_count_);
373 manager_->ChangeInputMethod(XkbId("xkb:us:dvorak:eng")); 364 manager_->ChangeInputMethod(ImeIdFromEngineId("xkb:us:dvorak:eng"));
374 EXPECT_FALSE(observer.last_show_message_); 365 EXPECT_FALSE(observer.last_show_message_);
375 366
376 // The observer is always notified even when the same input method ID is 367 // The observer is always notified even when the same input method ID is
377 // passed to ChangeInputMethod() more than twice. 368 // passed to ChangeInputMethod() more than twice.
378 // TODO(komatsu): Revisit if this is neccessary. 369 // TODO(komatsu): Revisit if this is neccessary.
379 EXPECT_EQ(3, observer.input_method_changed_count_); 370 EXPECT_EQ(3, observer.input_method_changed_count_);
380 371
381 // If the same input method ID is passed, PropertyChanged() is not 372 // If the same input method ID is passed, PropertyChanged() is not
382 // notified. 373 // notified.
383 EXPECT_EQ(2, observer.input_method_menu_item_changed_count_); 374 EXPECT_EQ(2, observer.input_method_menu_item_changed_count_);
384 375
385 manager_->RemoveObserver(&observer); 376 manager_->RemoveObserver(&observer);
386 menu_manager_->RemoveObserver(&observer); 377 menu_manager_->RemoveObserver(&observer);
387 } 378 }
388 379
389 TEST_F(InputMethodManagerImplTest, TestGetSupportedInputMethods) { 380 TEST_F(InputMethodManagerImplTest, TestGetSupportedInputMethods) {
390 InitComponentExtension(); 381 InitComponentExtension();
391 InputMethodDescriptors methods; 382 InputMethodDescriptors methods;
392 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { 383 methods = manager_->GetComponentExtensionIMEManager()
393 methods = manager_->GetComponentExtensionIMEManager() 384 ->GetXkbIMEAsInputMethodDescriptor();
394 ->GetXkbIMEAsInputMethodDescriptor();
395 } else {
396 methods = *(manager_->GetSupportedInputMethods());
397 }
398 // Try to find random 4-5 layuts and IMEs to make sure the returned list is 385 // Try to find random 4-5 layuts and IMEs to make sure the returned list is
399 // correct. 386 // correct.
400 const InputMethodDescriptor* id_to_find = 387 const InputMethodDescriptor* id_to_find =
401 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 388 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
402 kNaclMozcUsId); 389 ImeIdFromEngineId(kNaclMozcUsId));
403 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 390 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
404 XkbId("xkb:us::eng")); 391 ImeIdFromEngineId("xkb:us::eng"));
405 EXPECT_TRUE(Contain(methods, *id_to_find)); 392 EXPECT_TRUE(Contain(methods, *id_to_find));
406 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 393 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
407 XkbId("xkb:us:dvorak:eng")); 394 ImeIdFromEngineId("xkb:us:dvorak:eng"));
408 EXPECT_TRUE(Contain(methods, *id_to_find)); 395 EXPECT_TRUE(Contain(methods, *id_to_find));
409 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 396 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
410 XkbId("xkb:fr::fra")); 397 ImeIdFromEngineId("xkb:fr::fra"));
411 EXPECT_TRUE(Contain(methods, *id_to_find)); 398 EXPECT_TRUE(Contain(methods, *id_to_find));
412 } 399 }
413 400
414 TEST_F(InputMethodManagerImplTest, TestEnableLayouts) { 401 TEST_F(InputMethodManagerImplTest, TestEnableLayouts) {
415 // Currently 5 keyboard layouts are supported for en-US, and 1 for ja. See 402 // Currently 5 keyboard layouts are supported for en-US, and 1 for ja. See
416 // ibus_input_method.txt. 403 // ibus_input_method.txt.
417 std::vector<std::string> keyboard_layouts; 404 std::vector<std::string> keyboard_layouts;
418 405
419 InitComponentExtension(); 406 InitComponentExtension();
420 manager_->EnableLoginLayouts("en-US", keyboard_layouts); 407 manager_->EnableLoginLayouts("en-US", keyboard_layouts);
421 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); 408 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods());
422 409
423 // For http://crbug.com/19655#c11 - (5) 410 // For http://crbug.com/19655#c11 - (5)
424 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. 411 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U.
425 manager_->EnableLoginLayouts("ja", keyboard_layouts); // Japanese 412 manager_->EnableLoginLayouts("ja", keyboard_layouts); // Japanese
426 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 413 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
427 } 414 }
428 415
429 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) { 416 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) {
430 // For http://crbug.com/329061 417 // For http://crbug.com/329061
431 std::vector<std::string> keyboard_layouts; 418 std::vector<std::string> keyboard_layouts;
432 keyboard_layouts.push_back(XkbId("xkb:se::swe")); 419 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:se::swe"));
433 420
434 InitComponentExtension(); 421 InitComponentExtension();
435 manager_->EnableLoginLayouts("en-US", keyboard_layouts); 422 manager_->EnableLoginLayouts("en-US", keyboard_layouts);
436 const std::string im_id = manager_->GetCurrentInputMethod().id(); 423 const std::string im_id = manager_->GetCurrentInputMethod().id();
437 EXPECT_EQ(XkbId("xkb:se::swe"), im_id); 424 EXPECT_EQ(ImeIdFromEngineId("xkb:se::swe"), im_id);
438 } 425 }
439 426
440 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { 427 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) {
441 InitComponentExtension(); 428 InitComponentExtension();
442 // The physical layout is French. 429 // The physical layout is French.
443 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( 430 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting(
444 "xkb:fr::fra"); 431 "xkb:fr::fra");
445 manager_->EnableLoginLayouts( 432 manager_->EnableLoginLayouts(
446 "en-US", 433 "en-US",
447 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); 434 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds());
448 EXPECT_EQ(6U, manager_->GetNumActiveInputMethods()); // 5 + French 435 EXPECT_EQ(6U, manager_->GetNumActiveInputMethods()); // 5 + French
449 // The physical layout is Japanese. 436 // The physical layout is Japanese.
450 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( 437 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting(
451 "xkb:jp::jpn"); 438 "xkb:jp::jpn");
452 manager_->EnableLoginLayouts( 439 manager_->EnableLoginLayouts(
453 "ja", 440 "ja",
454 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); 441 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds());
455 // "xkb:us::eng" is not needed, hence 1. 442 // "xkb:us::eng" is not needed, hence 1.
456 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 443 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
457 444
458 // The physical layout is Russian. 445 // The physical layout is Russian.
459 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( 446 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting(
460 "xkb:ru::rus"); 447 "xkb:ru::rus");
461 manager_->EnableLoginLayouts( 448 manager_->EnableLoginLayouts(
462 "ru", 449 "ru",
463 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); 450 manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds());
464 // "xkb:us::eng" only. 451 // "xkb:us::eng" only.
465 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 452 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
466 EXPECT_EQ(XkbId("xkb:us::eng"), 453 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
467 manager_->GetActiveInputMethodIds().front()); 454 manager_->GetActiveInputMethodIds().front());
468 } 455 }
469 456
470 TEST_F(InputMethodManagerImplTest, TestEnableMultipleHardwareKeyboardLayout) { 457 TEST_F(InputMethodManagerImplTest, TestEnableMultipleHardwareKeyboardLayout) {
471 InitComponentExtension(); 458 InitComponentExtension();
472 // The physical layouts are French and Hungarian. 459 // The physical layouts are French and Hungarian.
473 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( 460 manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting(
474 "xkb:fr::fra,xkb:hu::hun"); 461 "xkb:fr::fra,xkb:hu::hun");
475 manager_->EnableLoginLayouts( 462 manager_->EnableLoginLayouts(
476 "en-US", 463 "en-US",
(...skipping 19 matching lines...) Expand all
496 InitComponentExtension(); 483 InitComponentExtension();
497 std::vector<std::string> keyboard_layouts; 484 std::vector<std::string> keyboard_layouts;
498 manager_->EnableLoginLayouts("ja", keyboard_layouts); // Japanese 485 manager_->EnableLoginLayouts("ja", keyboard_layouts); // Japanese
499 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 486 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
500 scoped_ptr<InputMethodDescriptors> methods( 487 scoped_ptr<InputMethodDescriptors> methods(
501 manager_->GetActiveInputMethods()); 488 manager_->GetActiveInputMethods());
502 ASSERT_TRUE(methods.get()); 489 ASSERT_TRUE(methods.get());
503 EXPECT_EQ(2U, methods->size()); 490 EXPECT_EQ(2U, methods->size());
504 const InputMethodDescriptor* id_to_find = 491 const InputMethodDescriptor* id_to_find =
505 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 492 manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
506 XkbId("xkb:us::eng")); 493 ImeIdFromEngineId("xkb:us::eng"));
507 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); 494 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find));
508 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 495 id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
509 XkbId("xkb:jp::jpn")); 496 ImeIdFromEngineId("xkb:jp::jpn"));
510 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); 497 EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find));
511 } 498 }
512 499
513 TEST_F(InputMethodManagerImplTest, TestEnableTwoLayouts) { 500 TEST_F(InputMethodManagerImplTest, TestEnableTwoLayouts) {
514 // For http://crbug.com/19655#c11 - (8), step 6. 501 // For http://crbug.com/19655#c11 - (8), step 6.
515 TestObserver observer; 502 TestObserver observer;
516 manager_->AddObserver(&observer); 503 manager_->AddObserver(&observer);
517 InitComponentExtension(); 504 InitComponentExtension();
518 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 505 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
519 std::vector<std::string> ids; 506 std::vector<std::string> ids;
520 ids.push_back(XkbId("xkb:us:dvorak:eng")); 507 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
521 ids.push_back(XkbId("xkb:us:colemak:eng")); 508 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng"));
522 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 509 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
523 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 510 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
524 // Since all the IDs added avobe are keyboard layouts, Start() should not be 511 // Since all the IDs added avobe are keyboard layouts, Start() should not be
525 // called. 512 // called.
526 EXPECT_EQ(1, observer.input_method_changed_count_); 513 EXPECT_EQ(1, observer.input_method_changed_count_);
527 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 514 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
528 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 515 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
529 // Disable Dvorak. 516 // Disable Dvorak.
530 ids.erase(ids.begin()); 517 ids.erase(ids.begin());
531 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 518 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
532 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 519 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
533 EXPECT_EQ(2, observer.input_method_changed_count_); 520 EXPECT_EQ(2, observer.input_method_changed_count_);
534 EXPECT_EQ(XkbId(ids[0]), // colemak 521 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // colemak
535 manager_->GetCurrentInputMethod().id()); 522 manager_->GetCurrentInputMethod().id());
536 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); 523 EXPECT_EQ("us(colemak)", keyboard_->last_layout_);
537 manager_->RemoveObserver(&observer); 524 manager_->RemoveObserver(&observer);
538 } 525 }
539 526
540 TEST_F(InputMethodManagerImplTest, TestEnableThreeLayouts) { 527 TEST_F(InputMethodManagerImplTest, TestEnableThreeLayouts) {
541 // For http://crbug.com/19655#c11 - (9). 528 // For http://crbug.com/19655#c11 - (9).
542 TestObserver observer; 529 TestObserver observer;
543 manager_->AddObserver(&observer); 530 manager_->AddObserver(&observer);
544 InitComponentExtension(); 531 InitComponentExtension();
545 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 532 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
546 std::vector<std::string> ids; 533 std::vector<std::string> ids;
547 ids.push_back(XkbId("xkb:us::eng")); 534 ids.push_back(ImeIdFromEngineId("xkb:us::eng"));
548 ids.push_back(XkbId("xkb:us:dvorak:eng")); 535 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
549 ids.push_back(XkbId("xkb:us:colemak:eng")); 536 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng"));
550 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 537 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
551 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); 538 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods());
552 EXPECT_EQ(1, observer.input_method_changed_count_); 539 EXPECT_EQ(1, observer.input_method_changed_count_);
553 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 540 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
554 EXPECT_EQ("us", keyboard_->last_layout_); 541 EXPECT_EQ("us", keyboard_->last_layout_);
555 // Switch to Dvorak. 542 // Switch to Dvorak.
556 manager_->SwitchToNextInputMethod(); 543 manager_->SwitchToNextInputMethod();
557 EXPECT_EQ(2, observer.input_method_changed_count_); 544 EXPECT_EQ(2, observer.input_method_changed_count_);
558 EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); 545 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id());
559 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 546 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
560 // Disable Dvorak. 547 // Disable Dvorak.
561 ids.erase(ids.begin() + 1); 548 ids.erase(ids.begin() + 1);
562 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 549 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
563 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 550 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
564 EXPECT_EQ(3, observer.input_method_changed_count_); 551 EXPECT_EQ(3, observer.input_method_changed_count_);
565 EXPECT_EQ(XkbId(ids[0]), // US Qwerty 552 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // US Qwerty
566 manager_->GetCurrentInputMethod().id()); 553 manager_->GetCurrentInputMethod().id());
567 EXPECT_EQ("us", keyboard_->last_layout_); 554 EXPECT_EQ("us", keyboard_->last_layout_);
568 manager_->RemoveObserver(&observer); 555 manager_->RemoveObserver(&observer);
569 } 556 }
570 557
571 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme) { 558 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme) {
572 // For http://crbug.com/19655#c11 - (10). 559 // For http://crbug.com/19655#c11 - (10).
573 TestObserver observer; 560 TestObserver observer;
574 manager_->AddObserver(&observer); 561 manager_->AddObserver(&observer);
575 InitComponentExtension(); 562 InitComponentExtension();
576 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 563 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
577 std::vector<std::string> ids; 564 std::vector<std::string> ids;
578 ids.push_back(XkbId("xkb:us:dvorak:eng")); 565 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
579 ids.push_back(kNaclMozcUsId); 566 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId));
580 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 567 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
581 EXPECT_EQ(1, observer.input_method_changed_count_); 568 EXPECT_EQ(1, observer.input_method_changed_count_);
582 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 569 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
583 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 570 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
584 // Switch to Mozc 571 // Switch to Mozc
585 manager_->SwitchToNextInputMethod(); 572 manager_->SwitchToNextInputMethod();
586 EXPECT_EQ(2, observer.input_method_changed_count_); 573 EXPECT_EQ(2, observer.input_method_changed_count_);
587 EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); 574 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id());
588 EXPECT_EQ("us", keyboard_->last_layout_); 575 EXPECT_EQ("us", keyboard_->last_layout_);
589 // Disable Mozc. 576 // Disable Mozc.
590 ids.erase(ids.begin() + 1); 577 ids.erase(ids.begin() + 1);
591 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 578 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
592 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 579 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
593 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 580 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
594 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 581 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
595 } 582 }
596 583
597 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme2) { 584 TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme2) {
598 // For http://crbug.com/19655#c11 - (11). 585 // For http://crbug.com/19655#c11 - (11).
599 TestObserver observer; 586 TestObserver observer;
600 manager_->AddObserver(&observer); 587 manager_->AddObserver(&observer);
601 InitComponentExtension(); 588 InitComponentExtension();
602 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 589 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
603 std::vector<std::string> ids; 590 std::vector<std::string> ids;
604 ids.push_back(XkbId("xkb:us:dvorak:eng")); 591 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
605 ids.push_back(kNaclMozcUsId); 592 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId));
606 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 593 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
607 EXPECT_EQ(1, observer.input_method_changed_count_); 594 EXPECT_EQ(1, observer.input_method_changed_count_);
608 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 595 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
609 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 596 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
610 597
611 // Disable Dvorak. 598 // Disable Dvorak.
612 ids.erase(ids.begin()); 599 ids.erase(ids.begin());
613 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 600 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
614 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 601 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
615 EXPECT_EQ(XkbId(ids[0]), // Mozc 602 EXPECT_EQ(ImeIdFromEngineId(ids[0]), // Mozc
616 manager_->GetCurrentInputMethod().id()); 603 manager_->GetCurrentInputMethod().id());
617 EXPECT_EQ("us", keyboard_->last_layout_); 604 EXPECT_EQ("us", keyboard_->last_layout_);
618 manager_->RemoveObserver(&observer); 605 manager_->RemoveObserver(&observer);
619 } 606 }
620 607
621 TEST_F(InputMethodManagerImplTest, TestEnableImes) { 608 TEST_F(InputMethodManagerImplTest, TestEnableImes) {
622 TestObserver observer; 609 TestObserver observer;
623 manager_->AddObserver(&observer); 610 manager_->AddObserver(&observer);
624 InitComponentExtension(); 611 InitComponentExtension();
625 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 612 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
626 std::vector<std::string> ids; 613 std::vector<std::string> ids;
627 ids.push_back(kExt2Engine1Id); 614 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id));
628 ids.push_back("mozc-dv"); 615 ids.push_back("mozc-dv");
629 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 616 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
630 EXPECT_EQ(1, observer.input_method_changed_count_); 617 EXPECT_EQ(1, observer.input_method_changed_count_);
631 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 618 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
632 EXPECT_EQ("us", keyboard_->last_layout_); 619 EXPECT_EQ("us", keyboard_->last_layout_);
633 manager_->RemoveObserver(&observer); 620 manager_->RemoveObserver(&observer);
634 } 621 }
635 622
636 TEST_F(InputMethodManagerImplTest, TestEnableUnknownIds) { 623 TEST_F(InputMethodManagerImplTest, TestEnableUnknownIds) {
637 TestObserver observer; 624 TestObserver observer;
638 manager_->AddObserver(&observer); 625 manager_->AddObserver(&observer);
639 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 626 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
640 std::vector<std::string> ids; 627 std::vector<std::string> ids;
641 ids.push_back("xkb:tl::tlh"); // Klingon, which is not supported. 628 ids.push_back("xkb:tl::tlh"); // Klingon, which is not supported.
642 ids.push_back("unknown-super-cool-ime"); 629 ids.push_back("unknown-super-cool-ime");
643 EXPECT_FALSE(manager_->ReplaceEnabledInputMethods(ids)); 630 EXPECT_FALSE(manager_->ReplaceEnabledInputMethods(ids));
644 631
645 // TODO(yusukes): Should we fall back to the hardware keyboard layout in this 632 // TODO(yusukes): Should we fall back to the hardware keyboard layout in this
646 // case? 633 // case?
647 EXPECT_EQ(0, observer.input_method_changed_count_); 634 EXPECT_EQ(0, observer.input_method_changed_count_);
648 635
649 manager_->RemoveObserver(&observer); 636 manager_->RemoveObserver(&observer);
650 } 637 }
651 638
652 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsThenLock) { 639 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsThenLock) {
653 // For http://crbug.com/19655#c11 - (14). 640 // For http://crbug.com/19655#c11 - (14).
654 TestObserver observer; 641 TestObserver observer;
655 manager_->AddObserver(&observer); 642 manager_->AddObserver(&observer);
656 InitComponentExtension(); 643 InitComponentExtension();
657 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 644 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
658 std::vector<std::string> ids; 645 std::vector<std::string> ids;
659 ids.push_back(XkbId("xkb:us::eng")); 646 ids.push_back(ImeIdFromEngineId("xkb:us::eng"));
660 ids.push_back(XkbId("xkb:us:dvorak:eng")); 647 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
661 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 648 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
662 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 649 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
663 EXPECT_EQ(1, observer.input_method_changed_count_); 650 EXPECT_EQ(1, observer.input_method_changed_count_);
664 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 651 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
665 EXPECT_EQ("us", keyboard_->last_layout_); 652 EXPECT_EQ("us", keyboard_->last_layout_);
666 653
667 // Switch to Dvorak. 654 // Switch to Dvorak.
668 manager_->SwitchToNextInputMethod(); 655 manager_->SwitchToNextInputMethod();
669 EXPECT_EQ(2, observer.input_method_changed_count_); 656 EXPECT_EQ(2, observer.input_method_changed_count_);
670 EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); 657 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id());
671 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 658 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
672 659
673 // Lock screen 660 // Lock screen
674 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); 661 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN);
675 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 662 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
676 EXPECT_EQ(XkbId(ids[1]), // still Dvorak 663 EXPECT_EQ(ImeIdFromEngineId(ids[1]), // still Dvorak
677 manager_->GetCurrentInputMethod().id()); 664 manager_->GetCurrentInputMethod().id());
678 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 665 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
679 // Switch back to Qwerty. 666 // Switch back to Qwerty.
680 manager_->SwitchToNextInputMethod(); 667 manager_->SwitchToNextInputMethod();
681 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 668 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
682 EXPECT_EQ("us", keyboard_->last_layout_); 669 EXPECT_EQ("us", keyboard_->last_layout_);
683 670
684 // Unlock screen. The original state, Dvorak, is restored. 671 // Unlock screen. The original state, Dvorak, is restored.
685 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 672 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
686 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 673 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
687 EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); 674 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id());
688 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 675 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
689 676
690 manager_->RemoveObserver(&observer); 677 manager_->RemoveObserver(&observer);
691 } 678 }
692 679
693 TEST_F(InputMethodManagerImplTest, SwitchInputMethodTest) { 680 TEST_F(InputMethodManagerImplTest, SwitchInputMethodTest) {
694 // For http://crbug.com/19655#c11 - (15). 681 // For http://crbug.com/19655#c11 - (15).
695 TestObserver observer; 682 TestObserver observer;
696 manager_->AddObserver(&observer); 683 manager_->AddObserver(&observer);
697 InitComponentExtension(); 684 InitComponentExtension();
698 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 685 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
699 std::vector<std::string> ids; 686 std::vector<std::string> ids;
700 ids.push_back(XkbId("xkb:us:dvorak:eng")); 687 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
701 ids.push_back(kExt2Engine2Id); 688 ids.push_back(ImeIdFromEngineId(kExt2Engine2Id));
702 ids.push_back(kExt2Engine1Id); 689 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id));
703 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 690 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
704 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); 691 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods());
705 EXPECT_EQ(1, observer.input_method_changed_count_); 692 EXPECT_EQ(1, observer.input_method_changed_count_);
706 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 693 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
707 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 694 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
708 695
709 // Switch to Mozc. 696 // Switch to Mozc.
710 manager_->SwitchToNextInputMethod(); 697 manager_->SwitchToNextInputMethod();
711 EXPECT_EQ(2, observer.input_method_changed_count_); 698 EXPECT_EQ(2, observer.input_method_changed_count_);
712 EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); 699 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id());
713 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 700 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
714 701
715 // Lock screen 702 // Lock screen
716 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); 703 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN);
717 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); // Qwerty+Dvorak. 704 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); // Qwerty+Dvorak.
718 EXPECT_EQ(XkbId("xkb:us:dvorak:eng"), 705 EXPECT_EQ(ImeIdFromEngineId("xkb:us:dvorak:eng"),
719 manager_->GetCurrentInputMethod().id()); 706 manager_->GetCurrentInputMethod().id());
720 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 707 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
721 manager_->SwitchToNextInputMethod(); 708 manager_->SwitchToNextInputMethod();
722 EXPECT_EQ(XkbId("xkb:us::eng"), // The hardware keyboard layout. 709 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), // The hardware keyboard layout.
723 manager_->GetCurrentInputMethod().id()); 710 manager_->GetCurrentInputMethod().id());
724 EXPECT_EQ("us", keyboard_->last_layout_); 711 EXPECT_EQ("us", keyboard_->last_layout_);
725 712
726 // Unlock screen. The original state, pinyin-dv, is restored. 713 // Unlock screen. The original state, pinyin-dv, is restored.
727 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 714 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
728 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); // Dvorak and 2 IMEs. 715 EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); // Dvorak and 2 IMEs.
729 EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); 716 EXPECT_EQ(ImeIdFromEngineId(ids[1]), manager_->GetCurrentInputMethod().id());
730 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 717 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
731 718
732 manager_->RemoveObserver(&observer); 719 manager_->RemoveObserver(&observer);
733 } 720 }
734 721
735 TEST_F(InputMethodManagerImplTest, TestXkbSetting) { 722 TEST_F(InputMethodManagerImplTest, TestXkbSetting) {
736 // For http://crbug.com/19655#c11 - (8), step 7-11. 723 // For http://crbug.com/19655#c11 - (8), step 7-11.
737 InitComponentExtension(); 724 InitComponentExtension();
738 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 725 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
739 std::vector<std::string> ids; 726 std::vector<std::string> ids;
740 ids.push_back(XkbId("xkb:us:dvorak:eng")); 727 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
741 ids.push_back(XkbId("xkb:us:colemak:eng")); 728 ids.push_back(ImeIdFromEngineId("xkb:us:colemak:eng"));
742 ids.push_back(kNaclMozcJpId); 729 ids.push_back(ImeIdFromEngineId(kNaclMozcJpId));
743 ids.push_back(kNaclMozcUsId); 730 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId));
744 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 731 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
745 EXPECT_EQ(4U, manager_->GetNumActiveInputMethods()); 732 EXPECT_EQ(4U, manager_->GetNumActiveInputMethods());
746 EXPECT_EQ(1, keyboard_->set_current_keyboard_layout_by_name_count_); 733 EXPECT_EQ(1, keyboard_->set_current_keyboard_layout_by_name_count_);
747 // See input_methods.txt for an expected XKB layout name. 734 // See input_methods.txt for an expected XKB layout name.
748 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 735 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
749 manager_->SwitchToNextInputMethod(); 736 manager_->SwitchToNextInputMethod();
750 EXPECT_EQ(2, keyboard_->set_current_keyboard_layout_by_name_count_); 737 EXPECT_EQ(2, keyboard_->set_current_keyboard_layout_by_name_count_);
751 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); 738 EXPECT_EQ("us(colemak)", keyboard_->last_layout_);
752 manager_->SwitchToNextInputMethod(); 739 manager_->SwitchToNextInputMethod();
753 EXPECT_EQ(3, keyboard_->set_current_keyboard_layout_by_name_count_); 740 EXPECT_EQ(3, keyboard_->set_current_keyboard_layout_by_name_count_);
(...skipping 26 matching lines...) Expand all
780 manager_->ActivateInputMethodMenuItem("key2"); 767 manager_->ActivateInputMethodMenuItem("key2");
781 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property()); 768 EXPECT_EQ(kKey, mock_engine_handler_->last_activated_property());
782 } 769 }
783 770
784 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) { 771 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodProperties) {
785 InitComponentExtension(); 772 InitComponentExtension();
786 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); 773 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
787 774
788 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 775 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
789 std::vector<std::string> ids; 776 std::vector<std::string> ids;
790 ids.push_back(XkbId("xkb:us::eng")); 777 ids.push_back(ImeIdFromEngineId("xkb:us::eng"));
791 ids.push_back(kNaclMozcUsId); 778 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId));
792 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 779 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
793 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 780 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
794 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); 781 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
795 manager_->ChangeInputMethod(kNaclMozcUsId); 782 manager_->ChangeInputMethod(ImeIdFromEngineId(kNaclMozcUsId));
796 783
797 ash::ime::InputMethodMenuItemList current_property_list; 784 ash::ime::InputMethodMenuItemList current_property_list;
798 current_property_list.push_back(ash::ime::InputMethodMenuItem( 785 current_property_list.push_back(ash::ime::InputMethodMenuItem(
799 "key", "label", false, false)); 786 "key", "label", false, false));
800 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); 787 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list);
801 788
802 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); 789 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size());
803 EXPECT_EQ("key", 790 EXPECT_EQ("key",
804 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); 791 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key);
805 792
806 manager_->ChangeInputMethod("xkb:us::eng"); 793 manager_->ChangeInputMethod("xkb:us::eng");
807 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); 794 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
808 } 795 }
809 796
810 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) { 797 TEST_F(InputMethodManagerImplTest, TestGetCurrentInputMethodPropertiesTwoImes) {
811 InitComponentExtension(); 798 InitComponentExtension();
812 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); 799 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
813 800
814 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 801 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
815 std::vector<std::string> ids; 802 std::vector<std::string> ids;
816 ids.push_back(kNaclMozcUsId); // Japanese 803 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId)); // Japanese
817 ids.push_back(kExt2Engine1Id); // T-Chinese 804 ids.push_back(ImeIdFromEngineId(kExt2Engine1Id)); // T-Chinese
818 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 805 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
819 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 806 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
820 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); 807 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
821 808
822 ash::ime::InputMethodMenuItemList current_property_list; 809 ash::ime::InputMethodMenuItemList current_property_list;
823 current_property_list.push_back(ash::ime::InputMethodMenuItem("key-mozc", 810 current_property_list.push_back(ash::ime::InputMethodMenuItem("key-mozc",
824 "label", 811 "label",
825 false, 812 false,
826 false)); 813 false));
827 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); 814 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list);
828 815
829 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); 816 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size());
830 EXPECT_EQ("key-mozc", 817 EXPECT_EQ("key-mozc",
831 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); 818 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key);
832 819
833 manager_->ChangeInputMethod(kExt2Engine1Id); 820 manager_->ChangeInputMethod(ImeIdFromEngineId(kExt2Engine1Id));
834 // Since the IME is changed, the property for mozc Japanese should be hidden. 821 // Since the IME is changed, the property for mozc Japanese should be hidden.
835 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty()); 822 EXPECT_TRUE(menu_manager_->GetCurrentInputMethodMenuItemList().empty());
836 823
837 // Asynchronous property update signal from mozc-chewing. 824 // Asynchronous property update signal from mozc-chewing.
838 current_property_list.clear(); 825 current_property_list.clear();
839 current_property_list.push_back(ash::ime::InputMethodMenuItem( 826 current_property_list.push_back(ash::ime::InputMethodMenuItem(
840 "key-chewing", "label", false, false)); 827 "key-chewing", "label", false, false));
841 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list); 828 menu_manager_->SetCurrentInputMethodMenuItemList(current_property_list);
842 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size()); 829 ASSERT_EQ(1U, menu_manager_->GetCurrentInputMethodMenuItemList().size());
843 EXPECT_EQ("key-chewing", 830 EXPECT_EQ("key-chewing",
844 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key); 831 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).key);
845 } 832 }
846 833
847 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { 834 TEST_F(InputMethodManagerImplTest, TestNextInputMethod) {
848 TestObserver observer; 835 TestObserver observer;
849 manager_->AddObserver(&observer); 836 manager_->AddObserver(&observer);
850 InitComponentExtension(); 837 InitComponentExtension();
851 std::vector<std::string> keyboard_layouts; 838 std::vector<std::string> keyboard_layouts;
852 keyboard_layouts.push_back(XkbId("xkb:us::eng")); 839 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng"));
853 // For http://crbug.com/19655#c11 - (1) 840 // For http://crbug.com/19655#c11 - (1)
854 manager_->EnableLoginLayouts("en-US", keyboard_layouts); 841 manager_->EnableLoginLayouts("en-US", keyboard_layouts);
855 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); 842 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods());
856 EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); 843 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
844 manager_->GetCurrentInputMethod().id());
857 EXPECT_EQ("us", keyboard_->last_layout_); 845 EXPECT_EQ("us", keyboard_->last_layout_);
858 manager_->SwitchToNextInputMethod(); 846 manager_->SwitchToNextInputMethod();
859 EXPECT_TRUE(observer.last_show_message_); 847 EXPECT_TRUE(observer.last_show_message_);
860 EXPECT_EQ(XkbId("xkb:us:intl:eng"), manager_->GetCurrentInputMethod().id()); 848 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"),
849 manager_->GetCurrentInputMethod().id());
861 EXPECT_EQ("us(intl)", keyboard_->last_layout_); 850 EXPECT_EQ("us(intl)", keyboard_->last_layout_);
862 manager_->SwitchToNextInputMethod(); 851 manager_->SwitchToNextInputMethod();
863 EXPECT_TRUE(observer.last_show_message_); 852 EXPECT_TRUE(observer.last_show_message_);
864 EXPECT_EQ(XkbId("xkb:us:altgr-intl:eng"), 853 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"),
865 manager_->GetCurrentInputMethod().id()); 854 manager_->GetCurrentInputMethod().id());
866 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); 855 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_);
867 manager_->SwitchToNextInputMethod(); 856 manager_->SwitchToNextInputMethod();
868 EXPECT_TRUE(observer.last_show_message_); 857 EXPECT_TRUE(observer.last_show_message_);
869 EXPECT_EQ(XkbId("xkb:us:dvorak:eng"), 858 EXPECT_EQ(ImeIdFromEngineId("xkb:us:dvorak:eng"),
870 manager_->GetCurrentInputMethod().id()); 859 manager_->GetCurrentInputMethod().id());
871 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 860 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
872 manager_->SwitchToNextInputMethod(); 861 manager_->SwitchToNextInputMethod();
873 EXPECT_TRUE(observer.last_show_message_); 862 EXPECT_TRUE(observer.last_show_message_);
874 EXPECT_EQ(XkbId("xkb:us:colemak:eng"), 863 EXPECT_EQ(ImeIdFromEngineId("xkb:us:colemak:eng"),
875 manager_->GetCurrentInputMethod().id()); 864 manager_->GetCurrentInputMethod().id());
876 EXPECT_EQ("us(colemak)", keyboard_->last_layout_); 865 EXPECT_EQ("us(colemak)", keyboard_->last_layout_);
877 manager_->SwitchToNextInputMethod(); 866 manager_->SwitchToNextInputMethod();
878 EXPECT_TRUE(observer.last_show_message_); 867 EXPECT_TRUE(observer.last_show_message_);
879 EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); 868 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
869 manager_->GetCurrentInputMethod().id());
880 EXPECT_EQ("us", keyboard_->last_layout_); 870 EXPECT_EQ("us", keyboard_->last_layout_);
881 871
882 manager_->RemoveObserver(&observer); 872 manager_->RemoveObserver(&observer);
883 } 873 }
884 874
885 TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) { 875 TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) {
886 TestObserver observer; 876 TestObserver observer;
887 manager_->AddObserver(&observer); 877 manager_->AddObserver(&observer);
888 InitComponentExtension(); 878 InitComponentExtension();
889 879
890 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 880 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
891 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); 881 keydown_accelerator.set_type(ui::ET_KEY_PRESSED);
892 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 882 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
893 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); 883 keyup_accelerator.set_type(ui::ET_KEY_RELEASED);
894 884
895 std::vector<std::string> keyboard_layouts; 885 std::vector<std::string> keyboard_layouts;
896 keyboard_layouts.push_back(XkbId("xkb:us::eng")); 886 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng"));
897 manager_->EnableLoginLayouts("en-US", keyboard_layouts); 887 manager_->EnableLoginLayouts("en-US", keyboard_layouts);
898 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); 888 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods());
899 EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); 889 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
890 manager_->GetCurrentInputMethod().id());
900 EXPECT_EQ("us", keyboard_->last_layout_); 891 EXPECT_EQ("us", keyboard_->last_layout_);
901 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); 892 EXPECT_TRUE(manager_->SwitchToNextInputMethod());
902 EXPECT_TRUE(observer.last_show_message_); 893 EXPECT_TRUE(observer.last_show_message_);
903 EXPECT_EQ(XkbId("xkb:us:intl:eng"), 894 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"),
904 manager_->GetCurrentInputMethod().id()); 895 manager_->GetCurrentInputMethod().id());
905 EXPECT_EQ("us(intl)", keyboard_->last_layout_); 896 EXPECT_EQ("us(intl)", keyboard_->last_layout_);
906 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 897 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator));
907 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 898 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator));
908 EXPECT_TRUE(observer.last_show_message_); 899 EXPECT_TRUE(observer.last_show_message_);
909 EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); 900 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
901 manager_->GetCurrentInputMethod().id());
910 EXPECT_EQ("us", keyboard_->last_layout_); 902 EXPECT_EQ("us", keyboard_->last_layout_);
911 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 903 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator));
912 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 904 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator));
913 EXPECT_TRUE(observer.last_show_message_); 905 EXPECT_TRUE(observer.last_show_message_);
914 EXPECT_EQ(XkbId("xkb:us:intl:eng"), manager_->GetCurrentInputMethod().id()); 906 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"),
907 manager_->GetCurrentInputMethod().id());
915 EXPECT_EQ("us(intl)", keyboard_->last_layout_); 908 EXPECT_EQ("us(intl)", keyboard_->last_layout_);
916 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 909 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator));
917 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 910 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator));
918 EXPECT_TRUE(observer.last_show_message_); 911 EXPECT_TRUE(observer.last_show_message_);
919 EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); 912 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
913 manager_->GetCurrentInputMethod().id());
920 EXPECT_EQ("us", keyboard_->last_layout_); 914 EXPECT_EQ("us", keyboard_->last_layout_);
921 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); 915 EXPECT_TRUE(manager_->SwitchToNextInputMethod());
922 EXPECT_TRUE(observer.last_show_message_); 916 EXPECT_TRUE(observer.last_show_message_);
923 EXPECT_EQ(XkbId("xkb:us:intl:eng"), manager_->GetCurrentInputMethod().id()); 917 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"),
918 manager_->GetCurrentInputMethod().id());
924 EXPECT_EQ("us(intl)", keyboard_->last_layout_); 919 EXPECT_EQ("us(intl)", keyboard_->last_layout_);
925 EXPECT_TRUE(manager_->SwitchToNextInputMethod()); 920 EXPECT_TRUE(manager_->SwitchToNextInputMethod());
926 EXPECT_TRUE(observer.last_show_message_); 921 EXPECT_TRUE(observer.last_show_message_);
927 EXPECT_EQ(XkbId("xkb:us:altgr-intl:eng"), 922 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"),
928 manager_->GetCurrentInputMethod().id()); 923 manager_->GetCurrentInputMethod().id());
929 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); 924 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_);
930 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 925 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator));
931 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 926 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator));
932 EXPECT_TRUE(observer.last_show_message_); 927 EXPECT_TRUE(observer.last_show_message_);
933 EXPECT_EQ(XkbId("xkb:us:intl:eng"), manager_->GetCurrentInputMethod().id()); 928 EXPECT_EQ(ImeIdFromEngineId("xkb:us:intl:eng"),
929 manager_->GetCurrentInputMethod().id());
934 EXPECT_EQ("us(intl)", keyboard_->last_layout_); 930 EXPECT_EQ("us(intl)", keyboard_->last_layout_);
935 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 931 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator));
936 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 932 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator));
937 EXPECT_TRUE(observer.last_show_message_); 933 EXPECT_TRUE(observer.last_show_message_);
938 EXPECT_EQ(XkbId("xkb:us:altgr-intl:eng"), 934 EXPECT_EQ(ImeIdFromEngineId("xkb:us:altgr-intl:eng"),
939 manager_->GetCurrentInputMethod().id()); 935 manager_->GetCurrentInputMethod().id());
940 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_); 936 EXPECT_EQ("us(altgr-intl)", keyboard_->last_layout_);
941 937
942 manager_->RemoveObserver(&observer); 938 manager_->RemoveObserver(&observer);
943 } 939 }
944 940
945 TEST_F(InputMethodManagerImplTest, 941 TEST_F(InputMethodManagerImplTest,
946 TestSwitchToPreviousInputMethodForOneActiveInputMethod) { 942 TestSwitchToPreviousInputMethodForOneActiveInputMethod) {
947 TestObserver observer; 943 TestObserver observer;
948 manager_->AddObserver(&observer); 944 manager_->AddObserver(&observer);
949 InitComponentExtension(); 945 InitComponentExtension();
950 946
951 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 947 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
952 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); 948 keydown_accelerator.set_type(ui::ET_KEY_PRESSED);
953 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 949 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
954 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); 950 keyup_accelerator.set_type(ui::ET_KEY_RELEASED);
955 951
956 std::vector<std::string> ids; 952 std::vector<std::string> ids;
957 ids.push_back(XkbId("xkb:us:dvorak:eng")); 953 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
958 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 954 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
959 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 955 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
960 956
961 // Ctrl+Space accelerator should not be consumed if there is only one active 957 // Ctrl+Space accelerator should not be consumed if there is only one active
962 // input method. 958 // input method.
963 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 959 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keydown_accelerator));
964 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 960 EXPECT_FALSE(manager_->SwitchToPreviousInputMethod(keyup_accelerator));
965 961
966 manager_->RemoveObserver(&observer); 962 manager_->RemoveObserver(&observer);
967 } 963 }
968 964
969 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { 965 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) {
970 std::string expect_id = XkbId("xkb:us::eng"); 966 std::string expect_id = ImeIdFromEngineId("xkb:us::eng");
971 TestObserver observer; 967 TestObserver observer;
972 manager_->AddObserver(&observer); 968 manager_->AddObserver(&observer);
973 InitComponentExtension(); 969 InitComponentExtension();
974 std::vector<std::string> keyboard_layouts; 970 std::vector<std::string> keyboard_layouts;
975 keyboard_layouts.push_back(XkbId("xkb:us::eng")); 971 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng"));
976 manager_->EnableLoginLayouts("en-US", keyboard_layouts); 972 manager_->EnableLoginLayouts("en-US", keyboard_layouts);
977 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); 973 EXPECT_EQ(5U, manager_->GetNumActiveInputMethods());
978 EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); 974 EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id());
979 EXPECT_EQ("us", keyboard_->last_layout_); 975 EXPECT_EQ("us", keyboard_->last_layout_);
980 976
981 // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs 977 // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs
982 // and keyboards are enabled. 978 // and keyboards are enabled.
983 EXPECT_FALSE(manager_->SwitchInputMethod( 979 EXPECT_FALSE(manager_->SwitchInputMethod(
984 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); 980 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE)));
985 EXPECT_FALSE(observer.last_show_message_); 981 EXPECT_FALSE(observer.last_show_message_);
(...skipping 18 matching lines...) Expand all
1004 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) { 1000 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) {
1005 // Enable "xkb:jp::jpn" and press Muhenkan/ZenkakuHankaku. 1001 // Enable "xkb:jp::jpn" and press Muhenkan/ZenkakuHankaku.
1006 InitComponentExtension(); 1002 InitComponentExtension();
1007 1003
1008 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 1004 ui::Accelerator keydown_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
1009 keydown_accelerator.set_type(ui::ET_KEY_PRESSED); 1005 keydown_accelerator.set_type(ui::ET_KEY_PRESSED);
1010 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 1006 ui::Accelerator keyup_accelerator(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
1011 keyup_accelerator.set_type(ui::ET_KEY_RELEASED); 1007 keyup_accelerator.set_type(ui::ET_KEY_RELEASED);
1012 1008
1013 std::vector<std::string> keyboard_layouts; 1009 std::vector<std::string> keyboard_layouts;
1014 keyboard_layouts.push_back(XkbId("xkb:us::eng")); 1010 keyboard_layouts.push_back(ImeIdFromEngineId("xkb:us::eng"));
1015 manager_->EnableLoginLayouts("ja", keyboard_layouts); 1011 manager_->EnableLoginLayouts("ja", keyboard_layouts);
1016 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1012 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
1017 EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); 1013 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
1014 manager_->GetCurrentInputMethod().id());
1018 EXPECT_EQ("us", keyboard_->last_layout_); 1015 EXPECT_EQ("us", keyboard_->last_layout_);
1019 EXPECT_TRUE(manager_->SwitchInputMethod( 1016 EXPECT_TRUE(manager_->SwitchInputMethod(
1020 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); 1017 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE)));
1021 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1018 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1019 manager_->GetCurrentInputMethod().id());
1022 EXPECT_EQ("jp", keyboard_->last_layout_); 1020 EXPECT_EQ("jp", keyboard_->last_layout_);
1023 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 1021 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator));
1024 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 1022 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator));
1025 EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); 1023 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
1024 manager_->GetCurrentInputMethod().id());
1026 EXPECT_EQ("us", keyboard_->last_layout_); 1025 EXPECT_EQ("us", keyboard_->last_layout_);
1027 EXPECT_TRUE(manager_->SwitchInputMethod( 1026 EXPECT_TRUE(manager_->SwitchInputMethod(
1028 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); 1027 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE)));
1029 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1028 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1029 manager_->GetCurrentInputMethod().id());
1030 EXPECT_EQ("jp", keyboard_->last_layout_); 1030 EXPECT_EQ("jp", keyboard_->last_layout_);
1031 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); 1031 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator));
1032 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); 1032 EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator));
1033 EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); 1033 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
1034 manager_->GetCurrentInputMethod().id());
1034 EXPECT_EQ("us", keyboard_->last_layout_); 1035 EXPECT_EQ("us", keyboard_->last_layout_);
1035 EXPECT_TRUE(manager_->SwitchInputMethod( 1036 EXPECT_TRUE(manager_->SwitchInputMethod(
1036 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); 1037 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE)));
1037 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1038 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1039 manager_->GetCurrentInputMethod().id());
1038 EXPECT_EQ("jp", keyboard_->last_layout_); 1040 EXPECT_EQ("jp", keyboard_->last_layout_);
1039 } 1041 }
1040 1042
1041 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) { 1043 TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) {
1042 InitComponentExtension(); 1044 InitComponentExtension();
1043 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1045 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1044 std::vector<std::string> ids; 1046 std::vector<std::string> ids;
1045 ids.push_back(XkbId("xkb:jp::jpn")); 1047 ids.push_back(ImeIdFromEngineId("xkb:jp::jpn"));
1046 ids.push_back(kNaclMozcJpId); 1048 ids.push_back(ImeIdFromEngineId(kNaclMozcJpId));
1047 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 1049 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
1048 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1050 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1051 manager_->GetCurrentInputMethod().id());
1049 EXPECT_EQ("jp", keyboard_->last_layout_); 1052 EXPECT_EQ("jp", keyboard_->last_layout_);
1050 EXPECT_TRUE(manager_->SwitchInputMethod( 1053 EXPECT_TRUE(manager_->SwitchInputMethod(
1051 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); 1054 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE)));
1052 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 1055 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId),
1056 manager_->GetCurrentInputMethod().id());
1053 EXPECT_EQ("jp", keyboard_->last_layout_); 1057 EXPECT_EQ("jp", keyboard_->last_layout_);
1054 EXPECT_TRUE(manager_->SwitchInputMethod( 1058 EXPECT_TRUE(manager_->SwitchInputMethod(
1055 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); 1059 ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE)));
1056 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1060 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1061 manager_->GetCurrentInputMethod().id());
1057 EXPECT_EQ("jp", keyboard_->last_layout_); 1062 EXPECT_EQ("jp", keyboard_->last_layout_);
1058 EXPECT_TRUE(manager_->SwitchInputMethod( 1063 EXPECT_TRUE(manager_->SwitchInputMethod(
1059 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); 1064 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE)));
1060 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 1065 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId),
1066 manager_->GetCurrentInputMethod().id());
1061 EXPECT_EQ("jp", keyboard_->last_layout_); 1067 EXPECT_EQ("jp", keyboard_->last_layout_);
1062 EXPECT_TRUE(manager_->SwitchInputMethod( 1068 EXPECT_TRUE(manager_->SwitchInputMethod(
1063 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); 1069 ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE)));
1064 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 1070 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId),
1071 manager_->GetCurrentInputMethod().id());
1065 EXPECT_EQ("jp", keyboard_->last_layout_); 1072 EXPECT_EQ("jp", keyboard_->last_layout_);
1066 EXPECT_TRUE(manager_->SwitchInputMethod( 1073 EXPECT_TRUE(manager_->SwitchInputMethod(
1067 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); 1074 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE)));
1068 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1075 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1076 manager_->GetCurrentInputMethod().id());
1069 EXPECT_EQ("jp", keyboard_->last_layout_); 1077 EXPECT_EQ("jp", keyboard_->last_layout_);
1070 EXPECT_TRUE(manager_->SwitchInputMethod( 1078 EXPECT_TRUE(manager_->SwitchInputMethod(
1071 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); 1079 ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE)));
1072 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1080 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1081 manager_->GetCurrentInputMethod().id());
1073 EXPECT_EQ("jp", keyboard_->last_layout_); 1082 EXPECT_EQ("jp", keyboard_->last_layout_);
1074 1083
1075 // Add Dvorak. 1084 // Add Dvorak.
1076 ids.push_back(XkbId("xkb:us:dvorak:eng")); 1085 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
1077 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 1086 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
1078 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1087 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1088 manager_->GetCurrentInputMethod().id());
1079 EXPECT_EQ("jp", keyboard_->last_layout_); 1089 EXPECT_EQ("jp", keyboard_->last_layout_);
1080 EXPECT_TRUE(manager_->SwitchInputMethod( 1090 EXPECT_TRUE(manager_->SwitchInputMethod(
1081 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); 1091 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE)));
1082 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 1092 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId),
1093 manager_->GetCurrentInputMethod().id());
1083 EXPECT_EQ("jp", keyboard_->last_layout_); 1094 EXPECT_EQ("jp", keyboard_->last_layout_);
1084 EXPECT_TRUE(manager_->SwitchInputMethod( 1095 EXPECT_TRUE(manager_->SwitchInputMethod(
1085 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); 1096 ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE)));
1086 EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); 1097 EXPECT_EQ(ImeIdFromEngineId("xkb:jp::jpn"),
1098 manager_->GetCurrentInputMethod().id());
1087 EXPECT_EQ("jp", keyboard_->last_layout_); 1099 EXPECT_EQ("jp", keyboard_->last_layout_);
1088 } 1100 }
1089 1101
1090 TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { 1102 TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) {
1091 TestObserver observer; 1103 TestObserver observer;
1092 manager_->AddObserver(&observer); 1104 manager_->AddObserver(&observer);
1093 InitComponentExtension(); 1105 InitComponentExtension();
1094 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1106 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1095 std::vector<std::string> ids; 1107 std::vector<std::string> ids;
1096 ids.push_back(XkbId("xkb:us:dvorak:eng")); 1108 ids.push_back(ImeIdFromEngineId("xkb:us:dvorak:eng"));
1097 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 1109 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
1098 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1110 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
1099 EXPECT_EQ(1, observer.input_method_changed_count_); 1111 EXPECT_EQ(1, observer.input_method_changed_count_);
1100 EXPECT_EQ(XkbId(ids[0]), 1112 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
1101 manager_->GetCurrentInputMethod().id());
1102 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 1113 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
1103 1114
1104 // Add two Extension IMEs. 1115 // Add two Extension IMEs.
1105 std::vector<std::string> layouts; 1116 std::vector<std::string> layouts;
1106 layouts.push_back("us"); 1117 layouts.push_back("us");
1107 std::vector<std::string> languages; 1118 std::vector<std::string> languages;
1108 languages.push_back("en-US"); 1119 languages.push_back("en-US");
1109 1120
1110 const std::string ext1_id = 1121 const std::string ext1_id =
1111 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); 1122 extension_ime_util::GetInputMethodID("deadbeef", "engine_id");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 manager_->RemoveInputMethodExtension(ext2_id); 1179 manager_->RemoveInputMethodExtension(ext2_id);
1169 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1180 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
1170 } 1181 }
1171 1182
1172 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { 1183 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) {
1173 TestObserver observer; 1184 TestObserver observer;
1174 InitComponentExtension(); 1185 InitComponentExtension();
1175 manager_->AddObserver(&observer); 1186 manager_->AddObserver(&observer);
1176 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1187 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1177 std::vector<std::string> ids; 1188 std::vector<std::string> ids;
1178 ids.push_back(XkbId("xkb:us::eng")); 1189 ids.push_back(ImeIdFromEngineId("xkb:us::eng"));
1179 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 1190 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
1180 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1191 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
1181 EXPECT_EQ(1, observer.input_method_changed_count_); 1192 EXPECT_EQ(1, observer.input_method_changed_count_);
1182 EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); 1193 EXPECT_EQ(ImeIdFromEngineId(ids[0]), manager_->GetCurrentInputMethod().id());
1183 EXPECT_EQ("us", keyboard_->last_layout_); 1194 EXPECT_EQ("us", keyboard_->last_layout_);
1184 1195
1185 // Add an Extension IME. 1196 // Add an Extension IME.
1186 std::vector<std::string> layouts; 1197 std::vector<std::string> layouts;
1187 layouts.push_back("us(dvorak)"); 1198 layouts.push_back("us(dvorak)");
1188 std::vector<std::string> languages; 1199 std::vector<std::string> languages;
1189 languages.push_back("en-US"); 1200 languages.push_back("en-US");
1190 1201
1191 const std::string ext_id = 1202 const std::string ext_id =
1192 extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); 1203 extension_ime_util::GetInputMethodID("deadbeef", "engine_id");
(...skipping 19 matching lines...) Expand all
1212 1223
1213 // Switch to the IME. 1224 // Switch to the IME.
1214 manager_->SwitchToNextInputMethod(); 1225 manager_->SwitchToNextInputMethod();
1215 EXPECT_EQ(3, observer.input_method_changed_count_); 1226 EXPECT_EQ(3, observer.input_method_changed_count_);
1216 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); 1227 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id());
1217 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 1228 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
1218 1229
1219 // Lock the screen. This is for crosbug.com/27049. 1230 // Lock the screen. This is for crosbug.com/27049.
1220 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); 1231 manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN);
1221 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); // Qwerty. No Ext. IME 1232 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); // Qwerty. No Ext. IME
1222 EXPECT_EQ(XkbId("xkb:us::eng"), 1233 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"),
1223 manager_->GetCurrentInputMethod().id()); 1234 manager_->GetCurrentInputMethod().id());
1224 EXPECT_EQ("us", keyboard_->last_layout_); 1235 EXPECT_EQ("us", keyboard_->last_layout_);
1225 1236
1226 // Unlock the screen. 1237 // Unlock the screen.
1227 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1238 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1228 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1239 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
1229 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id()); 1240 EXPECT_EQ(ext_id, manager_->GetCurrentInputMethod().id());
1230 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_); 1241 EXPECT_EQ("us(dvorak)", keyboard_->last_layout_);
1231 { 1242 {
1232 // This is for crosbug.com/27052. 1243 // This is for crosbug.com/27052.
1233 scoped_ptr<InputMethodDescriptors> methods( 1244 scoped_ptr<InputMethodDescriptors> methods(
1234 manager_->GetActiveInputMethods()); 1245 manager_->GetActiveInputMethods());
1235 ASSERT_EQ(2U, methods->size()); 1246 ASSERT_EQ(2U, methods->size());
1236 // Ext. IMEs should be at the end of the list. 1247 // Ext. IMEs should be at the end of the list.
1237 EXPECT_EQ(ext_id, methods->at(1).id()); 1248 EXPECT_EQ(ext_id, methods->at(1).id());
1238 } 1249 }
1239 manager_->RemoveObserver(&observer); 1250 manager_->RemoveObserver(&observer);
1240 } 1251 }
1241 1252
1242 TEST_F(InputMethodManagerImplTest, 1253 TEST_F(InputMethodManagerImplTest,
1243 ChangeInputMethodBeforeComponentExtensionInitialization_OneIME) { 1254 ChangeInputMethodBeforeComponentExtensionInitialization_OneIME) {
1244 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1255 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1245 std::vector<std::string> ids; 1256 std::vector<std::string> ids;
1246 ids.push_back(kNaclMozcUsId); 1257 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId));
1247 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 1258 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
1248 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); 1259 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
1249 manager_->ChangeInputMethod(kNaclMozcUsId); 1260 manager_->ChangeInputMethod(ImeIdFromEngineId(kNaclMozcUsId));
1250 1261
1251 InitComponentExtension(); 1262 InitComponentExtension();
1252 EXPECT_EQ(kNaclMozcUsId, manager_->GetCurrentInputMethod().id()); 1263 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcUsId),
1264 manager_->GetCurrentInputMethod().id());
1253 } 1265 }
1254 1266
1255 TEST_F(InputMethodManagerImplTest, 1267 TEST_F(InputMethodManagerImplTest,
1256 ChangeInputMethodBeforeComponentExtensionInitialization_TwoIME) { 1268 ChangeInputMethodBeforeComponentExtensionInitialization_TwoIME) {
1257 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1269 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1258 std::vector<std::string> ids; 1270 std::vector<std::string> ids;
1259 ids.push_back(kNaclMozcUsId); 1271 ids.push_back(ImeIdFromEngineId(kNaclMozcUsId));
1260 ids.push_back(kNaclMozcJpId); 1272 ids.push_back(ImeIdFromEngineId(kNaclMozcJpId));
1261 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 1273 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
1262 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1274 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
1263 manager_->ChangeInputMethod(kNaclMozcUsId); 1275 manager_->ChangeInputMethod(ImeIdFromEngineId(kNaclMozcUsId));
1264 manager_->ChangeInputMethod(kNaclMozcJpId); 1276 manager_->ChangeInputMethod(ImeIdFromEngineId(kNaclMozcJpId));
1265 1277
1266 InitComponentExtension(); 1278 InitComponentExtension();
1267 EXPECT_EQ(kNaclMozcJpId, manager_->GetCurrentInputMethod().id()); 1279 EXPECT_EQ(ImeIdFromEngineId(kNaclMozcJpId),
1280 manager_->GetCurrentInputMethod().id());
1268 } 1281 }
1269 1282
1270 TEST_F(InputMethodManagerImplTest, 1283 TEST_F(InputMethodManagerImplTest,
1271 ChangeInputMethodBeforeComponentExtensionInitialization_CompOneIME) { 1284 ChangeInputMethodBeforeComponentExtensionInitialization_CompOneIME) {
1272 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); 1285 manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN);
1273 const std::string ext_id = extension_ime_util::GetComponentInputMethodID( 1286 const std::string ext_id = extension_ime_util::GetComponentInputMethodID(
1274 ime_list_[1].id, 1287 ime_list_[1].id,
1275 ime_list_[1].engines[0].engine_id); 1288 ime_list_[1].engines[0].engine_id);
1276 std::vector<std::string> ids; 1289 std::vector<std::string> ids;
1277 ids.push_back(ext_id); 1290 ids.push_back(ext_id);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 std::vector<std::string> ids; 1344 std::vector<std::string> ids;
1332 ids.push_back(ext_id1); 1345 ids.push_back(ext_id1);
1333 ids.push_back(ext_id2); 1346 ids.push_back(ext_id2);
1334 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); 1347 EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids));
1335 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); 1348 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
1336 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id()); 1349 EXPECT_EQ(ext_id1, manager_->GetCurrentInputMethod().id());
1337 manager_->ChangeInputMethod(ext_id2); 1350 manager_->ChangeInputMethod(ext_id2);
1338 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); 1351 EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id());
1339 } 1352 }
1340 1353
1341 TEST_F(InputMethodManagerImplTest, MigrateInputMethodTest_1) { 1354 TEST_F(InputMethodManagerImplTest, MigrateInputMethodTest) {
1342 extension_ime_util::ScopedUseExtensionKeyboardFlagForTesting
1343 scoped_flag(true);
1344
1345 std::vector<std::string> input_method_ids; 1355 std::vector<std::string> input_method_ids;
1346 input_method_ids.push_back("xkb:us::eng"); 1356 input_method_ids.push_back("xkb:us::eng");
1347 input_method_ids.push_back("xkb:fr::fra"); 1357 input_method_ids.push_back("xkb:fr::fra");
1348 input_method_ids.push_back( 1358 input_method_ids.push_back(ImeIdFromEngineId("xkb:us::eng"));
1349 std::string("_comp_ime_") + kXkbExtId + "xkb:us::eng");
1350 input_method_ids.push_back("xkb:fr::fra"); 1359 input_method_ids.push_back("xkb:fr::fra");
1351 input_method_ids.push_back( 1360 input_method_ids.push_back(ImeIdFromEngineId("xkb:us::eng"));
1352 std::string("_comp_ime_") + kXkbExtId + "xkb:us::eng");
1353 input_method_ids.push_back("_comp_ime_asdf_pinyin"); 1361 input_method_ids.push_back("_comp_ime_asdf_pinyin");
1354 input_method_ids.push_back(kNaclMozcUsId); 1362 input_method_ids.push_back(ImeIdFromEngineId(kPinyinImeId));
1355 1363
1356 manager_->MigrateInputMethods(&input_method_ids); 1364 manager_->MigrateInputMethods(&input_method_ids);
1357 1365
1358 ASSERT_EQ(4U, input_method_ids.size()); 1366 ASSERT_EQ(4U, input_method_ids.size());
1359 1367
1360 EXPECT_EQ(std::string("_comp_ime_") + kXkbExtId + "xkb:us::eng", 1368 EXPECT_EQ(ImeIdFromEngineId("xkb:us::eng"), input_method_ids[0]);
1361 input_method_ids[0]); 1369 EXPECT_EQ(ImeIdFromEngineId("xkb:fr::fra"), input_method_ids[1]);
1362 EXPECT_EQ(std::string("_comp_ime_") + kXkbExtId + "xkb:fr::fra",
1363 input_method_ids[1]);
1364 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); 1370 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]);
1365 EXPECT_EQ("_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_us", 1371 EXPECT_EQ(ImeIdFromEngineId("zh-t-i0-pinyin"), input_method_ids[3]);
1366 input_method_ids[3]);
1367 }
1368
1369 TEST_F(InputMethodManagerImplTest, MigrateInputMethodTest_2) {
1370 extension_ime_util::ScopedUseExtensionKeyboardFlagForTesting
1371 scoped_flag(false);
1372
1373 std::vector<std::string> input_method_ids;
1374 input_method_ids.push_back("xkb:us::eng");
1375 input_method_ids.push_back("xkb:fr::fra");
1376 input_method_ids.push_back(
1377 std::string("_comp_ime_") + kXkbExtId + "xkb:us::eng");
1378 input_method_ids.push_back("xkb:fr::fra");
1379 input_method_ids.push_back(
1380 std::string("_comp_ime_") + kXkbExtId + "xkb:us::eng");
1381 input_method_ids.push_back("_comp_ime_asdf_pinyin");
1382
1383 manager_->MigrateInputMethods(&input_method_ids);
1384
1385 ASSERT_EQ(3U, input_method_ids.size());
1386
1387 EXPECT_EQ("xkb:us::eng", input_method_ids[0]);
1388 EXPECT_EQ("xkb:fr::fra", input_method_ids[1]);
1389 EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]);
1390 } 1372 }
1391 1373
1392 } // namespace input_method 1374 } // namespace input_method
1393 } // namespace chromeos 1375 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698