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

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: Removes dependence on basic_types.h and fixes a build error 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 } // 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 EXPECT(false, true);
pneubeck (no reviews) 2014/11/12 14:21:07 should be EXPECT_FALSE(true) ?
stevenjb 2014/11/12 18:05:13 Also, << error_name to help debug. You might want
kaliamoorthi 2014/11/13 12:16:31 Done.
kaliamoorthi 2014/11/13 12:16:31 Done.
43 }
44
45 protected:
46 scoped_ptr<ShillThirdPartyVpnDriverClient> client_;
47 };
48
49 TEST_F(ShillThirdPartyVpnDriverClientTest, PlatformSignal) {
50 uint32_t connected_state = 123456;
51 const int kPacketSize = 5;
52 uint8_t 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 // Expect each signal to be triggered once.
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, &parameters, 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_t 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698