| 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" |
| 10 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" | 13 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.
h" |
| 12 #include "chrome/browser/chromeos/input_method/mock_ibus_controller.h" | 14 #include "chrome/browser/chromeos/input_method/mock_ibus_controller.h" |
| 15 #include "chrome/browser/chromeos/input_method/mock_input_method_delegate.h" |
| 13 #include "chrome/browser/chromeos/input_method/mock_xkeyboard.h" | 16 #include "chrome/browser/chromeos/input_method/mock_xkeyboard.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/base/accelerators/accelerator.h" | 18 #include "ui/base/accelerators/accelerator.h" |
| 16 #include "ui/base/keycodes/keyboard_codes.h" | 19 #include "ui/base/keycodes/keyboard_codes.h" |
| 17 | 20 |
| 18 namespace chromeos { | 21 namespace chromeos { |
| 19 | 22 |
| 20 extern const char* kExtensionImePrefix; | 23 extern const char* kExtensionImePrefix; |
| 21 | 24 |
| 22 namespace input_method { | 25 namespace input_method { |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 class InputMethodManagerImplTest : public testing::Test { | 28 class InputMethodManagerImplTest : public testing::Test { |
| 26 public: | 29 public: |
| 27 InputMethodManagerImplTest() | 30 InputMethodManagerImplTest() |
| 28 : controller_(NULL), | 31 : delegate_(NULL), |
| 29 candidate_window_controller_(NULL) { | 32 controller_(NULL), |
| 33 candidate_window_controller_(NULL), |
| 34 xkeyboard_(NULL) { |
| 30 } | 35 } |
| 31 virtual ~InputMethodManagerImplTest() {} | 36 virtual ~InputMethodManagerImplTest() {} |
| 32 | 37 |
| 33 virtual void SetUp() { | 38 virtual void SetUp() OVERRIDE { |
| 34 manager_.reset(InputMethodManagerImpl::GetInstanceForTesting()); | 39 delegate_ = new MockInputMethodDelegate(); |
| 40 manager_.reset(new InputMethodManagerImpl( |
| 41 scoped_ptr<InputMethodDelegate>(delegate_))); |
| 35 controller_ = new MockIBusController; | 42 controller_ = new MockIBusController; |
| 36 manager_->SetIBusControllerForTesting(controller_); | 43 manager_->SetIBusControllerForTesting(controller_); |
| 37 candidate_window_controller_ = new MockCandidateWindowController; | 44 candidate_window_controller_ = new MockCandidateWindowController; |
| 38 manager_->SetCandidateWindowControllerForTesting( | 45 manager_->SetCandidateWindowControllerForTesting( |
| 39 candidate_window_controller_); | 46 candidate_window_controller_); |
| 40 xkeyboard_ = new MockXKeyboard; | 47 xkeyboard_ = new MockXKeyboard; |
| 41 manager_->SetXKeyboardForTesting(xkeyboard_); | 48 manager_->SetXKeyboardForTesting(xkeyboard_); |
| 42 } | 49 } |
| 43 | 50 |
| 44 virtual void TearDown() { | 51 virtual void TearDown() OVERRIDE { |
| 45 manager_.reset(); | 52 delegate_ = NULL; |
| 46 controller_ = NULL; | 53 controller_ = NULL; |
| 47 candidate_window_controller_ = NULL; | 54 candidate_window_controller_ = NULL; |
| 48 xkeyboard_ = NULL; | 55 xkeyboard_ = NULL; |
| 49 } | 56 manager_.reset(); |
| 50 | |
| 51 void SetHardwareKeyboardLayout(const std::string& input_method_id) { | |
| 52 manager_->GetInputMethodUtil()->SetHardwareInputMethodIdForTesting( | |
| 53 input_method_id); | |
| 54 } | 57 } |
| 55 | 58 |
| 56 protected: | 59 protected: |
| 57 scoped_ptr<InputMethodManagerImpl> manager_; | 60 scoped_ptr<InputMethodManagerImpl> manager_; |
| 61 MockInputMethodDelegate* delegate_; |
| 58 MockIBusController* controller_; | 62 MockIBusController* controller_; |
| 59 MockCandidateWindowController* candidate_window_controller_; | 63 MockCandidateWindowController* candidate_window_controller_; |
| 60 MockXKeyboard* xkeyboard_; | 64 MockXKeyboard* xkeyboard_; |
| 61 | 65 |
| 62 private: | 66 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); | 67 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImplTest); |
| 64 }; | 68 }; |
| 65 | 69 |
| 66 class TestObserver : public InputMethodManager::Observer { | 70 class TestObserver : public InputMethodManager::Observer { |
| 67 public: | 71 public: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 DISALLOW_COPY_AND_ASSIGN(TestCandidateWindowObserver); | 117 DISALLOW_COPY_AND_ASSIGN(TestCandidateWindowObserver); |
| 114 }; | 118 }; |
| 115 | 119 |
| 116 } // namespace | 120 } // namespace |
| 117 | 121 |
| 118 TEST_F(InputMethodManagerImplTest, TestGetXKeyboard) { | 122 TEST_F(InputMethodManagerImplTest, TestGetXKeyboard) { |
| 119 EXPECT_TRUE(manager_->GetXKeyboard()); | 123 EXPECT_TRUE(manager_->GetXKeyboard()); |
| 120 EXPECT_EQ(xkeyboard_, manager_->GetXKeyboard()); | 124 EXPECT_EQ(xkeyboard_, manager_->GetXKeyboard()); |
| 121 } | 125 } |
| 122 | 126 |
| 123 TEST_F(InputMethodManagerImplTest, TestGetInputMethodUtil) { | |
| 124 EXPECT_TRUE(manager_->GetInputMethodUtil()); | |
| 125 SetHardwareKeyboardLayout("xkb:fr::fra"); // check this does not crash. | |
| 126 } | |
| 127 | |
| 128 TEST_F(InputMethodManagerImplTest, TestCandidateWindowObserver) { | 127 TEST_F(InputMethodManagerImplTest, TestCandidateWindowObserver) { |
| 129 TestCandidateWindowObserver observer; | 128 TestCandidateWindowObserver observer; |
| 130 candidate_window_controller_->NotifyCandidateWindowOpened(); // nop | 129 candidate_window_controller_->NotifyCandidateWindowOpened(); // nop |
| 131 candidate_window_controller_->NotifyCandidateWindowClosed(); // nop | 130 candidate_window_controller_->NotifyCandidateWindowClosed(); // nop |
| 132 manager_->AddCandidateWindowObserver(&observer); | 131 manager_->AddCandidateWindowObserver(&observer); |
| 133 candidate_window_controller_->NotifyCandidateWindowOpened(); | 132 candidate_window_controller_->NotifyCandidateWindowOpened(); |
| 134 EXPECT_EQ(1, observer.candidate_window_opened_count_); | 133 EXPECT_EQ(1, observer.candidate_window_opened_count_); |
| 135 candidate_window_controller_->NotifyCandidateWindowClosed(); | 134 candidate_window_controller_->NotifyCandidateWindowClosed(); |
| 136 EXPECT_EQ(1, observer.candidate_window_closed_count_); | 135 EXPECT_EQ(1, observer.candidate_window_closed_count_); |
| 137 candidate_window_controller_->NotifyCandidateWindowOpened(); | 136 candidate_window_controller_->NotifyCandidateWindowOpened(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 213 |
| 215 // For http://crbug.com/19655#c11 - (5) | 214 // For http://crbug.com/19655#c11 - (5) |
| 216 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. | 215 // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. |
| 217 manager_->EnableLayouts("ja", ""); // Japanese | 216 manager_->EnableLayouts("ja", ""); // Japanese |
| 218 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 217 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 219 EXPECT_EQ(0, controller_->start_count_); | 218 EXPECT_EQ(0, controller_->start_count_); |
| 220 } | 219 } |
| 221 | 220 |
| 222 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { | 221 TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { |
| 223 // The physical layout is French. | 222 // The physical layout is French. |
| 224 SetHardwareKeyboardLayout("xkb:fr::fra"); | 223 delegate_->set_hardware_keyboard_layout("xkb:fr::fra"); |
| 225 manager_->EnableLayouts("en-US", ""); | 224 manager_->EnableLayouts("en-US", ""); |
| 226 EXPECT_EQ(6U, manager_->GetNumActiveInputMethods()); // 5 + French | 225 EXPECT_EQ(6U, manager_->GetNumActiveInputMethods()); // 5 + French |
| 227 // The physical layout is Japanese. | 226 // The physical layout is Japanese. |
| 228 SetHardwareKeyboardLayout("xkb:jp::jpn"); | 227 delegate_->set_hardware_keyboard_layout("xkb:jp::jpn"); |
| 229 manager_->EnableLayouts("ja", ""); | 228 manager_->EnableLayouts("ja", ""); |
| 230 // "xkb:us::eng" is not needed, hence 1. | 229 // "xkb:us::eng" is not needed, hence 1. |
| 231 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); | 230 EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); |
| 232 } | 231 } |
| 233 | 232 |
| 234 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { | 233 TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { |
| 235 manager_->EnableLayouts("ko", ""); // Korean | 234 manager_->EnableLayouts("ko", ""); // Korean |
| 236 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); | 235 EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); |
| 237 scoped_ptr<InputMethodDescriptors> methods( | 236 scoped_ptr<InputMethodDescriptors> methods( |
| 238 manager_->GetActiveInputMethods()); | 237 manager_->GetActiveInputMethods()); |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 EXPECT_EQ("mozc", controller_->change_input_method_id_); | 984 EXPECT_EQ("mozc", controller_->change_input_method_id_); |
| 986 EXPECT_EQ(1, controller_->reset_count_); | 985 EXPECT_EQ(1, controller_->reset_count_); |
| 987 manager_->ChangeInputMethod("xkb:us::eng"); | 986 manager_->ChangeInputMethod("xkb:us::eng"); |
| 988 EXPECT_EQ(2, controller_->change_input_method_count_); | 987 EXPECT_EQ(2, controller_->change_input_method_count_); |
| 989 EXPECT_EQ("mozc", controller_->change_input_method_id_); | 988 EXPECT_EQ("mozc", controller_->change_input_method_id_); |
| 990 EXPECT_EQ(1, controller_->reset_count_); | 989 EXPECT_EQ(1, controller_->reset_count_); |
| 991 } | 990 } |
| 992 | 991 |
| 993 } // namespace input_method | 992 } // namespace input_method |
| 994 } // namespace chromeos | 993 } // namespace chromeos |
| OLD | NEW |