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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 private: | 33 private: |
34 dbus::ObjectPath path_; | 34 dbus::ObjectPath path_; |
35 | 35 |
36 DISALLOW_COPY_AND_ASSIGN(SynchronousCreateEngineHandler); | 36 DISALLOW_COPY_AND_ASSIGN(SynchronousCreateEngineHandler); |
37 }; | 37 }; |
38 | 38 |
39 class AsynchronousCreateEngineHandler { | 39 class AsynchronousCreateEngineHandler { |
40 public: | 40 public: |
41 AsynchronousCreateEngineHandler(const dbus::ObjectPath& path, | 41 AsynchronousCreateEngineHandler(const dbus::ObjectPath& path, |
42 MessageLoop* message_loop) | 42 base::MessageLoop* message_loop) |
43 : path_(path), | 43 : path_(path), |
44 message_loop_(message_loop) {} | 44 message_loop_(message_loop) {} |
45 | 45 |
46 void Run(const IBusEngineFactoryService::CreateEngineResponseSender& sender) { | 46 void Run(const IBusEngineFactoryService::CreateEngineResponseSender& sender) { |
47 message_loop_->PostTask(FROM_HERE, base::Bind(sender, path_)); | 47 message_loop_->PostTask(FROM_HERE, base::Bind(sender, path_)); |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 dbus::ObjectPath path_; | 51 dbus::ObjectPath path_; |
52 MessageLoop* message_loop_; | 52 base::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 // GMock doesn't support mocking methods which take scoped_ptr<>. | 61 // GMock doesn't support mocking methods which take scoped_ptr<>. |
62 MOCK_METHOD1(MockRun, void(dbus::Response*)); | 62 MOCK_METHOD1(MockRun, void(dbus::Response*)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // The service to be tested. | 119 // The service to be tested. |
120 scoped_ptr<IBusEngineFactoryService> service_; | 120 scoped_ptr<IBusEngineFactoryService> service_; |
121 // The mock bus. | 121 // The mock bus. |
122 scoped_refptr<dbus::MockBus> mock_bus_; | 122 scoped_refptr<dbus::MockBus> mock_bus_; |
123 // The mock exported object. | 123 // The mock exported object. |
124 scoped_refptr<dbus::MockExportedObject> mock_exported_object_; | 124 scoped_refptr<dbus::MockExportedObject> mock_exported_object_; |
125 // The map from method name to method call handler. | 125 // The map from method name to method call handler. |
126 std::map<std::string, dbus::ExportedObject::MethodCallCallback> | 126 std::map<std::string, dbus::ExportedObject::MethodCallCallback> |
127 method_exported_map_; | 127 method_exported_map_; |
128 // A message loop to emulate asynchronous behavior. | 128 // A message loop to emulate asynchronous behavior. |
129 MessageLoop message_loop_; | 129 base::MessageLoop message_loop_; |
130 | 130 |
131 private: | 131 private: |
132 // Used to implement the method call exportation. | 132 // Used to implement the method call exportation. |
133 void OnMethodExported( | 133 void OnMethodExported( |
134 const std::string& interface_name, | 134 const std::string& interface_name, |
135 const std::string& method_name, | 135 const std::string& method_name, |
136 const dbus::ExportedObject::MethodCallCallback& method_callback, | 136 const dbus::ExportedObject::MethodCallCallback& method_callback, |
137 const dbus::ExportedObject::OnExportedCallback& on_exported_callback) { | 137 const dbus::ExportedObject::OnExportedCallback& on_exported_callback) { |
138 method_exported_map_[method_name] = method_callback; | 138 method_exported_map_[method_name] = method_callback; |
139 const bool success = true; | 139 const bool success = true; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // Unset the handler so expect not calling handler. | 224 // Unset the handler so expect not calling handler. |
225 service_->UnsetCreateEngineHandler(kSampleEngine); | 225 service_->UnsetCreateEngineHandler(kSampleEngine); |
226 method_exported_map_[ibus::engine_factory::kCreateEngineMethod].Run( | 226 method_exported_map_[ibus::engine_factory::kCreateEngineMethod].Run( |
227 &method_call, | 227 &method_call, |
228 base::Bind(&MockCreateEngineResponseSender::CheckCreateEngineResponse, | 228 base::Bind(&MockCreateEngineResponseSender::CheckCreateEngineResponse, |
229 base::Unretained(&response_sender))); | 229 base::Unretained(&response_sender))); |
230 message_loop_.RunUntilIdle(); | 230 message_loop_.RunUntilIdle(); |
231 } | 231 } |
232 | 232 |
233 } // namespace chromeos | 233 } // namespace chromeos |
OLD | NEW |