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 static void Success() {} | |
| 40 static void Failure(const std::string& error_name, | |
| 41 const std::string& error_message) { | |
| 42 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.
| |
| 43 } | |
| 44 | |
| 45 protected: | |
| 46 scoped_ptr<ShillThirdPartyVpnDriverClient> client_; | |
| 47 }; | |
| 48 | |
| 49 TEST_F(ShillThirdPartyVpnDriverClientTest, PlatformSignal) { | |
| 50 uint32 connected_state = 123456; | |
| 51 const int kPacketSize = 5; | |
| 52 uint8 data[kPacketSize] = {}; | |
| 53 dbus::Signal pmessage_signal(shill::kFlimflamThirdPartyVpnInterface, | |
| 54 shill::kOnPlatformMessageFunction); | |
| 55 { | |
| 56 dbus::MessageWriter writer(&pmessage_signal); | |
| 57 writer.AppendUint32(connected_state); | |
| 58 } | |
| 59 | |
| 60 dbus::Signal preceived_signal(shill::kFlimflamThirdPartyVpnInterface, | |
| 61 shill::kOnPacketReceivedFunction); | |
| 62 { | |
| 63 dbus::MessageWriter writer(&preceived_signal); | |
| 64 writer.AppendArrayOfBytes(data, kPacketSize); | |
| 65 } | |
| 66 | |
| 67 // 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
| |
| 68 MockShillThirdPartyVpnObserver observer; | |
| 69 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(1); | |
| 70 EXPECT_CALL(observer, OnPacketReceived(_, kPacketSize)).Times(1); | |
| 71 | |
| 72 // Add the observer | |
| 73 client_->AddShillThirdPartyVpnObserver(dbus::ObjectPath(kExampleIPConfigPath), | |
| 74 &observer); | |
| 75 | |
| 76 // Run the signal callback. | |
| 77 SendPlatformMessageSignal(&pmessage_signal); | |
| 78 SendPacketReceievedSignal(&preceived_signal); | |
| 79 | |
| 80 // Remove the observer. | |
| 81 client_->RemoveShillThirdPartyVpnObserver( | |
| 82 dbus::ObjectPath(kExampleIPConfigPath)); | |
| 83 | |
| 84 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(0); | |
| 85 EXPECT_CALL(observer, OnPacketReceived(_, kPacketSize)).Times(0); | |
| 86 | |
| 87 // Run the signal callback. | |
| 88 SendPlatformMessageSignal(&pmessage_signal); | |
| 89 SendPacketReceievedSignal(&preceived_signal); | |
| 90 | |
| 91 message_loop_.RunUntilIdle(); | |
| 92 } | |
| 93 | |
| 94 TEST_F(ShillThirdPartyVpnDriverClientTest, SetParameters) { | |
| 95 // Create response. | |
| 96 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 97 | |
| 98 base::DictionaryValue parameters; | |
| 99 const std::string kAddress("1.1.1.1"); | |
| 100 parameters.SetStringWithoutPathExpansion( | |
| 101 shill::kAddressParameterThirdPartyVpn, kAddress); | |
| 102 | |
| 103 // Set expectations. | |
| 104 PrepareForMethodCall( | |
| 105 shill::kSetParametersFunction, | |
| 106 base::Bind(&ExpectDictionaryValueArgument, ¶meters, true), | |
| 107 response.get()); | |
| 108 | |
| 109 client_->SetParameters(dbus::ObjectPath(kExampleIPConfigPath), parameters, | |
| 110 base::Bind(&Success), base::Bind(&Failure)); | |
| 111 | |
| 112 // Run the message loop. | |
| 113 message_loop_.RunUntilIdle(); | |
| 114 } | |
| 115 | |
| 116 TEST_F(ShillThirdPartyVpnDriverClientTest, UpdateConnectionState) { | |
| 117 // Create response. | |
| 118 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 119 uint32 connection_state = 2; | |
| 120 | |
| 121 // Set expectations. | |
| 122 PrepareForMethodCall(shill::kUpdateConnectionStateFunction, | |
| 123 base::Bind(&ExpectUint32Argument, connection_state), | |
| 124 response.get()); | |
| 125 | |
| 126 client_->UpdateConnectionState(dbus::ObjectPath(kExampleIPConfigPath), | |
| 127 connection_state, base::Bind(&Success), | |
| 128 base::Bind(&Failure)); | |
| 129 | |
| 130 // Run the message loop. | |
| 131 message_loop_.RunUntilIdle(); | |
| 132 } | |
| 133 | |
| 134 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) { | |
| 135 // Create response. | |
| 136 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 137 | |
| 138 const std::string data(5, 0); | |
| 139 | |
| 140 // Set expectations. | |
| 141 PrepareForMethodCall(shill::kSendPacketFunction, | |
| 142 base::Bind(&ExpectArrayOfBytesArgument, data), | |
| 143 response.get()); | |
| 144 | |
| 145 client_->SendPacket(dbus::ObjectPath(kExampleIPConfigPath), data, | |
| 146 base::Bind(&Success), base::Bind(&Failure)); | |
| 147 | |
| 148 // Run the message loop. | |
| 149 message_loop_.RunUntilIdle(); | |
| 150 } | |
| 151 | |
| 152 } // namespace chromeos | |
| OLD | NEW |