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

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 Steven 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() override {}
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 void SetUp() override {
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 void TearDown() override { ShillClientUnittestBase::TearDown(); }
46
47 MOCK_METHOD0(MockSuccess, void());
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, &observer);
81
82 // Run the signal callback.
83 SendPlatformMessageSignal(&pmessage_signal);
84 SendPacketReceievedSignal(&preceived_signal);
85
86 testing::Mock::VerifyAndClearExpectations(&observer);
87
88 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
89 uint32_t connection_state = 2;
90
91 PrepareForMethodCall(shill::kUpdateConnectionStateFunction,
92 base::Bind(&ExpectUint32Argument, connection_state),
93 response.get());
94
95 EXPECT_CALL(*this, MockSuccess()).Times(0);
96 client_->UpdateConnectionState(
97 kExampleIPConfigPath, connection_state,
98 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
99 base::Unretained(this)),
100 base::Bind(&Failure));
101
102 client_->RemoveShillThirdPartyVpnObserver(kExampleIPConfigPath);
103 testing::Mock::VerifyAndClearExpectations(this);
104
105 EXPECT_CALL(*this, MockSuccess()).Times(1);
106
107 // Check after removing the observer that there is no further signals.
108 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(0);
109 EXPECT_CALL(observer, OnPacketReceived(_, kPacketSize)).Times(0);
110
111 // Run the signal callback.
112 SendPlatformMessageSignal(&pmessage_signal);
113 SendPacketReceievedSignal(&preceived_signal);
114
115 testing::Mock::VerifyAndClearExpectations(&observer);
116
117 message_loop_.RunUntilIdle();
118 }
119
120 TEST_F(ShillThirdPartyVpnDriverClientTest, SetParameters) {
121 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
122
123 base::DictionaryValue parameters;
124 const std::string kAddress("1.1.1.1");
125 parameters.SetStringWithoutPathExpansion(
126 shill::kAddressParameterThirdPartyVpn, kAddress);
127
128 EXPECT_CALL(*this, MockSuccess()).Times(1);
129
130 PrepareForMethodCall(
131 shill::kSetParametersFunction,
132 base::Bind(&ExpectDictionaryValueArgument, &parameters, true),
133 response.get());
134
135 client_->SetParameters(
136 kExampleIPConfigPath, parameters,
137 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
138 base::Unretained(this)),
139 base::Bind(&Failure));
140
141 message_loop_.RunUntilIdle();
142 }
143
144 TEST_F(ShillThirdPartyVpnDriverClientTest, UpdateConnectionState) {
145 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
146 uint32_t connection_state = 2;
147
148 EXPECT_CALL(*this, MockSuccess()).Times(1);
149
150 PrepareForMethodCall(shill::kUpdateConnectionStateFunction,
151 base::Bind(&ExpectUint32Argument, connection_state),
152 response.get());
153
154 client_->UpdateConnectionState(
155 kExampleIPConfigPath, connection_state,
156 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
157 base::Unretained(this)),
158 base::Bind(&Failure));
159
160 message_loop_.RunUntilIdle();
161 }
162
163 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) {
164 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
165
166 const std::string data(5, 0);
167
168 EXPECT_CALL(*this, MockSuccess()).Times(1);
169
170 PrepareForMethodCall(shill::kSendPacketFunction,
171 base::Bind(&ExpectArrayOfBytesArgument, data),
172 response.get());
173
174 client_->SendPacket(
175 kExampleIPConfigPath, data,
176 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
177 base::Unretained(this)),
178 base::Bind(&Failure));
179
180 message_loop_.RunUntilIdle();
181 }
182
183 } // 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