Chromium Code Reviews| Index: chromeos/dbus/shill_third_party_vpn_driver_client_unittest.cc |
| diff --git a/chromeos/dbus/shill_third_party_vpn_driver_client_unittest.cc b/chromeos/dbus/shill_third_party_vpn_driver_client_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bc07155af68ae17097726ffa38cbc1353753dc62 |
| --- /dev/null |
| +++ b/chromeos/dbus/shill_third_party_vpn_driver_client_unittest.cc |
| @@ -0,0 +1,152 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/bind.h" |
| +#include "chromeos/dbus/shill_client_unittest_base.h" |
| +#include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
| +#include "chromeos/dbus/shill_third_party_vpn_observer.h" |
| +#include "third_party/cros_system_api/dbus/service_constants.h" |
| + |
| +using testing::_; |
| + |
| +namespace chromeos { |
| + |
| +namespace { |
| + |
| +const char kExampleIPConfigPath[] = "/foo/bar"; |
| + |
| +} // namespace |
| + |
| +class ShillThirdPartyVpnDriverClientTest : public ShillClientUnittestBase { |
| + public: |
| + ShillThirdPartyVpnDriverClientTest() |
| + : ShillClientUnittestBase(shill::kFlimflamThirdPartyVpnInterface, |
| + dbus::ObjectPath(kExampleIPConfigPath)) {} |
| + |
| + virtual void SetUp() { |
| + ShillClientUnittestBase::SetUp(); |
| + |
| + // Create a client with the mock bus. |
| + client_.reset(ShillThirdPartyVpnDriverClient::Create()); |
| + client_->Init(mock_bus_.get()); |
| + // Run the message loop to run the signal connection result callback. |
| + message_loop_.RunUntilIdle(); |
| + } |
| + |
| + virtual void TearDown() { ShillClientUnittestBase::TearDown(); } |
| + |
| + static void Success() {} |
| + static void Failure(const std::string& error_name, |
| + const std::string& error_message) { |
| + CHECK(false); |
|
pneubeck (no reviews)
2014/11/11 13:09:35
try not to crash the process if the class-under-te
kaliamoorthi
2014/11/11 14:58:34
Done.
|
| + } |
| + |
| + protected: |
| + scoped_ptr<ShillThirdPartyVpnDriverClient> client_; |
| +}; |
| + |
| +TEST_F(ShillThirdPartyVpnDriverClientTest, PlatformSignal) { |
| + uint32 connected_state = 123456; |
| + const int kPacketSize = 5; |
| + uint8 data[kPacketSize] = {}; |
| + dbus::Signal pmessage_signal(shill::kFlimflamThirdPartyVpnInterface, |
| + shill::kOnPlatformMessageFunction); |
| + { |
| + dbus::MessageWriter writer(&pmessage_signal); |
| + writer.AppendUint32(connected_state); |
| + } |
| + |
| + dbus::Signal preceived_signal(shill::kFlimflamThirdPartyVpnInterface, |
| + shill::kOnPacketReceivedFunction); |
| + { |
| + dbus::MessageWriter writer(&preceived_signal); |
| + writer.AppendArrayOfBytes(data, kPacketSize); |
| + } |
| + |
| + // Set expectations. |
|
pneubeck (no reviews)
2014/11/11 13:09:35
this doesn't convey new information.
maybe somethi
kaliamoorthi
2014/11/11 14:58:34
Done.
pneubeck (no reviews)
2014/11/12 14:21:07
the same argument applies to nearly every other co
|
| + MockShillThirdPartyVpnObserver observer; |
| + EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(1); |
| + EXPECT_CALL(observer, OnPacketReceived(_, kPacketSize)).Times(1); |
| + |
| + // Add the observer |
| + client_->AddShillThirdPartyVpnObserver(dbus::ObjectPath(kExampleIPConfigPath), |
| + &observer); |
| + |
| + // Run the signal callback. |
| + SendPlatformMessageSignal(&pmessage_signal); |
| + SendPacketReceievedSignal(&preceived_signal); |
| + |
| + // Remove the observer. |
| + client_->RemoveShillThirdPartyVpnObserver( |
| + dbus::ObjectPath(kExampleIPConfigPath)); |
| + |
| + EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(0); |
| + EXPECT_CALL(observer, OnPacketReceived(_, kPacketSize)).Times(0); |
| + |
| + // Run the signal callback. |
| + SendPlatformMessageSignal(&pmessage_signal); |
| + SendPacketReceievedSignal(&preceived_signal); |
| + |
| + message_loop_.RunUntilIdle(); |
| +} |
| + |
| +TEST_F(ShillThirdPartyVpnDriverClientTest, SetParameters) { |
| + // Create response. |
| + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| + |
| + base::DictionaryValue parameters; |
| + const std::string kAddress("1.1.1.1"); |
| + parameters.SetStringWithoutPathExpansion( |
| + shill::kAddressParameterThirdPartyVpn, kAddress); |
| + |
| + // Set expectations. |
| + PrepareForMethodCall( |
| + shill::kSetParametersFunction, |
| + base::Bind(&ExpectDictionaryValueArgument, ¶meters, true), |
| + response.get()); |
| + |
| + client_->SetParameters(dbus::ObjectPath(kExampleIPConfigPath), parameters, |
| + base::Bind(&Success), base::Bind(&Failure)); |
| + |
| + // Run the message loop. |
| + message_loop_.RunUntilIdle(); |
| +} |
| + |
| +TEST_F(ShillThirdPartyVpnDriverClientTest, UpdateConnectionState) { |
| + // Create response. |
| + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| + uint32 connection_state = 2; |
| + |
| + // Set expectations. |
| + PrepareForMethodCall(shill::kUpdateConnectionStateFunction, |
| + base::Bind(&ExpectUint32Argument, connection_state), |
| + response.get()); |
| + |
| + client_->UpdateConnectionState(dbus::ObjectPath(kExampleIPConfigPath), |
| + connection_state, base::Bind(&Success), |
| + base::Bind(&Failure)); |
| + |
| + // Run the message loop. |
| + message_loop_.RunUntilIdle(); |
| +} |
| + |
| +TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) { |
| + // Create response. |
| + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| + |
| + const std::string data(5, 0); |
| + |
| + // Set expectations. |
| + PrepareForMethodCall(shill::kSendPacketFunction, |
| + base::Bind(&ExpectArrayOfBytesArgument, data), |
| + response.get()); |
| + |
| + client_->SendPacket(dbus::ObjectPath(kExampleIPConfigPath), data, |
| + base::Bind(&Success), base::Bind(&Failure)); |
| + |
| + // Run the message loop. |
| + message_loop_.RunUntilIdle(); |
| +} |
| + |
| +} // namespace chromeos |