OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/scoped_task_environment.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
13 #include "chromeos/dbus/fake_shill_device_client.h" | 13 #include "chromeos/dbus/fake_shill_device_client.h" |
14 #include "chromeos/dbus/fake_shill_manager_client.h" | 14 #include "chromeos/dbus/fake_shill_manager_client.h" |
15 #include "chromeos/network/network_device_handler_impl.h" | 15 #include "chromeos/network/network_device_handler_impl.h" |
16 #include "chromeos/network/network_state_handler.h" | 16 #include "chromeos/network/network_state_handler.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
19 | 19 |
20 namespace chromeos { | 20 namespace chromeos { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kDefaultCellularDevicePath[] = "stub_cellular_device"; | 24 const char kDefaultCellularDevicePath[] = "stub_cellular_device"; |
25 const char kUnknownCellularDevicePath[] = "unknown_cellular_device"; | 25 const char kUnknownCellularDevicePath[] = "unknown_cellular_device"; |
26 const char kDefaultWifiDevicePath[] = "stub_wifi_device"; | 26 const char kDefaultWifiDevicePath[] = "stub_wifi_device"; |
27 const char kResultSuccess[] = "success"; | 27 const char kResultSuccess[] = "success"; |
28 const char kDefaultPin[] = "1111"; | 28 const char kDefaultPin[] = "1111"; |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 class NetworkDeviceHandlerTest : public testing::Test { | 32 class NetworkDeviceHandlerTest : public testing::Test { |
33 public: | 33 public: |
34 NetworkDeviceHandlerTest() : fake_device_client_(NULL) {} | 34 NetworkDeviceHandlerTest() |
| 35 : scoped_task_environment_( |
| 36 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
35 ~NetworkDeviceHandlerTest() override {} | 37 ~NetworkDeviceHandlerTest() override {} |
36 | 38 |
37 void SetUp() override { | 39 void SetUp() override { |
38 fake_device_client_ = new FakeShillDeviceClient; | 40 fake_device_client_ = new FakeShillDeviceClient; |
39 DBusThreadManager::GetSetterForTesting()->SetShillDeviceClient( | 41 DBusThreadManager::GetSetterForTesting()->SetShillDeviceClient( |
40 std::unique_ptr<ShillDeviceClient>(fake_device_client_)); | 42 std::unique_ptr<ShillDeviceClient>(fake_device_client_)); |
41 | 43 |
42 success_callback_ = base::Bind(&NetworkDeviceHandlerTest::SuccessCallback, | 44 success_callback_ = base::Bind(&NetworkDeviceHandlerTest::SuccessCallback, |
43 base::Unretained(this)); | 45 base::Unretained(this)); |
44 properties_success_callback_ = | 46 properties_success_callback_ = |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 result_ = kResultSuccess; | 94 result_ = kResultSuccess; |
93 properties_.reset(properties.DeepCopy()); | 95 properties_.reset(properties.DeepCopy()); |
94 } | 96 } |
95 | 97 |
96 void StringSuccessCallback(const std::string& result) { | 98 void StringSuccessCallback(const std::string& result) { |
97 VLOG(1) << "StringSuccessCallback: " << result; | 99 VLOG(1) << "StringSuccessCallback: " << result; |
98 result_ = result; | 100 result_ = result; |
99 } | 101 } |
100 | 102 |
101 protected: | 103 protected: |
| 104 base::test::ScopedTaskEnvironment scoped_task_environment_; |
102 std::string result_; | 105 std::string result_; |
103 | 106 FakeShillDeviceClient* fake_device_client_ = nullptr; |
104 FakeShillDeviceClient* fake_device_client_; | |
105 std::unique_ptr<NetworkDeviceHandler> network_device_handler_; | 107 std::unique_ptr<NetworkDeviceHandler> network_device_handler_; |
106 std::unique_ptr<NetworkStateHandler> network_state_handler_; | 108 std::unique_ptr<NetworkStateHandler> network_state_handler_; |
107 base::MessageLoopForUI message_loop_; | |
108 base::Closure success_callback_; | 109 base::Closure success_callback_; |
109 network_handler::DictionaryResultCallback properties_success_callback_; | 110 network_handler::DictionaryResultCallback properties_success_callback_; |
110 network_handler::StringResultCallback string_success_callback_; | 111 network_handler::StringResultCallback string_success_callback_; |
111 network_handler::ErrorCallback error_callback_; | 112 network_handler::ErrorCallback error_callback_; |
112 std::unique_ptr<base::DictionaryValue> properties_; | 113 std::unique_ptr<base::DictionaryValue> properties_; |
113 | 114 |
114 private: | 115 private: |
115 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest); | 116 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest); |
116 }; | 117 }; |
117 | 118 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 383 |
383 // Test that the shill error propagates to the error callback. | 384 // Test that the shill error propagates to the error callback. |
384 network_device_handler_->ChangePin(kDefaultCellularDevicePath, kIncorrectPin, | 385 network_device_handler_->ChangePin(kDefaultCellularDevicePath, kIncorrectPin, |
385 kNewPin, success_callback_, | 386 kNewPin, success_callback_, |
386 error_callback_); | 387 error_callback_); |
387 base::RunLoop().RunUntilIdle(); | 388 base::RunLoop().RunUntilIdle(); |
388 EXPECT_EQ(NetworkDeviceHandler::kErrorIncorrectPin, result_); | 389 EXPECT_EQ(NetworkDeviceHandler::kErrorIncorrectPin, result_); |
389 } | 390 } |
390 | 391 |
391 } // namespace chromeos | 392 } // namespace chromeos |
OLD | NEW |