OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/components/tether/tether_network_disconnection_handler.h" | 5 #include "chromeos/components/tether/tether_network_disconnection_handler.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/test/scoped_task_environment.h" | 10 #include "base/test/scoped_task_environment.h" |
11 #include "chromeos/components/tether/fake_active_host.h" | 11 #include "chromeos/components/tether/fake_active_host.h" |
12 #include "chromeos/components/tether/fake_managed_network_configuration_handler. h" | |
12 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
13 #include "chromeos/network/network_state.h" | 14 #include "chromeos/network/network_state.h" |
14 #include "chromeos/network/network_state_test.h" | 15 #include "chromeos/network/network_state_test.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | 18 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
20 | 21 |
21 namespace tether { | 22 namespace tether { |
(...skipping 22 matching lines...) Expand all Loading... | |
44 ~TetherNetworkDisconnectionHandlerTest() override {} | 45 ~TetherNetworkDisconnectionHandlerTest() override {} |
45 | 46 |
46 void SetUp() override { | 47 void SetUp() override { |
47 DBusThreadManager::Initialize(); | 48 DBusThreadManager::Initialize(); |
48 NetworkStateTest::SetUp(); | 49 NetworkStateTest::SetUp(); |
49 | 50 |
50 wifi_service_path_ = | 51 wifi_service_path_ = |
51 ConfigureService(CreateConnectedWifiConfigurationJsonString()); | 52 ConfigureService(CreateConnectedWifiConfigurationJsonString()); |
52 | 53 |
53 fake_active_host_ = base::MakeUnique<FakeActiveHost>(); | 54 fake_active_host_ = base::MakeUnique<FakeActiveHost>(); |
55 fake_managed_network_configuration_handler_ = | |
56 base::WrapUnique(new FakeManagedNetworkConfigurationHandler()); | |
54 | 57 |
55 handler_ = base::WrapUnique(new TetherNetworkDisconnectionHandler( | 58 handler_ = base::WrapUnique(new TetherNetworkDisconnectionHandler( |
56 fake_active_host_.get(), network_state_handler())); | 59 fake_active_host_.get(), network_state_handler(), |
60 fake_managed_network_configuration_handler_.get())); | |
57 } | 61 } |
58 | 62 |
59 void TearDown() override { | 63 void TearDown() override { |
60 // Delete handler before the NetworkStateHandler and |fake_active_host_|. | 64 // Delete handler before the NetworkStateHandler and |fake_active_host_|. |
61 handler_.reset(); | 65 handler_.reset(); |
62 ShutdownNetworkState(); | 66 ShutdownNetworkState(); |
63 NetworkStateTest::TearDown(); | 67 NetworkStateTest::TearDown(); |
64 DBusThreadManager::Shutdown(); | 68 DBusThreadManager::Shutdown(); |
65 } | 69 } |
66 | 70 |
67 void NotifyDisconnected() { | 71 void NotifyDisconnected() { |
68 SetServiceProperty(wifi_service_path_, std::string(shill::kStateProperty), | 72 SetServiceProperty(wifi_service_path_, std::string(shill::kStateProperty), |
69 base::Value(shill::kStateIdle)); | 73 base::Value(shill::kStateIdle)); |
70 } | 74 } |
71 | 75 |
72 base::test::ScopedTaskEnvironment scoped_task_environment_; | 76 base::test::ScopedTaskEnvironment scoped_task_environment_; |
73 std::string wifi_service_path_; | 77 std::string wifi_service_path_; |
74 | 78 |
75 std::unique_ptr<FakeActiveHost> fake_active_host_; | 79 std::unique_ptr<FakeActiveHost> fake_active_host_; |
80 std::unique_ptr<FakeManagedNetworkConfigurationHandler> | |
81 fake_managed_network_configuration_handler_; | |
76 | 82 |
77 std::unique_ptr<TetherNetworkDisconnectionHandler> handler_; | 83 std::unique_ptr<TetherNetworkDisconnectionHandler> handler_; |
78 | 84 |
79 private: | 85 private: |
80 DISALLOW_COPY_AND_ASSIGN(TetherNetworkDisconnectionHandlerTest); | 86 DISALLOW_COPY_AND_ASSIGN(TetherNetworkDisconnectionHandlerTest); |
81 }; | 87 }; |
82 | 88 |
83 TEST_F(TetherNetworkDisconnectionHandlerTest, TestConnectAndDisconnect) { | 89 TEST_F(TetherNetworkDisconnectionHandlerTest, TestConnectAndDisconnect) { |
84 // Connect to the network. |handler_| should start tracking the connection. | 90 // Connect to the network. |handler_| should start tracking the connection. |
85 fake_active_host_->SetActiveHostConnecting(kDeviceId, kTetherNetworkGuid); | 91 fake_active_host_->SetActiveHostConnecting(kDeviceId, kTetherNetworkGuid); |
86 fake_active_host_->SetActiveHostConnected(kDeviceId, kTetherNetworkGuid, | 92 fake_active_host_->SetActiveHostConnected(kDeviceId, kTetherNetworkGuid, |
87 kWifiNetworkGuid); | 93 kWifiNetworkGuid); |
88 | 94 |
89 // Now, disconnect the Wi-Fi network. This should result in | 95 // Now, disconnect the Wi-Fi network. This should result in |
90 // |fake_active_host_| becoming disconnected. | 96 // |fake_active_host_| becoming disconnected. |
91 NotifyDisconnected(); | 97 NotifyDisconnected(); |
92 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 98 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
93 fake_active_host_->GetActiveHostStatus()); | 99 fake_active_host_->GetActiveHostStatus()); |
100 | |
101 EXPECT_EQ(wifi_service_path_, fake_managed_network_configuration_handler_ | |
Kyle Horimoto
2017/04/17 20:34:53
nit: Can you fit the second parameter on its own l
stevenjb
2017/04/18 21:03:36
'git cl format'
Ryan Hansberry
2017/04/20 20:57:58
This was the style given by git cl format :(
| |
102 ->last_removed_configuration_path()); | |
94 } | 103 } |
95 | 104 |
96 } // namespace tether | 105 } // namespace tether |
97 | 106 |
98 } // namespace cryptauth | 107 } // namespace chromeos |
OLD | NEW |