chromium/chrome/browser/sync/test/integration/single_client_wallet_credential_sync_test.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/notreached.h"
#include "chrome/browser/sync/test/integration/fake_server_match_status_checker.h"
#include "chrome/browser/sync/test/integration/sync_service_impl_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/wallet_helper.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/payments_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "components/autofill/core/browser/personal_data_manager_test_utils.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/engine/loopback_server/persistent_tombstone_entity.h"
#include "content/public/test/browser_test.h"

ServerCvc;
kSyncAutofillWalletCredentialData;
CreateDefaultSyncWalletCard;
CreateDefaultSyncWalletCredential;
CreateSyncPaymentsCustomerData;
CreateSyncWalletCard;
CreateSyncWalletCredential;
ExpectDefaultWalletCredentialValues;
GetAccountWebDataService;
GetPersonalDataManager;
GetProfileWebDataService;
kDefaultBillingAddressID;

namespace {

// A helper class that waits for `AUTOFILL_WALLET_CREDENTIAL` to have the
// expected entries on the FakeServer.
class ServerCvcChecker : public fake_server::FakeServerMatchStatusChecker {};

ServerCvcChecker::ServerCvcChecker(const size_t expected_count)
    :{}

ServerCvcChecker::~ServerCvcChecker() = default;

bool ServerCvcChecker::IsExitConditionSatisfied(std::ostream* os) {}

class AutofillWebDataServiceConsumer : public WebDataServiceConsumer {};

#if !BUILDFLAG(IS_CHROMEOS_ASH)
std::vector<std::unique_ptr<autofill::CreditCard>> GetServerCards(
    scoped_refptr<autofill::AutofillWebDataService> service) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace

class SingleClientWalletCredentialSyncTest : public SyncTest {};

// Ensures that the `AUTOFILL_WALLET_CREDENTIAL` sync type is enabled by
// default.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest, EnabledByDefault) {}

// ChromeOS does not support late signin after profile creation, so the test
// below does not apply.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
// Verify card and CVC data is synced when the user signs in.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       DownloadCardCredential) {}

// Card and CVC data should get cleared from the database when the user signs
// out and different data should get downstreamed when the user signs in with a
// different account.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       ClearOnSignOutAndDownstreamOnSignIn) {}

// Verify if 2 cards are synced down along with a single wallet credential
// entity, the credential entity is attached to the correct card.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       CorrectCvcSyncAttachedToCardEntity) {}

// Verify that card and CVC data should get cleared from the database when the
// user signs out.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest, ClearOnSignOut) {}

// Verify that card and CVC data should get cleared from the database when the
// user signs out from Transport mode.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       ClearOnSignOutFromTransportMode) {}

#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)

// Verify that card and CVC data should get cleared from the database when the
// sync for Payments is disabled.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       ClearOnDisablePaymentsSync) {}

// Card and CVC data should get cleared from the database when the user enters
// the sync paused state (e.g. persistent auth error).
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       ClearOnSyncPaused) {}

// CVC data is using incremental updates. Make sure existing data doesn't get
// replaced when new data is synced down.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       NewSyncDataShouldBeIncremental) {}

// Verify that card and CVC data should get cleared from the database when the
// wallet sync is disabled.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       ClearOnDisableWalletSync) {}

// Verify when the corresponding card of a CVC is deleted from pay.google.com
// and wallet data sync is triggered, it will delete the orphaned CVC from local
// DB and Chrome sync server.
IN_PROC_BROWSER_TEST_F(SingleClientWalletCredentialSyncTest,
                       ReconcileServerCvcForWalletCards) {}