| 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..d1051eb51a34ae8799e269adb1c6d01d2f379651
|
| --- /dev/null
|
| +++ b/chromeos/dbus/shill_third_party_vpn_driver_client_unittest.cc
|
| @@ -0,0 +1,146 @@
|
| +// 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(); }
|
| +
|
| + 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.
|
| + 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(&ExpectNoResultValue));
|
| +
|
| + // 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(&ExpectNoResultValue));
|
| +
|
| + // Run the message loop.
|
| + message_loop_.RunUntilIdle();
|
| +}
|
| +
|
| +TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) {
|
| + // Create response.
|
| + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
|
| +
|
| + const std::vector<uint8> data(5, 0);
|
| +
|
| + // Set expectations.
|
| + PrepareForMethodCall(shill::kSendPacketFunction,
|
| + base::Bind(&ExpectArrayOfBytesArgument, data),
|
| + response.get());
|
| +
|
| + client_->SendPacket(dbus::ObjectPath(kExampleIPConfigPath), data,
|
| + base::Bind(&ExpectNoResultValue));
|
| +
|
| + // Run the message loop.
|
| + message_loop_.RunUntilIdle();
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|