OLD | NEW |
---|---|
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 "chromeos/dbus/shill_manager_client.h" | 5 #include "chromeos/dbus/shill_manager_client.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 std::string arg_string; | 45 std::string arg_string; |
46 ASSERT_TRUE(reader->PopString(&arg_string)); | 46 ASSERT_TRUE(reader->PopString(&arg_string)); |
47 EXPECT_EQ(*iter, arg_string); | 47 EXPECT_EQ(*iter, arg_string); |
48 } | 48 } |
49 dbus::ObjectPath path; | 49 dbus::ObjectPath path; |
50 ASSERT_TRUE(reader->PopObjectPath(&path)); | 50 ASSERT_TRUE(reader->PopObjectPath(&path)); |
51 EXPECT_EQ(object_path, path); | 51 EXPECT_EQ(object_path, path); |
52 EXPECT_FALSE(reader->HasMoreData()); | 52 EXPECT_FALSE(reader->HasMoreData()); |
53 } | 53 } |
54 | 54 |
55 void ExpectThrottlingArguments(bool throttling_enabled_expected, | |
56 uint32_t upload_rate_kbits_expected, | |
57 uint32_t download_rate_kbits_expected, | |
58 dbus::MessageReader* reader) { | |
59 bool throttling_enabled_actual; | |
60 uint32_t upload_rate_kbits_actual; | |
61 uint32_t download_rate_kbits_actual; | |
62 ASSERT_TRUE(reader->PopBool(&throttling_enabled_actual)); | |
63 EXPECT_EQ(throttling_enabled_actual, throttling_enabled_expected); | |
Lei Zhang
2016/10/29 16:04:05
nit: EXPECT_EQ(expected, actual) - reverse the arg
| |
64 ASSERT_TRUE(reader->PopUint32(&upload_rate_kbits_actual)); | |
65 EXPECT_EQ(upload_rate_kbits_expected, upload_rate_kbits_actual); | |
66 ASSERT_TRUE(reader->PopUint32(&download_rate_kbits_actual)); | |
67 EXPECT_EQ(download_rate_kbits_expected, download_rate_kbits_actual); | |
68 EXPECT_FALSE(reader->HasMoreData()); | |
69 } | |
55 | 70 |
56 } // namespace | 71 } // namespace |
57 | 72 |
58 class ShillManagerClientTest : public ShillClientUnittestBase { | 73 class ShillManagerClientTest : public ShillClientUnittestBase { |
59 public: | 74 public: |
60 ShillManagerClientTest() | 75 ShillManagerClientTest() |
61 : ShillClientUnittestBase(shill::kFlimflamManagerInterface, | 76 : ShillClientUnittestBase(shill::kFlimflamManagerInterface, |
62 dbus::ObjectPath(shill::kFlimflamServicePath)) { | 77 dbus::ObjectPath(shill::kFlimflamServicePath)) { |
63 } | 78 } |
64 | 79 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 client_->EnableTechnology(shill::kTypeWifi, | 257 client_->EnableTechnology(shill::kTypeWifi, |
243 mock_closure.GetCallback(), | 258 mock_closure.GetCallback(), |
244 mock_error_callback.GetCallback()); | 259 mock_error_callback.GetCallback()); |
245 EXPECT_CALL(mock_closure, Run()).Times(1); | 260 EXPECT_CALL(mock_closure, Run()).Times(1); |
246 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); | 261 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
247 | 262 |
248 // Run the message loop. | 263 // Run the message loop. |
249 base::RunLoop().RunUntilIdle(); | 264 base::RunLoop().RunUntilIdle(); |
250 } | 265 } |
251 | 266 |
267 TEST_F(ShillManagerClientTest, NetworkThrottling) { | |
268 // Create response. | |
269 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
270 // Set expectations. | |
271 const bool enabled = true; | |
272 const uint32_t upload_rate = 1200; | |
273 const uint32_t download_rate = 2000; | |
274 PrepareForMethodCall(shill::kSetNetworkThrottlingFunction, | |
275 base::Bind(&ExpectThrottlingArguments, enabled, | |
276 upload_rate, download_rate), | |
277 response.get()); | |
278 // Call method. | |
279 MockClosure mock_closure; | |
280 MockErrorCallback mock_error_callback; | |
281 client_->SetNetworkThrottlingStatus(enabled, upload_rate, download_rate, | |
282 mock_closure.GetCallback(), | |
283 mock_error_callback.GetCallback()); | |
284 EXPECT_CALL(mock_closure, Run()).Times(1); | |
285 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); | |
286 | |
287 // Run the message loop. | |
288 base::RunLoop().RunUntilIdle(); | |
289 } | |
290 | |
252 TEST_F(ShillManagerClientTest, DisableTechnology) { | 291 TEST_F(ShillManagerClientTest, DisableTechnology) { |
253 // Create response. | 292 // Create response. |
254 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 293 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
255 // Set expectations. | 294 // Set expectations. |
256 PrepareForMethodCall(shill::kDisableTechnologyFunction, | 295 PrepareForMethodCall(shill::kDisableTechnologyFunction, |
257 base::Bind(&ExpectStringArgument, shill::kTypeWifi), | 296 base::Bind(&ExpectStringArgument, shill::kTypeWifi), |
258 response.get()); | 297 response.get()); |
259 // Call method. | 298 // Call method. |
260 MockClosure mock_closure; | 299 MockClosure mock_closure; |
261 MockErrorCallback mock_error_callback; | 300 MockErrorCallback mock_error_callback; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 arguments[7], | 480 arguments[7], |
442 base::Bind(&ExpectStringResultWithoutStatus, expected), | 481 base::Bind(&ExpectStringResultWithoutStatus, expected), |
443 mock_error_callback.GetCallback()); | 482 mock_error_callback.GetCallback()); |
444 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); | 483 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
445 | 484 |
446 // Run the message loop. | 485 // Run the message loop. |
447 base::RunLoop().RunUntilIdle(); | 486 base::RunLoop().RunUntilIdle(); |
448 } | 487 } |
449 | 488 |
450 } // namespace chromeos | 489 } // namespace chromeos |
OLD | NEW |