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) {
ClearPrimaryAccount(identity_manager());
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 =
identity_manager_observer()->PrimaryAccountFromSetCallback();
event.GetCurrentState().primary_account;
EXPECT_EQ(kTestGaiaId, primary_account_from_set_callback.gaia);
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 =
identity_manager()->GetPrimaryAccountInfo();
EXPECT_EQ(kTestGaiaId, primary_account_info.gaia);
EXPECT_EQ(kTestEmail, primary_account_info.email);
// Primary account is by definition also unconsented primary account.
EXPECT_EQ(primary_account_info, identity_manager()->GetPrimaryAccountInfo(
ConsentLevel::kNotRequired));
......@@ -599,15 +600,20 @@ TEST_F(IdentityManagerTest, PrimaryAccountInfoAfterSigninAndSignout) {
// Sign the user out and check that the IdentityManager responds
// appropriately.
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 =
identity_manager_observer()->PrimaryAccountFromClearedCallback();
event.GetPreviousState().primary_account;
EXPECT_EQ(kTestGaiaId, primary_account_from_cleared_callback.gaia);
EXPECT_EQ(kTestEmail, primary_account_from_cleared_callback.email);
// After the sign-out, there is no unconsented primary account.
EXPECT_TRUE(identity_manager_observer()
->UnconsentedPrimaryAccountFromCallback()
EXPECT_TRUE(identity_manager()
->GetPrimaryAccountInfo(ConsentLevel::kNotRequired)
.IsEmpty());
CoreAccountInfo primary_account_info =
......@@ -675,8 +681,9 @@ TEST_F(IdentityManagerTest, HasPrimaryAccount) {
EXPECT_FALSE(
identity_manager()->HasPrimaryAccount(ConsentLevel::kNotRequired));
EXPECT_FALSE(identity_manager_observer()
->PrimaryAccountFromClearedCallback()
.IsEmpty());
->GetPrimaryAccountChangedEvent()
.GetPreviousState()
.primary_account.IsEmpty());
#endif
}
......
......@@ -198,7 +198,14 @@ void RevokeSyncConsent(IdentityManager* identity_manager) {
DCHECK(identity_manager->GetPrimaryAccountMutator());
base::RunLoop run_loop;
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(
signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC);
......@@ -220,7 +227,14 @@ void ClearPrimaryAccount(IdentityManager* identity_manager) {
identity_manager->HasPrimaryAccount(ConsentLevel::kSync);
base::RunLoop run_loop;
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(
signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC);
......
......@@ -20,34 +20,14 @@ TestIdentityManagerObserver::~TestIdentityManagerObserver() {
identity_manager_->RemoveObserver(this);
}
void TestIdentityManagerObserver::SetOnPrimaryAccountSetCallback(
base::OnceClosure callback) {
on_primary_account_set_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);
void TestIdentityManagerObserver::SetOnPrimaryAccountChangedCallback(
PrimaryAccountChangedCallback callback) {
on_primary_account_changed_callback_ = std::move(callback);
}
const CoreAccountInfo&
TestIdentityManagerObserver::PrimaryAccountFromClearedCallback() {
return primary_account_from_cleared_callback_;
}
void TestIdentityManagerObserver::SetOnUnconsentedPrimaryAccountChangedCallback(
base::OnceClosure callback) {
on_unconsented_primary_account_callback_ = std::move(callback);
}
const CoreAccountInfo&
TestIdentityManagerObserver::UnconsentedPrimaryAccountFromCallback() {
return unconsented_primary_account_from_callback_;
const PrimaryAccountChangeEvent&
TestIdentityManagerObserver::GetPrimaryAccountChangedEvent() {
return on_primary_account_changed_event_;
}
void TestIdentityManagerObserver::SetOnRefreshTokenUpdatedCallback(
......@@ -135,36 +115,9 @@ TestIdentityManagerObserver::BatchChangeRecords() const {
// IdentityManager::Observer:
void TestIdentityManagerObserver::OnPrimaryAccountChanged(
const PrimaryAccountChangeEvent& event) {
// TODO(https://crbug.com/1158855): Refactor this test observer to
// have a single on_primary_account_changed_callback_ and a single
// on_primary_account_changed_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;
}
on_primary_account_changed_event_ = event;
if (on_primary_account_changed_callback_)
std::move(on_primary_account_changed_callback_).Run(event);
}
void TestIdentityManagerObserver::OnRefreshTokenUpdatedForAccount(
......
......@@ -20,18 +20,15 @@ namespace signin {
// the potential results and/or errors returned after such events have occurred.
class TestIdentityManagerObserver : IdentityManager::Observer {
public:
using PrimaryAccountChangedCallback =
base::OnceCallback<void(PrimaryAccountChangeEvent)>;
explicit TestIdentityManagerObserver(IdentityManager* identity_manager);
~TestIdentityManagerObserver() override;
void SetOnPrimaryAccountSetCallback(base::OnceClosure callback);
const CoreAccountInfo& PrimaryAccountFromSetCallback();
void SetOnPrimaryAccountClearedCallback(base::OnceClosure callback);
const CoreAccountInfo& PrimaryAccountFromClearedCallback();
void SetOnUnconsentedPrimaryAccountChangedCallback(
base::OnceClosure callback);
const CoreAccountInfo& UnconsentedPrimaryAccountFromCallback();
void SetOnPrimaryAccountChangedCallback(
PrimaryAccountChangedCallback callback);
const PrimaryAccountChangeEvent& GetPrimaryAccountChangedEvent();
void SetOnRefreshTokenUpdatedCallback(base::OnceClosure callback);
const CoreAccountInfo& AccountFromRefreshTokenUpdatedCallback();
......@@ -88,14 +85,8 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
IdentityManager* identity_manager_;
base::OnceClosure on_primary_account_set_callback_;
CoreAccountInfo primary_account_from_set_callback_;
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_;
PrimaryAccountChangedCallback on_primary_account_changed_callback_;
PrimaryAccountChangeEvent on_primary_account_changed_event_;
base::OnceClosure on_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