OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromeos/components/tether/network_configuration_remover.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/test/scoped_task_environment.h" |
| 11 #include "chromeos/components/tether/fake_active_host.h" |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/network/mock_managed_network_configuration_handler.h" |
| 14 #include "chromeos/network/network_state.h" |
| 15 #include "chromeos/network/network_state_test.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
| 19 |
| 20 using testing::_; |
| 21 using testing::NiceMock; |
| 22 |
| 23 namespace chromeos { |
| 24 |
| 25 namespace tether { |
| 26 |
| 27 namespace { |
| 28 |
| 29 const char kWifiNetworkGuid[] = "wifiNetworkGuid"; |
| 30 |
| 31 std::string CreateConnectedWifiConfigurationJsonString() { |
| 32 std::stringstream ss; |
| 33 ss << "{" |
| 34 << " \"GUID\": \"" << kWifiNetworkGuid << "\"," |
| 35 << " \"Type\": \"" << shill::kTypeWifi << "\"," |
| 36 << " \"State\": \"" << shill::kStateReady << "\"" |
| 37 << "}"; |
| 38 return ss.str(); |
| 39 } |
| 40 |
| 41 } // namespace |
| 42 |
| 43 class NetworkConfigurationRemoverTest : public NetworkStateTest { |
| 44 protected: |
| 45 NetworkConfigurationRemoverTest() : NetworkStateTest() {} |
| 46 ~NetworkConfigurationRemoverTest() override {} |
| 47 |
| 48 void SetUp() override { |
| 49 DBusThreadManager::Initialize(); |
| 50 NetworkStateTest::SetUp(); |
| 51 |
| 52 wifi_service_path_ = |
| 53 ConfigureService(CreateConnectedWifiConfigurationJsonString()); |
| 54 |
| 55 mock_managed_network_configuration_manager_ = |
| 56 base::WrapUnique(new NiceMock<MockManagedNetworkConfigurationHandler>); |
| 57 |
| 58 network_configuration_remover_ = |
| 59 base::WrapUnique(new NetworkConfigurationRemover( |
| 60 network_state_handler(), |
| 61 mock_managed_network_configuration_manager_.get())); |
| 62 } |
| 63 |
| 64 void TearDown() override { |
| 65 // Delete manager before the NetworkStateHandler. |
| 66 network_configuration_remover_.reset(); |
| 67 ShutdownNetworkState(); |
| 68 NetworkStateTest::TearDown(); |
| 69 DBusThreadManager::Shutdown(); |
| 70 } |
| 71 |
| 72 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 73 std::string wifi_service_path_; |
| 74 |
| 75 std::unique_ptr<MockManagedNetworkConfigurationHandler> |
| 76 mock_managed_network_configuration_manager_; |
| 77 |
| 78 std::unique_ptr<NetworkConfigurationRemover> network_configuration_remover_; |
| 79 |
| 80 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationRemoverTest); |
| 82 }; |
| 83 |
| 84 TEST_F(NetworkConfigurationRemoverTest, TestRemoveNetworkConfiguration) { |
| 85 EXPECT_CALL(*mock_managed_network_configuration_manager_, |
| 86 RemoveConfiguration(wifi_service_path_, _, _)) |
| 87 .Times(1); |
| 88 |
| 89 network_configuration_remover_->RemoveNetworkConfiguration(kWifiNetworkGuid); |
| 90 } |
| 91 |
| 92 } // namespace tether |
| 93 |
| 94 } // namespace chromeos |
OLD | NEW |