chromium/chrome/browser/themes/theme_syncable_service_unittest.cc

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

#include "chrome/browser/themes/theme_syncable_service.h"

#include <memory>
#include <optional>

#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/no_destructor.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/values_test_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/background/ntp_custom_background_service_constants.h"
#include "chrome/browser/themes/test/theme_service_changed_waiter.h"
#include "chrome/browser/themes/theme_helper.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/themes/theme_service_utils.h"
#include "chrome/common/extensions/extension_test_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/features.h"
#include "components/sync/model/sync_change.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/proto_value_conversions.h"
#include "components/sync/protocol/theme_specifics.pb.h"
#include "components/sync/test/fake_sync_change_processor.h"
#include "components/sync/test/sync_change_processor_wrapper_for_test.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_url_handlers.h"
#include "extensions/common/permissions/api_permission_set.h"
#include "extensions/common/permissions/permission_set.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/login/users/chrome_user_manager_impl.h"
#include "chrome/browser/ash/settings/scoped_cros_settings_test_helper.h"
#include "components/user_manager/scoped_user_manager.h"
#endif

string;

namespace {

static const char kCustomThemeName[] =;
static const char kCustomThemeUrl[] =;

#if BUILDFLAG(IS_WIN)
const base::FilePath::CharType kExtensionFilePath[] =
    FILE_PATH_LITERAL("c:\\foo");
#elif BUILDFLAG(IS_POSIX)
const base::FilePath::CharType kExtensionFilePath[] =);
#else
#error "Unknown platform"
#endif

constexpr char kTestUrl[] =;

MATCHER_P2(DictionaryValuePtrHas, key, value, "") {}

const ThemeHelper& GetThemeHelper() {}

class FakeThemeService : public ThemeService {};

scoped_refptr<extensions::Extension> MakeThemeExtension(
    const base::FilePath& extension_path,
    const string& name,
    extensions::mojom::ManifestLocation location,
    const string& update_url) {}

syncer::SyncDataList MakeThemeDataList(
    const sync_pb::ThemeSpecifics& theme_specifics) {}

syncer::SyncChangeList MakeThemeChangeList(
    const sync_pb::ThemeSpecifics& theme_specifics) {}

}  // namespace

// ThemeSyncableServiceTest ----------------------------------------------------

class ThemeSyncableServiceTest : public testing::Test,
                                 public ThemeSyncableService::Observer {};

TEST_F(ThemeSyncableServiceTest, AreThemeSpecificsEquivalent) {}

TEST_F(ThemeSyncableServiceTest, SetCurrentThemeDefaultTheme) {}

TEST_F(ThemeSyncableServiceTest, SetCurrentThemeSystemTheme) {}

TEST_F(ThemeSyncableServiceTest, SetCurrentThemeCustomTheme_Extension) {}

TEST_F(ThemeSyncableServiceTest, SetCurrentThemeCustomTheme_Extension_Install) {}

TEST_F(ThemeSyncableServiceTest, SetCurrentThemeCustomTheme_Autogenerated) {}

TEST_F(ThemeSyncableServiceTest, DontResetThemeWhenSpecificsAreEqual) {}

TEST_F(ThemeSyncableServiceTest, UpdateThemeSpecifics_CurrentTheme_Extension) {}

TEST_F(ThemeSyncableServiceTest,
       UpdateThemeSpecifics_CurrentTheme_Autogenerated) {}

TEST_F(ThemeSyncableServiceTest, UpdateThemeSpecifics_CurrentTheme_Policy) {}

TEST_F(ThemeSyncableServiceTest, GetAllSyncDataForTesting_Extension) {}

TEST_F(ThemeSyncableServiceTest, GetAllSyncDataForTesting_Autogenerated) {}

TEST_F(ThemeSyncableServiceTest, GetAllSyncDataForTesting_Policy) {}

TEST_F(ThemeSyncableServiceTest, ProcessSyncThemeChange_Extension) {}

TEST_F(ThemeSyncableServiceTest, ProcessSyncThemeChange_Autogenerated) {}

TEST_F(ThemeSyncableServiceTest, OnThemeChangeByUser_Extension) {}

TEST_F(ThemeSyncableServiceTest, OnThemeChangeByUser_Autogenerated) {}

