Add type annotations to exif_parser.js.
[chromium-blink-merge.git] / chromeos / dbus / shill_service_client_unittest.cc
blob414adac411c16070a55c369025f1566a5ddc53b5
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.
5 #include "base/bind.h"
6 #include "base/values.h"
7 #include "chromeos/dbus/shill_client_unittest_base.h"
8 #include "chromeos/dbus/shill_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"
15 using testing::_;
16 using testing::ByRef;
18 namespace chromeos {
20 namespace {
22 const char kExampleServicePath[] = "/foo/bar";
24 } // namespace
26 class ShillServiceClientTest : public ShillClientUnittestBase {
27 public:
28 ShillServiceClientTest()
29 : ShillClientUnittestBase(shill::kFlimflamServiceInterface,
30 dbus::ObjectPath(kExampleServicePath)) {
33 virtual void SetUp() {
34 ShillClientUnittestBase::SetUp();
35 // Create a client with the mock bus.
36 client_.reset(ShillServiceClient::Create());
37 client_->Init(mock_bus_.get());
38 // Run the message loop to run the signal connection result callback.
39 message_loop_.RunUntilIdle();
42 virtual void TearDown() {
43 ShillClientUnittestBase::TearDown();
46 protected:
47 scoped_ptr<ShillServiceClient> client_;
50 TEST_F(ShillServiceClientTest, PropertyChanged) {
51 const int kValue = 42;
52 // Create a signal.
53 dbus::Signal signal(shill::kFlimflamServiceInterface,
54 shill::kMonitorPropertyChanged);
55 dbus::MessageWriter writer(&signal);
56 writer.AppendString(shill::kSignalStrengthProperty);
57 writer.AppendVariantOfByte(kValue);
59 // Set expectations.
60 const base::FundamentalValue value(kValue);
61 MockPropertyChangeObserver observer;
62 EXPECT_CALL(observer,
63 OnPropertyChanged(
64 shill::kSignalStrengthProperty,
65 ValueEq(ByRef(value)))).Times(1);
67 // Add the observer
68 client_->AddPropertyChangedObserver(
69 dbus::ObjectPath(kExampleServicePath),
70 &observer);
72 // Run the signal callback.
73 SendPropertyChangedSignal(&signal);
75 // Remove the observer.
76 client_->RemovePropertyChangedObserver(
77 dbus::ObjectPath(kExampleServicePath),
78 &observer);
80 EXPECT_CALL(observer, OnPropertyChanged(_, _)).Times(0);
82 // Run the signal callback again and make sure the observer isn't called.
83 SendPropertyChangedSignal(&signal);
86 TEST_F(ShillServiceClientTest, GetProperties) {
87 const int kValue = 42;
88 // Create response.
89 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
90 dbus::MessageWriter writer(response.get());
91 dbus::MessageWriter array_writer(NULL);
92 writer.OpenArray("{sv}", &array_writer);
93 dbus::MessageWriter entry_writer(NULL);
94 array_writer.OpenDictEntry(&entry_writer);
95 entry_writer.AppendString(shill::kSignalStrengthProperty);
96 entry_writer.AppendVariantOfByte(kValue);
97 array_writer.CloseContainer(&entry_writer);
98 writer.CloseContainer(&array_writer);
100 // Set expectations.
101 base::DictionaryValue value;
102 value.SetWithoutPathExpansion(shill::kSignalStrengthProperty,
103 new base::FundamentalValue(kValue));
104 PrepareForMethodCall(shill::kGetPropertiesFunction,
105 base::Bind(&ExpectNoArgument),
106 response.get());
107 // Call method.
108 client_->GetProperties(dbus::ObjectPath(kExampleServicePath),
109 base::Bind(&ExpectDictionaryValueResult, &value));
110 // Run the message loop.
111 message_loop_.RunUntilIdle();
114 TEST_F(ShillServiceClientTest, SetProperty) {
115 const char kValue[] = "passphrase";
116 // Create response.
117 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
119 // Set expectations.
120 const base::StringValue value(kValue);
121 PrepareForMethodCall(shill::kSetPropertyFunction,
122 base::Bind(&ExpectStringAndValueArguments,
123 shill::kPassphraseProperty,
124 &value),
125 response.get());
126 // Call method.
127 MockClosure mock_closure;
128 MockErrorCallback mock_error_callback;
129 client_->SetProperty(dbus::ObjectPath(kExampleServicePath),
130 shill::kPassphraseProperty,
131 value,
132 mock_closure.GetCallback(),
133 mock_error_callback.GetCallback());
134 EXPECT_CALL(mock_closure, Run()).Times(1);
135 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
137 // Run the message loop.
138 message_loop_.RunUntilIdle();
141 TEST_F(ShillServiceClientTest, SetProperties) {
142 // Create response.
143 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
145 // Set expectations.
146 scoped_ptr<base::DictionaryValue> arg(CreateExampleServiceProperties());
147 // Use a variant valued dictionary rather than a string valued one.
148 const bool string_valued = false;
149 PrepareForMethodCall(
150 shill::kSetPropertiesFunction,
151 base::Bind(&ExpectDictionaryValueArgument, arg.get(), string_valued),
152 response.get());
154 // Call method.
155 MockClosure mock_closure;
156 MockErrorCallback mock_error_callback;
157 client_->SetProperties(dbus::ObjectPath(kExampleServicePath),
158 *arg,
159 mock_closure.GetCallback(),
160 mock_error_callback.GetCallback());
161 EXPECT_CALL(mock_closure, Run()).Times(1);
162 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
164 // Run the message loop.
165 message_loop_.RunUntilIdle();
168 TEST_F(ShillServiceClientTest, ClearProperty) {
169 // Create response.
170 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
172 // Set expectations.
173 PrepareForMethodCall(shill::kClearPropertyFunction,
174 base::Bind(&ExpectStringArgument,
175 shill::kPassphraseProperty),
176 response.get());
177 // Call method.
178 MockClosure mock_closure;
179 MockErrorCallback mock_error_callback;
180 client_->ClearProperty(dbus::ObjectPath(kExampleServicePath),
181 shill::kPassphraseProperty,
182 mock_closure.GetCallback(),
183 mock_error_callback.GetCallback());
184 EXPECT_CALL(mock_closure, Run()).Times(1);
185 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
187 // Run the message loop.
188 message_loop_.RunUntilIdle();
191 TEST_F(ShillServiceClientTest, ClearProperties) {
192 // Create response.
193 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
194 dbus::MessageWriter writer(response.get());
195 dbus::MessageWriter array_writer(NULL);
196 writer.OpenArray("b", &array_writer);
197 array_writer.AppendBool(true);
198 array_writer.AppendBool(true);
199 writer.CloseContainer(&array_writer);
201 // Set expectations.
202 std::vector<std::string> keys;
203 keys.push_back(shill::kPassphraseProperty);
204 keys.push_back(shill::kSignalStrengthProperty);
205 PrepareForMethodCall(shill::kClearPropertiesFunction,
206 base::Bind(&ExpectArrayOfStringsArgument, keys),
207 response.get());
208 // Call method.
209 MockListValueCallback mock_list_value_callback;
210 MockErrorCallback mock_error_callback;
211 client_->ClearProperties(dbus::ObjectPath(kExampleServicePath),
212 keys,
213 mock_list_value_callback.GetCallback(),
214 mock_error_callback.GetCallback());
215 EXPECT_CALL(mock_list_value_callback, Run(_)).Times(1);
216 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
218 // Run the message loop.
219 message_loop_.RunUntilIdle();
222 TEST_F(ShillServiceClientTest, Connect) {
223 // Create response.
224 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
226 // Set expectations.
227 MockClosure mock_closure;
228 MockErrorCallback mock_error_callback;
229 PrepareForMethodCall(shill::kConnectFunction,
230 base::Bind(&ExpectNoArgument),
231 response.get());
232 EXPECT_CALL(mock_closure, Run()).Times(1);
233 // Call method.
234 client_->Connect(dbus::ObjectPath(kExampleServicePath),
235 mock_closure.GetCallback(),
236 mock_error_callback.GetCallback());
238 // Run the message loop.
239 message_loop_.RunUntilIdle();
242 TEST_F(ShillServiceClientTest, Disconnect) {
243 // Create response.
244 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
246 // Set expectations.
247 PrepareForMethodCall(shill::kDisconnectFunction,
248 base::Bind(&ExpectNoArgument),
249 response.get());
250 // Call method.
251 MockClosure mock_closure;
252 MockErrorCallback mock_error_callback;
253 client_->Disconnect(dbus::ObjectPath(kExampleServicePath),
254 mock_closure.GetCallback(),
255 mock_error_callback.GetCallback());
256 EXPECT_CALL(mock_closure, Run()).Times(1);
257 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
259 // Run the message loop.
260 message_loop_.RunUntilIdle();
263 TEST_F(ShillServiceClientTest, Remove) {
264 // Create response.
265 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
267 // Set expectations.
268 PrepareForMethodCall(shill::kRemoveServiceFunction,
269 base::Bind(&ExpectNoArgument),
270 response.get());
271 // Call method.
272 MockClosure mock_closure;
273 MockErrorCallback mock_error_callback;
274 client_->Remove(dbus::ObjectPath(kExampleServicePath),
275 mock_closure.GetCallback(),
276 mock_error_callback.GetCallback());
277 EXPECT_CALL(mock_closure, Run()).Times(1);
278 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
280 // Run the message loop.
281 message_loop_.RunUntilIdle();
284 TEST_F(ShillServiceClientTest, ActivateCellularModem) {
285 const char kCarrier[] = "carrier";
286 // Create response.
287 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
289 // Set expectations.
290 PrepareForMethodCall(shill::kActivateCellularModemFunction,
291 base::Bind(&ExpectStringArgument, kCarrier),
292 response.get());
293 // Call method.
294 MockClosure mock_closure;
295 MockErrorCallback mock_error_callback;
296 client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath),
297 kCarrier,
298 mock_closure.GetCallback(),
299 mock_error_callback.GetCallback());
300 EXPECT_CALL(mock_closure, Run()).Times(1);
301 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
303 // Run the message loop.
304 message_loop_.RunUntilIdle();
307 } // namespace chromeos