| 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 #ifndef CHROMEOS_DBUS_SHILL_CLIENT_UNITTEST_BASE_H_ | 5 #ifndef CHROMEOS_DBUS_SHILL_CLIENT_UNITTEST_BASE_H_ | 
| 6 #define CHROMEOS_DBUS_SHILL_CLIENT_UNITTEST_BASE_H_ | 6 #define CHROMEOS_DBUS_SHILL_CLIENT_UNITTEST_BASE_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" | 
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" | 
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" | 
| 13 #include "chromeos/dbus/dbus_method_call_status.h" | 13 #include "chromeos/dbus/dbus_method_call_status.h" | 
| 14 #include "chromeos/dbus/shill_client_helper.h" | 14 #include "chromeos/dbus/shill_client_helper.h" | 
| 15 #include "chromeos/dbus/shill_property_changed_observer.h" | 15 #include "chromeos/dbus/shill_property_changed_observer.h" | 
|  | 16 #include "chromeos/dbus/shill_third_party_vpn_observer.h" | 
| 16 #include "dbus/mock_bus.h" | 17 #include "dbus/mock_bus.h" | 
| 17 #include "dbus/mock_object_proxy.h" | 18 #include "dbus/mock_object_proxy.h" | 
| 18 #include "dbus/object_proxy.h" | 19 #include "dbus/object_proxy.h" | 
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" | 
| 20 | 21 | 
| 21 using ::testing::MatcherInterface; | 22 using ::testing::MatcherInterface; | 
| 22 using ::testing::MatchResultListener; | 23 using ::testing::MatchResultListener; | 
| 23 using ::testing::Matcher; | 24 using ::testing::Matcher; | 
| 24 using ::testing::MakeMatcher; | 25 using ::testing::MakeMatcher; | 
| 25 | 26 | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 90   // A mock PropertyChangedObserver that can be used to check expected values. | 91   // A mock PropertyChangedObserver that can be used to check expected values. | 
| 91   class MockPropertyChangeObserver | 92   class MockPropertyChangeObserver | 
| 92       : public ShillPropertyChangedObserver { | 93       : public ShillPropertyChangedObserver { | 
| 93    public: | 94    public: | 
| 94     MockPropertyChangeObserver(); | 95     MockPropertyChangeObserver(); | 
| 95     ~MockPropertyChangeObserver(); | 96     ~MockPropertyChangeObserver(); | 
| 96     MOCK_METHOD2(OnPropertyChanged, void(const std::string& name, | 97     MOCK_METHOD2(OnPropertyChanged, void(const std::string& name, | 
| 97                                          const base::Value& value)); | 98                                          const base::Value& value)); | 
| 98   }; | 99   }; | 
| 99 | 100 | 
|  | 101   class MockShillThirdPartyVpnObserver : public ShillThirdPartyVpnObserver { | 
|  | 102    public: | 
|  | 103     MockShillThirdPartyVpnObserver(); | 
|  | 104     ~MockShillThirdPartyVpnObserver(); | 
|  | 105     MOCK_METHOD2(OnPacketReceived, void(const uint8* data, size_t length)); | 
|  | 106     MOCK_METHOD1(OnPlatformMessage, void(uint32 message)); | 
|  | 107   }; | 
|  | 108 | 
| 100   explicit ShillClientUnittestBase(const std::string& interface_name, | 109   explicit ShillClientUnittestBase(const std::string& interface_name, | 
| 101                                       const dbus::ObjectPath& object_path); | 110                                       const dbus::ObjectPath& object_path); | 
| 102   virtual ~ShillClientUnittestBase(); | 111   virtual ~ShillClientUnittestBase(); | 
| 103 | 112 | 
| 104   virtual void SetUp() override; | 113   virtual void SetUp() override; | 
| 105   virtual void TearDown() override; | 114   virtual void TearDown() override; | 
| 106 | 115 | 
| 107  protected: | 116  protected: | 
| 108   // A callback to intercept and check the method call arguments. | 117   // A callback to intercept and check the method call arguments. | 
| 109   typedef base::Callback<void( | 118   typedef base::Callback<void( | 
| 110       dbus::MessageReader* reader)> ArgumentCheckCallback; | 119       dbus::MessageReader* reader)> ArgumentCheckCallback; | 
| 111 | 120 | 
| 112   // Sets expectations for called method name and arguments, and sets response. | 121   // Sets expectations for called method name and arguments, and sets response. | 
| 113   void PrepareForMethodCall(const std::string& method_name, | 122   void PrepareForMethodCall(const std::string& method_name, | 
| 114                             const ArgumentCheckCallback& argument_checker, | 123                             const ArgumentCheckCallback& argument_checker, | 
| 115                             dbus::Response* response); | 124                             dbus::Response* response); | 
| 116 | 125 | 
|  | 126   // Sends platform message signal to the tested client. | 
|  | 127   void SendPlatformMessageSignal(dbus::Signal* signal); | 
|  | 128 | 
|  | 129   // Sends packet received signal to the tested client. | 
|  | 130   void SendPacketReceievedSignal(dbus::Signal* signal); | 
|  | 131 | 
| 117   // Sends property changed signal to the tested client. | 132   // Sends property changed signal to the tested client. | 
| 118   void SendPropertyChangedSignal(dbus::Signal* signal); | 133   void SendPropertyChangedSignal(dbus::Signal* signal); | 
| 119 | 134 | 
| 120   // Checks the name and the value which are sent by PropertyChanged signal. | 135   // Checks the name and the value which are sent by PropertyChanged signal. | 
| 121   static void ExpectPropertyChanged(const std::string& expected_name, | 136   static void ExpectPropertyChanged(const std::string& expected_name, | 
| 122                                     const base::Value* expected_value, | 137                                     const base::Value* expected_value, | 
| 123                                     const std::string& name, | 138                                     const std::string& name, | 
| 124                                     const base::Value& value); | 139                                     const base::Value& value); | 
| 125 | 140 | 
| 126   // Expects the reader to be empty. | 141   // Expects the reader to be empty. | 
| 127   static void ExpectNoArgument(dbus::MessageReader* reader); | 142   static void ExpectNoArgument(dbus::MessageReader* reader); | 
| 128 | 143 | 
|  | 144   // Expects the reader to have a uint32 | 
|  | 145   static void ExpectUint32Argument(uint32 expected_value, | 
|  | 146                                    dbus::MessageReader* reader); | 
|  | 147 | 
|  | 148   // Expects the reader to have an array of bytes | 
|  | 149   static void ExpectArrayOfBytesArgument( | 
|  | 150       const std::vector<uint8>& expected_bytes, | 
|  | 151       dbus::MessageReader* reader); | 
|  | 152 | 
| 129   // Expects the reader to have a string. | 153   // Expects the reader to have a string. | 
| 130   static void ExpectStringArgument(const std::string& expected_string, | 154   static void ExpectStringArgument(const std::string& expected_string, | 
| 131                                    dbus::MessageReader* reader); | 155                                    dbus::MessageReader* reader); | 
| 132 | 156 | 
| 133   static void ExpectArrayOfStringsArgument( | 157   static void ExpectArrayOfStringsArgument( | 
| 134       const std::vector<std::string>& expected_strings, | 158       const std::vector<std::string>& expected_strings, | 
| 135       dbus::MessageReader* reader); | 159       dbus::MessageReader* reader); | 
| 136 | 160 | 
| 137   // Expects the reader to have a Value. | 161   // Expects the reader to have a Value. | 
| 138   static void ExpectValueArgument(const base::Value* expected_value, | 162   static void ExpectValueArgument(const base::Value* expected_value, | 
| 139                                   dbus::MessageReader* reader); | 163                                   dbus::MessageReader* reader); | 
| 140 | 164 | 
| 141   // Expects the reader to have a string and a Value. | 165   // Expects the reader to have a string and a Value. | 
| 142   static void ExpectStringAndValueArguments(const std::string& expected_string, | 166   static void ExpectStringAndValueArguments(const std::string& expected_string, | 
| 143                                             const base::Value* expected_value, | 167                                             const base::Value* expected_value, | 
| 144                                             dbus::MessageReader* reader); | 168                                             dbus::MessageReader* reader); | 
| 145 | 169 | 
| 146   // Expects the reader to have a string-to-variant dictionary. | 170   // Expects the reader to have a string-to-variant dictionary. | 
| 147   static void ExpectDictionaryValueArgument( | 171   static void ExpectDictionaryValueArgument( | 
| 148       const base::DictionaryValue* expected_dictionary, | 172       const base::DictionaryValue* expected_dictionary, | 
|  | 173       bool string_valued, | 
| 149       dbus::MessageReader* reader); | 174       dbus::MessageReader* reader); | 
| 150 | 175 | 
| 151   // Creates a DictionaryValue with example Service properties. The caller owns | 176   // Creates a DictionaryValue with example Service properties. The caller owns | 
| 152   // the result. | 177   // the result. | 
| 153   static base::DictionaryValue* CreateExampleServiceProperties(); | 178   static base::DictionaryValue* CreateExampleServiceProperties(); | 
| 154 | 179 | 
| 155   // Expects the call status to be SUCCESS. | 180   // Expects the call status to be SUCCESS. | 
| 156   static void ExpectNoResultValue(DBusMethodCallStatus call_status); | 181   static void ExpectNoResultValue(DBusMethodCallStatus call_status); | 
| 157 | 182 | 
| 158   // Checks the result and expects the call status to be SUCCESS. | 183   // Checks the result and expects the call status to be SUCCESS. | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 184       const base::DictionaryValue& result); | 209       const base::DictionaryValue& result); | 
| 185 | 210 | 
| 186   // A message loop to emulate asynchronous behavior. | 211   // A message loop to emulate asynchronous behavior. | 
| 187   base::MessageLoop message_loop_; | 212   base::MessageLoop message_loop_; | 
| 188   // The mock bus. | 213   // The mock bus. | 
| 189   scoped_refptr<dbus::MockBus> mock_bus_; | 214   scoped_refptr<dbus::MockBus> mock_bus_; | 
| 190 | 215 | 
| 191  private: | 216  private: | 
| 192   // Checks the requested interface name and signal name. | 217   // Checks the requested interface name and signal name. | 
| 193   // Used to implement the mock proxy. | 218   // Used to implement the mock proxy. | 
| 194   void OnConnectToSignal( | 219   void OnConnectToPlatformMessage( | 
| 195       const std::string& interface_name, | 220       const std::string& interface_name, | 
| 196       const std::string& signal_name, | 221       const std::string& signal_name, | 
| 197       const dbus::ObjectProxy::SignalCallback& signal_callback, | 222       const dbus::ObjectProxy::SignalCallback& signal_callback, | 
|  | 223       const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback); | 
|  | 224 | 
|  | 225   // Checks the requested interface name and signal name. | 
|  | 226   // Used to implement the mock proxy. | 
|  | 227   void OnConnectToPacketReceieved( | 
|  | 228       const std::string& interface_name, | 
|  | 229       const std::string& signal_name, | 
|  | 230       const dbus::ObjectProxy::SignalCallback& signal_callback, | 
|  | 231       const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback); | 
|  | 232 | 
|  | 233   // Checks the requested interface name and signal name. | 
|  | 234   // Used to implement the mock proxy. | 
|  | 235   void OnConnectToPropertyChanged( | 
|  | 236       const std::string& interface_name, | 
|  | 237       const std::string& signal_name, | 
|  | 238       const dbus::ObjectProxy::SignalCallback& signal_callback, | 
| 198       const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback); | 239       const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback); | 
| 199 | 240 | 
| 200   // Checks the content of the method call and returns the response. | 241   // Checks the content of the method call and returns the response. | 
| 201   // Used to implement the mock proxy. | 242   // Used to implement the mock proxy. | 
| 202   void OnCallMethod( | 243   void OnCallMethod( | 
| 203       dbus::MethodCall* method_call, | 244       dbus::MethodCall* method_call, | 
| 204       int timeout_ms, | 245       int timeout_ms, | 
| 205       const dbus::ObjectProxy::ResponseCallback& response_callback); | 246       const dbus::ObjectProxy::ResponseCallback& response_callback); | 
| 206 | 247 | 
| 207   // Checks the content of the method call and returns the response. | 248   // Checks the content of the method call and returns the response. | 
| 208   // Used to implement the mock proxy. | 249   // Used to implement the mock proxy. | 
| 209   void OnCallMethodWithErrorCallback( | 250   void OnCallMethodWithErrorCallback( | 
| 210       dbus::MethodCall* method_call, | 251       dbus::MethodCall* method_call, | 
| 211       int timeout_ms, | 252       int timeout_ms, | 
| 212       const dbus::ObjectProxy::ResponseCallback& response_callback, | 253       const dbus::ObjectProxy::ResponseCallback& response_callback, | 
| 213       const dbus::ObjectProxy::ErrorCallback& error_callback); | 254       const dbus::ObjectProxy::ErrorCallback& error_callback); | 
| 214 | 255 | 
| 215   // The interface name. | 256   // The interface name. | 
| 216   const std::string interface_name_; | 257   const std::string interface_name_; | 
| 217   // The object path. | 258   // The object path. | 
| 218   const dbus::ObjectPath object_path_; | 259   const dbus::ObjectPath object_path_; | 
| 219   // The mock object proxy. | 260   // The mock object proxy. | 
| 220   scoped_refptr<dbus::MockObjectProxy> mock_proxy_; | 261   scoped_refptr<dbus::MockObjectProxy> mock_proxy_; | 
|  | 262   // The PlatformMessage signal handler given by the tested client. | 
|  | 263   dbus::ObjectProxy::SignalCallback platform_message_handler_; | 
|  | 264   // The PacketReceived signal handler given by the tested client. | 
|  | 265   dbus::ObjectProxy::SignalCallback packet_receieved__handler_; | 
| 221   // The PropertyChanged signal handler given by the tested client. | 266   // The PropertyChanged signal handler given by the tested client. | 
| 222   dbus::ObjectProxy::SignalCallback property_changed_handler_; | 267   dbus::ObjectProxy::SignalCallback property_changed_handler_; | 
| 223   // The name of the method which is expected to be called. | 268   // The name of the method which is expected to be called. | 
| 224   std::string expected_method_name_; | 269   std::string expected_method_name_; | 
| 225   // The response which the mock object proxy returns. | 270   // The response which the mock object proxy returns. | 
| 226   dbus::Response* response_; | 271   dbus::Response* response_; | 
| 227   // A callback to intercept and check the method call arguments. | 272   // A callback to intercept and check the method call arguments. | 
| 228   ArgumentCheckCallback argument_checker_; | 273   ArgumentCheckCallback argument_checker_; | 
| 229 }; | 274 }; | 
| 230 | 275 | 
| 231 }  // namespace chromeos | 276 }  // namespace chromeos | 
| 232 | 277 | 
| 233 #endif  // CHROMEOS_DBUS_SHILL_CLIENT_UNITTEST_BASE_H_ | 278 #endif  // CHROMEOS_DBUS_SHILL_CLIENT_UNITTEST_BASE_H_ | 
| OLD | NEW | 
|---|