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_client.h" | 5 #include "chromeos/dbus/ibus/ibus_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chromeos/dbus/ibus/ibus_constants.h" | 10 #include "chromeos/dbus/ibus/ibus_constants.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 | 131 |
132 protected: | 132 protected: |
133 virtual void SetUp() OVERRIDE { | 133 virtual void SetUp() OVERRIDE { |
134 dbus::Bus::Options options; | 134 dbus::Bus::Options options; |
135 mock_bus_ = new dbus::MockBus(options); | 135 mock_bus_ = new dbus::MockBus(options); |
136 mock_proxy_ = new dbus::MockObjectProxy(mock_bus_.get(), | 136 mock_proxy_ = new dbus::MockObjectProxy(mock_bus_.get(), |
137 ibus::kServiceName, | 137 ibus::kServiceName, |
138 dbus::ObjectPath( | 138 dbus::ObjectPath( |
139 ibus::bus::kServicePath)); | 139 ibus::bus::kServicePath)); |
140 EXPECT_CALL(*mock_bus_, GetObjectProxy(ibus::kServiceName, | 140 EXPECT_CALL(*mock_bus_.get(), |
141 dbus::ObjectPath( | 141 GetObjectProxy(ibus::kServiceName, |
142 ibus::bus::kServicePath))) | 142 dbus::ObjectPath(ibus::bus::kServicePath))) |
143 .WillOnce(Return(mock_proxy_.get())); | 143 .WillOnce(Return(mock_proxy_.get())); |
144 | 144 |
145 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()); | 145 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()); |
146 client_.reset(IBusClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, | 146 client_.reset( |
147 mock_bus_)); | 147 IBusClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, mock_bus_.get())); |
148 } | 148 } |
149 | 149 |
150 virtual void TearDown() OVERRIDE { | 150 virtual void TearDown() OVERRIDE { |
151 mock_bus_->ShutdownAndBlock(); | 151 mock_bus_->ShutdownAndBlock(); |
152 } | 152 } |
153 | 153 |
154 // The IBus client to be tested. | 154 // The IBus client to be tested. |
155 scoped_ptr<IBusClient> client_; | 155 scoped_ptr<IBusClient> client_; |
156 | 156 |
157 // A message loop to emulate asynchronous behavior. | 157 // A message loop to emulate asynchronous behavior. |
158 base::MessageLoop message_loop_; | 158 base::MessageLoop message_loop_; |
159 scoped_refptr<dbus::MockBus> mock_bus_; | 159 scoped_refptr<dbus::MockBus> mock_bus_; |
160 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; | 160 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; |
161 | 161 |
162 // Response returned by mock methods. | 162 // Response returned by mock methods. |
163 dbus::Response* response_; | 163 dbus::Response* response_; |
164 dbus::ErrorResponse* error_response_; | 164 dbus::ErrorResponse* error_response_; |
165 }; | 165 }; |
166 | 166 |
167 TEST_F(IBusClientTest, CreateInputContextTest) { | 167 TEST_F(IBusClientTest, CreateInputContextTest) { |
168 // Set expectations. | 168 // Set expectations. |
169 const dbus::ObjectPath kInputContextObjectPath = | 169 const dbus::ObjectPath kInputContextObjectPath = |
170 dbus::ObjectPath("/some/object/path"); | 170 dbus::ObjectPath("/some/object/path"); |
171 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 171 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
172 .WillOnce(Invoke(this, &IBusClientTest::OnCreateInputContext)); | 172 .WillOnce(Invoke(this, &IBusClientTest::OnCreateInputContext)); |
173 MockCreateInputContextCallback callback; | 173 MockCreateInputContextCallback callback; |
174 EXPECT_CALL(callback, Run(kInputContextObjectPath)); | 174 EXPECT_CALL(callback, Run(kInputContextObjectPath)); |
175 MockErrorCallback error_callback; | 175 MockErrorCallback error_callback; |
176 EXPECT_CALL(error_callback, Run()).Times(0); | 176 EXPECT_CALL(error_callback, Run()).Times(0); |
177 | 177 |
178 // Create response. | 178 // Create response. |
179 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 179 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
180 dbus::MessageWriter writer(response.get()); | 180 dbus::MessageWriter writer(response.get()); |
181 writer.AppendObjectPath(kInputContextObjectPath); | 181 writer.AppendObjectPath(kInputContextObjectPath); |
182 response_ = response.get(); | 182 response_ = response.get(); |
183 | 183 |
184 // Call CreateInputContext. | 184 // Call CreateInputContext. |
185 client_->CreateInputContext( | 185 client_->CreateInputContext( |
186 kClientName, | 186 kClientName, |
187 base::Bind(&MockCreateInputContextCallback::Run, | 187 base::Bind(&MockCreateInputContextCallback::Run, |
188 base::Unretained(&callback)), | 188 base::Unretained(&callback)), |
189 base::Bind(&MockErrorCallback::Run, | 189 base::Bind(&MockErrorCallback::Run, |
190 base::Unretained(&error_callback))); | 190 base::Unretained(&error_callback))); |
191 | 191 |
192 // Run the message loop. | 192 // Run the message loop. |
193 message_loop_.RunUntilIdle(); | 193 message_loop_.RunUntilIdle(); |
194 } | 194 } |
195 | 195 |
196 TEST_F(IBusClientTest, CreateInputContext_NullResponseFail) { | 196 TEST_F(IBusClientTest, CreateInputContext_NullResponseFail) { |
197 // Set expectations. | 197 // Set expectations. |
198 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 198 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
199 .WillOnce(Invoke(this, &IBusClientTest::OnCreateInputContext)); | 199 .WillOnce(Invoke(this, &IBusClientTest::OnCreateInputContext)); |
200 MockCreateInputContextCallback callback; | 200 MockCreateInputContextCallback callback; |
201 EXPECT_CALL(callback, Run(_)).Times(0); | 201 EXPECT_CALL(callback, Run(_)).Times(0); |
202 MockErrorCallback error_callback; | 202 MockErrorCallback error_callback; |
203 EXPECT_CALL(error_callback, Run()); | 203 EXPECT_CALL(error_callback, Run()); |
204 | 204 |
205 // Set NULL response. | 205 // Set NULL response. |
206 response_ = NULL; | 206 response_ = NULL; |
207 | 207 |
208 // Call CreateInputContext. | 208 // Call CreateInputContext. |
209 client_->CreateInputContext( | 209 client_->CreateInputContext( |
210 kClientName, | 210 kClientName, |
211 base::Bind(&MockCreateInputContextCallback::Run, | 211 base::Bind(&MockCreateInputContextCallback::Run, |
212 base::Unretained(&callback)), | 212 base::Unretained(&callback)), |
213 base::Bind(&MockErrorCallback::Run, | 213 base::Bind(&MockErrorCallback::Run, |
214 base::Unretained(&error_callback))); | 214 base::Unretained(&error_callback))); |
215 | 215 |
216 // Run the message loop. | 216 // Run the message loop. |
217 message_loop_.RunUntilIdle(); | 217 message_loop_.RunUntilIdle(); |
218 } | 218 } |
219 | 219 |
220 TEST_F(IBusClientTest, CreateInputContext_InvalidResponseFail) { | 220 TEST_F(IBusClientTest, CreateInputContext_InvalidResponseFail) { |
221 // Set expectations. | 221 // Set expectations. |
222 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 222 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
223 .WillOnce(Invoke(this, &IBusClientTest::OnCreateInputContext)); | 223 .WillOnce(Invoke(this, &IBusClientTest::OnCreateInputContext)); |
224 MockCreateInputContextCallback callback; | 224 MockCreateInputContextCallback callback; |
225 EXPECT_CALL(callback, Run(_)).Times(0); | 225 EXPECT_CALL(callback, Run(_)).Times(0); |
226 MockErrorCallback error_callback; | 226 MockErrorCallback error_callback; |
227 EXPECT_CALL(error_callback, Run()); | 227 EXPECT_CALL(error_callback, Run()); |
228 | 228 |
229 // Create invalid(empty) response. | 229 // Create invalid(empty) response. |
230 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 230 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
231 response_ = response.get(); | 231 response_ = response.get(); |
232 | 232 |
233 // Call CreateInputContext. | 233 // Call CreateInputContext. |
234 client_->CreateInputContext( | 234 client_->CreateInputContext( |
235 kClientName, | 235 kClientName, |
236 base::Bind(&MockCreateInputContextCallback::Run, | 236 base::Bind(&MockCreateInputContextCallback::Run, |
237 base::Unretained(&callback)), | 237 base::Unretained(&callback)), |
238 base::Bind(&MockErrorCallback::Run, | 238 base::Bind(&MockErrorCallback::Run, |
239 base::Unretained(&error_callback))); | 239 base::Unretained(&error_callback))); |
240 | 240 |
241 // Run the message loop. | 241 // Run the message loop. |
242 message_loop_.RunUntilIdle(); | 242 message_loop_.RunUntilIdle(); |
243 } | 243 } |
244 | 244 |
245 TEST_F(IBusClientTest, CreateInputContext_MethodCallFail) { | 245 TEST_F(IBusClientTest, CreateInputContext_MethodCallFail) { |
246 // Set expectations | 246 // Set expectations |
247 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 247 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
248 .WillOnce(Invoke(this, &IBusClientTest::OnCreateInputContextFail)); | 248 .WillOnce(Invoke(this, &IBusClientTest::OnCreateInputContextFail)); |
249 MockCreateInputContextCallback callback; | 249 MockCreateInputContextCallback callback; |
250 EXPECT_CALL(callback, Run(_)).Times(0); | 250 EXPECT_CALL(callback, Run(_)).Times(0); |
251 MockErrorCallback error_callback; | 251 MockErrorCallback error_callback; |
252 EXPECT_CALL(error_callback, Run()); | 252 EXPECT_CALL(error_callback, Run()); |
253 | 253 |
254 // The error response is not used in CreateInputContext. | 254 // The error response is not used in CreateInputContext. |
255 error_response_ = NULL; | 255 error_response_ = NULL; |
256 | 256 |
257 // Call CreateInputContext. | 257 // Call CreateInputContext. |
258 client_->CreateInputContext( | 258 client_->CreateInputContext( |
259 kClientName, | 259 kClientName, |
260 base::Bind(&MockCreateInputContextCallback::Run, | 260 base::Bind(&MockCreateInputContextCallback::Run, |
261 base::Unretained(&callback)), | 261 base::Unretained(&callback)), |
262 base::Bind(&MockErrorCallback::Run, | 262 base::Bind(&MockErrorCallback::Run, |
263 base::Unretained(&error_callback))); | 263 base::Unretained(&error_callback))); |
264 | 264 |
265 // Run the message loop. | 265 // Run the message loop. |
266 message_loop_.RunUntilIdle(); | 266 message_loop_.RunUntilIdle(); |
267 } | 267 } |
268 | 268 |
269 TEST_F(IBusClientTest, SetGlobalEngineTest) { | 269 TEST_F(IBusClientTest, SetGlobalEngineTest) { |
270 // Set expectations | 270 // Set expectations |
271 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 271 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
272 .WillOnce(Invoke(this, &IBusClientTest::OnSetGlobalEngine)); | 272 .WillOnce(Invoke(this, &IBusClientTest::OnSetGlobalEngine)); |
273 MockErrorCallback error_callback; | 273 MockErrorCallback error_callback; |
274 EXPECT_CALL(error_callback, Run()).Times(0); | 274 EXPECT_CALL(error_callback, Run()).Times(0); |
275 | 275 |
276 // Create empty response. | 276 // Create empty response. |
277 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 277 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
278 response_ = response.get(); | 278 response_ = response.get(); |
279 | 279 |
280 // The error response is not used in SetGLobalEngine. | 280 // The error response is not used in SetGLobalEngine. |
281 error_response_ = NULL; | 281 error_response_ = NULL; |
282 | 282 |
283 // Call CreateInputContext. | 283 // Call CreateInputContext. |
284 client_->SetGlobalEngine( | 284 client_->SetGlobalEngine( |
285 kEngineName, | 285 kEngineName, |
286 base::Bind(&MockErrorCallback::Run, | 286 base::Bind(&MockErrorCallback::Run, |
287 base::Unretained(&error_callback))); | 287 base::Unretained(&error_callback))); |
288 | 288 |
289 // Run the message loop. | 289 // Run the message loop. |
290 message_loop_.RunUntilIdle(); | 290 message_loop_.RunUntilIdle(); |
291 } | 291 } |
292 | 292 |
293 TEST_F(IBusClientTest, SetGlobalEngineTest_InvalidResponse) { | 293 TEST_F(IBusClientTest, SetGlobalEngineTest_InvalidResponse) { |
294 // Set expectations | 294 // Set expectations |
295 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 295 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
296 .WillOnce(Invoke(this, &IBusClientTest::OnSetGlobalEngineFail)); | 296 .WillOnce(Invoke(this, &IBusClientTest::OnSetGlobalEngineFail)); |
297 MockErrorCallback error_callback; | 297 MockErrorCallback error_callback; |
298 EXPECT_CALL(error_callback, Run()); | 298 EXPECT_CALL(error_callback, Run()); |
299 | 299 |
300 // Set invalid response. | 300 // Set invalid response. |
301 response_ = NULL; | 301 response_ = NULL; |
302 | 302 |
303 // The error response is not used in SetGLobalEngine. | 303 // The error response is not used in SetGLobalEngine. |
304 error_response_ = NULL; | 304 error_response_ = NULL; |
305 | 305 |
306 // Call CreateInputContext. | 306 // Call CreateInputContext. |
307 client_->SetGlobalEngine( | 307 client_->SetGlobalEngine( |
308 kEngineName, | 308 kEngineName, |
309 base::Bind(&MockErrorCallback::Run, | 309 base::Bind(&MockErrorCallback::Run, |
310 base::Unretained(&error_callback))); | 310 base::Unretained(&error_callback))); |
311 | 311 |
312 // Run the message loop. | 312 // Run the message loop. |
313 message_loop_.RunUntilIdle(); | 313 message_loop_.RunUntilIdle(); |
314 } | 314 } |
315 | 315 |
316 TEST_F(IBusClientTest, SetGlobalEngineTest_MethodCallFail) { | 316 TEST_F(IBusClientTest, SetGlobalEngineTest_MethodCallFail) { |
317 // Set expectations | 317 // Set expectations |
318 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 318 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
319 .WillOnce(Invoke(this, &IBusClientTest::OnSetGlobalEngineFail)); | 319 .WillOnce(Invoke(this, &IBusClientTest::OnSetGlobalEngineFail)); |
320 MockErrorCallback error_callback; | 320 MockErrorCallback error_callback; |
321 EXPECT_CALL(error_callback, Run()); | 321 EXPECT_CALL(error_callback, Run()); |
322 | 322 |
323 // Create empty response. | 323 // Create empty response. |
324 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 324 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
325 response_ = response.get(); | 325 response_ = response.get(); |
326 | 326 |
327 // The error response is not used in SetGLobalEngine. | 327 // The error response is not used in SetGLobalEngine. |
328 error_response_ = NULL; | 328 error_response_ = NULL; |
329 | 329 |
330 // Call CreateInputContext. | 330 // Call CreateInputContext. |
331 client_->SetGlobalEngine( | 331 client_->SetGlobalEngine( |
332 kEngineName, | 332 kEngineName, |
333 base::Bind(&MockErrorCallback::Run, | 333 base::Bind(&MockErrorCallback::Run, |
334 base::Unretained(&error_callback))); | 334 base::Unretained(&error_callback))); |
335 | 335 |
336 // Run the message loop. | 336 // Run the message loop. |
337 message_loop_.RunUntilIdle(); | 337 message_loop_.RunUntilIdle(); |
338 } | 338 } |
339 | 339 |
340 TEST_F(IBusClientTest, ExitTest) { | 340 TEST_F(IBusClientTest, ExitTest) { |
341 // Set expectations | 341 // Set expectations |
342 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 342 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
343 .WillOnce(Invoke(this, &IBusClientTest::OnExit)); | 343 .WillOnce(Invoke(this, &IBusClientTest::OnExit)); |
344 MockErrorCallback error_callback; | 344 MockErrorCallback error_callback; |
345 EXPECT_CALL(error_callback, Run()).Times(0); | 345 EXPECT_CALL(error_callback, Run()).Times(0); |
346 | 346 |
347 // Create empty response. | 347 // Create empty response. |
348 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 348 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
349 response_ = response.get(); | 349 response_ = response.get(); |
350 | 350 |
351 // The error response is not used in SetGLobalEngine. | 351 // The error response is not used in SetGLobalEngine. |
352 error_response_ = NULL; | 352 error_response_ = NULL; |
353 | 353 |
354 // Call CreateInputContext. | 354 // Call CreateInputContext. |
355 client_->Exit( | 355 client_->Exit( |
356 IBusClient::RESTART_IBUS_DAEMON, | 356 IBusClient::RESTART_IBUS_DAEMON, |
357 base::Bind(&MockErrorCallback::Run, | 357 base::Bind(&MockErrorCallback::Run, |
358 base::Unretained(&error_callback))); | 358 base::Unretained(&error_callback))); |
359 | 359 |
360 // Run the message loop. | 360 // Run the message loop. |
361 message_loop_.RunUntilIdle(); | 361 message_loop_.RunUntilIdle(); |
362 } | 362 } |
363 | 363 |
364 TEST_F(IBusClientTest, ExitTest_InvalidResponse) { | 364 TEST_F(IBusClientTest, ExitTest_InvalidResponse) { |
365 // Set expectations | 365 // Set expectations |
366 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 366 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
367 .WillOnce(Invoke(this, &IBusClientTest::OnExit)); | 367 .WillOnce(Invoke(this, &IBusClientTest::OnExit)); |
368 MockErrorCallback error_callback; | 368 MockErrorCallback error_callback; |
369 EXPECT_CALL(error_callback, Run()); | 369 EXPECT_CALL(error_callback, Run()); |
370 | 370 |
371 // Set invalid response. | 371 // Set invalid response. |
372 response_ = NULL; | 372 response_ = NULL; |
373 | 373 |
374 // The error response is not used in SetGLobalEngine. | 374 // The error response is not used in SetGLobalEngine. |
375 error_response_ = NULL; | 375 error_response_ = NULL; |
376 | 376 |
377 // Call CreateInputContext. | 377 // Call CreateInputContext. |
378 client_->Exit( | 378 client_->Exit( |
379 IBusClient::RESTART_IBUS_DAEMON, | 379 IBusClient::RESTART_IBUS_DAEMON, |
380 base::Bind(&MockErrorCallback::Run, | 380 base::Bind(&MockErrorCallback::Run, |
381 base::Unretained(&error_callback))); | 381 base::Unretained(&error_callback))); |
382 | 382 |
383 // Run the message loop. | 383 // Run the message loop. |
384 message_loop_.RunUntilIdle(); | 384 message_loop_.RunUntilIdle(); |
385 } | 385 } |
386 | 386 |
387 TEST_F(IBusClientTest, ExitTest_MethodCallFail) { | 387 TEST_F(IBusClientTest, ExitTest_MethodCallFail) { |
388 // Set expectations | 388 // Set expectations |
389 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) | 389 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) |
390 .WillOnce(Invoke(this, &IBusClientTest::OnExitFail)); | 390 .WillOnce(Invoke(this, &IBusClientTest::OnExitFail)); |
391 MockErrorCallback error_callback; | 391 MockErrorCallback error_callback; |
392 EXPECT_CALL(error_callback, Run()); | 392 EXPECT_CALL(error_callback, Run()); |
393 | 393 |
394 // Create empty response. | 394 // Create empty response. |
395 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 395 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
396 response_ = response.get(); | 396 response_ = response.get(); |
397 | 397 |
398 // The error response is not used in SetGLobalEngine. | 398 // The error response is not used in SetGLobalEngine. |
399 error_response_ = NULL; | 399 error_response_ = NULL; |
400 | 400 |
401 // Call CreateInputContext. | 401 // Call CreateInputContext. |
402 client_->Exit( | 402 client_->Exit( |
403 IBusClient::RESTART_IBUS_DAEMON, | 403 IBusClient::RESTART_IBUS_DAEMON, |
404 base::Bind(&MockErrorCallback::Run, | 404 base::Bind(&MockErrorCallback::Run, |
405 base::Unretained(&error_callback))); | 405 base::Unretained(&error_callback))); |
406 | 406 |
407 // Run the message loop. | 407 // Run the message loop. |
408 message_loop_.RunUntilIdle(); | 408 message_loop_.RunUntilIdle(); |
409 } | 409 } |
410 | 410 |
411 } // namespace chromeos | 411 } // namespace chromeos |
OLD | NEW |