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 class MockShillThirdPartyVpnObserver : public ShillThirdPartyVpnObserver { | |
| 20 public: | |
| 21 MockShillThirdPartyVpnObserver() {} | |
| 22 ~MockShillThirdPartyVpnObserver() {} | |
| 23 MOCK_METHOD2(OnPacketReceived, void(const uint8_t* data, size_t length)); | |
| 24 MOCK_METHOD1(OnPlatformMessage, void(uint32_t message)); | |
| 25 }; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 class ShillThirdPartyVpnDriverClientTest : public ShillClientUnittestBase { | |
| 30 public: | |
| 31 ShillThirdPartyVpnDriverClientTest() | |
| 32 : ShillClientUnittestBase(shill::kFlimflamThirdPartyVpnInterface, | |
| 33 dbus::ObjectPath(kExampleIPConfigPath)) {} | |
| 34 | |
| 35 virtual void SetUp() { | |
| 36 ShillClientUnittestBase::SetUp(); | |
| 37 | |
| 38 // Create a client with the mock bus. | |
| 39 client_.reset(ShillThirdPartyVpnDriverClient::Create()); | |
| 40 client_->Init(mock_bus_.get()); | |
| 41 // Run the message loop to run the signal connection result callback. | |
| 42 message_loop_.RunUntilIdle(); | |
| 43 } | |
| 44 | |
| 45 virtual void TearDown() { ShillClientUnittestBase::TearDown(); } | |
| 46 | |
| 47 static void Success() {} | |
| 48 static void Failure(const std::string& error_name, | |
| 49 const std::string& error_message) { | |
| 50 EXPECT_FALSE(true) << error_name << error_message; | |
|
bartfab (slow)
2014/11/13 12:18:47
Instead of EXPECT_FALSE(true), you should use ADD_
kaliamoorthi
2014/11/13 16:10:52
Acknowledged.
| |
| 51 } | |
| 52 | |
| 53 protected: | |
| 54 scoped_ptr<ShillThirdPartyVpnDriverClient> client_; | |
| 55 }; | |
| 56 | |
| 57 TEST_F(ShillThirdPartyVpnDriverClientTest, PlatformSignal) { | |
| 58 uint32_t connected_state = 123456; | |
| 59 const int kPacketSize = 5; | |
| 60 uint8_t data[kPacketSize] = {}; | |
| 61 dbus::Signal pmessage_signal(shill::kFlimflamThirdPartyVpnInterface, | |
| 62 shill::kOnPlatformMessageFunction); | |
| 63 { | |
| 64 dbus::MessageWriter writer(&pmessage_signal); | |
| 65 writer.AppendUint32(connected_state); | |
| 66 } | |
| 67 | |
| 68 dbus::Signal preceived_signal(shill::kFlimflamThirdPartyVpnInterface, | |
| 69 shill::kOnPacketReceivedFunction); | |
| 70 { | |
| 71 dbus::MessageWriter writer(&preceived_signal); | |
| 72 writer.AppendArrayOfBytes(data, kPacketSize); | |
| 73 } | |
| 74 | |
| 75 // Expect each signal to be triggered once. | |
| 76 MockShillThirdPartyVpnObserver observer; | |
| 77 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(1); | |
| 78 EXPECT_CALL(observer, OnPacketReceived(_, kPacketSize)).Times(1); | |
| 79 | |
| 80 client_->AddShillThirdPartyVpnObserver(kExampleIPConfigPath, | |
| 81 &observer); | |
| 82 | |
| 83 // Run the signal callback. | |
| 84 SendPlatformMessageSignal(&pmessage_signal); | |
| 85 SendPacketReceievedSignal(&preceived_signal); | |
| 86 | |
| 87 client_->RemoveShillThirdPartyVpnObserver(kExampleIPConfigPath); | |
| 88 | |
| 89 // Check after removing the observer that there is no further signals. | |
| 90 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(0); | |
| 91 EXPECT_CALL(observer, OnPacketReceived(_, kPacketSize)).Times(0); | |
| 92 | |
| 93 // Run the signal callback. | |
| 94 SendPlatformMessageSignal(&pmessage_signal); | |
| 95 SendPacketReceievedSignal(&preceived_signal); | |
| 96 | |
| 97 message_loop_.RunUntilIdle(); | |
| 98 } | |
| 99 | |
| 100 TEST_F(ShillThirdPartyVpnDriverClientTest, SetParameters) { | |
| 101 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 102 | |
| 103 base::DictionaryValue parameters; | |
| 104 const std::string kAddress("1.1.1.1"); | |
| 105 parameters.SetStringWithoutPathExpansion( | |
| 106 shill::kAddressParameterThirdPartyVpn, kAddress); | |
| 107 | |
| 108 PrepareForMethodCall( | |
| 109 shill::kSetParametersFunction, | |
| 110 base::Bind(&ExpectDictionaryValueArgument, ¶meters, true), | |
| 111 response.get()); | |
| 112 | |
| 113 client_->SetParameters(kExampleIPConfigPath, parameters, | |
| 114 base::Bind(&Success), base::Bind(&Failure)); | |
| 115 | |
| 116 message_loop_.RunUntilIdle(); | |
| 117 } | |
| 118 | |
| 119 TEST_F(ShillThirdPartyVpnDriverClientTest, UpdateConnectionState) { | |
| 120 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 121 uint32_t connection_state = 2; | |
| 122 | |
| 123 PrepareForMethodCall(shill::kUpdateConnectionStateFunction, | |
| 124 base::Bind(&ExpectUint32Argument, connection_state), | |
| 125 response.get()); | |
| 126 | |
| 127 client_->UpdateConnectionState(kExampleIPConfigPath, | |
| 128 connection_state, base::Bind(&Success), | |
| 129 base::Bind(&Failure)); | |
| 130 | |
| 131 message_loop_.RunUntilIdle(); | |
| 132 } | |
| 133 | |
| 134 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) { | |
| 135 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 136 | |
| 137 const std::string data(5, 0); | |
| 138 | |
| 139 PrepareForMethodCall(shill::kSendPacketFunction, | |
| 140 base::Bind(&ExpectArrayOfBytesArgument, data), | |
| 141 response.get()); | |
| 142 | |
| 143 client_->SendPacket(kExampleIPConfigPath, data, | |
| 144 base::Bind(&Success), base::Bind(&Failure)); | |
| 145 | |
| 146 message_loop_.RunUntilIdle(); | |
| 147 } | |
| 148 | |
| 149 } // namespace chromeos | |
| OLD | NEW |