| OLD | NEW | 
|     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 "base/basictypes.h" |     9 #include "base/basictypes.h" | 
|    10 #include "base/compiler_specific.h" |    10 #include "base/compiler_specific.h" | 
|    11 #include "base/logging.h" |    11 #include "base/logging.h" | 
|    12 #include "base/memory/scoped_ptr.h" |    12 #include "base/memory/scoped_ptr.h" | 
|    13 #include "base/message_loop.h" |    13 #include "base/message_loop.h" | 
|    14 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
      h" |    14 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
      h" | 
|    15 #include "chrome/browser/chromeos/input_method/mock_ibus_controller.h" |    15 #include "chrome/browser/chromeos/input_method/mock_ibus_controller.h" | 
|    16 #include "chrome/browser/chromeos/input_method/mock_xkeyboard.h" |    16 #include "chrome/browser/chromeos/input_method/mock_xkeyboard.h" | 
|    17 #include "chromeos/dbus/ibus/mock_ibus_client.h" |    17 #include "chromeos/dbus/ibus/mock_ibus_client.h" | 
|    18 #include "chromeos/dbus/ibus/mock_ibus_input_context_client.h" |    18 #include "chromeos/dbus/ibus/mock_ibus_input_context_client.h" | 
|    19 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" |    19 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" | 
 |    20 #include "chromeos/ime/extension_ime_util.h" | 
