#include "components/sync_preferences/dual_layer_user_pref_store.h"
#include <map>
#include <set>
#include <string_view>
#include "base/memory/scoped_refptr.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "components/prefs/testing_pref_store.h"
#include "components/sync/test/test_sync_service.h"
#include "components/sync_preferences/pref_model_associator_client.h"
#include "components/sync_preferences/test_syncable_prefs_database.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sync_preferences {
namespace {
constexpr char kPref1[] = …;
constexpr char kPref2[] = …;
constexpr char kPref3[] = …;
constexpr char kPrefName[] = …;
constexpr char kPriorityPrefName[] = …;
constexpr char kNonExistentPrefName[] = …;
constexpr char kNonSyncablePrefName[] = …;
constexpr char kHistorySensitivePrefName[] = …;
constexpr char kMergeableListPref[] = …;
constexpr char kMergeableDictPref1[] = …;
constexpr char kMergeableDictPref2[] = …;
constexpr char kCustomMergePref[] = …;
const TestSyncablePrefsDatabase::PrefsMap kSyncablePrefsDatabase = …;
base::Value MakeDict(
const std::vector<std::pair<std::string, std::string>>& values) { … }
testing::AssertionResult ValueInStoreIs(const PrefStore& store,
const std::string& pref,
const base::Value& expected_value) { … }
testing::AssertionResult ValueInStoreIs(const PrefStore& store,
const std::string& pref,
const std::string& expected_value) { … }
testing::AssertionResult ValueInStoreIsAbsent(const PrefStore& store,
const std::string& pref) { … }
testing::AssertionResult ValueInDictByDottedPathIs(
const base::Value::Dict& dict,
const std::string& key,
const base::Value& expected_value) { … }
class MockPrefStoreObserver : public PrefStore::Observer { … };
class MockReadErrorDelegate : public PersistentPrefStore::ReadErrorDelegate { … };
class TestPrefModelAssociatorClient : public PrefModelAssociatorClient { … };
class DualLayerUserPrefStoreTestBase : public testing::Test { … };
class DualLayerUserPrefStoreTest : public DualLayerUserPrefStoreTestBase { … };
class DualLayerUserPrefStoreInitializationTest
: public DualLayerUserPrefStoreTestBase { … };
TEST_F(DualLayerUserPrefStoreInitializationTest,
ForwardsInitializationSuccess) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest,
ForwardsInitializationFailure) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest,
ShouldForwardLocalPrefStoreReadError) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest,
ShouldForwardAccountPrefStoreReadError) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest,
ShouldForwardLocalPrefStoreAsyncReadError) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest,
ShouldForwardAccountPrefStoreAsyncReadError) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest,
ShouldReportInitializationCompleteAfterRead) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest, HasReadErrorDelegate) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest,
HasReadErrorDelegateWithNullDelegate) { … }
TEST_F(DualLayerUserPrefStoreInitializationTest,
ShouldReportInitializationCompleteAsyncReadAsync) { … }
TEST_F(DualLayerUserPrefStoreTest, ReadsFromLocalStore) { … }
TEST_F(DualLayerUserPrefStoreTest, ReadsFromAccountStore) { … }
TEST_F(DualLayerUserPrefStoreTest, AccountTakesPrecedence) { … }
TEST_F(DualLayerUserPrefStoreTest, ReadsFromBothStores) { … }
TEST_F(DualLayerUserPrefStoreTest, WritesToBothStores) { … }
TEST_F(DualLayerUserPrefStoreTest, RemovesFromBothStores) { … }
TEST_F(DualLayerUserPrefStoreTest,
RemovesValuesByPrefixSilentlyFromBothStores) { … }
TEST_F(DualLayerUserPrefStoreTest,
RemoveValuesByPrefixSilentlyRemovesMultiplePrefs) { … }
TEST_F(DualLayerUserPrefStoreTest, DoesNotReturnNonexistentPref) { … }
TEST_F(DualLayerUserPrefStoreTest, WritesMutableValueFromLocalToBothStores) { … }
TEST_F(DualLayerUserPrefStoreTest, WritesMutableValueFromAccountToBothStores) { … }
TEST_F(DualLayerUserPrefStoreTest, WritesMutableValueFromBothToBothStores) { … }
TEST_F(DualLayerUserPrefStoreTest, ClearsMutableValueFromBothStores) { … }
TEST_F(DualLayerUserPrefStoreTest, NotifiesOfPrefChanges) { … }
TEST_F(DualLayerUserPrefStoreTest,
NotifiesOfPrefChangesOnlyIfEffectiveValueChanges) { … }
TEST_F(DualLayerUserPrefStoreTest, NotifiesOfPrefChangesInUnderlyingStores) { … }
TEST_F(DualLayerUserPrefStoreTest,
NotifiesOfPrefChangesInUnderlyingStoresOnlyIfEffectiveValueChanges) { … }
TEST_F(DualLayerUserPrefStoreTest, NotifiesOfRemoveOnlyIfPrefExists) { … }
TEST_F(DualLayerUserPrefStoreTest, NotifiesOfMutableValuePrefChanges) { … }
TEST_F(DualLayerUserPrefStoreTest, ShouldAddOnlySyncablePrefsToAccountStore) { … }
TEST_F(DualLayerUserPrefStoreTest, ShouldCommitPendingWritesForBothStores) { … }
TEST_F(
DualLayerUserPrefStoreTest,
ShouldNotNotifyIfEffectiveValueIsUnchangedUponSetValueInAccountStoreOnly) { … }
TEST_F(DualLayerUserPrefStoreTest,
ShouldNotifyIfEffectiveValueChangesUponSetValueInAccountStoreOnly) { … }
class DualLayerUserPrefStoreTestForTypes
: public DualLayerUserPrefStoreTestBase { … };
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldAddOnlyEnabledTypePrefsToAccountStore) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldAddPrefsToAccountStoreOnlyAfterEnabled) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldClearAllSyncablePrefsOfTypeFromAccountStoreOnDisable) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldNotifyObserversOnDisableIfEffectiveValueChanges) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldNotifyObserversOnDisableIfLocalValueDoesNotExist) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldNotNotifyObserversOnDisableIfEffectiveValueDoesNotChange) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldReturnAccountValueForNotActiveTypes) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldClearAllPrefsFromAccountStoreOnDisableAllTypes) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldSetAccountValueForNotActiveTypesIfAlreadyExists) { … }
TEST_F(DualLayerUserPrefStoreTestForTypes,
ShouldNotSetAccountValueForNotActiveTypesIfNotAlreadyExists) { … }
class MergeTestPrefModelAssociatorClient : public PrefModelAssociatorClient { … };
class DualLayerUserPrefStoreMergeTest : public testing::Test { … };
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUseAccountValueForNonMergeablePrefs) { … }
TEST_F(DualLayerUserPrefStoreMergeTest, ShouldMergeMergeableListPref) { … }
TEST_F(DualLayerUserPrefStoreMergeTest, ShouldMergeMergeableDictPref) { … }
TEST_F(DualLayerUserPrefStoreMergeTest, ShouldMergeSpecialCasedMergeablePref) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldApplyUpdatesToBothStoresForNonMergeablePrefOnSetValue) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldApplyUpdatesToBothStoresForNonMergeablePrefOnSetValueSilently) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldApplyUpdatesToBothStoresForNonMergeablePrefOnReportValueChanged) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUpdateMergedPrefOnWriteToUnderlyingStoresUsingSetValue) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUpdateMergedPrefOnWriteToUnderlyingStoresUsingSetValueSilently) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUpdateMergedPrefOnWriteToUnderlyingStoresUsingMutableValue) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUpdateMergedPrefOnRemoveFromUnderlyingStores) { … }
TEST_F(DualLayerUserPrefStoreMergeTest, ShouldClearMergedPrefOnRemove) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUnmergeMergeableDictPrefButNotAddUnchangedValueToAccountStore) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUnmergeMergeableDictPrefButNotAddUnchangedValueToLocalStore) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUnmergeAndApplyUpdatesForMergeableDictPrefOnSetValue) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUnmergeAndApplyUpdatesForMergeableDictPrefOnSetValueSilently) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldUnmergeAndApplyUpdatesForMergeableDictPrefOnReportPrefChanged) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldApplyUpdateOnMergeableListPrefAsNonMergeablePref) { … }
TEST_F(DualLayerUserPrefStoreMergeTest,
ShouldNotUnmergeIfIncorrectlyMarkedAsMergeableDict) { … }
TEST_F(
DualLayerUserPrefStoreMergeTest,
ShouldClearAccountPrefsOnDisableAndNotifyObserversIfEffectiveValueChanges) { … }
TEST_F(
DualLayerUserPrefStoreMergeTest,
ShouldClearAccountPrefsOnDisableButNotNotifyObserversIfEffectiveValueDoesNotChange) { … }
DualLayerUserPrefStoreHistoryOptInTest;
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldReturnHistorySensitivePrefFromLocalStoreIfHistorySyncOff) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldNotGetHistorySensitivePrefFromAccountStoreIfHistorySyncOff) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldGetHistorySensitivePrefFromAccountStoreIfHistorySyncOn) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldNotSetHistorySensitivePrefInAccountStoreIfHistorySyncIsOff) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldSetHistorySensitivePrefInAccountStoreIfHistorySyncOn) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldNotRemoveFromAccountStoreUponSetIfHistorySyncOff) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldNotRemoveFromAccountStoreUponRemoveIfHistorySyncOff) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldCheckHistoryOptInUponSubscribe) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldListenToHistorySyncDisable) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldListenToHistorySyncEnable) { … }
TEST_F(
DualLayerUserPrefStoreHistoryOptInTest,
ShouldNotNotifyObserversOnHistoryOptInChangeIfEffectiveValueDoesNotChange) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldNotifyObserversOnHistoryOptInChangeIfEffectiveValueChanges) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldNotReactIfHistoryOptInIsUnchanged) { … }
TEST_F(DualLayerUserPrefStoreHistoryOptInTest,
ShouldRemoveSensitivePrefsFromAccountStoreUponDisableIfHistorySyncOff) { … }
}
}