Chromium Code Reviews| Index: chromeos/dbus/shill_client_unittest_base.cc |
| diff --git a/chromeos/dbus/shill_client_unittest_base.cc b/chromeos/dbus/shill_client_unittest_base.cc |
| index a6df09e65cd958b63763cb6bda77150c7c4734e9..e8a016642b9d7ba8d85faec7b6d980760c8aa661 100644 |
| --- a/chromeos/dbus/shill_client_unittest_base.cc |
| +++ b/chromeos/dbus/shill_client_unittest_base.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/bind.h" |
| #include "base/json/json_writer.h" |
| #include "base/values.h" |
| +#include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
|
pneubeck (no reviews)
2014/11/11 13:09:35
already included in the header
kaliamoorthi
2014/11/11 14:58:32
Done.
|
| #include "chromeos/network/shill_property_util.h" |
| #include "dbus/message.h" |
| #include "dbus/object_path.h" |
| @@ -14,6 +15,8 @@ |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "third_party/cros_system_api/dbus/service_constants.h" |
| +// TODO(kaliamoorthi): Remove inclusion of shill_third_party_vpn_driver_client |
| +// after the string constants in it are moved to service_constants.h |
| using ::testing::_; |
| using ::testing::Invoke; |
| @@ -99,6 +102,12 @@ ShillClientUnittestBase::MockPropertyChangeObserver:: |
| ShillClientUnittestBase::MockPropertyChangeObserver:: |
| ~MockPropertyChangeObserver() {} |
| +ShillClientUnittestBase::MockShillThirdPartyVpnObserver:: |
| + MockShillThirdPartyVpnObserver() {} |
| + |
| +ShillClientUnittestBase::MockShillThirdPartyVpnObserver:: |
| + ~MockShillThirdPartyVpnObserver() {} |
| + |
| ShillClientHelper::ErrorCallback |
| ShillClientUnittestBase::MockErrorCallback::GetCallback() { |
| return base::Bind(&MockErrorCallback::Run, base::Unretained(this)); |
| @@ -140,12 +149,24 @@ void ShillClientUnittestBase::SetUp() { |
| this, &ShillClientUnittestBase::OnCallMethodWithErrorCallback)); |
| // Set an expectation so mock_proxy's ConnectToSignal() will use |
| - // OnConnectToSignal() to run the callback. |
| + // OnConnectToPropertyChanged() to run the callback. |
| EXPECT_CALL( |
| *mock_proxy_.get(), |
| ConnectToSignal(interface_name_, shill::kMonitorPropertyChanged, _, _)) |
| .WillRepeatedly( |
| - Invoke(this, &ShillClientUnittestBase::OnConnectToSignal)); |
| + Invoke(this, &ShillClientUnittestBase::OnConnectToPropertyChanged)); |
| + |
| + EXPECT_CALL( |
| + *mock_proxy_.get(), |
| + ConnectToSignal(interface_name_, shill::kOnPlatformMessageFunction, _, _)) |
| + .WillRepeatedly( |
| + Invoke(this, &ShillClientUnittestBase::OnConnectToPlatformMessage)); |
| + |
| + EXPECT_CALL( |
| + *mock_proxy_.get(), |
| + ConnectToSignal(interface_name_, shill::kOnPacketReceivedFunction, _, _)) |
| + .WillRepeatedly( |
| + Invoke(this, &ShillClientUnittestBase::OnConnectToPacketReceieved)); |
| // Set an expectation so mock_bus's GetObjectProxy() for the given |
| // service name and the object path will return mock_proxy_. |
| @@ -175,6 +196,18 @@ void ShillClientUnittestBase::PrepareForMethodCall( |
| response_ = response; |
| } |
| +void ShillClientUnittestBase::SendPlatformMessageSignal( |
| + dbus::Signal* signal) { |
| + ASSERT_FALSE(platform_message_handler_.is_null()); |
| + platform_message_handler_.Run(signal); |
| +} |
| + |
| +void ShillClientUnittestBase::SendPacketReceievedSignal( |
| + dbus::Signal* signal) { |
| + ASSERT_FALSE(packet_receieved__handler_.is_null()); |
| + packet_receieved__handler_.Run(signal); |
| +} |
| + |
| void ShillClientUnittestBase::SendPropertyChangedSignal( |
| dbus::Signal* signal) { |
| ASSERT_FALSE(property_changed_handler_.is_null()); |
| @@ -197,6 +230,30 @@ void ShillClientUnittestBase::ExpectNoArgument(dbus::MessageReader* reader) { |
| } |
| // static |
| +void ShillClientUnittestBase::ExpectUint32Argument( |
| + uint32 expected_value, |
| + dbus::MessageReader* reader) { |
| + uint32 value; |
| + ASSERT_TRUE(reader->PopUint32(&value)); |
| + EXPECT_EQ(expected_value, value); |
| + EXPECT_FALSE(reader->HasMoreData()); |
| +} |
| + |
| +// static |
| +void ShillClientUnittestBase::ExpectArrayOfBytesArgument( |
| + const std::string& expected_bytes, |
| + dbus::MessageReader* reader) { |
| + const uint8* bytes; |
|
pneubeck (no reviews)
2014/11/11 13:09:35
built-in types should be initialized
(also mention
kaliamoorthi
2014/11/11 14:58:32
Done.
|
| + size_t size; |
| + ASSERT_TRUE(reader->PopArrayOfBytes(&bytes, &size)); |
| + EXPECT_EQ(expected_bytes.size(), size); |
| + for (size_t i = 0; i < size; ++i) { |
| + EXPECT_EQ(expected_bytes[i], bytes[i]); |
| + } |
| + EXPECT_FALSE(reader->HasMoreData()); |
| +} |
| + |
| +// static |
| void ShillClientUnittestBase::ExpectStringArgument( |
| const std::string& expected_string, |
| dbus::MessageReader* reader) { |
| @@ -243,6 +300,7 @@ void ShillClientUnittestBase::ExpectStringAndValueArguments( |
| // static |
| void ShillClientUnittestBase::ExpectDictionaryValueArgument( |
| const base::DictionaryValue* expected_dictionary, |
| + bool string_valued, |
| dbus::MessageReader* reader) { |
| dbus::MessageReader array_reader(NULL); |
| ASSERT_TRUE(reader->PopArray(&array_reader)); |
| @@ -251,6 +309,15 @@ void ShillClientUnittestBase::ExpectDictionaryValueArgument( |
| ASSERT_TRUE(array_reader.PopDictEntry(&entry_reader)); |
| std::string key; |
| ASSERT_TRUE(entry_reader.PopString(&key)); |
| + if (string_valued) { |
|
pneubeck (no reviews)
2014/11/11 13:09:35
wouldn't it have the same effect if you just check
kaliamoorthi
2014/11/11 14:58:32
No, the way the data is marshaled is different if
|
| + std::string value; |
| + std::string expected_value; |
| + ASSERT_TRUE(entry_reader.PopString(&value)); |
| + EXPECT_TRUE(expected_dictionary->GetStringWithoutPathExpansion( |
| + key, &expected_value)); |
| + EXPECT_EQ(expected_value, value); |
| + continue; |
| + } |
| dbus::MessageReader variant_reader(NULL); |
| ASSERT_TRUE(entry_reader.PopVariant(&variant_reader)); |
| scoped_ptr<base::Value> value; |
| @@ -350,7 +417,35 @@ void ShillClientUnittestBase::ExpectDictionaryValueResult( |
| ExpectDictionaryValueResultWithoutStatus(expected_result, result); |
| } |
| -void ShillClientUnittestBase::OnConnectToSignal( |
| +void ShillClientUnittestBase::OnConnectToPlatformMessage( |
| + const std::string& interface_name, |
| + const std::string& signal_name, |
| + const dbus::ObjectProxy::SignalCallback& signal_callback, |
| + const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) { |
| + platform_message_handler_ = signal_callback; |
| + const bool success = true; |
| + message_loop_.PostTask(FROM_HERE, |
| + base::Bind(on_connected_callback, |
| + interface_name, |
| + signal_name, |
| + success)); |
| +} |
| + |
| +void ShillClientUnittestBase::OnConnectToPacketReceieved( |
| + const std::string& interface_name, |
| + const std::string& signal_name, |
| + const dbus::ObjectProxy::SignalCallback& signal_callback, |
| + const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) { |
| + packet_receieved__handler_ = signal_callback; |
| + const bool success = true; |
| + message_loop_.PostTask(FROM_HERE, |
| + base::Bind(on_connected_callback, |
| + interface_name, |
| + signal_name, |
| + success)); |
| +} |
| + |
| +void ShillClientUnittestBase::OnConnectToPropertyChanged( |
| const std::string& interface_name, |
| const std::string& signal_name, |
| const dbus::ObjectProxy::SignalCallback& signal_callback, |