|    20 #include "chromeos/ime/mock_ibus_daemon_controller.h" |    21 #include "chromeos/ime/mock_ibus_daemon_controller.h" | 
|    21 #include "chromeos/ime/mock_input_method_delegate.h" |    22 #include "chromeos/ime/mock_input_method_delegate.h" | 
|    22 #include "testing/gtest/include/gtest/gtest.h" |    23 #include "testing/gtest/include/gtest/gtest.h" | 
|    23 #include "ui/base/accelerators/accelerator.h" |    24 #include "ui/base/accelerators/accelerator.h" | 
|    24 #include "ui/base/ime/text_input_test_support.h" |    25 #include "ui/base/ime/text_input_test_support.h" | 
|    25 #include "ui/base/keycodes/keyboard_codes.h" |    26 #include "ui/base/keycodes/keyboard_codes.h" | 
|    26  |    27  | 
|    27 namespace chromeos { |    28 namespace chromeos { | 
|    28  |    29  | 
|    29 extern const char* kExtensionImePrefix; |  | 
|    30  |  | 
|    31 namespace input_method { |    30 namespace input_method { | 
|    32 namespace { |    31 namespace { | 
|    33  |    32  | 
|    34 class InputMethodManagerImplTest :  public testing::Test { |    33 class InputMethodManagerImplTest :  public testing::Test { | 
|    35  public: |    34  public: | 
|    36   InputMethodManagerImplTest() |    35   InputMethodManagerImplTest() | 
|    37       : delegate_(NULL), |    36       : delegate_(NULL), | 
|    38         controller_(NULL), |    37         controller_(NULL), | 
|    39         candidate_window_controller_(NULL), |    38         candidate_window_controller_(NULL), | 
|    40         xkeyboard_(NULL) { |    39         xkeyboard_(NULL) { | 
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   885   EXPECT_EQ(0, mock_ibus_daemon_controller_->start_count()); |   884   EXPECT_EQ(0, mock_ibus_daemon_controller_->start_count()); | 
|   886   EXPECT_EQ(1, observer.input_method_changed_count_); |   885   EXPECT_EQ(1, observer.input_method_changed_count_); | 
|   887   EXPECT_EQ(ids[0], |   886   EXPECT_EQ(ids[0], | 
|   888             manager_->GetCurrentInputMethod().id()); |   887             manager_->GetCurrentInputMethod().id()); | 
|   889   EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); |   888   EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); | 
|   890  |   889  | 
|   891   // Add two Extension IMEs. |   890   // Add two Extension IMEs. | 
|   892   std::vector<std::string> layouts; |   891   std::vector<std::string> layouts; | 
|   893   layouts.push_back("us"); |   892   layouts.push_back("us"); | 
|   894   manager_->AddInputMethodExtension( |   893   manager_->AddInputMethodExtension( | 
|   895       std::string(kExtensionImePrefix) + "deadbeef", |   894       extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 
|   896       "deadbeef input method", |   895       "deadbeef input method", | 
|   897       layouts, |   896       layouts, | 
|   898       "en-US", |   897       "en-US", | 
|   899       NULL); |   898       NULL); | 
|   900   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |   899   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 
|   901  |   900  | 
|   902   // should be started. |   901   // should be started. | 
|   903   EXPECT_EQ(1, mock_ibus_daemon_controller_->start_count()); |   902   EXPECT_EQ(1, mock_ibus_daemon_controller_->start_count()); | 
|   904   { |   903   { | 
|   905     scoped_ptr<InputMethodDescriptors> methods( |   904     scoped_ptr<InputMethodDescriptors> methods( | 
|   906         manager_->GetActiveInputMethods()); |   905         manager_->GetActiveInputMethods()); | 
|   907     ASSERT_EQ(2U, methods->size()); |   906     ASSERT_EQ(2U, methods->size()); | 
|   908     EXPECT_EQ(std::string(kExtensionImePrefix) + "deadbeef", |   907     EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 
|   909               // Ext IMEs should be at the end of the list. |   908               // Ext IMEs should be at the end of the list. | 
|   910               methods->at(1).id()); |   909               methods->at(1).id()); | 
|   911   } |   910   } | 
|   912   manager_->AddInputMethodExtension( |   911   manager_->AddInputMethodExtension( | 
|   913       std::string(kExtensionImePrefix) + "cafebabe", |   912       extension_ime_util::GetInputMethodID("cafebabe", "engine_id"), | 
|   914       "cafebabe input method", |   913       "cafebabe input method", | 
|   915       layouts, |   914       layouts, | 
|   916       "en-US", |   915       "en-US", | 
|   917       NULL); |   916       NULL); | 
|   918   EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); |   917   EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); | 
|   919   { |   918   { | 
|   920     scoped_ptr<InputMethodDescriptors> methods( |   919     scoped_ptr<InputMethodDescriptors> methods( | 
|   921         manager_->GetActiveInputMethods()); |   920         manager_->GetActiveInputMethods()); | 
|   922     ASSERT_EQ(3U, methods->size()); |   921     ASSERT_EQ(3U, methods->size()); | 
|   923     EXPECT_EQ(std::string(kExtensionImePrefix) + "deadbeef", |   922     EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 
|   924               // Ext IMEs should be at the end of the list. |   923               // Ext IMEs should be at the end of the list. | 
|   925               methods->at(1).id()); |   924               methods->at(1).id()); | 
|   926   } |   925   } | 
|   927  |   926  | 
|   928   // Remove them. |   927   // Remove them. | 
|   929   manager_->RemoveInputMethodExtension( |   928   manager_->RemoveInputMethodExtension( | 
|   930       std::string(kExtensionImePrefix) + "deadbeef"); |   929       extension_ime_util::GetInputMethodID("deadbeef", "engine_id")); | 
|   931   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |   930   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 
|   932   manager_->RemoveInputMethodExtension( |   931   manager_->RemoveInputMethodExtension( | 
|   933       std::string(kExtensionImePrefix) + "cafebabe"); |   932       extension_ime_util::GetInputMethodID("cafebabe", "engine_id")); | 
|   934   EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |   933   EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 
|   935   // Currently, to work around  a crash issue at crosbug.com/27051, |   934   // Currently, to work around  a crash issue at crosbug.com/27051, | 
|   936   // controller_->Stop(); is NOT called when all (extension) IMEs are disabled. |   935   // controller_->Stop(); is NOT called when all (extension) IMEs are disabled. | 
|   937   EXPECT_EQ(0, mock_ibus_daemon_controller_->stop_count()); |   936   EXPECT_EQ(0, mock_ibus_daemon_controller_->stop_count()); | 
|   938  |   937  | 
|   939   manager_->RemoveObserver(&observer); |   938   manager_->RemoveObserver(&observer); | 
|   940 } |   939 } | 
|   941  |   940  | 
|   942 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { |   941 TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { | 
|   943   TestObserver observer; |   942   TestObserver observer; | 
|   944   manager_->AddObserver(&observer); |   943   manager_->AddObserver(&observer); | 
|   945   manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |   944   manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 
|   946   std::vector<std::string> ids; |   945   std::vector<std::string> ids; | 
|   947   ids.push_back("xkb:us::eng"); |   946   ids.push_back("xkb:us::eng"); | 
|   948   EXPECT_TRUE(manager_->EnableInputMethods(ids)); |   947   EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 
|   949   EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |   948   EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 
|   950   EXPECT_EQ(1, observer.input_method_changed_count_); |   949   EXPECT_EQ(1, observer.input_method_changed_count_); | 
|   951   EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); |   950   EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); | 
|   952   EXPECT_EQ("us", xkeyboard_->last_layout_); |   951   EXPECT_EQ("us", xkeyboard_->last_layout_); | 
|   953  |   952  | 
|   954   // Add an Extension IME. |   953   // Add an Extension IME. | 
|   955   std::vector<std::string> layouts; |   954   std::vector<std::string> layouts; | 
|   956   layouts.push_back("us(dvorak)"); |   955   layouts.push_back("us(dvorak)"); | 
|   957   manager_->AddInputMethodExtension( |   956   manager_->AddInputMethodExtension( | 
|   958       std::string(kExtensionImePrefix) + "deadbeef", |   957       extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 
|   959       "deadbeef input method", |   958       "deadbeef input method", | 
|   960       layouts, |   959       layouts, | 
|   961       "en-US", |   960       "en-US", | 
|   962       NULL); |   961       NULL); | 
|   963   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |   962   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 
|   964   EXPECT_EQ(1, observer.input_method_changed_count_); |   963   EXPECT_EQ(1, observer.input_method_changed_count_); | 
|   965  |   964  | 
|   966   // Switch to the IME. |   965   // Switch to the IME. | 
|   967   manager_->SwitchToNextInputMethod(); |   966   manager_->SwitchToNextInputMethod(); | 
|   968   EXPECT_EQ(2, observer.input_method_changed_count_); |   967   EXPECT_EQ(2, observer.input_method_changed_count_); | 
|   969   EXPECT_EQ(std::string(kExtensionImePrefix) + "deadbeef", |   968   EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 
|   970             manager_->GetCurrentInputMethod().id()); |   969             manager_->GetCurrentInputMethod().id()); | 
|   971   EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); |   970   EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); | 
|   972  |   971  | 
|   973   // Lock the screen. This is for crosbug.com/27049. |   972   // Lock the screen. This is for crosbug.com/27049. | 
|   974   manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); |   973   manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); | 
|   975   EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());  // Qwerty. No Ext. IME |   974   EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());  // Qwerty. No Ext. IME | 
|   976   EXPECT_EQ("xkb:us::eng", |   975   EXPECT_EQ("xkb:us::eng", | 
|   977             manager_->GetCurrentInputMethod().id()); |   976             manager_->GetCurrentInputMethod().id()); | 
|   978   EXPECT_EQ("us", xkeyboard_->last_layout_); |   977   EXPECT_EQ("us", xkeyboard_->last_layout_); | 
|   979   EXPECT_EQ(0, mock_ibus_daemon_controller_->stop_count()); |   978   EXPECT_EQ(0, mock_ibus_daemon_controller_->stop_count()); | 
|   980  |   979  | 
|   981   // Unlock the screen. |   980   // Unlock the screen. | 
|   982   manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |   981   manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 
|   983   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |   982   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 
|   984   EXPECT_EQ(std::string(kExtensionImePrefix) + "deadbeef", |   983   EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 
|   985             manager_->GetCurrentInputMethod().id()); |   984             manager_->GetCurrentInputMethod().id()); | 
|   986   EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); |   985   EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); | 
|   987   { |   986   { | 
|   988     // This is for crosbug.com/27052. |   987     // This is for crosbug.com/27052. | 
|   989     scoped_ptr<InputMethodDescriptors> methods( |   988     scoped_ptr<InputMethodDescriptors> methods( | 
|   990         manager_->GetActiveInputMethods()); |   989         manager_->GetActiveInputMethods()); | 
|   991     ASSERT_EQ(2U, methods->size()); |   990     ASSERT_EQ(2U, methods->size()); | 
|   992     EXPECT_EQ(std::string(kExtensionImePrefix) + "deadbeef", |   991     EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), | 
|   993               // Ext. IMEs should be at the end of the list. |   992               // Ext. IMEs should be at the end of the list. | 
|   994               methods->at(1).id()); |   993               methods->at(1).id()); | 
|   995   } |   994   } | 
|   996   manager_->RemoveObserver(&observer); |   995   manager_->RemoveObserver(&observer); | 
|   997 } |   996 } | 
|   998  |   997  | 
|   999 TEST_F(InputMethodManagerImplTest, TestReset) { |   998 TEST_F(InputMethodManagerImplTest, TestReset) { | 
|  1000   manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); |   999   manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); | 
|  1001   std::vector<std::string> ids; |  1000   std::vector<std::string> ids; | 
|  1002   ids.push_back("xkb:us::eng"); |  1001   ids.push_back("xkb:us::eng"); | 
|  1003   ids.push_back("mozc"); |  1002   ids.push_back("mozc"); | 
|  1004   EXPECT_TRUE(manager_->EnableInputMethods(ids)); |  1003   EXPECT_TRUE(manager_->EnableInputMethods(ids)); | 
|  1005   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |  1004   EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 
|  1006   EXPECT_EQ(1, mock_ibus_input_context_client_->reset_call_count()); |  1005   EXPECT_EQ(1, mock_ibus_input_context_client_->reset_call_count()); | 
|  1007   manager_->ChangeInputMethod("mozc"); |  1006   manager_->ChangeInputMethod("mozc"); | 
|  1008   EXPECT_EQ(1, controller_->change_input_method_count_); |  1007   EXPECT_EQ(1, controller_->change_input_method_count_); | 
|  1009   EXPECT_EQ("mozc", controller_->change_input_method_id_); |  1008   EXPECT_EQ("mozc", controller_->change_input_method_id_); | 
|  1010   EXPECT_EQ(1, mock_ibus_input_context_client_->reset_call_count()); |  1009   EXPECT_EQ(1, mock_ibus_input_context_client_->reset_call_count()); | 
|  1011   manager_->ChangeInputMethod("xkb:us::eng"); |  1010   manager_->ChangeInputMethod("xkb:us::eng"); | 
|  1012   EXPECT_EQ(2, controller_->change_input_method_count_); |  1011   EXPECT_EQ(2, controller_->change_input_method_count_); | 
|  1013   EXPECT_EQ("mozc", controller_->change_input_method_id_); |  1012   EXPECT_EQ("mozc", controller_->change_input_method_id_); | 
|  1014   EXPECT_EQ(1, mock_ibus_input_context_client_->reset_call_count()); |  1013   EXPECT_EQ(1, mock_ibus_input_context_client_->reset_call_count()); | 
|  1015 } |  1014 } | 
|  1016  |  1015  | 
|  1017 }  // namespace input_method |  1016 }  // namespace input_method | 
|  1018 }  // namespace chromeos |  1017 }  // namespace chromeos | 
| OLD | NEW |