Commit 333143ef authored by Anastasiia N's avatar Anastasiia N Committed by Commit Bot

Add HasInstance method to TestNetworkConnectionTracker

Currently GetInstance() has a DCHECK for the instance pointer and
CreateInstance() overrides the current pointer, so there is no
way to check if CreateInstance() was already called.

We need to get a pointer to TestNetworkConnectionTracker in
IdentityTestEnvironment. Since some tests create it (e.g. if they use
TestingBrowserProcess) and others don't, we need a way to know if
CreateInstance was called.

Bug: 1068240
Change-Id: I99bb1dc64a170203beaae71d76de73d0b4483af9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2307249
Commit-Queue: Anastasiia N <anastasiian@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792351}
parent 18f7b5e8
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
namespace network { namespace network {
static TestNetworkConnectionTracker* g_test_network_connection_tracker_instance; static TestNetworkConnectionTracker*
g_test_network_connection_tracker_instance = nullptr;
namespace { namespace {
...@@ -50,6 +51,11 @@ TestNetworkConnectionTracker* TestNetworkConnectionTracker::GetInstance() { ...@@ -50,6 +51,11 @@ TestNetworkConnectionTracker* TestNetworkConnectionTracker::GetInstance() {
return g_test_network_connection_tracker_instance; return g_test_network_connection_tracker_instance;
} }
// static
bool TestNetworkConnectionTracker::HasInstance() {
return g_test_network_connection_tracker_instance != nullptr;
}
// static // static
NetworkConnectionTrackerGetter TestNetworkConnectionTracker::CreateGetter() { NetworkConnectionTrackerGetter TestNetworkConnectionTracker::CreateGetter() {
return base::BindRepeating(&GetNonTestInstance); return base::BindRepeating(&GetNonTestInstance);
......
...@@ -25,6 +25,10 @@ class TestNetworkConnectionTracker : public NetworkConnectionTracker { ...@@ -25,6 +25,10 @@ class TestNetworkConnectionTracker : public NetworkConnectionTracker {
// CreateInstance() must have been called before calling this. // CreateInstance() must have been called before calling this.
static TestNetworkConnectionTracker* GetInstance(); static TestNetworkConnectionTracker* GetInstance();
// Returns true if TestNetworkConnectionTracker instance already exists.
// It means that CreateInstance() was already called.
static bool HasInstance();
// Creates a NetworkConnectionTrackerGetter that will return the active // Creates a NetworkConnectionTrackerGetter that will return the active
// TestNetworkConnectionTracker instance when called. // TestNetworkConnectionTracker instance when called.
static NetworkConnectionTrackerGetter CreateGetter(); static NetworkConnectionTrackerGetter CreateGetter();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment