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

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

#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) {}

// Reads a json file and returns it as a dict value. If `key` is provided, only
// the value for that key is returned. This returns nullopt if there was an
// error reading the values from the file, for example, the file doesn't exist.
// NOTE: `key` missing from the json file would be returned as an empty dict,
// and not a nullopt.
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) {}

// Regression test to verify that pagination during GetUpdates() contributes
// properly to UMA histograms.
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest,
                       EmitDataTypeEntityChangeToUma) {}

// TODO(crbug.com/40200835): PRE_ tests are not supported on Android.
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest,
                       PRE_PersistProgressMarkerOnRestart) {}

IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest,
                       PersistProgressMarkerOnRestart) {}
#endif  // !BUILDFLAG(IS_ANDROID)

// Verifies that priority synced preferences and regular synced preferences are
// kept separate. Tests that incoming priority preference change does not have
// any effect if the corresponding pref is registered as a regular preference.
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest,
                       ShouldIsolatePreferencesOfDifferentTypes) {}

class SingleClientPreferencesWithAccountStorageSyncTest
    : public SingleClientPreferencesSyncTest {};

IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
                       ShouldPreserveLocalPrefsAndNotUploadToAccountOnSignin) {}

// ChromeOS does not support signing out of a primary account.
#if !BUILDFLAG(IS_CHROMEOS)

IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
                       ShouldCleanupAccountStoreOnSignout) {}

#endif  // !BUILDFLAG(IS_CHROMEOS)

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) {}

// Regression test for crbug.com/1456872.
// ChromeOS does not support signing out of a primary account.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
                       ShouldHandleWalletSideEffectsWhenSyncDisabled) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)

IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
                       ShouldCleanupAccountPreferencesFileOnDisable) {}

#if !BUILDFLAG(IS_CHROMEOS)

IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
                       ShouldCleanupAccountPreferencesFileOnSignout) {}

#endif  // !BUILDFLAG(IS_CHROMEOS)

// TODO(crbug.com/40200835): PRE_ tests are not supported on Android.
#if !BUILDFLAG(IS_ANDROID)
// Adds pref values to persistent storage.
IN_PROC_BROWSER_TEST_F(
    SingleClientPreferencesWithAccountStorageSyncTest,
    PRE_ShouldReadAccountPreferencesFromFileBeforeSyncStart) {}

IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
                       ShouldReadAccountPreferencesFromFileBeforeSyncStart) {}

// Adds pref values to persistent storage.
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
                       PRE_ShouldNotNotifyUponSyncStart) {}

// Regression test for crbug.com/1470161.
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesWithAccountStorageSyncTest,
                       ShouldNotNotifyUponSyncStart) {}

#endif  // !BUILDFLAG(IS_ANDROID)

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) {}

// Preference tracking is not required on android and chromeos.
#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  // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace