Commit 4bfc5e12 authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Chromium LUCI CQ

Refactor TestIdentityManagerObserver to use on_primary_account_changed_callback

Methods OnPrimaryAccountSet/OnPrimaryAccountCleared are deprecated.
This cl removes artifacts used by these method overrides in
TestIdentityManagerObserver and replaces them with a single callback for
OnPrimaryAccountChanged.

Bug: 1158855
Change-Id: If0cd666626268c7e21fcde33d26a5c0cfbc298de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2618438
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842974}
parent 13b8cfa7
...@@ -561,22 +561,23 @@ TEST_F(IdentityManagerTest, PrimaryAccountInfoAfterSignin) { ...@@ -561,22 +561,23 @@ TEST_F(IdentityManagerTest, PrimaryAccountInfoAfterSignin) {
ClearPrimaryAccount(identity_manager()); ClearPrimaryAccount(identity_manager());
SetPrimaryAccount(identity_manager(), kTestEmail); SetPrimaryAccount(identity_manager(), kTestEmail);
auto event = identity_manager_observer()->GetPrimaryAccountChangedEvent();
EXPECT_EQ(PrimaryAccountChangeEvent::Type::kSet,
event.GetEventTypeFor(ConsentLevel::kSync));
EXPECT_EQ(PrimaryAccountChangeEvent::Type::kSet,
event.GetEventTypeFor(ConsentLevel::kNotRequired));
CoreAccountInfo primary_account_from_set_callback = CoreAccountInfo primary_account_from_set_callback =
identity_manager_observer()->PrimaryAccountFromSetCallback(); event.GetCurrentState().primary_account;
EXPECT_EQ(kTestGaiaId, primary_account_from_set_callback.gaia); EXPECT_EQ(kTestGaiaId, primary_account_from_set_callback.gaia);
EXPECT_EQ(kTestEmail, primary_account_from_set_callback.email); EXPECT_EQ(kTestEmail, primary_account_from_set_callback.email);
// Primary account is by definition also unconsented primary account.
EXPECT_EQ(
primary_account_from_set_callback,
identity_manager_observer()->UnconsentedPrimaryAccountFromCallback());
CoreAccountInfo primary_account_info = CoreAccountInfo primary_account_info =
identity_manager()->GetPrimaryAccountInfo(); identity_manager()->GetPrimaryAccountInfo();
EXPECT_EQ(kTestGaiaId, primary_account_info.gaia); EXPECT_EQ(kTestGaiaId, primary_account_info.gaia);
EXPECT_EQ(kTestEmail, primary_account_info.email); EXPECT_EQ(kTestEmail, primary_account_info.email);
// Primary account is by definition also unconsented primary account.
EXPECT_EQ(primary_account_info, identity_manager()->GetPrimaryAccountInfo( EXPECT_EQ(primary_account_info, identity_manager()->GetPrimaryAccountInfo(
ConsentLevel::kNotRequired)); ConsentLevel::kNotRequired));
...@@ -599,15 +600,20 @@ TEST_F(IdentityManagerTest, PrimaryAccountInfoAfterSigninAndSignout) { ...@@ -599,15 +600,20 @@ TEST_F(IdentityManagerTest, PrimaryAccountInfoAfterSigninAndSignout) {
// Sign the user out and check that the IdentityManager responds // Sign the user out and check that the IdentityManager responds
// appropriately. // appropriately.
ClearPrimaryAccount(identity_manager()); ClearPrimaryAccount(identity_manager());
auto event = identity_manager_observer()->GetPrimaryAccountChangedEvent();
EXPECT_EQ(PrimaryAccountChangeEvent::Type::kCleared,
event.GetEventTypeFor(ConsentLevel::kSync));
EXPECT_EQ(PrimaryAccountChangeEvent::Type::kCleared,
event.GetEventTypeFor(ConsentLevel::kNotRequired));
CoreAccountInfo primary_account_from_cleared_callback = CoreAccountInfo primary_account_from_cleared_callback =
identity_manager_observer()->PrimaryAccountFromClearedCallback(); event.GetPreviousState().primary_account;
EXPECT_EQ(kTestGaiaId, primary_account_from_cleared_callback.gaia); EXPECT_EQ(kTestGaiaId, primary_account_from_cleared_callback.gaia);
EXPECT_EQ(kTestEmail, primary_account_from_cleared_callback.email); EXPECT_EQ(kTestEmail, primary_account_from_cleared_callback.email);
// After the sign-out, there is no unconsented primary account. // After the sign-out, there is no unconsented primary account.
EXPECT_TRUE(identity_manager_observer() EXPECT_TRUE(identity_manager()
->UnconsentedPrimaryAccountFromCallback() ->GetPrimaryAccountInfo(ConsentLevel::kNotRequired)
.IsEmpty()); .IsEmpty());
CoreAccountInfo primary_account_info = CoreAccountInfo primary_account_info =
...@@ -675,8 +681,9 @@ TEST_F(IdentityManagerTest, HasPrimaryAccount) { ...@@ -675,8 +681,9 @@ TEST_F(IdentityManagerTest, HasPrimaryAccount) {
EXPECT_FALSE( EXPECT_FALSE(
identity_manager()->HasPrimaryAccount(ConsentLevel::kNotRequired)); identity_manager()->HasPrimaryAccount(ConsentLevel::kNotRequired));
EXPECT_FALSE(identity_manager_observer() EXPECT_FALSE(identity_manager_observer()
->PrimaryAccountFromClearedCallback() ->GetPrimaryAccountChangedEvent()
.IsEmpty()); .GetPreviousState()
.primary_account.IsEmpty());
#endif #endif
} }
......
...@@ -198,7 +198,14 @@ void RevokeSyncConsent(IdentityManager* identity_manager) { ...@@ -198,7 +198,14 @@ void RevokeSyncConsent(IdentityManager* identity_manager) {
DCHECK(identity_manager->GetPrimaryAccountMutator()); DCHECK(identity_manager->GetPrimaryAccountMutator());
base::RunLoop run_loop; base::RunLoop run_loop;
TestIdentityManagerObserver signout_observer(identity_manager); TestIdentityManagerObserver signout_observer(identity_manager);
signout_observer.SetOnPrimaryAccountClearedCallback(run_loop.QuitClosure()); signout_observer.SetOnPrimaryAccountChangedCallback(base::BindOnce(
[](base::RunLoop* run_loop, PrimaryAccountChangeEvent event) {
if (event.GetEventTypeFor(ConsentLevel::kSync) ==
PrimaryAccountChangeEvent::Type::kCleared) {
run_loop->Quit();
}
},
&run_loop));
identity_manager->GetPrimaryAccountMutator()->RevokeSyncConsent( identity_manager->GetPrimaryAccountMutator()->RevokeSyncConsent(
signin_metrics::SIGNOUT_TEST, signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC); signin_metrics::SignoutDelete::IGNORE_METRIC);
...@@ -220,7 +227,14 @@ void ClearPrimaryAccount(IdentityManager* identity_manager) { ...@@ -220,7 +227,14 @@ void ClearPrimaryAccount(IdentityManager* identity_manager) {
identity_manager->HasPrimaryAccount(ConsentLevel::kSync); identity_manager->HasPrimaryAccount(ConsentLevel::kSync);
base::RunLoop run_loop; base::RunLoop run_loop;
TestIdentityManagerObserver signout_observer(identity_manager); TestIdentityManagerObserver signout_observer(identity_manager);
signout_observer.SetOnPrimaryAccountClearedCallback(run_loop.QuitClosure()); signout_observer.SetOnPrimaryAccountChangedCallback(base::BindOnce(
[](base::RunLoop* run_loop, PrimaryAccountChangeEvent event) {
if (event.GetEventTypeFor(ConsentLevel::kNotRequired) ==
PrimaryAccountChangeEvent::Type::kCleared) {
run_loop->Quit();
}
},
&run_loop));
identity_manager->GetPrimaryAccountMutator()->ClearPrimaryAccount( identity_manager->GetPrimaryAccountMutator()->ClearPrimaryAccount(
signin_metrics::SIGNOUT_TEST, signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC); signin_metrics::SignoutDelete::IGNORE_METRIC);
......
...@@ -20,34 +20,14 @@ TestIdentityManagerObserver::~TestIdentityManagerObserver() { ...@@ -20,34 +20,14 @@ TestIdentityManagerObserver::~TestIdentityManagerObserver() {
identity_manager_->RemoveObserver(this); identity_manager_->RemoveObserver(this);
} }
void TestIdentityManagerObserver::SetOnPrimaryAccountSetCallback( void TestIdentityManagerObserver::SetOnPrimaryAccountChangedCallback(
base::OnceClosure callback) { PrimaryAccountChangedCallback callback) {
on_primary_account_set_callback_ = std::move(callback); on_primary_account_changed_callback_ = std::move(callback);
}
const CoreAccountInfo&
TestIdentityManagerObserver::PrimaryAccountFromSetCallback() {
return primary_account_from_set_callback_;
}
void TestIdentityManagerObserver::SetOnPrimaryAccountClearedCallback(
base::OnceClosure callback) {
on_primary_account_cleared_callback_ = std::move(callback);
} }
const CoreAccountInfo& const PrimaryAccountChangeEvent&
TestIdentityManagerObserver::PrimaryAccountFromClearedCallback() { TestIdentityManagerObserver::GetPrimaryAccountChangedEvent() {
return primary_account_from_cleared_callback_; return on_primary_account_changed_event_;
}
void TestIdentityManagerObserver::SetOnUnconsentedPrimaryAccountChangedCallback(
base::OnceClosure callback) {
on_unconsented_primary_account_callback_ = std::move(callback);
}
const CoreAccountInfo&
TestIdentityManagerObserver::UnconsentedPrimaryAccountFromCallback() {
return unconsented_primary_account_from_callback_;
} }
void TestIdentityManagerObserver::SetOnRefreshTokenUpdatedCallback( void TestIdentityManagerObserver::SetOnRefreshTokenUpdatedCallback(
...@@ -135,36 +115,9 @@ TestIdentityManagerObserver::BatchChangeRecords() const { ...@@ -135,36 +115,9 @@ TestIdentityManagerObserver::BatchChangeRecords() const {
// IdentityManager::Observer: // IdentityManager::Observer:
void TestIdentityManagerObserver::OnPrimaryAccountChanged( void TestIdentityManagerObserver::OnPrimaryAccountChanged(
const PrimaryAccountChangeEvent& event) { const PrimaryAccountChangeEvent& event) {
// TODO(https://crbug.com/1158855): Refactor this test observer to on_primary_account_changed_event_ = event;
// have a single on_primary_account_changed_callback_ and a single if (on_primary_account_changed_callback_)
// on_primary_account_changed_event_. std::move(on_primary_account_changed_callback_).Run(event);
switch (event.GetEventTypeFor(ConsentLevel::kNotRequired)) {
case PrimaryAccountChangeEvent::Type::kSet:
case PrimaryAccountChangeEvent::Type::kCleared:
unconsented_primary_account_from_callback_ =
event.GetCurrentState().primary_account;
if (on_unconsented_primary_account_callback_)
std::move(on_unconsented_primary_account_callback_).Run();
break;
case PrimaryAccountChangeEvent::Type::kNone:
break;
}
switch (event.GetEventTypeFor(ConsentLevel::kSync)) {
case PrimaryAccountChangeEvent::Type::kSet:
primary_account_from_set_callback_ =
event.GetCurrentState().primary_account;
if (on_primary_account_set_callback_)
std::move(on_primary_account_set_callback_).Run();
break;
case PrimaryAccountChangeEvent::Type::kCleared:
primary_account_from_cleared_callback_ =
event.GetPreviousState().primary_account;
if (on_primary_account_cleared_callback_)
std::move(on_primary_account_cleared_callback_).Run();
break;
case PrimaryAccountChangeEvent::Type::kNone:
break;
}
} }
void TestIdentityManagerObserver::OnRefreshTokenUpdatedForAccount( void TestIdentityManagerObserver::OnRefreshTokenUpdatedForAccount(
......
...@@ -20,18 +20,15 @@ namespace signin { ...@@ -20,18 +20,15 @@ namespace signin {
// the potential results and/or errors returned after such events have occurred. // the potential results and/or errors returned after such events have occurred.
class TestIdentityManagerObserver : IdentityManager::Observer { class TestIdentityManagerObserver : IdentityManager::Observer {
public: public:
using PrimaryAccountChangedCallback =
base::OnceCallback<void(PrimaryAccountChangeEvent)>;
explicit TestIdentityManagerObserver(IdentityManager* identity_manager); explicit TestIdentityManagerObserver(IdentityManager* identity_manager);
~TestIdentityManagerObserver() override; ~TestIdentityManagerObserver() override;
void SetOnPrimaryAccountSetCallback(base::OnceClosure callback); void SetOnPrimaryAccountChangedCallback(
const CoreAccountInfo& PrimaryAccountFromSetCallback(); PrimaryAccountChangedCallback callback);
const PrimaryAccountChangeEvent& GetPrimaryAccountChangedEvent();
void SetOnPrimaryAccountClearedCallback(base::OnceClosure callback);
const CoreAccountInfo& PrimaryAccountFromClearedCallback();
void SetOnUnconsentedPrimaryAccountChangedCallback(
base::OnceClosure callback);
const CoreAccountInfo& UnconsentedPrimaryAccountFromCallback();
void SetOnRefreshTokenUpdatedCallback(base::OnceClosure callback); void SetOnRefreshTokenUpdatedCallback(base::OnceClosure callback);
const CoreAccountInfo& AccountFromRefreshTokenUpdatedCallback(); const CoreAccountInfo& AccountFromRefreshTokenUpdatedCallback();
...@@ -88,14 +85,8 @@ class TestIdentityManagerObserver : IdentityManager::Observer { ...@@ -88,14 +85,8 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
IdentityManager* identity_manager_; IdentityManager* identity_manager_;
base::OnceClosure on_primary_account_set_callback_; PrimaryAccountChangedCallback on_primary_account_changed_callback_;
CoreAccountInfo primary_account_from_set_callback_; PrimaryAccountChangeEvent on_primary_account_changed_event_;
base::OnceClosure on_primary_account_cleared_callback_;
CoreAccountInfo primary_account_from_cleared_callback_;
base::OnceClosure on_unconsented_primary_account_callback_;
CoreAccountInfo unconsented_primary_account_from_callback_;
base::OnceClosure on_refresh_token_updated_callback_; base::OnceClosure on_refresh_token_updated_callback_;
CoreAccountInfo account_from_refresh_token_updated_callback_; CoreAccountInfo account_from_refresh_token_updated_callback_;
......
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