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

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

Issue 10915106: Renaming instances of "flimflam" with "shill", now that we're only (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Upload after merge Created 8 years, 3 months 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
« no previous file with comments | « chromeos/dbus/flimflam_service_client.cc ('k') | chromeos/dbus/gsm_sms_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "base/values.h"
7 #include "chromeos/dbus/flimflam_client_unittest_base.h"
8 #include "chromeos/dbus/flimflam_service_client.h"
9 #include "dbus/message.h"
10 #include "dbus/object_path.h"
11 #include "dbus/values_util.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
14
15 namespace chromeos {
16
17 namespace {
18
19 const char kExampleServicePath[] = "/foo/bar";
20
21 } // namespace
22
23 class FlimflamServiceClientTest : public FlimflamClientUnittestBase {
24 public:
25 FlimflamServiceClientTest()
26 : FlimflamClientUnittestBase(flimflam::kFlimflamServiceInterface,
27 dbus::ObjectPath(kExampleServicePath)) {
28 }
29
30 virtual void SetUp() {
31 FlimflamClientUnittestBase::SetUp();
32 // Create a client with the mock bus.
33 client_.reset(FlimflamServiceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION,
34 mock_bus_));
35 // Run the message loop to run the signal connection result callback.
36 message_loop_.RunAllPending();
37 }
38
39 virtual void TearDown() {
40 FlimflamClientUnittestBase::TearDown();
41 }
42
43 protected:
44 scoped_ptr<FlimflamServiceClient> client_;
45 };
46
47 TEST_F(FlimflamServiceClientTest, PropertyChanged) {
48 const int kValue = 42;
49 // Create a signal.
50 dbus::Signal signal(flimflam::kFlimflamServiceInterface,
51 flimflam::kMonitorPropertyChanged);
52 dbus::MessageWriter writer(&signal);
53 writer.AppendString(flimflam::kSignalStrengthProperty);
54 writer.AppendVariantOfByte(kValue);
55
56 // Set expectations.
57 const base::FundamentalValue value(kValue);
58 client_->SetPropertyChangedHandler(
59 dbus::ObjectPath(kExampleServicePath),
60 base::Bind(&ExpectPropertyChanged,
61 flimflam::kSignalStrengthProperty,
62 &value));
63 // Run the signal callback.
64 SendPropertyChangedSignal(&signal);
65
66 // Reset the handler.
67 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleServicePath));
68 }
69
70 TEST_F(FlimflamServiceClientTest, GetProperties) {
71 const int kValue = 42;
72 // Create response.
73 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
74 dbus::MessageWriter writer(response.get());
75 dbus::MessageWriter array_writer(NULL);
76 writer.OpenArray("{sv}", &array_writer);
77 dbus::MessageWriter entry_writer(NULL);
78 array_writer.OpenDictEntry(&entry_writer);
79 entry_writer.AppendString(flimflam::kSignalStrengthProperty);
80 entry_writer.AppendVariantOfByte(kValue);
81 array_writer.CloseContainer(&entry_writer);
82 writer.CloseContainer(&array_writer);
83
84 // Set expectations.
85 base::DictionaryValue value;
86 value.SetWithoutPathExpansion(flimflam::kSignalStrengthProperty,
87 base::Value::CreateIntegerValue(kValue));
88 PrepareForMethodCall(flimflam::kGetPropertiesFunction,
89 base::Bind(&ExpectNoArgument),
90 response.get());
91 // Call method.
92 client_->GetProperties(dbus::ObjectPath(kExampleServicePath),
93 base::Bind(&ExpectDictionaryValueResult, &value));
94 // Run the message loop.
95 message_loop_.RunAllPending();
96 }
97
98 TEST_F(FlimflamServiceClientTest, SetProperty) {
99 const char kValue[] = "passphrase";
100 // Create response.
101 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
102
103 // Set expectations.
104 const base::StringValue value(kValue);
105 PrepareForMethodCall(flimflam::kSetPropertyFunction,
106 base::Bind(&ExpectStringAndValueArguments,
107 flimflam::kPassphraseProperty,
108 &value),
109 response.get());
110 // Call method.
111 client_->SetProperty(dbus::ObjectPath(kExampleServicePath),
112 flimflam::kPassphraseProperty,
113 value,
114 base::Bind(&ExpectNoResultValue));
115 // Run the message loop.
116 message_loop_.RunAllPending();
117 }
118
119 TEST_F(FlimflamServiceClientTest, ClearProperty) {
120 // Create response.
121 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
122
123 // Set expectations.
124 PrepareForMethodCall(flimflam::kClearPropertyFunction,
125 base::Bind(&ExpectStringArgument,
126 flimflam::kPassphraseProperty),
127 response.get());
128 // Call method.
129 client_->ClearProperty(dbus::ObjectPath(kExampleServicePath),
130 flimflam::kPassphraseProperty,
131 base::Bind(&ExpectNoResultValue));
132 // Run the message loop.
133 message_loop_.RunAllPending();
134 }
135
136 TEST_F(FlimflamServiceClientTest, Connect) {
137 // Create response.
138 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
139
140 // Set expectations.
141 MockClosure mock_closure;
142 MockErrorCallback mock_error_callback;
143 PrepareForMethodCall(flimflam::kConnectFunction,
144 base::Bind(&ExpectNoArgument),
145 response.get());
146 EXPECT_CALL(mock_closure, Run()).Times(1);
147 // Call method.
148 client_->Connect(dbus::ObjectPath(kExampleServicePath),
149 mock_closure.GetCallback(),
150 mock_error_callback.GetCallback());
151
152 // Run the message loop.
153 message_loop_.RunAllPending();
154 }
155
156 TEST_F(FlimflamServiceClientTest, Disconnect) {
157 // Create response.
158 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
159
160 // Set expectations.
161 PrepareForMethodCall(flimflam::kDisconnectFunction,
162 base::Bind(&ExpectNoArgument),
163 response.get());
164 // Call method.
165 client_->Disconnect(dbus::ObjectPath(kExampleServicePath),
166 base::Bind(&ExpectNoResultValue));
167 // Run the message loop.
168 message_loop_.RunAllPending();
169 }
170
171 TEST_F(FlimflamServiceClientTest, Remove) {
172 // Create response.
173 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
174
175 // Set expectations.
176 PrepareForMethodCall(flimflam::kRemoveServiceFunction,
177 base::Bind(&ExpectNoArgument),
178 response.get());
179 // Call method.
180 client_->Remove(dbus::ObjectPath(kExampleServicePath),
181 base::Bind(&ExpectNoResultValue));
182 // Run the message loop.
183 message_loop_.RunAllPending();
184 }
185
186 TEST_F(FlimflamServiceClientTest, ActivateCellularModem) {
187 const char kCarrier[] = "carrier";
188 // Create response.
189 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
190
191 // Set expectations.
192 PrepareForMethodCall(flimflam::kActivateCellularModemFunction,
193 base::Bind(&ExpectStringArgument, kCarrier),
194 response.get());
195 // Call method.
196 client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath),
197 kCarrier,
198 base::Bind(&ExpectNoResultValue));
199 // Run the message loop.
200 message_loop_.RunAllPending();
201 }
202
203 TEST_F(FlimflamServiceClientTest, CallActivateCellularModemAndBlock) {
204 const char kCarrier[] = "carrier";
205 // Create response.
206 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
207
208 // Set expectations.
209 PrepareForMethodCall(flimflam::kActivateCellularModemFunction,
210 base::Bind(&ExpectStringArgument, kCarrier),
211 response.get());
212 // Call method.
213 const bool result = client_->CallActivateCellularModemAndBlock(
214 dbus::ObjectPath(kExampleServicePath), kCarrier);
215 EXPECT_TRUE(result);
216 }
217
218 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/flimflam_service_client.cc ('k') | chromeos/dbus/gsm_sms_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698