1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_ASH_COMPONENTS_NETWORK_NETWORK_TEST_HELPER_BASE_H_
#define CHROMEOS_ASH_COMPONENTS_NETWORK_NETWORK_TEST_HELPER_BASE_H_
#include <memory>
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/ash/components/dbus/hermes/hermes_euicc_client.h"
#include "chromeos/ash/components/dbus/hermes/hermes_manager_client.h"
#include "chromeos/ash/components/dbus/hermes/hermes_profile_client.h"
#include "chromeos/ash/components/dbus/shill/shill_device_client.h"
#include "chromeos/ash/components/dbus/shill/shill_ipconfig_client.h"
#include "chromeos/ash/components/dbus/shill/shill_manager_client.h"
#include "chromeos/ash/components/dbus/shill/shill_profile_client.h"
#include "chromeos/ash/components/dbus/shill/shill_service_client.h"
namespace ash {
// 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);
// Configures a new WiFi service with state |state|. Returns the service
// path of the new service.
std::string ConfigureWiFi(const std::string& state);
// Returns a double value for property |key| associated with |service_path|.
std::optional<double> GetServiceDoubleProperty(
const std::string& service_path,
const std::string& key);
// 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);
// Returns a base::Value::List for property |key| associated with
// |service_path|.
std::optional<base::Value::List> GetServiceListProperty(
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_;
int wifi_index_ = 0;
raw_ptr<ShillManagerClient::TestInterface, DanglingUntriaged> manager_test_;
raw_ptr<ShillProfileClient::TestInterface, DanglingUntriaged> profile_test_;
raw_ptr<ShillDeviceClient::TestInterface, DanglingUntriaged> device_test_;
raw_ptr<ShillServiceClient::TestInterface, DanglingUntriaged> service_test_;
raw_ptr<ShillIPConfigClient::TestInterface, DanglingUntriaged>
ip_config_test_;
raw_ptr<HermesEuiccClient::TestInterface, DanglingUntriaged>
hermes_euicc_test_;
raw_ptr<HermesManagerClient::TestInterface, DanglingUntriaged>
hermes_manager_test_;
raw_ptr<HermesProfileClient::TestInterface, DanglingUntriaged>
hermes_profile_test_;
base::WeakPtrFactory<NetworkTestHelperBase> weak_ptr_factory_{this};
};
} // namespace ash
#endif // CHROMEOS_ASH_COMPONENTS_NETWORK_NETWORK_TEST_HELPER_BASE_H_
|