1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
// Copyright 2025 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/glic/glic_enabling.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/glic/glic_metrics_provider.h"
#include "chrome/browser/glic/glic_pref_names.h"
#include "chrome/browser/glic/test_support/glic_test_util.h"
#include "chrome/browser/global_features.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_test_util.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/in_process_browser_test.h"
#include "components/metrics/metrics_service.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
#include "third_party/metrics_proto/system_profile.pb.h"
using base::test::FeatureRef;
namespace glic {
namespace {
class GlicEnablingTest : public InProcessBrowserTest {
public:
void SetUp() override {
InitializeFeatureList();
InProcessBrowserTest::SetUp();
}
void TearDown() override {
scoped_feature_list_.Reset();
InProcessBrowserTest::TearDown();
}
protected:
virtual void InitializeFeatureList() {
scoped_feature_list_.InitWithFeatures(
{features::kGlic, features::kTabstripComboButton,
features::kGlicRollout},
{});
}
Profile* profile() { return browser()->profile(); }
ProfileManager* profile_manager() {
return g_browser_process->profile_manager();
}
ProfileAttributesStorage& attributes_storage() {
return profile_manager()->GetProfileAttributesStorage();
}
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(GlicEnablingTest, EnabledForProfileTest) {
ASSERT_FALSE(GlicEnabling::IsEnabledForProfile(nullptr));
ASSERT_FALSE(GlicEnabling::IsEnabledForProfile(profile()));
ForceSigninAndModelExecutionCapability(profile());
ASSERT_TRUE(GlicEnabling::IsEnabledForProfile(profile()));
}
IN_PROC_BROWSER_TEST_F(GlicEnablingTest, AttributeEntryUpdatesOnChange) {
SigninWithPrimaryAccount(profile());
ASSERT_FALSE(GlicEnabling::IsEnabledForProfile(profile()));
ProfileAttributesEntry* entry =
attributes_storage().GetAllProfilesAttributes().front();
EXPECT_FALSE(entry->IsGlicEligible());
// Setting the model execution capability updates the glic AttributeEntry.
SetModelExecutionCapability(profile(), true);
ASSERT_TRUE(GlicEnabling::IsEnabledForProfile(profile()));
ASSERT_FALSE(GlicEnabling::IsEnabledAndConsentForProfile(profile()));
EXPECT_TRUE(entry->IsGlicEligible());
}
class GlicEnablingTieredRolloutTest : public GlicEnablingTest {
public:
void InitializeFeatureList() override {
scoped_feature_list_.InitWithFeatures(
{features::kGlic, features::kTabstripComboButton,
features::kGlicTieredRollout},
{features::kGlicRollout});
}
~GlicEnablingTieredRolloutTest() override = default;
void SetTieredRolloutEligibilityForProfile(bool is_eligible) {
profile()->GetPrefs()->SetBoolean(prefs::kGlicRolloutEligibility,
is_eligible);
}
// Explicitly calls ProvideCurrentSessionData() for all metrics providers.
void ProvideCurrentSessionData() {
// The purpose of the below call is to avoid a DCHECK failure in an
// unrelated metrics provider, in
// |FieldTrialsProvider::ProvideCurrentSessionData()|.
metrics::SystemProfileProto system_profile_proto;
g_browser_process->metrics_service()
->GetDelegatingProviderForTesting()
->ProvideSystemProfileMetricsWithLogCreationTime(base::TimeTicks::Now(),
&system_profile_proto);
metrics::ChromeUserMetricsExtension uma_proto;
g_browser_process->metrics_service()
->GetDelegatingProviderForTesting()
->ProvideCurrentSessionData(&uma_proto);
}
};
IN_PROC_BROWSER_TEST_F(GlicEnablingTieredRolloutTest, EnabledForProfileTest) {
ForceSigninAndModelExecutionCapability(profile());
// Should not be enabled as profile not eligible for tiered rollout.
EXPECT_FALSE(GlicEnabling::IsEnabledForProfile(profile()));
// Should be enabled as now eligible for tiered rollout.
SetTieredRolloutEligibilityForProfile(/*is_eligible=*/true);
EXPECT_TRUE(GlicEnabling::IsEnabledForProfile(profile()));
// Simulate user no longer eligible.
SetTieredRolloutEligibilityForProfile(/*is_eligible=*/false);
EXPECT_FALSE(GlicEnabling::IsEnabledForProfile(profile()));
}
IN_PROC_BROWSER_TEST_F(GlicEnablingTieredRolloutTest,
InTieredRolloutGroupOtherCriteriaNotPassing) {
// Should be enabled as profile.
SetTieredRolloutEligibilityForProfile(/*is_eligible=*/true);
EXPECT_FALSE(GlicEnabling::IsEnabledForProfile(profile()));
// No profiles eligible so this trial should not be emitted.
base::HistogramTester histogram_tester;
ProvideCurrentSessionData();
histogram_tester.ExpectTotalCount("Glic.TieredRolloutEnablementStatus", 0);
}
class GlicEnablingSimultaneousRolloutTest
: public GlicEnablingTieredRolloutTest {
public:
void InitializeFeatureList() override {
scoped_feature_list_.InitWithFeatures(
{features::kGlic, features::kTabstripComboButton,
features::kGlicTieredRollout, features::kGlicRollout},
{});
}
~GlicEnablingSimultaneousRolloutTest() override = default;
};
IN_PROC_BROWSER_TEST_F(GlicEnablingSimultaneousRolloutTest,
EnabledForProfileTest) {
ForceSigninAndModelExecutionCapability(profile());
// Eligible for tiered rollout. Profile enabled for GLIC.
SetTieredRolloutEligibilityForProfile(/*is_eligible=*/true);
ASSERT_TRUE(GlicEnabling::IsEnabledForProfile(profile()));
{
base::HistogramTester histogram_tester;
ProvideCurrentSessionData();
histogram_tester.ExpectUniqueSample(
"Glic.TieredRolloutEnablementStatus",
GlicTieredRolloutEnablementStatus::kAllProfilesEnabled, 1);
}
// Add another profile and have it signed in. The default value for
// tiered rollout is false but this profile is enabled via the general
// GlicRollout flag and canUseModelExecutionFeatures check.
ProfileManager* profile_manager = g_browser_process->profile_manager();
base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath();
Profile* second_profile =
&profiles::testing::CreateProfileSync(profile_manager, new_path);
ForceSigninAndModelExecutionCapability(second_profile);
ASSERT_TRUE(GlicEnabling::IsEnabledForProfile(second_profile));
{
base::HistogramTester histogram_tester;
ProvideCurrentSessionData();
histogram_tester.ExpectUniqueSample(
"Glic.TieredRolloutEnablementStatus",
GlicTieredRolloutEnablementStatus::kSomeProfilesEnabled, 1);
}
// Primary profile no longer eligible for tiered rollout. Should not have
// effect on overall enablement, but will have an effect on the histogram
// emitted.
SetTieredRolloutEligibilityForProfile(/*is_eligible=*/false);
ASSERT_TRUE(GlicEnabling::IsEnabledForProfile(profile()));
{
base::HistogramTester histogram_tester;
ProvideCurrentSessionData();
histogram_tester.ExpectUniqueSample(
"Glic.TieredRolloutEnablementStatus",
GlicTieredRolloutEnablementStatus::kNoProfilesEnabled, 1);
}
}
} // namespace
} // namespace glic
|