Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 #include "base/bind.h" | |
| 6 #include "chromeos/dbus/shill_client_unittest_base.h" | |
| 7 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" | |
| 8 #include "chromeos/dbus/shill_third_party_vpn_observer.h" | |
| 9 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 10 | |
| 11 using testing::_; | |
| 12 | |
| 13 namespace chromeos { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const char kExampleIPConfigPath[] = "/foo/bar"; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 class ShillThirdPartyVpnDriverClientTest : public ShillClientUnittestBase { | |
| 22 public: | |
| 23 ShillThirdPartyVpnDriverClientTest() | |
| 24 : ShillClientUnittestBase(shill::kFlimflamThirdPartyVpnInterface, | |
| 25 dbus::ObjectPath(kExampleIPConfigPath)) {} | |
| 26 | |
| 27 virtual void SetUp() { | |
| 28 ShillClientUnittestBase::SetUp(); | |
| 29 | |
| 30 // Create a client with the mock bus. | |
| 31 client_.reset(ShillThirdPartyVpnDriverClient::Create()); | |
| 32 client_->Init(mock_bus_.get()); | |
| 33 // Run the message loop to run the signal connection result callback. | |
| 34 message_loop_.RunUntilIdle(); | |
| 35 } | |
| 36 | |
| 37 virtual void TearDown() { ShillClientUnittestBase::TearDown(); } | |
| 38 | |
| 39 protected: | |
| 40 scoped_ptr<ShillThirdPartyVpnDriverClient> client_; | |
| 41 }; | |
| 42 | |
| 43 TEST_F(ShillThirdPartyVpnDriverClientTest, PlatformSignal) { | |
| 44 uint32 connected_state = 123456; | |
| 45 #define PACKET_SIZE 5 | |
|
stevenjb
2014/10/31 16:35:42
Avoid defines like this, use 'const int kPacketSiz
kaliamoorthi
2014/11/03 10:55:38
Done.
| |
| 46 uint8 data[PACKET_SIZE] = {}; | |
| 47 dbus::Signal pmessage_signal(shill::kFlimflamThirdPartyVpnInterface, | |
| 48 shill::kOnPlatformMessageFunction); | |
| 49 { | |
| 50 dbus::MessageWriter writer(&pmessage_signal); | |
| 51 writer.AppendUint32(connected_state); | |
| 52 } | |
| 53 | |
| 54 dbus::Signal preceived_signal(shill::kFlimflamThirdPartyVpnInterface, | |
| 55 shill::kOnPacketReceivedFunction); | |
| 56 { | |
| 57 dbus::MessageWriter writer(&preceived_signal); | |
| 58 writer.AppendArrayOfBytes(data, PACKET_SIZE); | |
| 59 } | |
| 60 | |
| 61 // Set expectations. | |
| 62 MockShillThirdPartyVpnObserver observer; | |
| 63 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(1); | |
| 64 EXPECT_CALL(observer, OnPacketReceived(_, PACKET_SIZE)).Times(1); | |
| 65 | |
| 66 // Add the observer | |
| 67 client_->AddShillThirdPartyVpnObserver(dbus::ObjectPath(kExampleIPConfigPath), | |
| 68 &observer); | |
| 69 | |
| 70 // Run the signal callback. | |
| 71 SendPlatformMessageSignal(&pmessage_signal); | |
| 72 SendPacketReceievedSignal(&preceived_signal); | |
| 73 | |
| 74 // Remove the observer. | |
| 75 client_->RemoveShillThirdPartyVpnObserver( | |
| 76 dbus::ObjectPath(kExampleIPConfigPath)); | |
| 77 | |
| 78 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(0); | |
| 79 EXPECT_CALL(observer, OnPacketReceived(_, PACKET_SIZE)).Times(0); | |
| 80 | |
| 81 // Run the signal callback. | |
| 82 SendPlatformMessageSignal(&pmessage_signal); | |
| 83 SendPacketReceievedSignal(&preceived_signal); | |
| 84 | |
| 85 message_loop_.RunUntilIdle(); | |
| 86 } | |
| 87 | |
| 88 TEST_F(ShillThirdPartyVpnDriverClientTest, SetParameters) { | |
| 89 // Create response. | |
| 90 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 91 | |
| 92 base::DictionaryValue parameters; | |
| 93 const std::string kAddress("1.1.1.1"); | |
| 94 parameters.SetStringWithoutPathExpansion( | |
| 95 shill::kAddressParameterThirdPartyVpn, kAddress); | |
| 96 | |
| 97 // Set expectations. | |
| 98 PrepareForMethodCall( | |
| 99 shill::kSetParametersFunction, | |
| 100 base::Bind(&ExpectDictionaryValueArgument, ¶meters, true), | |
| 101 response.get()); | |
| 102 | |
| 103 client_->SetParameters(dbus::ObjectPath(kExampleIPConfigPath), parameters, | |
| 104 base::Bind(&ExpectNoResultValue)); | |
| 105 | |
| 106 // Run the message loop. | |
| 107 message_loop_.RunUntilIdle(); | |
| 108 } | |
| 109 | |
| 110 TEST_F(ShillThirdPartyVpnDriverClientTest, UpdateConnectionState) { | |
| 111 // Create response. | |
| 112 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 113 uint32 connection_state = 2; | |
| 114 | |
| 115 // Set expectations. | |
| 116 PrepareForMethodCall(shill::kUpdateConnectionStateFunction, | |
| 117 base::Bind(&ExpectUint32Argument, connection_state), | |
| 118 response.get()); | |
| 119 | |
| 120 client_->UpdateConnectionState(dbus::ObjectPath(kExampleIPConfigPath), | |
| 121 connection_state, | |
| 122 base::Bind(&ExpectNoResultValue)); | |
| 123 | |
| 124 // Run the message loop. | |
| 125 message_loop_.RunUntilIdle(); | |
| 126 } | |
| 127 | |
| 128 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) { | |
| 129 // Create response. | |
| 130 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 131 | |
| 132 const std::vector<uint8> data(5, 0); | |
| 133 | |
| 134 // Set expectations. | |
| 135 PrepareForMethodCall(shill::kSendPacketFunction, | |
| 136 base::Bind(&ExpectArrayOfBytesArgument, data), | |
| 137 response.get()); | |
| 138 | |
| 139 client_->SendPacket(dbus::ObjectPath(kExampleIPConfigPath), data, | |
| 140 base::Bind(&ExpectNoResultValue)); | |
| 141 | |
| 142 // Run the message loop. | |
| 143 message_loop_.RunUntilIdle(); | |
| 144 } | |
| 145 | |
| 146 } // namespace chromeos | |
| OLD | NEW |