summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-19 18:52:32 +0000
committerrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-19 18:52:32 +0000
commit933729bcb0e1bba8dbe99059de9a97beff308efe (patch)
tree196a39b4c67997df4f27e0b216a5a3318cad3620 /base
parent22c981da75b0251c726f1f3520da8605fa78002a (diff)
downloadchromium_src-933729bcb0e1bba8dbe99059de9a97beff308efe.zip
chromium_src-933729bcb0e1bba8dbe99059de9a97beff308efe.tar.gz
chromium_src-933729bcb0e1bba8dbe99059de9a97beff308efe.tar.bz2
.c Feature to disable field trials in old versions of Chromium. Field trials
tests are (usually) monitored for a fixed length of time. With this change field trial tests turn them selves off (will use the default group) after the expiration time (specified in the Field Trial constructor). BUG=13463 TEST=field_trial_unittests tests this code thorougly. spdy session and testing field_trials in renderer process would be very helpful. thanks much. Review URL: http://codereview.chromium.org/6317004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71820 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/metrics/field_trial.cc119
-rw-r--r--base/metrics/field_trial.h75
-rw-r--r--base/metrics/field_trial_unittest.cc131
3 files changed, 242 insertions, 83 deletions
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc
index 654746c..5db88c1 100644
--- a/base/metrics/field_trial.cc
+++ b/base/metrics/field_trial.cc
@@ -7,14 +7,15 @@
#include "base/logging.h"
#include "base/rand_util.h"
#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
namespace base {
// static
-const int FieldTrial::kNotParticipating = -1;
+const int FieldTrial::kNotFinalized = -1;
// static
-const int FieldTrial::kAllRemainingProbability = -2;
+const int FieldTrial::kDefaultGroupNumber = 0;
// static
bool FieldTrial::enable_benchmarking_ = false;
@@ -28,30 +29,53 @@ static const char kHistogramFieldTrialSeparator('_');
// FieldTrial methods and members.
FieldTrial::FieldTrial(const std::string& name,
- const Probability total_probability)
+ const Probability total_probability,
+ const std::string& default_group_name,
+ const int year,
+ const int month,
+ const int day_of_month)
: name_(name),
divisor_(total_probability),
+ default_group_name_(default_group_name),
random_(static_cast<Probability>(divisor_ * base::RandDouble())),
accumulated_group_probability_(0),
- next_group_number_(0),
- group_(kNotParticipating) {
+ next_group_number_(kDefaultGroupNumber+1),
+ group_(kNotFinalized) {
+ DCHECK(!default_group_name_.empty());
FieldTrialList::Register(this);
+
+ DCHECK_GT(year, 1970);
+ DCHECK_GT(month, 0);
+ DCHECK_LT(month, 13);
+ DCHECK_GT(day_of_month, 0);
+ DCHECK_LT(day_of_month, 32);
+
+ base::Time::Exploded exploded;
+ exploded.year = year;
+ exploded.month = month;
+ exploded.day_of_week = 0; // Should be unusued.
+ exploded.day_of_month = day_of_month;
+ exploded.hour = 0;
+ exploded.minute = 0;
+ exploded.second = 0;
+ exploded.millisecond = 0;
+
+ base::Time expiration_time = Time::FromLocalExploded(exploded);
+ disable_field_trial_ = (GetBuildTime() > expiration_time) ? true : false;
}
int FieldTrial::AppendGroup(const std::string& name,
Probability group_probability) {
DCHECK(group_probability <= divisor_);
- DCHECK(group_probability >=0 ||
- group_probability == kAllRemainingProbability);
- if (group_probability == kAllRemainingProbability) {
- accumulated_group_probability_ = divisor_;
- } else {
- if (enable_benchmarking_)
- group_probability = 0;
- accumulated_group_probability_ += group_probability;
- }
+ DCHECK_GE(group_probability, 0);
+
+ if (enable_benchmarking_ || disable_field_trial_)
+ group_probability = 0;
+
+ accumulated_group_probability_ += group_probability;
+
DCHECK(accumulated_group_probability_ <= divisor_);
- if (group_ == kNotParticipating && accumulated_group_probability_ > random_) {
+ if (group_ == kNotFinalized && accumulated_group_probability_ > random_) {
// This is the group that crossed the random line, so we do the assignment.
group_ = next_group_number_;
if (name.empty())
@@ -62,6 +86,20 @@ int FieldTrial::AppendGroup(const std::string& name,
return next_group_number_++;
}
+int FieldTrial::group() {
+ if (group_ == kNotFinalized) {
+ accumulated_group_probability_ = divisor_;
+ group_ = kDefaultGroupNumber;
+ group_name_ = default_group_name_;
+ }
+ return group_;
+}
+
+std::string FieldTrial::group_name() {
+ group(); // call group() to make group assignment was done.
+ return group_name_;
+}
+
// static
std::string FieldTrial::MakeName(const std::string& name_prefix,
const std::string& trial_name) {
@@ -76,6 +114,16 @@ void FieldTrial::EnableBenchmarking() {
enable_benchmarking_ = true;
}
+// static
+Time FieldTrial::GetBuildTime() {
+ Time integral_build_time;
+ const char* kDateTime = __DATE__ " " __TIME__;
+ bool result = Time::FromString(ASCIIToWide(kDateTime).c_str(),
+ &integral_build_time);
+ DCHECK(result);
+ return integral_build_time;
+}
+
FieldTrial::~FieldTrial() {}
//------------------------------------------------------------------------------
@@ -129,7 +177,7 @@ int FieldTrialList::FindValue(const std::string& name) {
FieldTrial* field_trial = Find(name);
if (field_trial)
return field_trial->group();
- return FieldTrial::kNotParticipating;
+ return FieldTrial::kNotFinalized;
}
// static
@@ -149,9 +197,11 @@ void FieldTrialList::StatesToString(std::string* output) {
for (RegistrationList::iterator it = global_->registered_.begin();
it != global_->registered_.end(); ++it) {
const std::string name = it->first;
- const std::string group_name = it->second->group_name();
+ std::string group_name = it->second->group_name_internal();
if (group_name.empty())
- continue; // No definitive winner in this trial.
+ // No definitive winner in this trial, use default_group_name as the
+ // group_name.
+ group_name = it->second->default_group_name();
DCHECK_EQ(name.find(kPersistentStringSeparator), std::string::npos);
DCHECK_EQ(group_name.find(kPersistentStringSeparator), std::string::npos);
output->append(name);
@@ -162,34 +212,43 @@ void FieldTrialList::StatesToString(std::string* output) {
}
// static
-bool FieldTrialList::StringAugmentsState(const std::string& prior_state) {
+bool FieldTrialList::CreateTrialsInChildProcess(
+ const std::string& parent_trials) {
DCHECK(global_);
- if (prior_state.empty() || !global_)
+ if (parent_trials.empty() || !global_)
return true;
+ Time::Exploded exploded;
+ Time two_years_from_now =
+ Time::NowFromSystemTime() + TimeDelta::FromDays(730);
+ two_years_from_now.LocalExplode(&exploded);
+ const int kTwoYearsFromNow = exploded.year;
+
size_t next_item = 0;
- while (next_item < prior_state.length()) {
- size_t name_end = prior_state.find(kPersistentStringSeparator, next_item);
- if (name_end == prior_state.npos || next_item == name_end)
+ while (next_item < parent_trials.length()) {
+ size_t name_end = parent_trials.find(kPersistentStringSeparator, next_item);
+ if (name_end == parent_trials.npos || next_item == name_end)
return false;
- size_t group_name_end = prior_state.find(kPersistentStringSeparator,
- name_end + 1);
- if (group_name_end == prior_state.npos || name_end + 1 == group_name_end)
+ size_t group_name_end = parent_trials.find(kPersistentStringSeparator,
+ name_end + 1);
+ if (group_name_end == parent_trials.npos || name_end + 1 == group_name_end)
return false;
- std::string name(prior_state, next_item, name_end - next_item);
- std::string group_name(prior_state, name_end + 1,
+ std::string name(parent_trials, next_item, name_end - next_item);
+ std::string group_name(parent_trials, name_end + 1,
group_name_end - name_end - 1);
next_item = group_name_end + 1;
FieldTrial *field_trial(FieldTrialList::Find(name));
if (field_trial) {
// In single process mode, we may have already created the field trial.
- if (field_trial->group_name() != group_name)
+ if ((field_trial->group_name_internal() != group_name) &&
+ (field_trial->default_group_name() != group_name))
return false;
continue;
}
const int kTotalProbability = 100;
- field_trial = new FieldTrial(name, kTotalProbability);
+ field_trial = new FieldTrial(name, kTotalProbability, group_name,
+ kTwoYearsFromNow, 1, 1);
field_trial->AppendGroup(group_name, kTotalProbability);
}
return true;
diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h
index 8902077..077a88c 100644
--- a/base/metrics/field_trial.h
+++ b/base/metrics/field_trial.h
@@ -66,36 +66,40 @@
#include <map>
#include <string>
+#include "base/gtest_prod_util.h"
#include "base/lock.h"
#include "base/ref_counted.h"
#include "base/time.h"
namespace base {
+class FieldTrialList;
+
class FieldTrial : public RefCounted<FieldTrial> {
public:
typedef int Probability; // Probability type for being selected in a trial.
// A return value to indicate that a given instance has not yet had a group
// assignment (and hence is not yet participating in the trial).
- static const int kNotParticipating;
+ static const int kNotFinalized;
- // Provide an easy way to assign all remaining probability to a group. Note
- // that this will force an instance to participate, and make it illegal to
- // attempt to probabalistically add any other groups to the trial. When doing
- // A/B tests with timings, it is often best to define all groups, so that
- // histograms will get unique names via the MakeName() methods.
- static const Probability kAllRemainingProbability;
+ // This is the group number of the 'default' group. This provides an easy way
+ // to assign all the remaining probability to a group ('default').
+ static const int kDefaultGroupNumber;
// The name is used to register the instance with the FieldTrialList class,
// and can be used to find the trial (only one trial can be present for each
// name).
// Group probabilities that are later supplied must sum to less than or equal
- // to the total_probability.
- FieldTrial(const std::string& name, Probability total_probability);
+ // to the total_probability. Arguments year, month and day_of_month specify
+ // the expiration time. If the build time is after the expiration time then
+ // the field trial reverts to the 'default' group.
+ FieldTrial(const std::string& name, Probability total_probability,
+ const std::string& default_group_name, const int year,
+ const int month, const int day_of_month);
// Establish the name and probability of the next group in this trial.
- // Sometimes, based on construction randomization, this call may causes the
+ // Sometimes, based on construction randomization, this call may cause the
// provided group to be *THE* group selected for use in this instance.
int AppendGroup(const std::string& name, Probability group_probability);
@@ -103,14 +107,18 @@ class FieldTrial : public RefCounted<FieldTrial> {
std::string name() const { return name_; }
// Return the randomly selected group number that was assigned.
- // Return kNotParticipating if the instance is not participating in the
- // experiment.
- int group() const { return group_; }
+ // Return kDefaultGroupNumber if the instance is in the 'default' group.
+ // Note that this will force an instance to participate, and make it illegal
+ // to attempt to probabalistically add any other groups to the trial.
+ int group();
// If the field trial is not in an experiment, this returns the empty string.
// if the group's name is empty, a name of "_" concatenated with the group
// number is used as the group name.
- std::string group_name() const { return group_name_; }
+ std::string group_name();
+
+ // Return the default group name of the FieldTrial.
+ std::string default_group_name() const { return default_group_name_; }
// Helper function for the most common use: as an argument to specifiy the
// name of a HISTOGRAM. Use the original histogram name as the name_prefix.
@@ -121,17 +129,40 @@ class FieldTrial : public RefCounted<FieldTrial> {
static void EnableBenchmarking();
private:
+ // Allow tests to access our innards for testing purposes.
+ FRIEND_TEST(FieldTrialTest, Registration);
+ FRIEND_TEST(FieldTrialTest, AbsoluteProbabilities);
+ FRIEND_TEST(FieldTrialTest, RemainingProbability);
+ FRIEND_TEST(FieldTrialTest, FiftyFiftyProbability);
+ FRIEND_TEST(FieldTrialTest, MiddleProbabilities);
+ FRIEND_TEST(FieldTrialTest, OneWinner);
+ FRIEND_TEST(FieldTrialTest, DisableProbability);
+ FRIEND_TEST(FieldTrialTest, Save);
+ FRIEND_TEST(FieldTrialTest, DuplicateRestore);
+ FRIEND_TEST(FieldTrialTest, MakeName);
+
+ friend class base::FieldTrialList;
+
friend class RefCounted<FieldTrial>;
virtual ~FieldTrial();
+ // Returns the group_name. A winner need not have been chosen.
+ std::string group_name_internal() const { return group_name_; }
+
+ // Get build time.
+ static Time GetBuildTime();
+
// The name of the field trial, as can be found via the FieldTrialList.
// This is empty of the trial is not in the experiment.
const std::string name_;
// The maximum sum of all probabilities supplied, which corresponds to 100%.
// This is the scaling factor used to adjust supplied probabilities.
- Probability divisor_;
+ const Probability divisor_;
+
+ // The name of the default group.
+ const std::string default_group_name_;
// The randomly selected probability that is used to select a group (or have
// the instance not participate). It is the product of divisor_ and a random
@@ -144,15 +175,19 @@ class FieldTrial : public RefCounted<FieldTrial> {
int next_group_number_;
// The pseudo-randomly assigned group number.
- // This is kNotParticipating if no group has been assigned.
+ // This is kNotFinalized if no group has been assigned.
int group_;
- // A textual name for the randomly selected group, including the Trial name.
- // If this Trial is not a member of an group, this string is empty.
+ // A textual name for the randomly selected group. If this Trial is not a
+ // member of an group, this string is empty.
std::string group_name_;
+ // When disable_field_trial_ is true, field trial reverts to the 'default'
+ // group.
+ bool disable_field_trial_;
+
// When benchmarking is enabled, field trials all revert to the 'default'
- // bucket.
+ // group.
static bool enable_benchmarking_;
DISALLOW_COPY_AND_ASSIGN(FieldTrial);
@@ -199,7 +234,7 @@ class FieldTrialList {
// is commonly used in a sub-process, to carry randomly selected state in a
// parent process into this sub-process.
// Currently only the group_name_ and name_ are restored.
- static bool StringAugmentsState(const std::string& prior_state);
+ static bool CreateTrialsInChildProcess(const std::string& prior_trials);
// The time of construction of the global map is recorded in a static variable
// and is commonly used by experiments to identify the time since the start
diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc
index a8138bb..0af6d60 100644
--- a/base/metrics/field_trial_unittest.cc
+++ b/base/metrics/field_trial_unittest.cc
@@ -13,7 +13,23 @@ namespace base {
class FieldTrialTest : public testing::Test {
public:
- FieldTrialTest() : trial_list_() { }
+ FieldTrialTest() : trial_list_() {
+ Time now = Time::NowFromSystemTime();
+ TimeDelta oneYear = TimeDelta::FromDays(365);
+ Time::Exploded exploded;
+
+ Time next_year_time = now + oneYear;
+ next_year_time.LocalExplode(&exploded);
+ next_year_ = exploded.year;
+
+ Time last_year_time = now - oneYear;
+ last_year_time.LocalExplode(&exploded);
+ last_year_ = exploded.year;
+ }
+
+ protected:
+ int next_year_;
+ int last_year_;
private:
FieldTrialList trial_list_;
@@ -27,20 +43,22 @@ TEST_F(FieldTrialTest, Registration) {
EXPECT_FALSE(FieldTrialList::Find(name1));
EXPECT_FALSE(FieldTrialList::Find(name2));
- FieldTrial* trial1 = new FieldTrial(name1, 10);
- EXPECT_EQ(FieldTrial::kNotParticipating, trial1->group());
+ FieldTrial* trial1 =
+ new FieldTrial(name1, 10, "default name 1 test", next_year_, 12, 31);
+ EXPECT_EQ(FieldTrial::kNotFinalized, trial1->group_);
EXPECT_EQ(name1, trial1->name());
- EXPECT_EQ("", trial1->group_name());
+ EXPECT_EQ("", trial1->group_name_internal());
trial1->AppendGroup("", 7);
EXPECT_EQ(trial1, FieldTrialList::Find(name1));
EXPECT_FALSE(FieldTrialList::Find(name2));
- FieldTrial* trial2 = new FieldTrial(name2, 10);
- EXPECT_EQ(FieldTrial::kNotParticipating, trial2->group());
+ FieldTrial* trial2 =
+ new FieldTrial(name2, 10, "default name 2 test", next_year_, 12, 31);
+ EXPECT_EQ(FieldTrial::kNotFinalized, trial2->group_);
EXPECT_EQ(name2, trial2->name());
- EXPECT_EQ("", trial2->group_name());
+ EXPECT_EQ("", trial2->group_name_internal());
trial2->AppendGroup("a first group", 7);
@@ -51,20 +69,28 @@ TEST_F(FieldTrialTest, Registration) {
TEST_F(FieldTrialTest, AbsoluteProbabilities) {
char always_true[] = " always true";
+ char default_always_true[] = " default always true";
char always_false[] = " always false";
+ char default_always_false[] = " default always false";
for (int i = 1; i < 250; ++i) {
// Try lots of names, by changing the first character of the name.
always_true[0] = i;
+ default_always_true[0] = i;
always_false[0] = i;
+ default_always_false[0] = i;
- FieldTrial* trial_true = new FieldTrial(always_true, 10);
+ FieldTrial* trial_true =
+ new FieldTrial(
+ always_true, 10, default_always_true, next_year_, 12, 31);
const std::string winner = "TheWinner";
int winner_group = trial_true->AppendGroup(winner, 10);
EXPECT_EQ(winner_group, trial_true->group());
EXPECT_EQ(winner, trial_true->group_name());
- FieldTrial* trial_false = new FieldTrial(always_false, 10);
+ FieldTrial* trial_false =
+ new FieldTrial(
+ always_false, 10, default_always_false, next_year_, 12, 31);
int loser_group = trial_false->AppendGroup("ALoser", 0);
EXPECT_NE(loser_group, trial_false->group());
@@ -79,12 +105,13 @@ TEST_F(FieldTrialTest, RemainingProbability) {
int counter = 0;
do {
std::string name = StringPrintf("trial%d", ++counter);
- trial = new FieldTrial(name, 10);
+ trial = new FieldTrial(name, 10, winner, next_year_, 12, 31);
trial->AppendGroup(loser, 5); // 50% chance of not being chosen.
- } while (trial->group() != FieldTrial::kNotParticipating);
+ // If a group is not assigned, group_ will be kNotFinalized.
+ } while (trial->group_ != FieldTrial::kNotFinalized);
- // Now add a winner with all remaining probability.
- trial->AppendGroup(winner, FieldTrial::kAllRemainingProbability);
+ // And that 'default' group (winner) should always win.
+ EXPECT_EQ(FieldTrial::kDefaultGroupNumber, trial->group());
// And that winner should ALWAYS win.
EXPECT_EQ(winner, trial->group_name());
@@ -100,14 +127,18 @@ TEST_F(FieldTrialTest, FiftyFiftyProbability) {
int counter = 0;
do {
std::string name = base::StringPrintf("FiftyFifty%d", ++counter);
- scoped_refptr<FieldTrial> trial(new FieldTrial(name, 2));
+ std::string default_group_name = base::StringPrintf("Default FiftyFifty%d",
+ ++counter);
+ scoped_refptr<FieldTrial> trial(
+ new FieldTrial(name, 2, default_group_name, next_year_, 12, 31));
trial->AppendGroup("first", 1); // 50% chance of being chosen.
- if (trial->group() != FieldTrial::kNotParticipating) {
+ // If group_ is kNotFinalized, then a group assignement hasn't been done.
+ if (trial->group_ != FieldTrial::kNotFinalized) {
first_winner = true;
continue;
}
trial->AppendGroup("second", 1); // Always chosen at this point.
- EXPECT_NE(FieldTrial::kNotParticipating, trial->group());
+ EXPECT_NE(FieldTrial::kNotFinalized, trial->group());
second_winner = true;
} while ((!second_winner || !first_winner) && counter < 100);
EXPECT_TRUE(second_winner);
@@ -116,11 +147,14 @@ TEST_F(FieldTrialTest, FiftyFiftyProbability) {
TEST_F(FieldTrialTest, MiddleProbabilities) {
char name[] = " same name";
+ char default_group_name[] = " default same name";
bool false_event_seen = false;
bool true_event_seen = false;
for (int i = 1; i < 250; ++i) {
name[0] = i;
- FieldTrial* trial = new FieldTrial(name, 10);
+ default_group_name[0] = i;
+ FieldTrial* trial =
+ new FieldTrial(name, 10, default_group_name, next_year_, 12, 31);
int might_win = trial->AppendGroup("MightWin", 5);
if (trial->group() == might_win) {
@@ -139,16 +173,21 @@ TEST_F(FieldTrialTest, MiddleProbabilities) {
TEST_F(FieldTrialTest, OneWinner) {
char name[] = "Some name";
+ char default_group_name[] = "Default some name";
int group_count(10);
- FieldTrial* trial = new FieldTrial(name, group_count);
+ FieldTrial* trial =
+ new FieldTrial(
+ name, group_count, default_group_name, next_year_, 12, 31);
int winner_index(-2);
std::string winner_name;
for (int i = 1; i <= group_count; ++i) {
int might_win = trial->AppendGroup("", 1);
- if (trial->group() == might_win) {
+ // Because we keep appending groups, we want to see if the last group that
+ // was added has been assigned or not.
+ if (trial->group_ == might_win) {
EXPECT_EQ(-2, winner_index);
winner_index = might_win;
StringAppendF(&winner_name, "%d", might_win);
@@ -160,14 +199,34 @@ TEST_F(FieldTrialTest, OneWinner) {
EXPECT_EQ(trial->group_name(), winner_name);
}
+TEST_F(FieldTrialTest, DisableProbability) {
+ const std::string default_group_name = "Default group";
+ const std::string loser = "Loser";
+ const std::string name = "Trial";
+
+ // Create a field trail that has expired.
+ scoped_refptr<FieldTrial> trial;
+ trial = new FieldTrial(
+ name, 1000000000, default_group_name, last_year_, 1, 1);
+ trial->AppendGroup(loser, 999999999); // 99.9999999% chance of being chosen.
+
+ // Because trial has expired, we should always be in the default group.
+ EXPECT_EQ(FieldTrial::kDefaultGroupNumber, trial->group());
+
+ // And that default_group_name should ALWAYS win.
+ EXPECT_EQ(default_group_name, trial->group_name());
+}
+
TEST_F(FieldTrialTest, Save) {
std::string save_string;
- FieldTrial* trial = new FieldTrial("Some name", 10);
+ FieldTrial* trial =
+ new FieldTrial(
+ "Some name", 10, "Default some name", next_year_, 12, 31);
// There is no winner yet, so no textual group name is associated with trial.
- EXPECT_EQ("", trial->group_name());
+ EXPECT_EQ("", trial->group_name_internal());
FieldTrialList::StatesToString(&save_string);
- EXPECT_EQ("", save_string);
+ EXPECT_EQ("Some name/Default some name/", save_string);
save_string.clear();
// Create a winning group.
@@ -177,7 +236,8 @@ TEST_F(FieldTrialTest, Save) {
save_string.clear();
// Create a second trial and winning group.
- FieldTrial* trial2 = new FieldTrial("xxx", 10);
+ FieldTrial* trial2 =
+ new FieldTrial("xxx", 10, "Default xxx", next_year_, 12, 31);
trial2->AppendGroup("yyyy", 10);
FieldTrialList::StatesToString(&save_string);
@@ -189,7 +249,7 @@ TEST_F(FieldTrialTest, Restore) {
EXPECT_TRUE(FieldTrialList::Find("Some_name") == NULL);
EXPECT_TRUE(FieldTrialList::Find("xxx") == NULL);
- FieldTrialList::StringAugmentsState("Some_name/Winner/xxx/yyyy/");
+ FieldTrialList::CreateTrialsInChildProcess("Some_name/Winner/xxx/yyyy/");
FieldTrial* trial = FieldTrialList::Find("Some_name");
ASSERT_NE(static_cast<FieldTrial*>(NULL), trial);
@@ -203,29 +263,34 @@ TEST_F(FieldTrialTest, Restore) {
}
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/"));
+ EXPECT_FALSE(FieldTrialList::CreateTrialsInChildProcess("MissingSlash"));
+ EXPECT_FALSE(FieldTrialList::CreateTrialsInChildProcess("MissingGroupName/"));
+ EXPECT_FALSE(
+ FieldTrialList::CreateTrialsInChildProcess("MissingFinalSlash/gname"));
+ EXPECT_FALSE(
+ FieldTrialList::CreateTrialsInChildProcess("/noname, only group/"));
}
TEST_F(FieldTrialTest, DuplicateRestore) {
- FieldTrial* trial = new FieldTrial("Some name", 10);
+ FieldTrial* trial =
+ new FieldTrial(
+ "Some name", 10, "Default some name", next_year_, 12, 31);
trial->AppendGroup("Winner", 10);
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_TRUE(FieldTrialList::StringAugmentsState(save_string));
+ EXPECT_TRUE(FieldTrialList::CreateTrialsInChildProcess(save_string));
// But it is an error to try to change to a different winner.
- EXPECT_FALSE(FieldTrialList::StringAugmentsState("Some name/Loser/"));
+ EXPECT_FALSE(FieldTrialList::CreateTrialsInChildProcess("Some name/Loser/"));
}
TEST_F(FieldTrialTest, MakeName) {
- FieldTrial* trial = new FieldTrial("Field Trial", 10);
- trial->AppendGroup("Winner", 10);
+ FieldTrial* trial =
+ new FieldTrial("Field Trial", 10, "Winner", next_year_, 12, 31);
+ trial->group();
EXPECT_EQ("Histogram_Winner",
FieldTrial::MakeName("Histogram", "Field Trial"));
}