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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/browser/chromeos/input_method/ibus_controller_impl.h" | 6 #include "chrome/browser/chromeos/input_method/ibus_controller_impl.h" |
7 #include "chromeos/ime/input_method_property.h" | 7 #include "chromeos/ime/input_method_property.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace chromeos { | 10 namespace chromeos { |
11 namespace input_method { | 11 namespace input_method { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 bool FindAndUpdateProperty(const InputMethodProperty& new_prop, | 15 bool FindAndUpdateProperty(const InputMethodProperty& new_prop, |
16 InputMethodPropertyList* prop_list) { | 16 InputMethodPropertyList* prop_list) { |
17 return IBusControllerImpl::FindAndUpdatePropertyForTesting(new_prop, | 17 return IBusControllerImpl::FindAndUpdatePropertyForTesting(new_prop, |
18 prop_list); | 18 prop_list); |
19 } | 19 } |
20 | 20 |
| 21 // A mock class for testing AddObserver() and RemoveObserver() methods |
| 22 // in IBusControllerImpl. |
| 23 class TestIBusController : public IBusControllerImpl { |
| 24 public: |
| 25 TestIBusController() { |
| 26 } |
| 27 |
| 28 virtual ~TestIBusController() { |
| 29 } |
| 30 |
| 31 bool HasObservers() const { |
| 32 return observers_.might_have_observers(); |
| 33 } |
| 34 |
| 35 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(TestIBusController); |
| 37 }; |
| 38 |
| 39 class TestObserver : public IBusController::Observer { |
| 40 public: |
| 41 // IBusController::Observer overrides: |
| 42 virtual void PropertyChanged() OVERRIDE {} |
| 43 }; |
21 } // namespace | 44 } // namespace |
22 | 45 |
23 TEST(IBusControllerImplTest, TestFindAndUpdateProperty) { | 46 TEST(IBusControllerImplTest, TestFindAndUpdateProperty) { |
24 InputMethodPropertyList properties; | 47 InputMethodPropertyList properties; |
25 EXPECT_FALSE(FindAndUpdateProperty(InputMethodProperty(), &properties)); | 48 EXPECT_FALSE(FindAndUpdateProperty(InputMethodProperty(), &properties)); |
26 | 49 |
27 properties.push_back( | 50 properties.push_back( |
28 InputMethodProperty("key1", "label1", false, false)); | 51 InputMethodProperty("key1", "label1", false, false)); |
29 EXPECT_FALSE(FindAndUpdateProperty(InputMethodProperty(), &properties)); | 52 EXPECT_FALSE(FindAndUpdateProperty(InputMethodProperty(), &properties)); |
30 EXPECT_FALSE(FindAndUpdateProperty( | 53 EXPECT_FALSE(FindAndUpdateProperty( |
(...skipping 11 matching lines...) Expand all Loading... |
42 EXPECT_FALSE(FindAndUpdateProperty( | 65 EXPECT_FALSE(FindAndUpdateProperty( |
43 InputMethodProperty("keyX", "labelX", false, false), &properties)); | 66 InputMethodProperty("keyX", "labelX", false, false), &properties)); |
44 EXPECT_EQ(InputMethodProperty("key2", "label2", false, false), | 67 EXPECT_EQ(InputMethodProperty("key2", "label2", false, false), |
45 properties[1]); | 68 properties[1]); |
46 EXPECT_TRUE(FindAndUpdateProperty( | 69 EXPECT_TRUE(FindAndUpdateProperty( |
47 InputMethodProperty("key2", "labelZ", false, false), &properties)); | 70 InputMethodProperty("key2", "labelZ", false, false), &properties)); |
48 EXPECT_EQ(InputMethodProperty("key2", "labelZ", false, false), | 71 EXPECT_EQ(InputMethodProperty("key2", "labelZ", false, false), |
49 properties[1]); | 72 properties[1]); |
50 } | 73 } |
51 | 74 |
| 75 TEST(IBusControllerImplTest, TestAddRemoveObserver) { |
| 76 IBusBridge::Initialize(); |
| 77 { |
| 78 TestIBusController controller; |
| 79 TestObserver observer1; |
| 80 TestObserver observer2; |
| 81 TestObserver observer3; |
| 82 EXPECT_FALSE(controller.HasObservers()); |
| 83 controller.AddObserver(&observer1); |
| 84 EXPECT_TRUE(controller.HasObservers()); |
| 85 controller.AddObserver(&observer2); |
| 86 EXPECT_TRUE(controller.HasObservers()); |
| 87 controller.RemoveObserver(&observer3); // nop |
| 88 EXPECT_TRUE(controller.HasObservers()); |
| 89 controller.RemoveObserver(&observer1); |
| 90 EXPECT_TRUE(controller.HasObservers()); |
| 91 controller.RemoveObserver(&observer1); // nop |
| 92 EXPECT_TRUE(controller.HasObservers()); |
| 93 controller.RemoveObserver(&observer2); |
| 94 EXPECT_FALSE(controller.HasObservers()); |
| 95 } |
| 96 IBusBridge::Shutdown(); |
| 97 } |
| 98 |
| 99 TEST(IBusControllerImplTest, TestGetCurrentProperties) { |
| 100 IBusBridge::Initialize(); |
| 101 { |
| 102 IBusControllerImpl controller; |
| 103 EXPECT_EQ(0U, controller.GetCurrentProperties().size()); |
| 104 } |
| 105 IBusBridge::Shutdown(); |
| 106 } |
| 107 |
52 } // namespace input_method | 108 } // namespace input_method |
53 } // namespace chromeos | 109 } // namespace chromeos |
OLD | NEW |