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

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 comments from Philipp 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);
pneubeck (no reviews) 2014/11/13 16:40:12 ah, I missed before that you have to run the messa
kaliamoorthi 2014/11/13 17:13:43 Done.
85
86 EXPECT_CALL(*this, MockSuccess()).Times(1);
pneubeck (no reviews) 2014/11/13 16:40:12 you should set this expectation after you called R
kaliamoorthi 2014/11/13 17:13:43 Done.
87 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
88 uint32_t connection_state = 2;
89
90 PrepareForMethodCall(shill::kUpdateConnectionStateFunction,
91 base::Bind(&ExpectUint32Argument, connection_state),
92 response.get());
93
94 client_->UpdateConnectionState(
95 kExampleIPConfigPath, connection_state,
96 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
97 base::Unretained(this)),
98 base::Bind(&Failure));
99
100 client_->RemoveShillThirdPartyVpnObserver(kExampleIPConfigPath);
101
102 // Check after removing the observer that there is no further signals.
103 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(0);
104 EXPECT_CALL(observer, OnPacketReceived(_, kPacketSize)).Times(0);
105
106 // Run the signal callback.
107 SendPlatformMessageSignal(&pmessage_signal);
108 SendPacketReceievedSignal(&preceived_signal);
109
110 message_loop_.RunUntilIdle();
111 }
112
113 TEST_F(ShillThirdPartyVpnDriverClientTest, SetParameters) {
114 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
115
116 base::DictionaryValue parameters;
117 const std::string kAddress("1.1.1.1");
118 parameters.SetStringWithoutPathExpansion(
119 shill::kAddressParameterThirdPartyVpn, kAddress);
120
121 EXPECT_CALL(*this, MockSuccess()).Times(1);
122
123 PrepareForMethodCall(
124 shill::kSetParametersFunction,
125 base::Bind(&ExpectDictionaryValueArgument, &parameters, true),
126 response.get());
127
128 client_->SetParameters(
129 kExampleIPConfigPath, parameters,
130 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
131 base::Unretained(this)),
132 base::Bind(&Failure));
133
134 message_loop_.RunUntilIdle();
135 }
136
137 TEST_F(ShillThirdPartyVpnDriverClientTest, UpdateConnectionState) {
138 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
139 uint32_t connection_state = 2;
140
141 EXPECT_CALL(*this, MockSuccess()).Times(1);
142
143 PrepareForMethodCall(shill::kUpdateConnectionStateFunction,
144 base::Bind(&ExpectUint32Argument, connection_state),
145 response.get());
146
147 client_->UpdateConnectionState(
148 kExampleIPConfigPath, connection_state,
149 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
150 base::Unretained(this)),
151 base::Bind(&Failure));
152
153 message_loop_.RunUntilIdle();
154 }
155
156 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) {
157 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
158
159 const std::string data(5, 0);
160
161 EXPECT_CALL(*this, MockSuccess()).Times(1);
162
163 PrepareForMethodCall(shill::kSendPacketFunction,
164 base::Bind(&ExpectArrayOfBytesArgument, data),
165 response.get());
166
167 client_->SendPacket(
168 kExampleIPConfigPath, data,
169 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
170 base::Unretained(this)),
171 base::Bind(&Failure));
172
173 message_loop_.RunUntilIdle();
174 }
175
176 } // 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