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 "chromeos/dbus/ibus/ibus_engine_factory_service.h" | 5 #include "chromeos/dbus/ibus/ibus_engine_factory_service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chromeos/dbus/ibus/ibus_constants.h" | 10 #include "chromeos/dbus/ibus/ibus_constants.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 dbus::ObjectPath path_; | 51 dbus::ObjectPath path_; |
52 MessageLoop* message_loop_; | 52 MessageLoop* message_loop_; |
53 | 53 |
54 DISALLOW_COPY_AND_ASSIGN(AsynchronousCreateEngineHandler); | 54 DISALLOW_COPY_AND_ASSIGN(AsynchronousCreateEngineHandler); |
55 }; | 55 }; |
56 | 56 |
57 class MockCreateEngineResponseSender { | 57 class MockCreateEngineResponseSender { |
58 public: | 58 public: |
59 explicit MockCreateEngineResponseSender(const dbus::ObjectPath& expected_path) | 59 explicit MockCreateEngineResponseSender(const dbus::ObjectPath& expected_path) |
60 : expected_path_(expected_path) {} | 60 : expected_path_(expected_path) {} |
61 MOCK_METHOD1(Run, void(dbus::Response*)); | 61 // GMock doesn't support mocking methods which take scoped_ptr<>. |
| 62 MOCK_METHOD1(MockRun, void(dbus::Response*)); |
| 63 void Run(scoped_ptr<dbus::Response> response) { |
| 64 MockRun(response.get()); |
| 65 } |
62 | 66 |
63 // Checks the given |response| meets expectation for the CreateEngine method. | 67 // Checks the given |response| meets expectation for the CreateEngine method. |
64 void CheckCreateEngineResponse(dbus::Response* response) { | 68 void CheckCreateEngineResponsePtr(dbus::Response* response) { |
65 scoped_ptr<dbus::Response> response_deleter(response); | |
66 dbus::MessageReader reader(response); | 69 dbus::MessageReader reader(response); |
67 dbus::ObjectPath actual_path; | 70 dbus::ObjectPath actual_path; |
68 ASSERT_TRUE(reader.PopObjectPath(&actual_path)); | 71 ASSERT_TRUE(reader.PopObjectPath(&actual_path)); |
69 EXPECT_EQ(expected_path_, actual_path); | 72 EXPECT_EQ(expected_path_, actual_path); |
70 } | 73 } |
| 74 void CheckCreateEngineResponse(scoped_ptr<dbus::Response> response) { |
| 75 CheckCreateEngineResponsePtr(response.get()); |
| 76 } |
71 | 77 |
72 private: | 78 private: |
73 dbus::ObjectPath expected_path_; | 79 dbus::ObjectPath expected_path_; |
74 }; | 80 }; |
75 | 81 |
76 class IBusEngineFactoryServiceTest : public testing::Test { | 82 class IBusEngineFactoryServiceTest : public testing::Test { |
77 public: | 83 public: |
78 IBusEngineFactoryServiceTest() {} | 84 IBusEngineFactoryServiceTest() {} |
79 | 85 |
80 virtual void SetUp() OVERRIDE { | 86 virtual void SetUp() OVERRIDE { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 method_name, | 142 method_name, |
137 success)); | 143 success)); |
138 } | 144 } |
139 }; | 145 }; |
140 | 146 |
141 TEST_F(IBusEngineFactoryServiceTest, SyncCreateEngineTest) { | 147 TEST_F(IBusEngineFactoryServiceTest, SyncCreateEngineTest) { |
142 // Set expectations. | 148 // Set expectations. |
143 const char kSampleEngine[] = "Sample Engine"; | 149 const char kSampleEngine[] = "Sample Engine"; |
144 const dbus::ObjectPath kObjectPath("/org/freedesktop/IBus/Engine/10"); | 150 const dbus::ObjectPath kObjectPath("/org/freedesktop/IBus/Engine/10"); |
145 MockCreateEngineResponseSender response_sender(kObjectPath); | 151 MockCreateEngineResponseSender response_sender(kObjectPath); |
146 EXPECT_CALL(response_sender, Run(_)) | 152 EXPECT_CALL(response_sender, MockRun(_)) |
147 .WillOnce( | 153 .WillOnce( |
148 Invoke(&response_sender, | 154 Invoke(&response_sender, |
149 &MockCreateEngineResponseSender::CheckCreateEngineResponse)); | 155 &MockCreateEngineResponseSender:: |
| 156 CheckCreateEngineResponsePtr)); |
150 | 157 |
151 SynchronousCreateEngineHandler handler(kObjectPath); | 158 SynchronousCreateEngineHandler handler(kObjectPath); |
152 // Set handler expectations. | 159 // Set handler expectations. |
153 service_->SetCreateEngineHandler( | 160 service_->SetCreateEngineHandler( |
154 kSampleEngine, | 161 kSampleEngine, |
155 base::Bind(&SynchronousCreateEngineHandler::Run, | 162 base::Bind(&SynchronousCreateEngineHandler::Run, |
156 base::Unretained(&handler))); | 163 base::Unretained(&handler))); |
157 message_loop_.RunUntilIdle(); | 164 message_loop_.RunUntilIdle(); |
158 | 165 |
159 // Invoke method call. | 166 // Invoke method call. |
(...skipping 18 matching lines...) Expand all Loading... |
178 base::Bind(&MockCreateEngineResponseSender::CheckCreateEngineResponse, | 185 base::Bind(&MockCreateEngineResponseSender::CheckCreateEngineResponse, |
179 base::Unretained(&response_sender))); | 186 base::Unretained(&response_sender))); |
180 message_loop_.RunUntilIdle(); | 187 message_loop_.RunUntilIdle(); |
181 } | 188 } |
182 | 189 |
183 TEST_F(IBusEngineFactoryServiceTest, AsyncCreateEngineTest) { | 190 TEST_F(IBusEngineFactoryServiceTest, AsyncCreateEngineTest) { |
184 // Set expectations. | 191 // Set expectations. |
185 const char kSampleEngine[] = "Sample Engine"; | 192 const char kSampleEngine[] = "Sample Engine"; |
186 const dbus::ObjectPath kObjectPath("/org/freedesktop/IBus/Engine/10"); | 193 const dbus::ObjectPath kObjectPath("/org/freedesktop/IBus/Engine/10"); |
187 MockCreateEngineResponseSender response_sender(kObjectPath); | 194 MockCreateEngineResponseSender response_sender(kObjectPath); |
188 EXPECT_CALL(response_sender, Run(_)) | 195 EXPECT_CALL(response_sender, MockRun(_)) |
189 .WillOnce( | 196 .WillOnce( |
190 Invoke(&response_sender, | 197 Invoke(&response_sender, |
191 &MockCreateEngineResponseSender::CheckCreateEngineResponse)); | 198 &MockCreateEngineResponseSender:: |
| 199 CheckCreateEngineResponsePtr)); |
192 | 200 |
193 AsynchronousCreateEngineHandler handler(kObjectPath, &message_loop_); | 201 AsynchronousCreateEngineHandler handler(kObjectPath, &message_loop_); |
194 // Set handler expectations. | 202 // Set handler expectations. |
195 service_->SetCreateEngineHandler( | 203 service_->SetCreateEngineHandler( |
196 kSampleEngine, | 204 kSampleEngine, |
197 base::Bind(&AsynchronousCreateEngineHandler::Run, | 205 base::Bind(&AsynchronousCreateEngineHandler::Run, |
198 base::Unretained(&handler))); | 206 base::Unretained(&handler))); |
199 message_loop_.RunUntilIdle(); | 207 message_loop_.RunUntilIdle(); |
200 | 208 |
201 // Invoke method call. | 209 // Invoke method call. |
(...skipping 14 matching lines...) Expand all Loading... |
216 // Unset the handler so expect not calling handler. | 224 // Unset the handler so expect not calling handler. |
217 service_->UnsetCreateEngineHandler(kSampleEngine); | 225 service_->UnsetCreateEngineHandler(kSampleEngine); |
218 method_exported_map_[ibus::engine_factory::kCreateEngineMethod].Run( | 226 method_exported_map_[ibus::engine_factory::kCreateEngineMethod].Run( |
219 &method_call, | 227 &method_call, |
220 base::Bind(&MockCreateEngineResponseSender::CheckCreateEngineResponse, | 228 base::Bind(&MockCreateEngineResponseSender::CheckCreateEngineResponse, |
221 base::Unretained(&response_sender))); | 229 base::Unretained(&response_sender))); |
222 message_loop_.RunUntilIdle(); | 230 message_loop_.RunUntilIdle(); |
223 } | 231 } |
224 | 232 |
225 } // namespace chromeos | 233 } // namespace chromeos |
OLD | NEW |