Commit 399e44a7 authored by James Vecore's avatar James Vecore Committed by Commit Bot

[Nearby] Remove dependence on |NearbyProcessManager| singleton in tests

This CL mocks the IsProfileActive method on the
|MockNearbyProcessManager| so we don't need to depended on calling
singleton methods in tests and tear down.

Change-Id: If690f77baee8ae7e106be2b9ca3a618a058437d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354990
Commit-Queue: James Vecore <vecore@google.com>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Auto-Submit: James Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#798184}
parent 1c9581af
...@@ -28,6 +28,7 @@ class MockNearbyProcessManager : public NearbyProcessManager { ...@@ -28,6 +28,7 @@ class MockNearbyProcessManager : public NearbyProcessManager {
GetOrStartNearbySharingDecoder, GetOrStartNearbySharingDecoder,
(Profile * profile), (Profile * profile),
(override)); (override));
MOCK_METHOD(bool, IsActiveProfile, (Profile * profile), (const, override));
}; };
#endif // CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_PROCESS_MANAGER_H_ #endif // CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_PROCESS_MANAGER_H_
...@@ -62,7 +62,7 @@ class NearbyProcessManager : public ProfileManagerObserver { ...@@ -62,7 +62,7 @@ class NearbyProcessManager : public ProfileManagerObserver {
// Returns whether the |profile| is the active profile to use the Nearby // Returns whether the |profile| is the active profile to use the Nearby
// process. Convenience method to calling GetActiveProfile() and manually // process. Convenience method to calling GetActiveProfile() and manually
// comparing if they match. // comparing if they match.
bool IsActiveProfile(Profile* profile) const; virtual bool IsActiveProfile(Profile* profile) const;
// Returns if any profile is currently set as the active profile. Note that // Returns if any profile is currently set as the active profile. Note that
// the active profile might not be loaded yet. // the active profile might not be loaded yet.
......
...@@ -245,10 +245,7 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -245,10 +245,7 @@ class NearbySharingServiceImplTest : public testing::Test {
.WillRepeatedly(testing::Return(&mock_decoder_)); .WillRepeatedly(testing::Return(&mock_decoder_));
} }
void TearDown() override { void TearDown() override { profile_manager_.DeleteAllTestingProfiles(); }
profile_manager_.DeleteAllTestingProfiles();
NearbyProcessManager::GetInstance().ClearActiveProfile();
}
std::unique_ptr<NearbySharingServiceImpl> CreateService( std::unique_ptr<NearbySharingServiceImpl> CreateService(
const std::string& profile_name) { const std::string& profile_name) {
...@@ -262,8 +259,8 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -262,8 +259,8 @@ class NearbySharingServiceImplTest : public testing::Test {
&prefs_, notification_display_service, profile, &prefs_, notification_display_service, profile,
base::WrapUnique(fake_nearby_connections_manager_), base::WrapUnique(fake_nearby_connections_manager_),
&mock_nearby_process_manager_); &mock_nearby_process_manager_);
NearbyProcessManager& process_manager = NearbyProcessManager::GetInstance(); ON_CALL(mock_nearby_process_manager_, IsActiveProfile(profile))
process_manager.SetActiveProfile(profile); .WillByDefault(Return(true));
// Allow the posted task to fetch the BluetoothAdapter to finish. // Allow the posted task to fetch the BluetoothAdapter to finish.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -618,8 +615,8 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -618,8 +615,8 @@ TEST_F(NearbySharingServiceImplTest,
RegisterSendSurfaceNoActiveProfilesNotDiscovering) { RegisterSendSurfaceNoActiveProfilesNotDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE); ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NearbyProcessManager& process_manager = NearbyProcessManager::GetInstance(); ON_CALL(mock_nearby_process_manager_, IsActiveProfile(_))
process_manager.ClearActiveProfile(); .WillByDefault(Return(false));
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
EXPECT_EQ( EXPECT_EQ(
......
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