| Index: chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc
|
| diff --git a/chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc b/chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc
|
| index 53081eefb7d3a21b5af7828316326d1c1f065eac..672e6d104f37fe9f9f86b45221e9ff28f5cf8787 100644
|
| --- a/chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc
|
| +++ b/chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc
|
| @@ -6,13 +6,17 @@
|
| #include "base/command_line.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/chrome_notification_types.h"
|
| +#include "chrome/browser/sync/profile_sync_service.h"
|
| #include "chrome/browser/sync/test/integration/autofill_helper.h"
|
| #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
|
| +#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
|
| #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
|
| #include "chrome/browser/sync/test/integration/sync_test.h"
|
| #include "components/autofill/core/browser/credit_card.h"
|
| #include "components/autofill/core/browser/field_types.h"
|
| #include "components/autofill/core/browser/personal_data_manager.h"
|
| +#include "content/public/browser/notification_service.h"
|
| #include "sync/internal_api/public/base/model_type.h"
|
| #include "sync/test/fake_server/fake_server_entity.h"
|
| #include "sync/test/fake_server/unique_client_entity.h"
|
| @@ -27,6 +31,8 @@ namespace {
|
| const char kWalletSyncEnabledPreferencesContents[] =
|
| "{\"autofill\": { \"wallet_import_sync_experiment_enabled\": true } }";
|
|
|
| +const char kWalletSyncExperimentTag[] = "wallet_sync";
|
| +
|
| } // namespace
|
|
|
| class SingleClientWalletSyncTest : public SyncTest {
|
| @@ -34,25 +40,131 @@ class SingleClientWalletSyncTest : public SyncTest {
|
| SingleClientWalletSyncTest() : SyncTest(SINGLE_CLIENT) {}
|
| ~SingleClientWalletSyncTest() override {}
|
|
|
| + void TriggerSyncCycle() {
|
| + // Note: we use the experiments type here as we want to be able to trigger a
|
| + // sync cycle even when wallet is not enabled yet.
|
| + const syncer::ModelTypeSet kExperimentsType(syncer::EXPERIMENTS);
|
| + content::NotificationService::current()->Notify(
|
| + chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
|
| + content::Source<Profile>(GetProfile(0)),
|
| + content::Details<const syncer::ModelTypeSet>(&kExperimentsType));
|
| + }
|
| +
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(SingleClientWalletSyncTest);
|
| };
|
|
|
| +// Checker that will wait until an asynchronous Wallet datatype enable event
|
| +// happens, or times out.
|
| +class WalletEnabledChecker : public SingleClientStatusChangeChecker {
|
| + public:
|
| + WalletEnabledChecker()
|
| + : SingleClientStatusChangeChecker(
|
| + sync_datatype_helper::test()->GetSyncService(0)) {}
|
| + ~WalletEnabledChecker() override {}
|
| +
|
| + // SingleClientStatusChangeChecker overrides.
|
| + bool IsExitConditionSatisfied() override {
|
| + return service()->GetActiveDataTypes().Has(syncer::AUTOFILL_WALLET_DATA);
|
| + }
|
| + std::string GetDebugMessage() const override {
|
| + return "Waiting for wallet enable event.";
|
| + }
|
| +};
|
| +
|
| +// Checker that will wait until an asynchronous Wallet datatype disable event
|
| +// happens, or times out
|
| +class WalletDisabledChecker : public SingleClientStatusChangeChecker {
|
| + public:
|
| + WalletDisabledChecker()
|
| + : SingleClientStatusChangeChecker(
|
| + sync_datatype_helper::test()->GetSyncService(0)) {}
|
| + ~WalletDisabledChecker() override {}
|
| +
|
| + // SingleClientStatusChangeChecker overrides.
|
| + bool IsExitConditionSatisfied() override {
|
| + return !service()->GetActiveDataTypes().Has(syncer::AUTOFILL_WALLET_DATA);
|
| + }
|
| + std::string GetDebugMessage() const override {
|
| + return "Waiting for wallet disable event.";
|
| + }
|
| +};
|
| +
|
| IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, DisabledByDefault) {
|
| ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
|
| // The type should not be enabled without the experiment enabled.
|
| - ASSERT_FALSE(GetClient(0)->IsTypePreferred(syncer::AUTOFILL_WALLET_DATA));
|
| + ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes().Has(
|
| + syncer::AUTOFILL_WALLET_DATA));
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, EnabledViaPreference) {
|
| SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents);
|
| ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
|
| // The type should not be enabled without the experiment enabled.
|
| - ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncer::AUTOFILL_WALLET_DATA));
|
| + ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has(
|
| + syncer::AUTOFILL_WALLET_DATA));
|
| // TODO(pvalenzuela): Assert that the local root node for AUTOFILL_WALLET_DATA
|
| // exists.
|
| }
|
|
|
| +// Tests that an experiment received at sync startup time (during sign-in)
|
| +// enables the wallet datatype.
|
| +IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest,
|
| + EnabledViaExperimentStartup) {
|
| + sync_pb::EntitySpecifics experiment_entity;
|
| + sync_pb::ExperimentsSpecifics* experiment_specifics =
|
| + experiment_entity.mutable_experiments();
|
| + experiment_specifics->mutable_wallet_sync()->set_enabled(true);
|
| + GetFakeServer()->InjectEntity(
|
| + fake_server::UniqueClientEntity::CreateForInjection(
|
| + syncer::EXPERIMENTS,
|
| + kWalletSyncExperimentTag,
|
| + experiment_entity));
|
| +
|
| + ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
|
| + ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has(
|
| + syncer::AUTOFILL_WALLET_DATA));
|
| +}
|
| +
|
| +// Tests receiving an enable experiment at runtime, followed by a disabled
|
| +// experiment, and verifies the datatype is enabled/disabled as necessary.
|
| +IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest,
|
| + EnabledDisabledViaExperiment) {
|
| + ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
|
| + ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes().
|
| + Has(syncer::AUTOFILL_WALLET_DATA));
|
| +
|
| + sync_pb::EntitySpecifics experiment_entity;
|
| + sync_pb::ExperimentsSpecifics* experiment_specifics =
|
| + experiment_entity.mutable_experiments();
|
| +
|
| + // First enable the experiment.
|
| + experiment_specifics->mutable_wallet_sync()->set_enabled(true);
|
| + GetFakeServer()->InjectEntity(
|
| + fake_server::UniqueClientEntity::CreateForInjection(
|
| + syncer::EXPERIMENTS, kWalletSyncExperimentTag, experiment_entity));
|
| + TriggerSyncCycle();
|
| +
|
| + WalletEnabledChecker enabled_checker;
|
| + enabled_checker.Wait();
|
| + ASSERT_FALSE(enabled_checker.TimedOut());
|
| + ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has(
|
| + syncer::AUTOFILL_WALLET_DATA));
|
| +
|
| + // Then disable the experiment.
|
| + experiment_specifics->mutable_wallet_sync()->set_enabled(false);
|
| + GetFakeServer()->InjectEntity(
|
| + fake_server::UniqueClientEntity::CreateForInjection(
|
| + syncer::EXPERIMENTS, kWalletSyncExperimentTag, experiment_entity));
|
| + TriggerSyncCycle();
|
| +
|
| + WalletDisabledChecker disable_checker;
|
| + disable_checker.Wait();
|
| + ASSERT_FALSE(disable_checker.TimedOut());
|
| + ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes().
|
| + Has(syncer::AUTOFILL_WALLET_DATA));
|
| +}
|
| +
|
| IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, Download) {
|
| SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents);
|
|
|
|
|