#include "base/feature_list.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/optimization_guide/browser_test_util.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/optimization_guide/core/model_execution/model_execution_features.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/optimization_guide/core/optimization_guide_prefs.h"
#include "components/prefs/pref_service.h"
#include "components/search/ntp_features.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ui_base_features.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/ownership/owner_settings_service_ash.h"
#include "chrome/browser/ash/ownership/owner_settings_service_ash_factory.h"
#endif
class WallpaperSearchBrowserTest : public InProcessBrowserTest { … };
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(WallpaperSearchBrowserTest,
PRE_EnablingWallpaperSearchEnables) { … }
IN_PROC_BROWSER_TEST_F(WallpaperSearchBrowserTest,
EnablingWallpaperSearchEnables) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
class WallpaperSearchServiceBrowserChromeAshTest
: public WallpaperSearchBrowserTest,
public ::testing::WithParamInterface<bool> {
public:
bool IsDeviceOwner() const { return GetParam(); }
};
INSTANTIATE_TEST_SUITE_P(All,
WallpaperSearchServiceBrowserChromeAshTest,
::testing::Bool());
IN_PROC_BROWSER_TEST_P(WallpaperSearchServiceBrowserChromeAshTest,
PRE_EnablingWallpaperSearchEnables) {
signin::MakePrimaryAccountAvailable(
IdentityManagerFactory::GetForProfile(browser()->profile()),
"[email protected]", signin::ConsentLevel::kSync);
browser()->profile()->GetPrefs()->SetInteger(
optimization_guide::prefs::GetSettingEnabledPrefName(
optimization_guide::UserVisibleFeatureKey::kWallpaperSearch),
static_cast<int>(optimization_guide::prefs::FeatureOptInState::kEnabled));
ash::OwnerSettingsServiceAshFactory::GetForBrowserContext(
browser()->profile()->GetOriginalProfile())
->RunPendingIsOwnerCallbacksForTesting(IsDeviceOwner());
}
IN_PROC_BROWSER_TEST_P(WallpaperSearchServiceBrowserChromeAshTest,
EnablingWallpaperSearchEnables) {
auto* keyed_service =
OptimizationGuideKeyedServiceFactory::GetForProfile(browser()->profile());
EXPECT_TRUE(keyed_service->ShouldFeatureBeCurrentlyEnabledForUser(
optimization_guide::UserVisibleFeatureKey::kWallpaperSearch));
}
#endif