Chromium Code Reviews| 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..ff5c7c4c776fb4a641156f3d2066d641a7928f37 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; |
| +} |
|
Ilya Sherman
2015/09/16 00:50:44
nit: Perhaps create a helper file to contain this
Alexei Svitkine (slow)
2015/09/23 17:33:32
Doing this in a separate CL: https://codereview.ch
|
| + |
| // 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 starts inactive, so |GetActiveGroup()| should return false. |
|
Ilya Sherman
2015/09/16 00:50:44
This comment seems like it was probably written be
Alexei Svitkine (slow)
2015/09/22 21:19:59
Done.
|
| + 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; |