Commit 747b67f2 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Fix sharded QuickUnlockPrivateUnitTest

These tests would often fail when run in parallel, but would always pass
in isolation. This change fixes the tests via proper use of SetUp and
TearDown, and moves some initialization of EasyUnlockServiceRegular
from the ctor to InitializeInternal(). This also removes some virtual
method calls from the ctor, as per the style guide: "Constructors should
never call virtual functions"

Bug: none
Change-Id: Ibdb8628778105ed242c137ffa5ee12ffa018b06e
Reviewed-on: https://chromium-review.googlesource.com/c/1493072
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Auto-Submit: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636590}
parent ba8fc163
...@@ -135,9 +135,8 @@ class QuickUnlockPrivateUnitTest ...@@ -135,9 +135,8 @@ class QuickUnlockPrivateUnitTest
: public ExtensionApiUnittest, : public ExtensionApiUnittest,
public ::testing::WithParamInterface<TestType> { public ::testing::WithParamInterface<TestType> {
public: public:
QuickUnlockPrivateUnitTest() QuickUnlockPrivateUnitTest() = default;
: fake_user_manager_(new FakeChromeUserManager()), ~QuickUnlockPrivateUnitTest() override = default;
scoped_user_manager_(base::WrapUnique(fake_user_manager_)) {}
protected: protected:
void SetUp() override { void SetUp() override {
...@@ -152,6 +151,10 @@ class QuickUnlockPrivateUnitTest ...@@ -152,6 +151,10 @@ class QuickUnlockPrivateUnitTest
std::move(cryptohome_client)); std::move(cryptohome_client));
SystemSaltGetter::Initialize(); SystemSaltGetter::Initialize();
fake_user_manager_ = new FakeChromeUserManager();
scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>(
base::WrapUnique(fake_user_manager_));
ExtensionApiUnittest::SetUp(); ExtensionApiUnittest::SetUp();
SystemSaltGetter::Get()->SetRawSaltForTesting({1, 2, 3, 4, 5, 6, 7, 8}); SystemSaltGetter::Get()->SetRawSaltForTesting({1, 2, 3, 4, 5, 6, 7, 8});
...@@ -190,10 +193,13 @@ class QuickUnlockPrivateUnitTest ...@@ -190,10 +193,13 @@ class QuickUnlockPrivateUnitTest
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExtensionApiUnittest::TearDown();
fake_user_manager_ = nullptr; fake_user_manager_ = nullptr;
scoped_user_manager_.reset();
ExtensionApiUnittest::TearDown();
SystemSaltGetter::Shutdown(); SystemSaltGetter::Shutdown();
DBusThreadManager::Shutdown();
cryptohome::HomedirMethods::Shutdown(); cryptohome::HomedirMethods::Shutdown();
} }
...@@ -501,8 +507,8 @@ class QuickUnlockPrivateUnitTest ...@@ -501,8 +507,8 @@ class QuickUnlockPrivateUnitTest
expect_modes_changed_ = false; expect_modes_changed_ = false;
} }
FakeChromeUserManager* fake_user_manager_; FakeChromeUserManager* fake_user_manager_ = nullptr;
user_manager::ScopedUserManager scoped_user_manager_; std::unique_ptr<user_manager::ScopedUserManager> scoped_user_manager_;
QuickUnlockPrivateSetModesFunction::ModesChangedEventHandler QuickUnlockPrivateSetModesFunction::ModesChangedEventHandler
modes_changed_handler_; modes_changed_handler_;
bool expect_modes_changed_ = false; bool expect_modes_changed_ = false;
......
...@@ -107,23 +107,9 @@ EasyUnlockServiceRegular::EasyUnlockServiceRegular( ...@@ -107,23 +107,9 @@ EasyUnlockServiceRegular::EasyUnlockServiceRegular(
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client) multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client)
: EasyUnlockService(profile, secure_channel_client), : EasyUnlockService(profile, secure_channel_client),
lock_screen_last_shown_timestamp_(base::TimeTicks::Now()), lock_screen_last_shown_timestamp_(base::TimeTicks::Now()),
deferring_device_load_(false),
notification_controller_(std::move(notification_controller)), notification_controller_(std::move(notification_controller)),
device_sync_client_(device_sync_client), device_sync_client_(device_sync_client),
multidevice_setup_client_(multidevice_setup_client), multidevice_setup_client_(multidevice_setup_client) {}
shown_pairing_changed_notification_(false),
weak_ptr_factory_(this) {
// If |device_sync_client_| is not ready yet, wait for it to call back on
// OnReady().
if (device_sync_client_->is_ready())
OnReady();
device_sync_client_->AddObserver(this);
OnFeatureStatesChanged(multidevice_setup_client_->GetFeatureStates());
multidevice_setup_client_->AddObserver(this);
}
EasyUnlockServiceRegular::~EasyUnlockServiceRegular() = default; EasyUnlockServiceRegular::~EasyUnlockServiceRegular() = default;
...@@ -347,6 +333,17 @@ void EasyUnlockServiceRegular::RecordPasswordLoginEvent( ...@@ -347,6 +333,17 @@ void EasyUnlockServiceRegular::RecordPasswordLoginEvent(
} }
void EasyUnlockServiceRegular::InitializeInternal() { void EasyUnlockServiceRegular::InitializeInternal() {
// If |device_sync_client_| is not ready yet, wait for it to call back on
// OnReady().
if (device_sync_client_->is_ready())
OnReady();
device_sync_client_->AddObserver(this);
OnFeatureStatesChanged(multidevice_setup_client_->GetFeatureStates());
multidevice_setup_client_->AddObserver(this);
proximity_auth::ScreenlockBridge::Get()->AddObserver(this); proximity_auth::ScreenlockBridge::Get()->AddObserver(this);
pref_manager_.reset(new proximity_auth::ProximityAuthProfilePrefManager( pref_manager_.reset(new proximity_auth::ProximityAuthProfilePrefManager(
......
...@@ -145,7 +145,7 @@ class EasyUnlockServiceRegular ...@@ -145,7 +145,7 @@ class EasyUnlockServiceRegular
// loading the RemoteDevice until the screen is unlocked. For security, // loading the RemoteDevice until the screen is unlocked. For security,
// this deferment prevents the lock screen from being changed by a network // this deferment prevents the lock screen from being changed by a network
// event. // event.
bool deferring_device_load_; bool deferring_device_load_ = false;
// Responsible for showing all the notifications used for EasyUnlock. // Responsible for showing all the notifications used for EasyUnlock.
std::unique_ptr<EasyUnlockNotificationController> notification_controller_; std::unique_ptr<EasyUnlockNotificationController> notification_controller_;
...@@ -170,12 +170,12 @@ class EasyUnlockServiceRegular ...@@ -170,12 +170,12 @@ class EasyUnlockServiceRegular
// True if the pairing changed notification was shown, so that the next time // True if the pairing changed notification was shown, so that the next time
// the Chromebook is unlocked, we can show the subsequent 'pairing applied' // the Chromebook is unlocked, we can show the subsequent 'pairing applied'
// notification. // notification.
bool shown_pairing_changed_notification_; bool shown_pairing_changed_notification_ = false;
// Listens to pref changes. // Listens to pref changes.
PrefChangeRegistrar registrar_; PrefChangeRegistrar registrar_;
base::WeakPtrFactory<EasyUnlockServiceRegular> weak_ptr_factory_; base::WeakPtrFactory<EasyUnlockServiceRegular> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceRegular); DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceRegular);
}; };
......
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