#include "chrome/browser/glic/public/glic_enabling.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/glic/test_support/glic_test_util.h"
#include "chrome/browser/global_features.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ash/test/glic_user_session_test_helper.h"
#include "chromeos/constants/chromeos_features.h"
#endif
using base::test::FeatureRef;
namespace glic {
namespace {
class GlicEnablingTest : public testing::Test {
public:
void SetUp() override {
testing::Test::SetUp();
scoped_feature_list_.InitWithFeatures(
{
features::kGlic,
features::kTabstripComboButton,
#if BUILDFLAG(IS_CHROMEOS)
chromeos::features::kFeatureManagementGlic,
#endif
},
{});
}
void TearDown() override {
scoped_feature_list_.Reset();
testing::Test::TearDown();
}
protected:
content::BrowserTaskEnvironment task_environment_;
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(GlicEnablingTest, GlicFeatureEnabledTest) {
EXPECT_EQ(GlicEnabling::IsEnabledByFlags(), true);
}
TEST_F(GlicEnablingTest, GlicFeatureNotEnabledTest) {
scoped_feature_list_.Reset();
scoped_feature_list_.InitWithFeatures({}, {features::kGlic});
EXPECT_EQ(GlicEnabling::IsEnabledByFlags(), false);
}
TEST_F(GlicEnablingTest, TabStripComboButtonFeatureNotEnabledTest) {
scoped_feature_list_.Reset();
scoped_feature_list_.InitWithFeatures({}, {features::kTabstripComboButton});
EXPECT_EQ(GlicEnabling::IsEnabledByFlags(), false);
}
class GlicEnablingProfileEligibilityTest : public testing::Test {
public:
GlicEnablingProfileEligibilityTest() {
scoped_feature_list_.InitWithFeatures(
{
features::kGlic,
features::kTabstripComboButton,
#if BUILDFLAG(IS_CHROMEOS)
chromeos::features::kFeatureManagementGlic,
#endif
},
{});
}
~GlicEnablingProfileEligibilityTest() override = default;
void SetUp() override {
testing_profile_manager_ = std::make_unique<TestingProfileManager>(
TestingBrowserProcess::GetGlobal());
ASSERT_TRUE(testing_profile_manager_->SetUp());
TestingBrowserProcess::GetGlobal()->CreateGlobalFeaturesForTesting();
#if BUILDFLAG(IS_CHROMEOS)
glic_user_session_test_helper_.PreProfileSetUp(
testing_profile_manager_->profile_manager());
#endif
profile_ = testing_profile_manager_->CreateTestingProfile(
TestingProfile::kDefaultProfileUserName);
}
void TearDown() override {
TestingBrowserProcess::GetGlobal()->GetFeatures()->Shutdown();
profile_ = nullptr;
testing_profile_manager_.reset();
#if BUILDFLAG(IS_CHROMEOS)
glic_user_session_test_helper_.PostProfileTearDown();
#endif
}
protected:
Profile* profile() { return profile_.get(); }
private:
content::BrowserTaskEnvironment task_environment_;
base::test::ScopedFeatureList scoped_feature_list_;
#if BUILDFLAG(IS_CHROMEOS)
ash::GlicUserSessionTestHelper glic_user_session_test_helper_;
#endif
std::unique_ptr<TestingProfileManager> testing_profile_manager_;
raw_ptr<TestingProfile> profile_ = nullptr;
};
TEST_F(GlicEnablingProfileEligibilityTest, Eligible) {
EXPECT_TRUE(GlicEnabling::IsProfileEligible(profile()));
}
}
}