#ifndef NET_BASE_MOCK_NETWORK_CHANGE_NOTIFIER_H_
#define NET_BASE_MOCK_NETWORK_CHANGE_NOTIFIER_H_
#include <memory>
#include "net/base/network_change_notifier.h"
#include "net/base/network_handle.h"
namespace net {
class SystemDnsConfigChangeNotifier;
namespace test {
class MockNetworkChangeNotifier : public NetworkChangeNotifier {
public:
static std::unique_ptr<MockNetworkChangeNotifier> Create();
~MockNetworkChangeNotifier() override;
ConnectionType GetCurrentConnectionType() const override;
void ForceNetworkHandlesSupported();
bool AreNetworkHandlesCurrentlySupported() const override;
void SetConnectionType(ConnectionType connection_type) {
connection_type_ = connection_type;
}
void SetConnectedNetworksList(const NetworkList& network_list);
void GetCurrentConnectedNetworks(NetworkList* network_list) const override;
void NotifyNetworkMadeDefault(handles::NetworkHandle network);
void QueueNetworkMadeDefault(handles::NetworkHandle network);
void NotifyNetworkDisconnected(handles::NetworkHandle network);
void QueueNetworkDisconnected(handles::NetworkHandle network);
void NotifyNetworkConnected(handles::NetworkHandle network);
void SetConnectionTypeAndNotifyObservers(ConnectionType connection_type);
void SetConnectionCost(ConnectionCost connection_cost) {
connection_cost_ = connection_cost;
}
bool IsDefaultNetworkActiveInternal() override;
void SetIsDefaultNetworkActiveInternalForTesting(bool is_active) {
is_default_network_active_ = is_active;
}
void SetUseDefaultConnectionCostImplementation(
bool use_default_connection_cost_implementation) {
use_default_connection_cost_implementation_ =
use_default_connection_cost_implementation;
}
ConnectionCost GetCurrentConnectionCost() override;
private:
explicit MockNetworkChangeNotifier(
std::unique_ptr<SystemDnsConfigChangeNotifier> dns_config_notifier);
bool force_network_handles_supported_ = false;
bool is_default_network_active_ = true;
ConnectionType connection_type_ = CONNECTION_UNKNOWN;
ConnectionCost connection_cost_ = CONNECTION_COST_UNKNOWN;
bool use_default_connection_cost_implementation_ = false;
NetworkChangeNotifier::NetworkList connected_networks_;
std::unique_ptr<SystemDnsConfigChangeNotifier> dns_config_notifier_;
};
class ScopedMockNetworkChangeNotifier {
public:
ScopedMockNetworkChangeNotifier();
~ScopedMockNetworkChangeNotifier();
MockNetworkChangeNotifier* mock_network_change_notifier();
private:
std::unique_ptr<NetworkChangeNotifier::DisableForTest>
disable_network_change_notifier_for_tests_;
std::unique_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_;
};
}
}
#endif