summaryrefslogtreecommitdiffstats
path: root/base/field_trial_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/field_trial_unittest.cc')
-rw-r--r--base/field_trial_unittest.cc56
1 files changed, 39 insertions, 17 deletions
diff --git a/base/field_trial_unittest.cc b/base/field_trial_unittest.cc
index f678b0b..59d8e15 100644
--- a/base/field_trial_unittest.cc
+++ b/base/field_trial_unittest.cc
@@ -116,42 +116,64 @@ TEST_F(FieldTrialTest, OneWinner) {
}
TEST_F(FieldTrialTest, Save) {
+ std::string save_string;
+
FieldTrial* trial = new FieldTrial("Some name", 10);
// There is no winner yet, so no textual group name is associated with trial.
EXPECT_EQ(trial->group_name(), "");
- EXPECT_EQ(trial->MakePersistentString(), "Some name/");
+ FieldTrialList::StatesToString(&save_string);
+ EXPECT_EQ(save_string, "");
+ save_string.clear();
// Create a winning group.
trial->AppendGroup("Winner", 10);
- EXPECT_EQ(trial->MakePersistentString(), "Some name/Winner");
+ FieldTrialList::StatesToString(&save_string);
+ EXPECT_EQ(save_string, "Some name/Winner/");
+ save_string.clear();
+
+ // Create a second trial and winning group.
+ FieldTrial* trial2 = new FieldTrial("xxx", 10);
+ trial2->AppendGroup("yyyy", 10);
+
+ FieldTrialList::StatesToString(&save_string);
+ // We assume names are alphabetized... though this is not critical.
+ EXPECT_EQ(save_string, "Some name/Winner/xxx/yyyy/");
}
TEST_F(FieldTrialTest, Restore) {
- FieldTrial* trial = FieldTrial::RestorePersistentString("Some name/winner");
- EXPECT_EQ(trial->group_name(), "winner");
- EXPECT_EQ(trial->name(), "Some name");
-}
+ EXPECT_EQ(NULL, FieldTrialList::Find("Some_name"));
+ EXPECT_EQ(NULL, FieldTrialList::Find("xxx"));
-TEST_F(FieldTrialTest, BogusRestore) {
- const FieldTrial *trial = FieldTrial::RestorePersistentString("MissingSlash");
- EXPECT_EQ(trial, static_cast<FieldTrial *>(NULL));
+ FieldTrialList::StringAugmentsState("Some_name/Winner/xxx/yyyy/");
+
+ FieldTrial* trial = FieldTrialList::Find("Some_name");
+ ASSERT_NE(static_cast<FieldTrial*>(NULL), trial);
+ EXPECT_EQ(trial->group_name(), "Winner");
+ EXPECT_EQ(trial->name(), "Some_name");
- trial = FieldTrial::RestorePersistentString("MissingGroupName/");
- EXPECT_EQ(trial, static_cast<FieldTrial *>(NULL));
+ trial = FieldTrialList::Find("xxx");
+ ASSERT_NE(static_cast<FieldTrial*>(NULL), trial);
+ EXPECT_EQ(trial->group_name(), "yyyy");
+ EXPECT_EQ(trial->name(), "xxx");
+}
- trial = FieldTrial::RestorePersistentString("/MissingName");
- EXPECT_EQ(trial, static_cast<FieldTrial *>(NULL));
+TEST_F(FieldTrialTest, BogusRestore) {
+ EXPECT_FALSE(FieldTrialList::StringAugmentsState("MissingSlash"));
+ EXPECT_FALSE(FieldTrialList::StringAugmentsState("MissingGroupName/"));
+ EXPECT_FALSE(FieldTrialList::StringAugmentsState("MissingFinalSlash/gname"));
+ EXPECT_FALSE(FieldTrialList::StringAugmentsState("/noname, only group/"));
}
TEST_F(FieldTrialTest, DuplicateRestore) {
FieldTrial* trial = new FieldTrial("Some name", 10);
trial->AppendGroup("Winner", 10);
- EXPECT_EQ(trial->MakePersistentString(), "Some name/Winner");
+ std::string save_string;
+ FieldTrialList::StatesToString(&save_string);
+ EXPECT_EQ("Some name/Winner/", save_string);
// It is OK if we redundantly specify a winner.
- EXPECT_EQ(trial, FieldTrial::RestorePersistentString("Some name/Winner"));
+ EXPECT_TRUE(FieldTrialList::StringAugmentsState(save_string));
// But it is an error to try to change to a different winner.
- EXPECT_EQ(FieldTrial::RestorePersistentString("Some name/Loser"),
- static_cast<FieldTrial *>(NULL));
+ EXPECT_FALSE(FieldTrialList::StringAugmentsState("Some name/Loser/"));
}