TEST_F(ThemeSyncableServiceTest, StopSync) {}

TEST_F(ThemeSyncableServiceTest, RestoreSystemThemeBitWhenChangeToCustomTheme) {}

TEST_F(ThemeSyncableServiceTest, DistinctSystemTheme) {}

TEST_F(ThemeSyncableServiceTest, SystemThemeSameAsDefaultTheme) {}

TEST_F(ThemeSyncableServiceTest, GetThemePrefNameInMigrationIfFlagDisabled) {}

TEST_F(ThemeSyncableServiceTest, GetThemePrefNameInMigrationIfFlagEnabled) {}

// PolicyInstalledThemeTest ----------------------------------------------------

class PolicyInstalledThemeTest : public ThemeSyncableServiceTest {};

TEST_F(PolicyInstalledThemeTest, InstallThemeByPolicy) {}

// RealThemeSyncableServiceTest ------------------------------------------------

// Uses the real `ThemeService` impl instead of the fake used by
// `ThemeSyncableServiceTest`, in order to more closely test production behavior
// and asserts.
class RealThemeSyncableServiceTest
    : public extensions::ExtensionServiceTestBase {};

// Regression test for crbug.com/1409996.
TEST_F(RealThemeSyncableServiceTest, ProcessSyncThemeChange_DisabledExtension) {}

class ThemeSyncableServiceWithMigrationFlagDisabledTest
    : public RealThemeSyncableServiceTest {};

TEST_F(ThemeSyncableServiceWithMigrationFlagDisabledTest,
       ShouldNotDownloadUserColorTheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagDisabledTest,
       ShouldNotUploadUserColorTheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagDisabledTest,
       ShouldNotDownloadGrayscale) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagDisabledTest,
       ShouldNotUploadGrayscale) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagDisabledTest,
       ShouldNotDownloadBrowserColorScheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagDisabledTest,
       ShouldNotUploadBrowserColorScheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagDisabledTest,
       ShouldNotDownloadNtpBackground) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagDisabledTest,
       ShouldNotUploadNtpBackground) {}

class ThemeSyncableServiceWithMigrationFlagEnabledTest
    : public RealThemeSyncableServiceTest {};

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldDownloadUserColorTheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldUploadUserColorTheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldDownloadGrayscale) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldUploadGrayscale) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldDownloadBrowserColorScheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldUploadBrowserColorScheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldDownloadNtpBackground) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldUploadNtpBackground) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldApplyRemoteNtpBackgroundChange) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldNotApplyEmptyRemoteNtpBackgroundChange) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldNotApplyMissingRemoteNtpBackgroundChange) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldApplyRemoteBrowserColorSchemeChanges) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldPriortizeExtensionThemeOverUserColor) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldPriortizeExtensionThemeOverAutogeneratedTheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldPriortizeExtensionThemeOverGrayscale) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldPrioritizeExtensionThemeInAreThemeSpecificsEquivalent) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldConsiderBrowserColorSchemeInAreThemeSpecificsEquivalent) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldConsiderNtpBackgroundInAreThemeSpecificsEquivalent) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldApplyBrowserColorSchemeWithUserColorTheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldApplyBrowserColorSchemeWithGrayscale) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldApplyBrowserColorSchemeWithAutogeneratedTheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldApplyNtpBackgroundWithUserColorTheme) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldApplyNtpBackgroundWithGrayscale) {}

TEST_F(ThemeSyncableServiceWithMigrationFlagEnabledTest,
       ShouldApplyNtpBackgroundWithAutogeneratedTheme) {}

class ThemePrefsMigrationTest : public ::testing::Test {};

TEST_F(ThemePrefsMigrationTest, MigrateSyncingThemePrefsToNonSyncing) {}

TEST_F(ThemePrefsMigrationTest,
       DoNotMigrateSyncingThemePrefsToNonSyncingIfFlagDisabled) {}

TEST_F(ThemePrefsMigrationTest,
       DoNotMigrateSyncingThemePrefsToNonSyncingIfAlreadyDone) {}

TEST_F(ThemePrefsMigrationTest,
       ClearFlagUponMigrateSyncingThemePrefsToNonSyncingIfFlagDisabled) {}