#include <map>
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/prefs/chrome_pref_service_factory.h"
#include "chrome/browser/sync/test/integration/preferences_helper.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 "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/ntp_tiles/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/mock_pref_change_callback.h"
#include "components/prefs/pref_service.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/engine/cycle/entity_change_metric_recording.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/preference_specifics.pb.h"
#include "components/sync/service/sync_service_impl.h"
#include "components/sync_preferences/common_syncable_prefs_database.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_launcher.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace {
ChangeBooleanPref;
ConvertPrefValueToValueInSpecifics;
GetPrefs;
GetRegistry;
Eq;
Ne;
NotNull;
PrefRegistrySyncable;
sync_pb::PreferenceSpecifics* GetPreferenceSpecifics(
syncer::DataType data_type,
sync_pb::EntitySpecifics& specifics) { … }
std::optional<base::Value::Dict> ReadValuesFromFile(
const base::FilePath& file_path,
const std::optional<std::string>& key = std::nullopt) { … }
class SingleClientPreferencesSyncTest : public SyncTest { … };
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest, Sanity) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest,
EmitDataTypeEntityChangeToUma) { … }
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest,
PRE_PersistProgressMarkerOnRestart) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest,
PersistProgressMarkerOnRestart) { … }
#endif
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest,
ShouldIsolatePreferencesOfDifferentTypes) { … }
class SingleClientPreferencesWithAccountStorageSyncTest
: public SingleClientPreferencesSyncTest { … };
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldPreserveLocalPrefsAndNotUploadToAccountOnSignin) { … }
#if !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldCleanupAccountStoreOnSignout) { … }
#endif
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldCleanupAccountStoreOnDisable) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldChangeSyncablePrefLocallyAndOnAccount) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldNotSyncNonSyncablePrefToAccount) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldNotSyncSensitivePrefsIfHistorySyncOff) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldSyncSensitivePrefsIfHistorySyncOn) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldListenToHistorySyncOptInChanges) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldHandleWalletSideEffectsWhenSyncDisabled) { … }
#endif
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldCleanupAccountPreferencesFileOnDisable) { … }
#if !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldCleanupAccountPreferencesFileOnSignout) { … }
#endif
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(
SingleClientPreferencesWithAccountStorageSyncTest,
PRE_ShouldReadAccountPreferencesFromFileBeforeSyncStart) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldReadAccountPreferencesFromFileBeforeSyncStart) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
PRE_ShouldNotNotifyUponSyncStart) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
ShouldNotNotifyUponSyncStart) { … }
#endif
SingleClientPreferencesWithAccountStorageMergeSyncTest;
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageMergeSyncTest,
ShouldMergeLocalAndAccountMergeableDictPref) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageMergeSyncTest,
ShouldUnmergeMergeableDictPrefUponUpdate) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageMergeSyncTest,
ShouldMergeLocalAndAccountMergeableListPref) { … }
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageMergeSyncTest,
ShouldUnmergeMergeableListPrefUponUpdate) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)
const char* kProtectedPrefName = …;
const char* kUnprotectedPrefName = …;
class SingleClientTrackedPreferencesSyncTest
: public SingleClientPreferencesWithAccountStorageSyncTest { … };
IN_PROC_BROWSER_TEST_F(SingleClientTrackedPreferencesSyncTest,
ShouldStoreUnprotectedPrefsInPreferencesFile) { … }
IN_PROC_BROWSER_TEST_F(SingleClientTrackedPreferencesSyncTest,
ShouldStoreProtectedPrefsInCorrectPreferencesFile) { … }
IN_PROC_BROWSER_TEST_F(SingleClientTrackedPreferencesSyncTest,
ShouldHashTrackedSyncablePrefs) { … }
IN_PROC_BROWSER_TEST_F(SingleClientTrackedPreferencesSyncTest,
PRE_ShouldLoadTrackedSyncablePrefsBeforeSyncStart) { … }
IN_PROC_BROWSER_TEST_F(SingleClientTrackedPreferencesSyncTest,
ShouldLoadTrackedSyncablePrefsBeforeSyncStart) { … }
class SingleClientTrackedPreferencesSyncTestWithAttack
: public SingleClientTrackedPreferencesSyncTest { … };
IN_PROC_BROWSER_TEST_F(SingleClientTrackedPreferencesSyncTestWithAttack,
PRE_ShouldProtectTrackedSyncablePrefs) { … }
IN_PROC_BROWSER_TEST_F(SingleClientTrackedPreferencesSyncTestWithAttack,
ShouldProtectTrackedSyncablePrefs) { … }
#endif
}