| // Copyright 2021 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef CHROMEOS_NETWORK_NETWORK_TEST_HELPER_BASE_H_ |
| #define CHROMEOS_NETWORK_NETWORK_TEST_HELPER_BASE_H_ |
| |
| #include <memory> |
| #include <string> |
| |
| #include "base/memory/weak_ptr.h" |
| #include "chromeos/dbus/hermes/hermes_euicc_client.h" |
| #include "chromeos/dbus/hermes/hermes_manager_client.h" |
| #include "chromeos/dbus/hermes/hermes_profile_client.h" |
| #include "chromeos/dbus/shill/shill_device_client.h" |
| #include "chromeos/dbus/shill/shill_ipconfig_client.h" |
| #include "chromeos/dbus/shill/shill_manager_client.h" |
| #include "chromeos/dbus/shill/shill_profile_client.h" |
| #include "chromeos/dbus/shill/shill_service_client.h" |
| |
| namespace chromeos { |
| |
| // Base Network test helper class. This base class handles initialization and |
| // shutdown of Shill and Hermes DBus clients and provides utility methods to |
| // setup various network conditions. Initialization is done on construction and |
| // shutdown on destruction. This helper also provides utility methods for |
| // setting up various test network conditions. |
| // |
| // NOTE: For tests that use NetworkHandler::Get() directly, use |
| // NetworkHandlerTestHelper. For tests that only need NetworkStateHandler |
| // and or NetworkDeviceHandler to be initialized, use NetworkStateTestHelper. |
| class NetworkTestHelperBase { |
| public: |
| ~NetworkTestHelperBase(); |
| |
| // Adds default shared profile and user profile in Shill profile client. |
| void AddDefaultProfiles(); |
| |
| // Resets the devices and services to the default (wifi device only). |
| void ResetDevicesAndServices(); |
| |
| // Clears any fake devices. |
| void ClearDevices(); |
| |
| // Clears any fake services. |
| void ClearServices(); |
| |
| // Clears the profile list. |
| void ClearProfiles(); |
| |
| // Configures a new service using Shill properties from |shill_json_string| |
| // which must include a GUID and Type. Returns the service path, or "" if the |
| // service could not be configured. Note: the 'GUID' key is also used as the |
| // name of the service if no 'Name' key is provided. |
| std::string ConfigureService(const std::string& shill_json_string); |
| |
| // Returns a string value for property |key| associated with |service_path|. |
| // The result will be empty if the service or property do not exist. |
| std::string GetServiceStringProperty(const std::string& service_path, |
| const std::string& key); |
| |
| void SetServiceProperty(const std::string& service_path, |
| const std::string& key, |
| const base::Value& value); |
| |
| std::string GetProfileStringProperty(const std::string& profile_path, |
| const std::string& key); |
| |
| void SetProfileProperty(const std::string& profile_path, |
| const std::string& key, |
| const base::Value& value); |
| |
| // Returns the path used for the shared and user profiles. |
| const char* ProfilePathUser(); |
| |
| // Returns the hash used for the user profile. |
| const char* UserHash(); |
| |
| ShillManagerClient::TestInterface* manager_test() { return manager_test_; } |
| ShillProfileClient::TestInterface* profile_test() { return profile_test_; } |
| ShillDeviceClient::TestInterface* device_test() { return device_test_; } |
| ShillServiceClient::TestInterface* service_test() { return service_test_; } |
| ShillIPConfigClient::TestInterface* ip_config_test() { |
| return ip_config_test_; |
| } |
| |
| HermesEuiccClient::TestInterface* hermes_euicc_test() { |
| return hermes_euicc_test_; |
| } |
| HermesManagerClient::TestInterface* hermes_manager_test() { |
| return hermes_manager_test_; |
| } |
| HermesProfileClient::TestInterface* hermes_profile_test() { |
| return hermes_profile_test_; |
| } |
| |
| protected: |
| NetworkTestHelperBase(); |
| |
| private: |
| void ConfigureCallback(const dbus::ObjectPath& result); |
| |
| bool shill_clients_initialized_ = false; |
| bool hermes_clients_initialized_ = false; |
| |
| std::string last_created_service_path_; |
| |
| ShillManagerClient::TestInterface* manager_test_; |
| ShillProfileClient::TestInterface* profile_test_; |
| ShillDeviceClient::TestInterface* device_test_; |
| ShillServiceClient::TestInterface* service_test_; |
| ShillIPConfigClient::TestInterface* ip_config_test_; |
| |
| HermesEuiccClient::TestInterface* hermes_euicc_test_; |
| HermesManagerClient::TestInterface* hermes_manager_test_; |
| HermesProfileClient::TestInterface* hermes_profile_test_; |
| |
| base::WeakPtrFactory<NetworkTestHelperBase> weak_ptr_factory_{this}; |
| }; |
| |
| } // namespace chromeos |
| |
| #endif // CHROMEOS_NETWORK_NETWORK_TEST_HELPER_BASE_H_ |