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

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

#include <string>

#include "base/test/scoped_feature_list.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/test/integration/contact_info_helper.h"
#include "chrome/browser/sync/test/integration/encryption_helper.h"
#include "chrome/browser/sync/test/integration/fake_server_match_status_checker.h"
#include "chrome/browser/sync/test/integration/sync_integration_test_util.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/updated_progress_marker_checker.h"
#include "components/autofill/core/browser/address_data_manager.h"
#include "components/autofill/core/browser/data_model/autofill_profile_test_api.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/addresses/contact_info_sync_util.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/account_capabilities_test_mutator.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/engine/loopback_server/persistent_unique_client_entity.h"
#include "components/sync/protocol/contact_info_specifics.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/test/fake_server.h"
#include "content/public/test/browser_test.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if !BUILDFLAG(IS_ANDROID)
#include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h"
#endif

namespace {

AutofillProfile;
AddressDataManagerProfileChecker;
BuildTestAccountProfile;
IsEmpty;
UnorderedElementsAre;

#if !BUILDFLAG(IS_ANDROID)
std::string CreateSerializedProtoField(int field_number,
                                       const std::string& value) {}

// Matches a sync::entity_data has a contact info field with `guid` and a set of
// `unknown_fields`.
MATCHER_P2(HasContactInfoWithGuidAndUnknownFields, guid, unknown_fields, "") {}
#endif

// Checker to wait until the CONTACT_INFO datatype becomes (in)active, depending
// on `expect_active`.
// This is required because ContactInfoDataTypeController has custom logic to
// wait, and stays temporarily stopped even after sync-the-transport is active,
// until account capabilities are determined for eligibility.
class ContactInfoActiveChecker : public SingleClientStatusChangeChecker {};

// Helper class to wait until the fake server's ContactInfoSpecifics match a
// given predicate.
// Unfortunately, since protos don't have an equality operator, the comparisons
// are based on the `SerializeAsString()` representation of the specifics.
class FakeServerSpecificsChecker
    : public fake_server::FakeServerMatchStatusChecker {};

// Since the sync server operates in terms of entity specifics, this helper
// function converts a given `profile` to the equivalent ContactInfoSpecifics.
sync_pb::ContactInfoSpecifics AsContactInfoSpecifics(
    const AutofillProfile& profile) {}

// Adds the given `specifics` to the `fake_server` at creation time 0.
void AddSpecificsToServer(const sync_pb::ContactInfoSpecifics& specifics,
                          fake_server::FakeServer* fake_server) {}

class SingleClientContactInfoSyncTest : public SyncTest {};

IN_PROC_BROWSER_TEST_F(SingleClientContactInfoSyncTest, DownloadInitialData) {}

IN_PROC_BROWSER_TEST_F(SingleClientContactInfoSyncTest, UploadProfile) {}

// Tests that profile changes due to `AutofillProfile::FinalizeAfterImport()`
// don't cause a reupload and hence can't cause ping-pong loops.
// This is not expected to happen because only the PersonalDataManager can
// trigger reuploads - and it only operates on finalized profiles.
IN_PROC_BROWSER_TEST_F(SingleClientContactInfoSyncTest, FinalizeAfterImport) {}

// ChromeOS does not support signing out of a primary account.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(SingleClientContactInfoSyncTest, ClearOnSignout) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)

// Specialized fixture to test the behavior for custom passphrase users with and
// without kSyncEnableContactInfoDataTypeForCustomPassphraseUsers enabled.
class SingleClientContactInfoPassphraseSyncTest
    : public SingleClientContactInfoSyncTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// TODO(336993637): Flaky on Android.
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_Passphrase
#else
#define MAYBE_Passphrase
#endif
IN_PROC_BROWSER_TEST_P(SingleClientContactInfoPassphraseSyncTest,
                       MAYBE_Passphrase) {}

// Specialized fixture that enables AutofillAccountProfilesOnSignIn.
class SingleClientContactInfoTransportSyncTest
    : public SingleClientContactInfoSyncTest {};

// When SyncEnableContactInfoDataTypeInTransportMode is enabled, the
// CONTACT_INFO type should run in transport mode and the availability of
// account profiles should depend on the signed-in state.
IN_PROC_BROWSER_TEST_F(SingleClientContactInfoTransportSyncTest,
                       TransportMode) {}

#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SingleClientContactInfoTransportSyncTest,
                       DeleteAccountDataInErrorState) {}

// Account storage is not enabled when the user is in auth error.
IN_PROC_BROWSER_TEST_F(SingleClientContactInfoTransportSyncTest,
                       AuthErrorState) {}

// Regression test for https://crbug.com/340194452
IN_PROC_BROWSER_TEST_F(SingleClientContactInfoTransportSyncTest,
                       IsAutofillSyncToggleAvailable) {}

IN_PROC_BROWSER_TEST_F(SingleClientContactInfoSyncTest,
                       PreservesUnsupportedFieldsDataOnCommits) {}

// Overwrite the Sync test account with a non-gmail account. This treats it as a
// Dasher account.
// On Android, `switches::kSyncUserForTest` isn't supported, so it's currently
// not possible to simulate a non-gmail account.
class SingleClientContactInfoManagedAccountTest
    : public SingleClientContactInfoSyncTest {};

IN_PROC_BROWSER_TEST_F(SingleClientContactInfoManagedAccountTest,
                       DisabledForManagedAccounts) {}

// Tests the behavior for accounts under parental supervision, depending on
// whether `kSyncEnableContactInfoDataTypeForChildUsers` is enabled.
class SingleClientContactInfoChildAccountTest
    : public SingleClientContactInfoSyncTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// TODO(crbug.com/40265115): Enable this test on Android.
IN_PROC_BROWSER_TEST_P(SingleClientContactInfoChildAccountTest,
                       DisableForChildAccounts) {}
#endif

}  // namespace