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

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

Issue 2314853004: Remove calls to deprecated MessageLoop methods in chromeos. (Closed)
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/run_loop.h"
6 #include "base/values.h" 7 #include "base/values.h"
7 #include "chromeos/dbus/shill_client_unittest_base.h" 8 #include "chromeos/dbus/shill_client_unittest_base.h"
8 #include "chromeos/dbus/shill_service_client.h" 9 #include "chromeos/dbus/shill_service_client.h"
9 #include "dbus/message.h" 10 #include "dbus/message.h"
10 #include "dbus/object_path.h" 11 #include "dbus/object_path.h"
11 #include "dbus/values_util.h" 12 #include "dbus/values_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 14 #include "third_party/cros_system_api/dbus/service_constants.h"
14 15
15 using testing::_; 16 using testing::_;
(...skipping 13 matching lines...) Expand all
29 : ShillClientUnittestBase(shill::kFlimflamServiceInterface, 30 : ShillClientUnittestBase(shill::kFlimflamServiceInterface,
30 dbus::ObjectPath(kExampleServicePath)) { 31 dbus::ObjectPath(kExampleServicePath)) {
31 } 32 }
32 33
33 void SetUp() override { 34 void SetUp() override {
34 ShillClientUnittestBase::SetUp(); 35 ShillClientUnittestBase::SetUp();
35 // Create a client with the mock bus. 36 // Create a client with the mock bus.
36 client_.reset(ShillServiceClient::Create()); 37 client_.reset(ShillServiceClient::Create());
37 client_->Init(mock_bus_.get()); 38 client_->Init(mock_bus_.get());
38 // Run the message loop to run the signal connection result callback. 39 // Run the message loop to run the signal connection result callback.
39 message_loop_.RunUntilIdle(); 40 base::RunLoop().RunUntilIdle();
40 } 41 }
41 42
42 void TearDown() override { ShillClientUnittestBase::TearDown(); } 43 void TearDown() override { ShillClientUnittestBase::TearDown(); }
43 44
44 protected: 45 protected:
45 std::unique_ptr<ShillServiceClient> client_; 46 std::unique_ptr<ShillServiceClient> client_;
46 }; 47 };
47 48
48 TEST_F(ShillServiceClientTest, PropertyChanged) { 49 TEST_F(ShillServiceClientTest, PropertyChanged) {
49 const int kValue = 42; 50 const int kValue = 42;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 base::DictionaryValue value; 100 base::DictionaryValue value;
100 value.SetWithoutPathExpansion(shill::kSignalStrengthProperty, 101 value.SetWithoutPathExpansion(shill::kSignalStrengthProperty,
101 new base::FundamentalValue(kValue)); 102 new base::FundamentalValue(kValue));
102 PrepareForMethodCall(shill::kGetPropertiesFunction, 103 PrepareForMethodCall(shill::kGetPropertiesFunction,
103 base::Bind(&ExpectNoArgument), 104 base::Bind(&ExpectNoArgument),
104 response.get()); 105 response.get());
105 // Call method. 106 // Call method.
106 client_->GetProperties(dbus::ObjectPath(kExampleServicePath), 107 client_->GetProperties(dbus::ObjectPath(kExampleServicePath),
107 base::Bind(&ExpectDictionaryValueResult, &value)); 108 base::Bind(&ExpectDictionaryValueResult, &value));
108 // Run the message loop. 109 // Run the message loop.
109 message_loop_.RunUntilIdle(); 110 base::RunLoop().RunUntilIdle();
110 } 111 }
111 112
112 TEST_F(ShillServiceClientTest, SetProperty) { 113 TEST_F(ShillServiceClientTest, SetProperty) {
113 const char kValue[] = "passphrase"; 114 const char kValue[] = "passphrase";
114 // Create response. 115 // Create response.
115 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 116 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
116 117
117 // Set expectations. 118 // Set expectations.
118 const base::StringValue value(kValue); 119 const base::StringValue value(kValue);
119 PrepareForMethodCall(shill::kSetPropertyFunction, 120 PrepareForMethodCall(shill::kSetPropertyFunction,
120 base::Bind(&ExpectStringAndValueArguments, 121 base::Bind(&ExpectStringAndValueArguments,
121 shill::kPassphraseProperty, 122 shill::kPassphraseProperty,
122 &value), 123 &value),
123 response.get()); 124 response.get());
124 // Call method. 125 // Call method.
125 MockClosure mock_closure; 126 MockClosure mock_closure;
126 MockErrorCallback mock_error_callback; 127 MockErrorCallback mock_error_callback;
127 client_->SetProperty(dbus::ObjectPath(kExampleServicePath), 128 client_->SetProperty(dbus::ObjectPath(kExampleServicePath),
128 shill::kPassphraseProperty, 129 shill::kPassphraseProperty,
129 value, 130 value,
130 mock_closure.GetCallback(), 131 mock_closure.GetCallback(),
131 mock_error_callback.GetCallback()); 132 mock_error_callback.GetCallback());
132 EXPECT_CALL(mock_closure, Run()).Times(1); 133 EXPECT_CALL(mock_closure, Run()).Times(1);
133 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 134 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
134 135
135 // Run the message loop. 136 // Run the message loop.
136 message_loop_.RunUntilIdle(); 137 base::RunLoop().RunUntilIdle();
137 } 138 }
138 139
139 TEST_F(ShillServiceClientTest, SetProperties) { 140 TEST_F(ShillServiceClientTest, SetProperties) {
140 // Create response. 141 // Create response.
141 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 142 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
142 143
143 // Set expectations. 144 // Set expectations.
144 std::unique_ptr<base::DictionaryValue> arg(CreateExampleServiceProperties()); 145 std::unique_ptr<base::DictionaryValue> arg(CreateExampleServiceProperties());
145 // Use a variant valued dictionary rather than a string valued one. 146 // Use a variant valued dictionary rather than a string valued one.
146 const bool string_valued = false; 147 const bool string_valued = false;
147 PrepareForMethodCall( 148 PrepareForMethodCall(
148 shill::kSetPropertiesFunction, 149 shill::kSetPropertiesFunction,
149 base::Bind(&ExpectDictionaryValueArgument, arg.get(), string_valued), 150 base::Bind(&ExpectDictionaryValueArgument, arg.get(), string_valued),
150 response.get()); 151 response.get());
151 152
152 // Call method. 153 // Call method.
153 MockClosure mock_closure; 154 MockClosure mock_closure;
154 MockErrorCallback mock_error_callback; 155 MockErrorCallback mock_error_callback;
155 client_->SetProperties(dbus::ObjectPath(kExampleServicePath), 156 client_->SetProperties(dbus::ObjectPath(kExampleServicePath),
156 *arg, 157 *arg,
157 mock_closure.GetCallback(), 158 mock_closure.GetCallback(),
158 mock_error_callback.GetCallback()); 159 mock_error_callback.GetCallback());
159 EXPECT_CALL(mock_closure, Run()).Times(1); 160 EXPECT_CALL(mock_closure, Run()).Times(1);
160 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 161 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
161 162
162 // Run the message loop. 163 // Run the message loop.
163 message_loop_.RunUntilIdle(); 164 base::RunLoop().RunUntilIdle();
164 } 165 }
165 166
166 TEST_F(ShillServiceClientTest, ClearProperty) { 167 TEST_F(ShillServiceClientTest, ClearProperty) {
167 // Create response. 168 // Create response.
168 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 169 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
169 170
170 // Set expectations. 171 // Set expectations.
171 PrepareForMethodCall(shill::kClearPropertyFunction, 172 PrepareForMethodCall(shill::kClearPropertyFunction,
172 base::Bind(&ExpectStringArgument, 173 base::Bind(&ExpectStringArgument,
173 shill::kPassphraseProperty), 174 shill::kPassphraseProperty),
174 response.get()); 175 response.get());
175 // Call method. 176 // Call method.
176 MockClosure mock_closure; 177 MockClosure mock_closure;
177 MockErrorCallback mock_error_callback; 178 MockErrorCallback mock_error_callback;
178 client_->ClearProperty(dbus::ObjectPath(kExampleServicePath), 179 client_->ClearProperty(dbus::ObjectPath(kExampleServicePath),
179 shill::kPassphraseProperty, 180 shill::kPassphraseProperty,
180 mock_closure.GetCallback(), 181 mock_closure.GetCallback(),
181 mock_error_callback.GetCallback()); 182 mock_error_callback.GetCallback());
182 EXPECT_CALL(mock_closure, Run()).Times(1); 183 EXPECT_CALL(mock_closure, Run()).Times(1);
183 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 184 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
184 185
185 // Run the message loop. 186 // Run the message loop.
186 message_loop_.RunUntilIdle(); 187 base::RunLoop().RunUntilIdle();
187 } 188 }
188 189
189 TEST_F(ShillServiceClientTest, ClearProperties) { 190 TEST_F(ShillServiceClientTest, ClearProperties) {
190 // Create response. 191 // Create response.
191 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 192 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
192 dbus::MessageWriter writer(response.get()); 193 dbus::MessageWriter writer(response.get());
193 dbus::MessageWriter array_writer(NULL); 194 dbus::MessageWriter array_writer(NULL);
194 writer.OpenArray("b", &array_writer); 195 writer.OpenArray("b", &array_writer);
195 array_writer.AppendBool(true); 196 array_writer.AppendBool(true);
196 array_writer.AppendBool(true); 197 array_writer.AppendBool(true);
(...skipping 10 matching lines...) Expand all
207 MockListValueCallback mock_list_value_callback; 208 MockListValueCallback mock_list_value_callback;
208 MockErrorCallback mock_error_callback; 209 MockErrorCallback mock_error_callback;
209 client_->ClearProperties(dbus::ObjectPath(kExampleServicePath), 210 client_->ClearProperties(dbus::ObjectPath(kExampleServicePath),
210 keys, 211 keys,
211 mock_list_value_callback.GetCallback(), 212 mock_list_value_callback.GetCallback(),
212 mock_error_callback.GetCallback()); 213 mock_error_callback.GetCallback());
213 EXPECT_CALL(mock_list_value_callback, Run(_)).Times(1); 214 EXPECT_CALL(mock_list_value_callback, Run(_)).Times(1);
214 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 215 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
215 216
216 // Run the message loop. 217 // Run the message loop.
217 message_loop_.RunUntilIdle(); 218 base::RunLoop().RunUntilIdle();
218 } 219 }
219 220
220 TEST_F(ShillServiceClientTest, Connect) { 221 TEST_F(ShillServiceClientTest, Connect) {
221 // Create response. 222 // Create response.
222 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 223 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
223 224
224 // Set expectations. 225 // Set expectations.
225 MockClosure mock_closure; 226 MockClosure mock_closure;
226 MockErrorCallback mock_error_callback; 227 MockErrorCallback mock_error_callback;
227 PrepareForMethodCall(shill::kConnectFunction, 228 PrepareForMethodCall(shill::kConnectFunction,
228 base::Bind(&ExpectNoArgument), 229 base::Bind(&ExpectNoArgument),
229 response.get()); 230 response.get());
230 EXPECT_CALL(mock_closure, Run()).Times(1); 231 EXPECT_CALL(mock_closure, Run()).Times(1);
231 // Call method. 232 // Call method.
232 client_->Connect(dbus::ObjectPath(kExampleServicePath), 233 client_->Connect(dbus::ObjectPath(kExampleServicePath),
233 mock_closure.GetCallback(), 234 mock_closure.GetCallback(),
234 mock_error_callback.GetCallback()); 235 mock_error_callback.GetCallback());
235 236
236 // Run the message loop. 237 // Run the message loop.
237 message_loop_.RunUntilIdle(); 238 base::RunLoop().RunUntilIdle();
238 } 239 }
239 240
240 TEST_F(ShillServiceClientTest, Disconnect) { 241 TEST_F(ShillServiceClientTest, Disconnect) {
241 // Create response. 242 // Create response.
242 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 243 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
243 244
244 // Set expectations. 245 // Set expectations.
245 PrepareForMethodCall(shill::kDisconnectFunction, 246 PrepareForMethodCall(shill::kDisconnectFunction,
246 base::Bind(&ExpectNoArgument), 247 base::Bind(&ExpectNoArgument),
247 response.get()); 248 response.get());
248 // Call method. 249 // Call method.
249 MockClosure mock_closure; 250 MockClosure mock_closure;
250 MockErrorCallback mock_error_callback; 251 MockErrorCallback mock_error_callback;
251 client_->Disconnect(dbus::ObjectPath(kExampleServicePath), 252 client_->Disconnect(dbus::ObjectPath(kExampleServicePath),
252 mock_closure.GetCallback(), 253 mock_closure.GetCallback(),
253 mock_error_callback.GetCallback()); 254 mock_error_callback.GetCallback());
254 EXPECT_CALL(mock_closure, Run()).Times(1); 255 EXPECT_CALL(mock_closure, Run()).Times(1);
255 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 256 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
256 257
257 // Run the message loop. 258 // Run the message loop.
258 message_loop_.RunUntilIdle(); 259 base::RunLoop().RunUntilIdle();
259 } 260 }
260 261
261 TEST_F(ShillServiceClientTest, Remove) { 262 TEST_F(ShillServiceClientTest, Remove) {
262 // Create response. 263 // Create response.
263 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 264 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
264 265
265 // Set expectations. 266 // Set expectations.
266 PrepareForMethodCall(shill::kRemoveServiceFunction, 267 PrepareForMethodCall(shill::kRemoveServiceFunction,
267 base::Bind(&ExpectNoArgument), 268 base::Bind(&ExpectNoArgument),
268 response.get()); 269 response.get());
269 // Call method. 270 // Call method.
270 MockClosure mock_closure; 271 MockClosure mock_closure;
271 MockErrorCallback mock_error_callback; 272 MockErrorCallback mock_error_callback;
272 client_->Remove(dbus::ObjectPath(kExampleServicePath), 273 client_->Remove(dbus::ObjectPath(kExampleServicePath),
273 mock_closure.GetCallback(), 274 mock_closure.GetCallback(),
274 mock_error_callback.GetCallback()); 275 mock_error_callback.GetCallback());
275 EXPECT_CALL(mock_closure, Run()).Times(1); 276 EXPECT_CALL(mock_closure, Run()).Times(1);
276 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 277 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
277 278
278 // Run the message loop. 279 // Run the message loop.
279 message_loop_.RunUntilIdle(); 280 base::RunLoop().RunUntilIdle();
280 } 281 }
281 282
282 TEST_F(ShillServiceClientTest, ActivateCellularModem) { 283 TEST_F(ShillServiceClientTest, ActivateCellularModem) {
283 const char kCarrier[] = "carrier"; 284 const char kCarrier[] = "carrier";
284 // Create response. 285 // Create response.
285 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 286 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
286 287
287 // Set expectations. 288 // Set expectations.
288 PrepareForMethodCall(shill::kActivateCellularModemFunction, 289 PrepareForMethodCall(shill::kActivateCellularModemFunction,
289 base::Bind(&ExpectStringArgument, kCarrier), 290 base::Bind(&ExpectStringArgument, kCarrier),
290 response.get()); 291 response.get());
291 // Call method. 292 // Call method.
292 MockClosure mock_closure; 293 MockClosure mock_closure;
293 MockErrorCallback mock_error_callback; 294 MockErrorCallback mock_error_callback;
294 client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath), 295 client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath),
295 kCarrier, 296 kCarrier,
296 mock_closure.GetCallback(), 297 mock_closure.GetCallback(),
297 mock_error_callback.GetCallback()); 298 mock_error_callback.GetCallback());
298 EXPECT_CALL(mock_closure, Run()).Times(1); 299 EXPECT_CALL(mock_closure, Run()).Times(1);
299 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 300 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
300 301
301 // Run the message loop. 302 // Run the message loop.
302 message_loop_.RunUntilIdle(); 303 base::RunLoop().RunUntilIdle();
303 } 304 }
304 305
305 } // namespace chromeos 306 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698