Skip to content

Commit

Permalink
[AF] Make wallet controllers for USS/Directory consistent
Browse files Browse the repository at this point in the history
This CL makes the old Directory controller react to the toggle in
Payments methods as well.

Bug: 898141
Change-Id: I09918c9aace663376f7beb0ed0cd5f2ef3854b0e
Reviewed-on: https://chromium-review.googlesource.com/c/1296598
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Reviewed-by: Florian Uunk <feuunk@chromium.org>
Reviewed-by: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602272}
  • Loading branch information
Jan Krcal authored and Commit Bot committed Oct 24, 2018
1 parent db6a033 commit 45399d3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ AutofillWalletDataTypeController::AutofillWalletDataTypeController(
pref_registrar_.Init(sync_client_->GetPrefService());
pref_registrar_.Add(
autofill::prefs::kAutofillWalletImportEnabled,
base::Bind(&AutofillWalletDataTypeController::OnUserPrefChanged,
base::AsWeakPtr(this)));
base::BindRepeating(&AutofillWalletDataTypeController::OnUserPrefChanged,
base::Unretained(this)));
pref_registrar_.Add(
autofill::prefs::kAutofillCreditCardEnabled,
base::BindRepeating(&AutofillWalletDataTypeController::OnUserPrefChanged,
base::AsWeakPtr(this)));
}

AutofillWalletDataTypeController::~AutofillWalletDataTypeController() {}
Expand Down Expand Up @@ -124,8 +128,10 @@ bool AutofillWalletDataTypeController::IsEnabled() {
DCHECK(CalledOnValidThread());

// Require the user-visible pref to be enabled to sync Wallet data/metadata.
return autofill::prefs::IsPaymentsIntegrationEnabled(
sync_client_->GetPrefService());
return sync_client_->GetPrefService()->GetBoolean(
autofill::prefs::kAutofillWalletImportEnabled) &&
sync_client_->GetPrefService()->GetBoolean(
autofill::prefs::kAutofillCreditCardEnabled);
}
void AutofillWalletDataTypeController::DisableForPolicy() {
if (state() != NOT_RUNNING && state() != STOPPING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class AutofillWalletDataTypeControllerTest : public testing::Test,
void SetUp() override {
prefs_.registry()->RegisterBooleanPref(
autofill::prefs::kAutofillWalletImportEnabled, true);
prefs_.registry()->RegisterBooleanPref(
autofill::prefs::kAutofillCreditCardEnabled, true);

web_data_service_ = base::MakeRefCounted<FakeWebDataService>(
base::ThreadTaskRunnerHandle::Get(),
Expand Down Expand Up @@ -166,7 +168,8 @@ TEST_F(AutofillWalletDataTypeControllerTest, StartDatatypeEnabled) {
EXPECT_EQ(syncer::DataTypeController::RUNNING, autofill_wallet_dtc_->state());
}

TEST_F(AutofillWalletDataTypeControllerTest, DatatypeDisabledWhileRunning) {
TEST_F(AutofillWalletDataTypeControllerTest,
DatatypeDisabledByWalletImportWhileRunning) {
SetStartExpectations();
web_data_service_->LoadDatabase();
EXPECT_CALL(start_callback_,
Expand All @@ -179,14 +182,49 @@ TEST_F(AutofillWalletDataTypeControllerTest, DatatypeDisabledWhileRunning) {
EXPECT_FALSE(last_error_.IsSet());
EXPECT_EQ(syncer::AUTOFILL_WALLET_DATA, last_type_);
autofill::prefs::SetPaymentsIntegrationEnabled(GetPrefService(), false);
autofill::prefs::SetCreditCardAutofillEnabled(GetPrefService(), true);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(last_error_.IsSet());
}

TEST_F(AutofillWalletDataTypeControllerTest, DatatypeDisabledAtStartup) {
TEST_F(AutofillWalletDataTypeControllerTest,
DatatypeDisabledByCreditCardsWhileRunning) {
SetStartExpectations();
web_data_service_->LoadDatabase();
EXPECT_CALL(start_callback_,
Run(syncer::DataTypeController::OK, testing::_, testing::_));

EXPECT_EQ(syncer::DataTypeController::NOT_RUNNING,
autofill_wallet_dtc_->state());
Start();
EXPECT_EQ(syncer::DataTypeController::RUNNING, autofill_wallet_dtc_->state());
EXPECT_FALSE(last_error_.IsSet());
EXPECT_EQ(syncer::AUTOFILL_WALLET_DATA, last_type_);
autofill::prefs::SetPaymentsIntegrationEnabled(GetPrefService(), true);
autofill::prefs::SetCreditCardAutofillEnabled(GetPrefService(), false);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(last_error_.IsSet());
}

TEST_F(AutofillWalletDataTypeControllerTest,
DatatypeDisabledByWalletImportAtStartup) {
SetStartExpectations();
web_data_service_->LoadDatabase();
autofill::prefs::SetPaymentsIntegrationEnabled(GetPrefService(), false);
autofill::prefs::SetCreditCardAutofillEnabled(GetPrefService(), true);
EXPECT_EQ(syncer::DataTypeController::NOT_RUNNING,
autofill_wallet_dtc_->state());
Start();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(last_error_.IsSet());
}

TEST_F(AutofillWalletDataTypeControllerTest,
DatatypeDisabledByCreditCardsAtStartup) {
SetStartExpectations();
web_data_service_->LoadDatabase();
autofill::prefs::SetPaymentsIntegrationEnabled(GetPrefService(), true);
autofill::prefs::SetCreditCardAutofillEnabled(GetPrefService(), false);
EXPECT_EQ(syncer::DataTypeController::NOT_RUNNING,
autofill_wallet_dtc_->state());
Start();
Expand Down

0 comments on commit 45399d3

Please sign in to comment.