Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: chromeos/dbus/shill_third_party_vpn_driver_client_unittest.cc

Issue 681723003: Add new shill client for VPN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes nit from Bartosz Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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() {}
pneubeck (no reviews) 2014/11/13 14:06:11 misses an override (didn't this complain at compil
kaliamoorthi 2014/11/13 16:10:52 Done.
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() {
pneubeck (no reviews) 2014/11/13 14:06:11 virtual -> override
kaliamoorthi 2014/11/13 16:10:52 Done.
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(); }
pneubeck (no reviews) 2014/11/13 14:06:11 virtual -> override
kaliamoorthi 2014/11/13 16:10:52 Done.
46
47 static void Success() {}
48 static void Failure(const std::string& error_name,
49 const std::string& error_message) {
50 ADD_FAILURE() << error_name << error_message;
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, &parameters, 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
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_third_party_vpn_driver_client.cc ('k') | chromeos/dbus/shill_third_party_vpn_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698