#include <vector>
#include "base/containers/contains.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "content/browser/network/network_service_util_internal.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/network_service_util.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "sandbox/policy/features.h"
#include "services/network/public/cpp/network_quality_tracker.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/network_service_test.mojom.h"
#if BUILDFLAG(IS_ANDROID)
#include "net/android/network_change_notifier_delegate_android.h"
#include "net/android/network_library.h"
#endif
namespace content {
namespace {
std::ostream& operator<<(
std::ostream& os,
const std::vector<net::EffectiveConnectionType>& types) { … }
class TestNetworkQualityObserver
: public network::NetworkQualityTracker::EffectiveConnectionTypeObserver { … };
class SandboxedNQEBrowserTest : public ContentBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SandboxedNQEBrowserTest, GetNetworkService) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_NetworkQualityTracker …
#else
#define MAYBE_NetworkQualityTracker …
#endif
IN_PROC_BROWSER_TEST_F(SandboxedNQEBrowserTest, MAYBE_NetworkQualityTracker) { … }
#if BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SandboxedNQEBrowserTest, TurnWifiEnabled) {
const std::string wifi_ssid = net::android::GetWifiSSID();
if (wifi_ssid.empty()) {
GTEST_SKIP() << "This test requires wifi network.";
}
ForceNetworkQualityEstimatorReportWifiAsSlow2G();
net::NetworkChangeNotifierDelegateAndroid::
EnableNetworkChangeNotifierAutoDetectForTest();
std::unique_ptr<network::NetworkQualityTracker> tracker =
std::make_unique<network::NetworkQualityTracker>(
base::BindRepeating(&GetNetworkService));
TestNetworkQualityObserver network_quality_observer;
tracker->AddEffectiveConnectionTypeObserver(&network_quality_observer);
net::android::SetWifiEnabledForTesting(true);
network_quality_observer.WaitForNotification(
net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
net::android::SetWifiEnabledForTesting(false);
network_quality_observer.WaitForNotification(
net::EFFECTIVE_CONNECTION_TYPE_4G);
net::android::SetWifiEnabledForTesting(true);
network_quality_observer.WaitForNotification(
net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
}
#endif
}
}