| Index: base/metrics/field_trial_unittest.cc
|
| diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc
|
| index ed84d865d5ef081a4017f9e06eda7e9262ce3a4a..bbcf169bab11d1c47c6cbded25e3071b3394171e 100644
|
| --- a/base/metrics/field_trial_unittest.cc
|
| +++ b/base/metrics/field_trial_unittest.cc
|
| @@ -38,6 +38,18 @@ int OneYearBeforeBuildTime() {
|
| return exploded.year;
|
| }
|
|
|
| +// Tests whether a field trial is active (i.e. group() has been called on it),
|
| +// using public FieldTrial API (which doesn't expose this state on the object).
|
| +bool IsFieldTrialActive(FieldTrial* trial) {
|
| + base::FieldTrial::ActiveGroups active_groups;
|
| + base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups);
|
| + for (size_t i = 0; i < active_groups.size(); ++i) {
|
| + if (active_groups[i].trial_name == trial->trial_name())
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| // FieldTrialList::Observer implementation for testing.
|
| class TestFieldTrialObserver : public FieldTrialList::Observer {
|
| public:
|
| @@ -72,6 +84,8 @@ class FieldTrialTest : public testing::Test {
|
| private:
|
| MessageLoop message_loop_;
|
| FieldTrialList trial_list_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FieldTrialTest);
|
| };
|
|
|
| // Test registration, and also check that destructors are called for trials
|
| @@ -376,6 +390,28 @@ TEST_F(FieldTrialTest, ActiveGroupsNotFinalized) {
|
| EXPECT_EQ(active_group.group_name, active_groups[0].group_name);
|
| }
|
|
|
| +TEST_F(FieldTrialTest, GetGroupNameWithoutActivation) {
|
| + const char kTrialName[] = "TestTrial";
|
| + const char kSecondaryGroupName[] = "SecondaryGroup";
|
| +
|
| + int default_group = -1;
|
| + scoped_refptr<FieldTrial> trial =
|
| + CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
|
| + trial->AppendGroup(kSecondaryGroupName, 50);
|
| +
|
| + // The trial should start inactive.
|
| + EXPECT_FALSE(IsFieldTrialActive(trial.get()));
|
| +
|
| + // Calling |GetGroupNameWithoutActivation()| should not activate the trial.
|
| + std::string group_name = trial->GetGroupNameWithoutActivation();
|
| + EXPECT_FALSE(group_name.empty());
|
| + EXPECT_FALSE(IsFieldTrialActive(trial.get()));
|
| +
|
| + // Calling |group_name()| should activate it and return the same group name.
|
| + EXPECT_EQ(group_name, trial->group_name());
|
| + EXPECT_TRUE(IsFieldTrialActive(trial.get()));
|
| +}
|
| +
|
| TEST_F(FieldTrialTest, Save) {
|
| std::string save_string;
|
|
|
|
|