Commit 45e571ef authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Add an integration test for PersonalDataManager switching card storage

When Sync switches from transport mode to feature mode, PersonalDataManager
should switch from ephemeral to persistent storage for server credit cards.
This adds a first integration test for that.

Bug: 885211
Change-Id: I0ba6cbceb192b4e024d7c286e48a430ee9da2125
Reviewed-on: https://chromium-review.googlesource.com/1238334Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593484}
parent 2ff70d4f
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/sync/test/integration/autofill_helper.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/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/secondary_account_helper.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h" #include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h" #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h" #include "chrome/browser/sync/test/integration/sync_test.h"
...@@ -388,7 +389,6 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, EnabledByDefault) { ...@@ -388,7 +389,6 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, EnabledByDefault) {
} }
IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, DownloadProfileStorage) { IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, DownloadProfileStorage) {
base::test::ScopedFeatureList feature_list;
InitWithFeatures(/*enabled_features=*/{}, InitWithFeatures(/*enabled_features=*/{},
/*disabled_features=*/ /*disabled_features=*/
{autofill::features::kAutofillEnableAccountWalletStorage}); {autofill::features::kAutofillEnableAccountWalletStorage});
...@@ -833,6 +833,104 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, ...@@ -833,6 +833,104 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
EXPECT_EQ(kDefaultBillingAddressId, cards[0]->billing_address_id()); EXPECT_EQ(kDefaultBillingAddressId, cards[0]->billing_address_id());
} }
class SingleClientWalletSecondaryAccountSyncTest
: public SingleClientWalletSyncTest {
public:
SingleClientWalletSecondaryAccountSyncTest() {
features_.InitWithFeatures(
/*enabled_features=*/{switches::kSyncStandaloneTransport,
switches::kSyncSupportSecondaryAccount,
switches::kSyncUSSAutofillWalletData,
autofill::features::
kAutofillEnableAccountWalletStorage},
/*disabled_features=*/{});
}
~SingleClientWalletSecondaryAccountSyncTest() override {}
void SetUpInProcessBrowserTestFixture() override {
fake_gaia_cookie_manager_factory_ =
secondary_account_helper::SetUpFakeGaiaCookieManagerService();
}
void SetUpOnMainThread() override {
#if defined(OS_CHROMEOS)
secondary_account_helper::InitNetwork();
#endif // defined(OS_CHROMEOS)
}
Profile* profile() { return GetProfile(0); }
private:
base::test::ScopedFeatureList features_;
secondary_account_helper::ScopedFakeGaiaCookieManagerServiceFactory
fake_gaia_cookie_manager_factory_;
DISALLOW_COPY_AND_ASSIGN(SingleClientWalletSecondaryAccountSyncTest);
};
// ChromeOS doesn't support changes to the primary account after startup, so
// this test doesn't apply.
#if !defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(SingleClientWalletSecondaryAccountSyncTest,
SwitchesFromAccountToProfileStorage) {
ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
GetPersonalDataManager(0)->OnSyncServiceInitialized(GetSyncService(0));
GetFakeServer()->SetWalletData({CreateDefaultSyncWalletCard()});
// Set up Sync in transport mode for a non-primary account.
secondary_account_helper::SignInSecondaryAccount(profile(), "user@email.com");
ASSERT_TRUE(GetClient(0)->AwaitSyncSetupCompletion(
/*skip_passphrase_verification=*/false));
ASSERT_EQ(syncer::SyncService::TransportState::ACTIVE,
GetSyncService(0)->GetTransportState());
ASSERT_FALSE(GetSyncService(0)->IsSyncFeatureEnabled());
ASSERT_FALSE(GetSyncService(0)->IsSyncFeatureActive());
ASSERT_TRUE(GetSyncService(0)->GetActiveDataTypes().Has(
syncer::AUTOFILL_WALLET_DATA));
// PersonalDataManager should use (ephemeral) account storage.
EXPECT_FALSE(GetPersonalDataManager(0)->IsSyncFeatureEnabled());
EXPECT_TRUE(
GetPersonalDataManager(0)->IsUsingAccountStorageForServerCardsForTest());
auto account_data = GetAccountWebDataService(0);
ASSERT_NE(nullptr, account_data);
auto profile_data = GetProfileWebDataService(0);
ASSERT_NE(nullptr, profile_data);
// Check that the card is stored in the account storage (ephemeral), but not
// in the profile storage (persisted).
EXPECT_EQ(1U, GetServerCards(account_data).size());
EXPECT_EQ(0U, GetServerCards(profile_data).size());
// Simulate the user opting in to full Sync: Make the account primary, and
// set first-time setup to complete.
secondary_account_helper::MakeAccountPrimary(profile(), "user@email.com");
GetSyncService(0)->SetFirstSetupComplete();
// Wait for Sync to get reconfigured into feature mode.
ASSERT_TRUE(GetClient(0)->AwaitSyncSetupCompletion(
/*skip_passphrase_verification=*/false));
ASSERT_EQ(syncer::SyncService::TransportState::ACTIVE,
GetSyncService(0)->GetTransportState());
ASSERT_TRUE(GetSyncService(0)->IsSyncFeatureEnabled());
ASSERT_TRUE(GetSyncService(0)->IsSyncFeatureActive());
ASSERT_TRUE(GetSyncService(0)->GetActiveDataTypes().Has(
syncer::AUTOFILL_WALLET_DATA));
// PersonalDataManager should have switched to persistent storage.
EXPECT_TRUE(GetPersonalDataManager(0)->IsSyncFeatureEnabled());
EXPECT_FALSE(
GetPersonalDataManager(0)->IsUsingAccountStorageForServerCardsForTest());
// The card should now be in the profile storage (persisted).
EXPECT_EQ(0U, GetServerCards(account_data).size());
EXPECT_EQ(1U, GetServerCards(profile_data).size());
}
#endif // !defined(OS_CHROMEOS)
INSTANTIATE_TEST_CASE_P(USS, INSTANTIATE_TEST_CASE_P(USS,
SingleClientWalletSyncTest, SingleClientWalletSyncTest,
::testing::Values(false, true)); ::testing::Values(false, true));
...@@ -1075,6 +1075,10 @@ void PersonalDataManager::AddServerCreditCardForTest( ...@@ -1075,6 +1075,10 @@ void PersonalDataManager::AddServerCreditCardForTest(
server_credit_cards_.push_back(std::move(credit_card)); server_credit_cards_.push_back(std::move(credit_card));
} }
bool PersonalDataManager::IsUsingAccountStorageForServerCardsForTest() const {
return database_helper_->IsUsingAccountStorageForServerCards();
}
void PersonalDataManager::SetSyncServiceForTest( void PersonalDataManager::SetSyncServiceForTest(
syncer::SyncService* sync_service) { syncer::SyncService* sync_service) {
if (sync_service_) if (sync_service_)
......
...@@ -60,10 +60,6 @@ class SyncService; ...@@ -60,10 +60,6 @@ class SyncService;
namespace autofill { namespace autofill {
extern const char kFrecencyFieldTrialName[];
extern const char kFrecencyFieldTrialStateEnabled[];
extern const char kFrecencyFieldTrialLimitParam[];
// Handles loading and saving Autofill profile information to the web database. // Handles loading and saving Autofill profile information to the web database.
// This class also stores the profiles loaded from the database for use during // This class also stores the profiles loaded from the database for use during
// Autofill. // Autofill.
...@@ -198,6 +194,10 @@ class PersonalDataManager : public KeyedService, ...@@ -198,6 +194,10 @@ class PersonalDataManager : public KeyedService,
// Sets a server credit card for test. // Sets a server credit card for test.
void AddServerCreditCardForTest(std::unique_ptr<CreditCard> credit_card); void AddServerCreditCardForTest(std::unique_ptr<CreditCard> credit_card);
// Returns whether server credit cards are stored in account (i.e. ephemeral)
// storage.
bool IsUsingAccountStorageForServerCardsForTest() const;
// Sets which SyncService to use and observe in a test. |sync_service| is not // Sets which SyncService to use and observe in a test. |sync_service| is not
// owned by this class and must outlive |this|. // owned by this class and must outlive |this|.
void SetSyncServiceForTest(syncer::SyncService* sync_service); void SetSyncServiceForTest(syncer::SyncService* sync_service);
......
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