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
content / public / test / network_connection_change_simulator.h [blame]
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_TEST_NETWORK_CONNECTION_CHANGE_SIMULATOR_H_
#define CONTENT_PUBLIC_TEST_NETWORK_CONNECTION_CHANGE_SIMULATOR_H_
#include "build/chromeos_buildflags.h"
#include "services/network/public/cpp/network_connection_tracker.h"
namespace base {
class RunLoop;
}
namespace content {
// A class to help tests set the network connection type.
class NetworkConnectionChangeSimulator
: public network::NetworkConnectionTracker::NetworkConnectionObserver {
public:
NetworkConnectionChangeSimulator();
NetworkConnectionChangeSimulator(const NetworkConnectionChangeSimulator&) =
delete;
NetworkConnectionChangeSimulator& operator=(
const NetworkConnectionChangeSimulator&) = delete;
~NetworkConnectionChangeSimulator() override;
#if BUILDFLAG(IS_CHROMEOS)
// Initializes the ChromeOS network connection type.
// This should be used in tests that don't have a DBus set up.
void InitializeChromeosConnectionType();
#endif
// Synchronously sets the connection type.
void SetConnectionType(network::mojom::ConnectionType connection_type);
private:
static void SimulateNetworkChange(network::mojom::ConnectionType type);
// network::NetworkConnectionTracker::NetworkConnectionObserver:
void OnConnectionChanged(network::mojom::ConnectionType type) override;
std::unique_ptr<base::RunLoop> run_loop_;
};
} // namespace content
#endif // CONTENT_PUBLIC_TEST_NETWORK_CONNECTION_CHANGE_SIMULATOR_H_