Commit 4e6d1c85 authored by Helen Li's avatar Helen Li Committed by Commit Bot

Make ChromeSigninClient use content::NetworkConnectionTracker

This CL makes ChromeSigninClient use content::NetworkConnectionTracker
instead of net::NetworkChangeNotifier.

This CL additionally modifies NetworkConnectionTracker's
constructor so we can mock it in TestingBrowserProcess and tests.

Bug: 754709
Change-Id: Ic05662830839403d5b327793f8faf7284a0da0bd
Reviewed-on: https://chromium-review.googlesource.com/757583Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Helen Li <xunjieli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515965}
parent c444846e
...@@ -576,7 +576,8 @@ BrowserProcessImpl::network_connection_tracker() { ...@@ -576,7 +576,8 @@ BrowserProcessImpl::network_connection_tracker() {
DCHECK(io_thread_); DCHECK(io_thread_);
if (!network_connection_tracker_) { if (!network_connection_tracker_) {
network_connection_tracker_ = network_connection_tracker_ =
std::make_unique<content::NetworkConnectionTracker>( std::make_unique<content::NetworkConnectionTracker>();
network_connection_tracker_->Initialize(
io_thread_->GetNetworkServiceOnUIThread()); io_thread_->GetNetworkServiceOnUIThread());
} }
return network_connection_tracker_.get(); return network_connection_tracker_.get();
......
...@@ -68,10 +68,12 @@ ChromeSigninClient::ChromeSigninClient( ...@@ -68,10 +68,12 @@ ChromeSigninClient::ChromeSigninClient(
SigninErrorController* signin_error_controller) SigninErrorController* signin_error_controller)
: OAuth2TokenService::Consumer("chrome_signin_client"), : OAuth2TokenService::Consumer("chrome_signin_client"),
profile_(profile), profile_(profile),
signin_error_controller_(signin_error_controller) { signin_error_controller_(signin_error_controller),
weak_ptr_factory_(this) {
signin_error_controller_->AddObserver(this); signin_error_controller_->AddObserver(this);
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
net::NetworkChangeNotifier::AddNetworkChangeObserver(this); g_browser_process->network_connection_tracker()->AddNetworkConnectionObserver(
this);
#else #else
// UserManager may not exist in unit_tests. // UserManager may not exist in unit_tests.
if (!user_manager::UserManager::IsInitialized()) if (!user_manager::UserManager::IsInitialized())
...@@ -103,11 +105,9 @@ ChromeSigninClient::ChromeSigninClient( ...@@ -103,11 +105,9 @@ ChromeSigninClient::ChromeSigninClient(
ChromeSigninClient::~ChromeSigninClient() { ChromeSigninClient::~ChromeSigninClient() {
signin_error_controller_->RemoveObserver(this); signin_error_controller_->RemoveObserver(this);
}
void ChromeSigninClient::Shutdown() {
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); g_browser_process->network_connection_tracker()
->RemoveNetworkConnectionObserver(this);
#endif #endif
} }
...@@ -378,9 +378,9 @@ void ChromeSigninClient::OnGetTokenFailure( ...@@ -378,9 +378,9 @@ void ChromeSigninClient::OnGetTokenFailure(
} }
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
void ChromeSigninClient::OnNetworkChanged( void ChromeSigninClient::OnConnectionChanged(
net::NetworkChangeNotifier::ConnectionType type) { content::mojom::ConnectionType type) {
if (type >= net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) if (type == content::mojom::ConnectionType::CONNECTION_NONE)
return; return;
for (const base::Closure& callback : delayed_callbacks_) for (const base::Closure& callback : delayed_callbacks_)
...@@ -398,7 +398,13 @@ void ChromeSigninClient::DelayNetworkCall(const base::Closure& callback) { ...@@ -398,7 +398,13 @@ void ChromeSigninClient::DelayNetworkCall(const base::Closure& callback) {
return; return;
#else #else
// Don't bother if we don't have any kind of network connection. // Don't bother if we don't have any kind of network connection.
if (net::NetworkChangeNotifier::IsOffline()) { content::mojom::ConnectionType type;
bool sync =
g_browser_process->network_connection_tracker()->GetConnectionType(
&type, base::BindOnce(&ChromeSigninClient::OnConnectionChanged,
weak_ptr_factory_.GetWeakPtr()));
if (!sync || type == content::mojom::ConnectionType::CONNECTION_NONE) {
// Connection type cannot be retrieved synchronously so delay the callback.
delayed_callbacks_.push_back(callback); delayed_callbacks_.push_back(callback);
} else { } else {
callback.Run(); callback.Run();
......
...@@ -7,14 +7,16 @@ ...@@ -7,14 +7,16 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/signin/core/browser/signin_client.h" #include "components/signin/core/browser/signin_client.h"
#include "components/signin/core/browser/signin_error_controller.h" #include "components/signin/core/browser/signin_error_controller.h"
#include "content/public/common/network_change_manager.mojom.h"
#include "google_apis/gaia/gaia_oauth_client.h" #include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gaia/oauth2_token_service.h"
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
#include "net/base/network_change_notifier.h" #include "content/public/common/network_connection_tracker.h"
#endif #endif
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
...@@ -25,7 +27,7 @@ class Profile; ...@@ -25,7 +27,7 @@ class Profile;
class ChromeSigninClient class ChromeSigninClient
: public SigninClient, : public SigninClient,
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
public net::NetworkChangeNotifier::NetworkChangeObserver, public content::NetworkConnectionTracker::NetworkConnectionObserver,
#endif #endif
public SigninErrorController::Observer, public SigninErrorController::Observer,
public gaia::GaiaOAuthClient::Delegate, public gaia::GaiaOAuthClient::Delegate,
...@@ -34,7 +36,6 @@ class ChromeSigninClient ...@@ -34,7 +36,6 @@ class ChromeSigninClient
explicit ChromeSigninClient( explicit ChromeSigninClient(
Profile* profile, SigninErrorController* signin_error_controller); Profile* profile, SigninErrorController* signin_error_controller);
~ChromeSigninClient() override; ~ChromeSigninClient() override;
void Shutdown() override;
void DoFinalInit() override; void DoFinalInit() override;
// Utility method. // Utility method.
...@@ -97,9 +98,9 @@ class ChromeSigninClient ...@@ -97,9 +98,9 @@ class ChromeSigninClient
const GoogleServiceAuthError& error) override; const GoogleServiceAuthError& error) override;
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
// net::NetworkChangeController::NetworkChangeObserver implementation. // content::NetworkConnectionTracker::NetworkConnectionObserver
void OnNetworkChanged(net::NetworkChangeNotifier::ConnectionType type) // implementation.
override; void OnConnectionChanged(content::mojom::ConnectionType type) override;
#endif #endif
void AfterCredentialsCopied() override; void AfterCredentialsCopied() override;
...@@ -132,6 +133,8 @@ class ChromeSigninClient ...@@ -132,6 +133,8 @@ class ChromeSigninClient
std::unique_ptr<gaia::GaiaOAuthClient> oauth_client_; std::unique_ptr<gaia::GaiaOAuthClient> oauth_client_;
std::unique_ptr<OAuth2TokenService::Request> oauth_request_; std::unique_ptr<OAuth2TokenService::Request> oauth_request_;
base::WeakPtrFactory<ChromeSigninClient> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ChromeSigninClient); DISALLOW_COPY_AND_ASSIGN(ChromeSigninClient);
}; };
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/public/common/network_connection_tracker.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "net/base/network_change_notifier.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -28,31 +28,52 @@ ...@@ -28,31 +28,52 @@
namespace { namespace {
class MockNetworkChangeNotifierNeverOffline : class MockNetworkConnectionTrackerNeverOffline
public net::NetworkChangeNotifier { : public content::NetworkConnectionTracker {
public: public:
net::NetworkChangeNotifier::ConnectionType GetCurrentConnectionType() const MockNetworkConnectionTrackerNeverOffline()
override { : content::NetworkConnectionTracker() {}
return NetworkChangeNotifier::CONNECTION_3G; ~MockNetworkConnectionTrackerNeverOffline() override {}
bool GetConnectionType(content::mojom::ConnectionType* type,
ConnectionTypeCallback callback) override {
*type = content::mojom::ConnectionType::CONNECTION_3G;
return true;
} }
}; };
class MockNetworkChangeNotifierOfflineUntilChange : class MockNetworkConnectionTrackerGetConnectionTypeAsync
public net::NetworkChangeNotifier { : public content::NetworkConnectionTracker {
public: public:
MockNetworkChangeNotifierOfflineUntilChange() : online_(false) {} MockNetworkConnectionTrackerGetConnectionTypeAsync()
net::NetworkChangeNotifier::ConnectionType GetCurrentConnectionType() const : content::NetworkConnectionTracker() {}
override { ~MockNetworkConnectionTrackerGetConnectionTypeAsync() override {}
return online_ ? net::NetworkChangeNotifier::CONNECTION_3G
: net::NetworkChangeNotifier::CONNECTION_NONE; void CompleteCallback() {
OnInitialConnectionType(content::mojom::ConnectionType::CONNECTION_3G);
} }
};
class MockNetworkConnectionTrackerOfflineUntilChange
: public content::NetworkConnectionTracker {
public:
MockNetworkConnectionTrackerOfflineUntilChange()
: content::NetworkConnectionTracker(), online_(false) {}
~MockNetworkConnectionTrackerOfflineUntilChange() override {}
bool GetConnectionType(content::mojom::ConnectionType* type,
ConnectionTypeCallback callback) override {
if (online_) {
*type = content::mojom::ConnectionType::CONNECTION_3G;
} else {
*type = content::mojom::ConnectionType::CONNECTION_NONE;
}
return true;
}
void GoOnline() { void GoOnline() {
online_ = true; online_ = true;
net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( OnNetworkChanged(content::mojom::ConnectionType::CONNECTION_3G);
net::NetworkChangeNotifier::CONNECTION_3G);
} }
private: private:
bool online_; bool online_;
}; };
...@@ -81,7 +102,16 @@ bool CallbackTester::WasCalledExactlyOnce() { ...@@ -81,7 +102,16 @@ bool CallbackTester::WasCalledExactlyOnce() {
class ChromeSigninClientTest : public testing::Test { class ChromeSigninClientTest : public testing::Test {
public: public:
ChromeSigninClientTest() {} ChromeSigninClientTest() {}
void SetUp() override;
void Initialize(std::unique_ptr<content::NetworkConnectionTracker> tracker) {
TestingBrowserProcess::GetGlobal()->SetNetworkConnectionTracker(
std::move(tracker));
// Create a signed-in profile.
TestingProfile::Builder builder;
profile_ = builder.Build();
signin_client_ = ChromeSigninClientFactory::GetForProfile(profile());
}
Profile* profile() { return profile_.get(); } Profile* profile() { return profile_.get(); }
SigninClient* signin_client() { return signin_client_; } SigninClient* signin_client() { return signin_client_; }
...@@ -92,28 +122,34 @@ class ChromeSigninClientTest : public testing::Test { ...@@ -92,28 +122,34 @@ class ChromeSigninClientTest : public testing::Test {
SigninClient* signin_client_; SigninClient* signin_client_;
}; };
void ChromeSigninClientTest::SetUp() { TEST_F(ChromeSigninClientTest, DelayNetworkCallRunsImmediatelyWithNetwork) {
// Create a signed-in profile. Initialize(std::make_unique<MockNetworkConnectionTrackerNeverOffline>());
TestingProfile::Builder builder; CallbackTester tester;
profile_ = builder.Build(); signin_client()->DelayNetworkCall(
base::Bind(&CallbackTester::Increment, base::Unretained(&tester)));
signin_client_ = ChromeSigninClientFactory::GetForProfile(profile()); ASSERT_TRUE(tester.WasCalledExactlyOnce());
} }
TEST_F(ChromeSigninClientTest, DelayNetworkCallRunsImmediatelyWithNetwork) { TEST_F(ChromeSigninClientTest, DelayNetworkCallRunsAfterGetConnectionType) {
std::unique_ptr<net::NetworkChangeNotifier> mock( auto tracker =
new MockNetworkChangeNotifierNeverOffline); std::make_unique<MockNetworkConnectionTrackerGetConnectionTypeAsync>();
MockNetworkConnectionTrackerGetConnectionTypeAsync* mock = tracker.get();
Initialize(std::move(tracker));
CallbackTester tester; CallbackTester tester;
signin_client()->DelayNetworkCall(base::Bind(&CallbackTester::Increment, signin_client()->DelayNetworkCall(base::Bind(&CallbackTester::Increment,
base::Unretained(&tester))); base::Unretained(&tester)));
ASSERT_FALSE(tester.WasCalledExactlyOnce());
mock->CompleteCallback();
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(tester.WasCalledExactlyOnce()); ASSERT_TRUE(tester.WasCalledExactlyOnce());
} }
TEST_F(ChromeSigninClientTest, DelayNetworkCallRunsAfterNetworkFound) { TEST_F(ChromeSigninClientTest, DelayNetworkCallRunsAfterNetworkChange) {
std::unique_ptr<MockNetworkChangeNotifierOfflineUntilChange> mock( auto tracker =
new MockNetworkChangeNotifierOfflineUntilChange()); std::make_unique<MockNetworkConnectionTrackerOfflineUntilChange>();
// Install a SigninClient after the NetworkChangeNotifier's created. MockNetworkConnectionTrackerOfflineUntilChange* mock = tracker.get();
SetUp(); Initialize(std::move(tracker));
CallbackTester tester; CallbackTester tester;
signin_client()->DelayNetworkCall(base::Bind(&CallbackTester::Increment, signin_client()->DelayNetworkCall(base::Bind(&CallbackTester::Increment,
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/subresource_filter/content/browser/content_ruleset_service.h" #include "components/subresource_filter/content/browser/content_ruleset_service.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/common/network_connection_tracker.h"
#include "extensions/features/features.h" #include "extensions/features/features.h"
#include "media/media_features.h" #include "media/media_features.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
...@@ -55,6 +56,25 @@ ...@@ -55,6 +56,25 @@
#include "components/keep_alive_registry/keep_alive_registry.h" #include "components/keep_alive_registry/keep_alive_registry.h"
#endif #endif
namespace {
class MockNetworkConnectionTracker : public content::NetworkConnectionTracker {
public:
MockNetworkConnectionTracker() : content::NetworkConnectionTracker() {}
~MockNetworkConnectionTracker() override {}
bool GetConnectionType(content::mojom::ConnectionType* type,
ConnectionTypeCallback callback) override {
*type = content::mojom::ConnectionType::CONNECTION_UNKNOWN;
return true;
}
private:
DISALLOW_COPY_AND_ASSIGN(MockNetworkConnectionTracker);
};
} // namespace
// static // static
TestingBrowserProcess* TestingBrowserProcess::GetGlobal() { TestingBrowserProcess* TestingBrowserProcess::GetGlobal() {
return static_cast<TestingBrowserProcess*>(g_browser_process); return static_cast<TestingBrowserProcess*>(g_browser_process);
...@@ -145,7 +165,11 @@ TestingBrowserProcess::system_network_context_manager() { ...@@ -145,7 +165,11 @@ TestingBrowserProcess::system_network_context_manager() {
content::NetworkConnectionTracker* content::NetworkConnectionTracker*
TestingBrowserProcess::network_connection_tracker() { TestingBrowserProcess::network_connection_tracker() {
return nullptr; if (!network_connection_tracker_) {
network_connection_tracker_ =
std::make_unique<MockNetworkConnectionTracker>();
}
return network_connection_tracker_.get();
} }
WatchDogThread* TestingBrowserProcess::watchdog_thread() { WatchDogThread* TestingBrowserProcess::watchdog_thread() {
...@@ -435,6 +459,11 @@ void TestingBrowserProcess::SetSystemRequestContext( ...@@ -435,6 +459,11 @@ void TestingBrowserProcess::SetSystemRequestContext(
system_request_context_ = context_getter; system_request_context_ = context_getter;
} }
void TestingBrowserProcess::SetNetworkConnectionTracker(
std::unique_ptr<content::NetworkConnectionTracker> tracker) {
network_connection_tracker_ = std::move(tracker);
}
void TestingBrowserProcess::SetNotificationUIManager( void TestingBrowserProcess::SetNotificationUIManager(
std::unique_ptr<NotificationUIManager> notification_ui_manager) { std::unique_ptr<NotificationUIManager> notification_ui_manager) {
notification_ui_manager_.swap(notification_ui_manager); notification_ui_manager_.swap(notification_ui_manager);
......
...@@ -147,6 +147,8 @@ class TestingBrowserProcess : public BrowserProcess { ...@@ -147,6 +147,8 @@ class TestingBrowserProcess : public BrowserProcess {
std::unique_ptr<optimization_guide::OptimizationGuideService> std::unique_ptr<optimization_guide::OptimizationGuideService>
optimization_guide_service); optimization_guide_service);
void SetSystemRequestContext(net::URLRequestContextGetter* context_getter); void SetSystemRequestContext(net::URLRequestContextGetter* context_getter);
void SetNetworkConnectionTracker(
std::unique_ptr<content::NetworkConnectionTracker> tracker);
void SetNotificationUIManager( void SetNotificationUIManager(
std::unique_ptr<NotificationUIManager> notification_ui_manager); std::unique_ptr<NotificationUIManager> notification_ui_manager);
void SetNotificationPlatformBridge( void SetNotificationPlatformBridge(
...@@ -166,6 +168,8 @@ class TestingBrowserProcess : public BrowserProcess { ...@@ -166,6 +168,8 @@ class TestingBrowserProcess : public BrowserProcess {
std::unique_ptr<policy::BrowserPolicyConnector> browser_policy_connector_; std::unique_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
bool created_browser_policy_connector_ = false; bool created_browser_policy_connector_ = false;
std::unique_ptr<content::NetworkConnectionTracker>
network_connection_tracker_;
std::unique_ptr<ProfileManager> profile_manager_; std::unique_ptr<ProfileManager> profile_manager_;
std::unique_ptr<NotificationUIManager> notification_ui_manager_; std::unique_ptr<NotificationUIManager> notification_ui_manager_;
std::unique_ptr<NotificationPlatformBridge> notification_platform_bridge_; std::unique_ptr<NotificationPlatformBridge> notification_platform_bridge_;
......
...@@ -32,15 +32,18 @@ static const int32_t kConnectionTypeInvalid = -1; ...@@ -32,15 +32,18 @@ static const int32_t kConnectionTypeInvalid = -1;
} // namespace } // namespace
NetworkConnectionTracker::NetworkConnectionTracker( NetworkConnectionTracker::NetworkConnectionTracker()
mojom::NetworkService* network_service)
: task_runner_(base::ThreadTaskRunnerHandle::Get()), : task_runner_(base::ThreadTaskRunnerHandle::Get()),
connection_type_(kConnectionTypeInvalid), connection_type_(kConnectionTypeInvalid),
network_change_observer_list_( network_change_observer_list_(
new base::ObserverListThreadSafe<NetworkConnectionObserver>( new base::ObserverListThreadSafe<NetworkConnectionObserver>(
base::ObserverListBase< base::ObserverListBase<
NetworkConnectionObserver>::NOTIFY_EXISTING_ONLY)), NetworkConnectionObserver>::NOTIFY_EXISTING_ONLY)),
binding_(this) { binding_(this) {}
void NetworkConnectionTracker::Initialize(
mojom::NetworkService* network_service) {
DCHECK(!binding_.is_bound());
DCHECK(network_service); DCHECK(network_service);
// Get NetworkChangeManagerPtr. // Get NetworkChangeManagerPtr.
mojom::NetworkChangeManagerPtr manager_ptr; mojom::NetworkChangeManagerPtr manager_ptr;
......
...@@ -45,16 +45,24 @@ class CONTENT_EXPORT NetworkConnectionTracker ...@@ -45,16 +45,24 @@ class CONTENT_EXPORT NetworkConnectionTracker
DISALLOW_COPY_AND_ASSIGN(NetworkConnectionObserver); DISALLOW_COPY_AND_ASSIGN(NetworkConnectionObserver);
}; };
explicit NetworkConnectionTracker(mojom::NetworkService* network_service); NetworkConnectionTracker();
~NetworkConnectionTracker() override; ~NetworkConnectionTracker() override;
// Starts listening for connection notifications from |network_service|.
// Observers may be added and GetConnectionType called, but no network
// information will be provided until this method is called. For unit tests,
// this class can be subclassed, and OnInitialConnectionType /
// OnNetworkChanged may be called directly, instead of providing a
// NetworkService.
void Initialize(mojom::NetworkService* network_service);
// If connection type can be retrieved synchronously, returns true and |type| // If connection type can be retrieved synchronously, returns true and |type|
// will contain the current connection type; Otherwise, returns false, in // will contain the current connection type; Otherwise, returns false, in
// which case, |callback| will be called on the calling thread when connection // which case, |callback| will be called on the calling thread when connection
// type is ready. This method is thread safe. Please also refer to // type is ready. This method is thread safe. Please also refer to
// net::NetworkChangeNotifier::GetConnectionType() for documentation. // net::NetworkChangeNotifier::GetConnectionType() for documentation.
bool GetConnectionType(mojom::ConnectionType* type, virtual bool GetConnectionType(mojom::ConnectionType* type,
ConnectionTypeCallback callback); ConnectionTypeCallback callback);
// Returns true if |type| is a cellular connection. // Returns true if |type| is a cellular connection.
...@@ -74,13 +82,14 @@ class CONTENT_EXPORT NetworkConnectionTracker ...@@ -74,13 +82,14 @@ class CONTENT_EXPORT NetworkConnectionTracker
// All observers must be unregistred before |this| is destroyed. // All observers must be unregistred before |this| is destroyed.
void RemoveNetworkConnectionObserver(NetworkConnectionObserver* observer); void RemoveNetworkConnectionObserver(NetworkConnectionObserver* observer);
private: protected:
FRIEND_TEST_ALL_PREFIXES(NetworkGetConnectionTest, // NetworkChangeManagerClient implementation. Protected for testing.
GetConnectionTypeOnDifferentThread);
// NetworkChangeManagerClient implementation:
void OnInitialConnectionType(mojom::ConnectionType type) override; void OnInitialConnectionType(mojom::ConnectionType type) override;
void OnNetworkChanged(mojom::ConnectionType type) override; void OnNetworkChanged(mojom::ConnectionType type) override;
private:
FRIEND_TEST_ALL_PREFIXES(NetworkGetConnectionTest,
GetConnectionTypeOnDifferentThread);
// The task runner that |this| lives on. // The task runner that |this| lives on.
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
......
...@@ -129,8 +129,8 @@ class NetworkConnectionTrackerTest : public testing::Test { ...@@ -129,8 +129,8 @@ class NetworkConnectionTrackerTest : public testing::Test {
network_service_ = network_service_ =
NetworkService::Create(std::move(network_service_request), NetworkService::Create(std::move(network_service_request),
/*netlog=*/nullptr); /*netlog=*/nullptr);
tracker_ = tracker_ = std::make_unique<NetworkConnectionTracker>();
std::make_unique<NetworkConnectionTracker>(network_service_.get()); tracker_->Initialize(network_service_.get());
observer_ = std::make_unique<TestNetworkConnectionObserver>(tracker_.get()); observer_ = std::make_unique<TestNetworkConnectionObserver>(tracker_.get());
} }
...@@ -219,7 +219,8 @@ TEST_F(NetworkConnectionTrackerTest, GetConnectionType) { ...@@ -219,7 +219,8 @@ TEST_F(NetworkConnectionTrackerTest, GetConnectionType) {
mojo::MakeRequest(&network_service_ptr); mojo::MakeRequest(&network_service_ptr);
std::unique_ptr<NetworkService> network_service = std::unique_ptr<NetworkService> network_service =
NetworkService::Create(std::move(network_service_request), nullptr); NetworkService::Create(std::move(network_service_request), nullptr);
NetworkConnectionTracker tracker(network_service_ptr.get()); NetworkConnectionTracker tracker;
tracker.Initialize(network_service_ptr.get());
ConnectionTypeGetter getter1(&tracker), getter2(&tracker); ConnectionTypeGetter getter1(&tracker), getter2(&tracker);
// These two GetConnectionType() will finish asynchonously because network // These two GetConnectionType() will finish asynchonously because network
......
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