| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/message_loop.h" | |
| 13 #include "chrome/browser/chromeos/dbus/dbus_method_call_status.h" | |
| 14 #include "dbus/mock_bus.h" | |
| 15 #include "dbus/mock_object_proxy.h" | |
| 16 #include "dbus/object_proxy.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 namespace base { | |
| 20 | |
| 21 class Value; | |
| 22 class DictionaryValue; | |
| 23 | |
| 24 } // namespace base | |
| 25 | |
| 26 namespace dbus { | |
| 27 | |
| 28 class MessageReader; | |
| 29 | |
| 30 } // namespace dbus | |
| 31 | |
| 32 namespace chromeos { | |
| 33 | |
| 34 // A class to provide functionalities needed for testing Flimflam D-Bus clients. | |
| 35 class FlimflamClientUnittestBase : public testing::Test { | |
| 36 public: | |
| 37 explicit FlimflamClientUnittestBase(const std::string& interface_name); | |
| 38 virtual ~FlimflamClientUnittestBase(); | |
| 39 | |
| 40 virtual void SetUp() OVERRIDE; | |
| 41 virtual void TearDown() OVERRIDE; | |
| 42 | |
| 43 protected: | |
| 44 // A callback to intercept and check the method call arguments. | |
| 45 typedef base::Callback<void( | |
| 46 dbus::MessageReader* reader)> ArgumentCheckCallback; | |
| 47 | |
| 48 // Sets expectations for called method name and arguments, and sets response. | |
| 49 void PrepareForMethodCall(const std::string& method_name, | |
| 50 ArgumentCheckCallback argument_checker, | |
| 51 dbus::Response* response); | |
| 52 | |
| 53 // Sends property changed signal to the tested client. | |
| 54 void SendPropertyChangedSignal(dbus::Signal* signal); | |
| 55 | |
| 56 // Checks the name and the value which are sent by PropertyChanged signal. | |
| 57 static void ExpectPropertyChanged(const std::string& expected_name, | |
| 58 const base::Value* expected_value, | |
| 59 const std::string& name, | |
| 60 const base::Value& value); | |
| 61 | |
| 62 // Expects the reader to be empty. | |
| 63 static void ExpectNoArgument(dbus::MessageReader* reader); | |
| 64 | |
| 65 // Expects the reader to have a string. | |
| 66 static void ExpectStringArgument(const std::string& expected_string, | |
| 67 dbus::MessageReader* reader); | |
| 68 | |
| 69 // Expects the reader to have a Value. | |
| 70 static void ExpectValueArgument(const base::Value* expected_value, | |
| 71 dbus::MessageReader* reader); | |
| 72 | |
| 73 // Expects the reader to have a string and a Value. | |
| 74 static void ExpectStringAndValueArguments(const std::string& expected_string, | |
| 75 const base::Value* expected_value, | |
| 76 dbus::MessageReader* reader); | |
| 77 | |
| 78 // Expects the call status to be SUCCESS. | |
| 79 static void ExpectNoResultValue(DBusMethodCallStatus call_status); | |
| 80 | |
| 81 // Checks the result and expects the call status to be SUCCESS. | |
| 82 static void ExpectDictionaryValueResult( | |
| 83 const base::DictionaryValue* expected_result, | |
| 84 DBusMethodCallStatus call_status, | |
| 85 const base::DictionaryValue& result); | |
| 86 | |
| 87 // A message loop to emulate asynchronous behavior. | |
| 88 MessageLoop message_loop_; | |
| 89 // The mock bus. | |
| 90 scoped_refptr<dbus::MockBus> mock_bus_; | |
| 91 | |
| 92 private: | |
| 93 // Checks the requested interface name and signal name. | |
| 94 // Used to implement the mock proxy. | |
| 95 void OnConnectToSignal( | |
| 96 const std::string& interface_name, | |
| 97 const std::string& signal_name, | |
| 98 dbus::ObjectProxy::SignalCallback signal_callback, | |
| 99 dbus::ObjectProxy::OnConnectedCallback on_connected_callback); | |
| 100 | |
| 101 // Checks the content of the method call and returns the response. | |
| 102 // Used to implement the mock proxy. | |
| 103 void OnCallMethod(dbus::MethodCall* method_call, | |
| 104 int timeout_ms, | |
| 105 dbus::ObjectProxy::ResponseCallback response_callback); | |
| 106 | |
| 107 // The interface name. | |
| 108 const std::string interface_name_; | |
| 109 // The mock object proxy. | |
| 110 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; | |
| 111 // The PropertyChanged signal handler given by the tested client. | |
| 112 dbus::ObjectProxy::SignalCallback property_changed_handler_; | |
| 113 // The name of the method which is expected to be called. | |
| 114 std::string expected_method_name_; | |
| 115 // The response which the mock object proxy returns. | |
| 116 dbus::Response* response_; | |
| 117 // A callback to intercept and check the method call arguments. | |
| 118 ArgumentCheckCallback argument_checker_; | |
| 119 }; | |
| 120 | |
| 121 } // namespace chromeos | |
| 122 | |
| 123 #endif // CHROME_BROWSER_CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ | |
| OLD | NEW |