#include "components/sync/service/sync_user_settings_impl.h"
#include <memory>
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "build/chromeos_buildflags.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/signin/public/base/signin_pref_names.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/service/glue/sync_transport_data_prefs.h"
#include "components/sync/service/sync_prefs.h"
#include "components/sync/service/sync_service_crypto.h"
#include "components/trusted_vault/test/fake_trusted_vault_client.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace {
DataTypeSet GetUserTypes() { … }
DataTypeSet GetPreferredUserTypes(
const SyncUserSettingsImpl& sync_user_settings) { … }
class MockSyncServiceCryptoDelegate : public SyncServiceCrypto::Delegate { … };
class SyncUserSettingsImplTest : public testing::Test,
public SyncUserSettingsImpl::Delegate { … };
TEST_F(SyncUserSettingsImplTest, PreferredTypesSyncEverything) { … }
TEST_F(SyncUserSettingsImplTest, GetSelectedTypesWhileSignedOut) { … }
TEST_F(SyncUserSettingsImplTest, DefaultSelectedTypesWhileSignedIn) { … }
TEST_F(SyncUserSettingsImplTest, SetSelectedTypeInTransportMode) { … }
TEST_F(SyncUserSettingsImplTest, SetSelectedTypeInFullSyncMode) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncUserSettingsImplTest, PreferredTypesSyncAllOsTypes) {
std::unique_ptr<SyncUserSettingsImpl> sync_user_settings =
MakeSyncUserSettings(GetUserTypes());
DataTypeSet expected_types = GetUserTypes();
expected_types.RemoveAll({WEB_APKS});
EXPECT_TRUE(sync_user_settings->IsSyncAllOsTypesEnabled());
EXPECT_EQ(expected_types, GetPreferredUserTypes(*sync_user_settings));
for (UserSelectableOsType type : UserSelectableOsTypeSet::All()) {
sync_user_settings->SetSelectedOsTypes(true,
{type});
EXPECT_EQ(expected_types, GetPreferredUserTypes(*sync_user_settings));
}
}
#endif
TEST_F(SyncUserSettingsImplTest, PreferredTypesNotKeepEverythingSynced) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncUserSettingsImplTest, PreferredTypesNotAllOsTypesSynced) {
std::unique_ptr<SyncUserSettingsImpl> sync_user_settings =
MakeSyncUserSettings(GetUserTypes());
sync_user_settings->SetSelectedTypes(
false,
UserSelectableTypeSet());
sync_user_settings->SetSelectedOsTypes(
false,
UserSelectableOsTypeSet());
EXPECT_FALSE(sync_user_settings->IsSyncEverythingEnabled());
EXPECT_FALSE(sync_user_settings->IsSyncAllOsTypesEnabled());
EXPECT_EQ(AlwaysPreferredUserTypes(),
GetPreferredUserTypes(*sync_user_settings));
for (UserSelectableOsType type : UserSelectableOsTypeSet::All()) {
DataTypeSet expected_preferred_types =
UserSelectableOsTypeToAllDataTypes(type);
expected_preferred_types.PutAll(AlwaysPreferredUserTypes());
sync_user_settings->SetSelectedOsTypes(false,
{type});
EXPECT_EQ(expected_preferred_types,
GetPreferredUserTypes(*sync_user_settings));
}
}
#endif
TEST_F(SyncUserSettingsImplTest, DeviceInfo) { … }
TEST_F(SyncUserSettingsImplTest, UserConsents) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncUserSettingsImplTest, AlwaysPreferredTypes_ChromeOS) {
std::unique_ptr<SyncUserSettingsImpl> sync_user_settings =
MakeSyncUserSettings(GetUserTypes());
sync_user_settings->SetSelectedTypes(
false,
UserSelectableTypeSet());
sync_user_settings->SetSelectedOsTypes(
false,
UserSelectableOsTypeSet());
DataTypeSet preferred_types = sync_user_settings->GetPreferredDataTypes();
EXPECT_TRUE(preferred_types.Has(DEVICE_INFO));
EXPECT_TRUE(preferred_types.Has(USER_CONSENTS));
}
TEST_F(SyncUserSettingsImplTest, AppsAreHandledByOsSettings) {
std::unique_ptr<SyncUserSettingsImpl> settings =
MakeSyncUserSettings(GetUserTypes());
ASSERT_TRUE(settings->IsSyncEverythingEnabled());
ASSERT_TRUE(settings->IsSyncAllOsTypesEnabled());
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APP_LIST));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APP_SETTINGS));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APPS));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(ARC_PACKAGE));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(WEB_APPS));
settings->SetSelectedTypes(
false,
UserSelectableTypeSet());
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APP_LIST));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APP_SETTINGS));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APPS));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(ARC_PACKAGE));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(WEB_APPS));
settings->SetSelectedOsTypes(
false,
UserSelectableOsTypeSet());
EXPECT_FALSE(settings->GetPreferredDataTypes().Has(APP_LIST));
EXPECT_FALSE(settings->GetPreferredDataTypes().Has(APP_SETTINGS));
EXPECT_FALSE(settings->GetPreferredDataTypes().Has(APPS));
EXPECT_FALSE(settings->GetPreferredDataTypes().Has(ARC_PACKAGE));
EXPECT_FALSE(settings->GetPreferredDataTypes().Has(WEB_APPS));
}
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
TEST_F(SyncUserSettingsImplTest, AppsAreHandledByOsSettings) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(kSyncChromeOSAppsToggleSharing);
std::unique_ptr<SyncUserSettingsImpl> settings =
MakeSyncUserSettings(GetUserTypes());
ASSERT_TRUE(settings->IsSyncEverythingEnabled());
EXPECT_FALSE(settings->GetPreferredDataTypes().Has(APP_SETTINGS));
EXPECT_FALSE(settings->GetPreferredDataTypes().Has(APPS));
EXPECT_FALSE(settings->GetPreferredDataTypes().Has(WEB_APPS));
settings->SetAppsSyncEnabledByOs(true);
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APP_SETTINGS));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APPS));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(WEB_APPS));
settings->SetSelectedTypes(false,
UserSelectableTypeSet());
ASSERT_FALSE(settings->IsSyncEverythingEnabled());
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APP_SETTINGS));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(APPS));
EXPECT_TRUE(settings->GetPreferredDataTypes().Has(WEB_APPS));
}
#endif
TEST_F(SyncUserSettingsImplTest, ShouldSyncSessionsOnlyIfOpenTabsIsSelected) { … }
TEST_F(SyncUserSettingsImplTest, ShouldMutePassphrasePrompt) { … }
TEST_F(SyncUserSettingsImplTest, ShouldClearPassphrasePromptMuteUponUpgrade) { … }
TEST_F(SyncUserSettingsImplTest, EncryptionBootstrapTokenForSyncingUser) { … }
TEST_F(SyncUserSettingsImplTest, EncryptionBootstrapTokenPerAccountSignedOut) { … }
TEST_F(SyncUserSettingsImplTest, EncryptionBootstrapTokenPerAccount) { … }
TEST_F(SyncUserSettingsImplTest, ClearEncryptionBootstrapTokenPerAccount) { … }
}
}