summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-30 15:11:29 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-30 15:11:29 +0000
commitebcf69f02f4f02e508e77193e51dd6557e6c0085 (patch)
tree80f883eca03bd26b3a5211f9156ff2e860c909ff /base
parentb554d462229e4498ba6576d7cd0c2336fb468175 (diff)
downloadchromium_src-ebcf69f02f4f02e508e77193e51dd6557e6c0085.zip
chromium_src-ebcf69f02f4f02e508e77193e51dd6557e6c0085.tar.gz
chromium_src-ebcf69f02f4f02e508e77193e51dd6557e6c0085.tar.bz2
Make field trial randomization type a constructor param.
Changes the Field Trial API to require users to pass ONE_TIME_RANDOMIZED or SESSION_RANDOMIZED at the time the field trial is created. This removes a source of human errors, where developers would sometimes previously forget to call UseOneTimeRandomization() in their CLs. It's a small startup performance win, since one time randomized trials will no longer call RandDouble() that will be then replaced by a value from the entropy provider. (This was showing up in profiles when I was measuring metrics startup perf on mobile.) BUG=262971 TEST=Existing unit tests. TBR=isherman@chromium.org, thakis@chromium.org Review URL: https://codereview.chromium.org/20777005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/metrics/field_trial.cc66
-rw-r--r--base/metrics/field_trial.h75
-rw-r--r--base/metrics/field_trial_unittest.cc188
3 files changed, 157 insertions, 172 deletions
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc
index 3b96040..4456a79 100644
--- a/base/metrics/field_trial.cc
+++ b/base/metrics/field_trial.cc
@@ -55,11 +55,12 @@ int FieldTrialList::kNoExpirationYear = 0;
FieldTrial::FieldTrial(const std::string& trial_name,
const Probability total_probability,
- const std::string& default_group_name)
+ const std::string& default_group_name,
+ double entropy_value)
: trial_name_(trial_name),
divisor_(total_probability),
default_group_name_(default_group_name),
- random_(static_cast<Probability>(divisor_ * RandDouble())),
+ random_(static_cast<Probability>(divisor_ * entropy_value)),
accumulated_group_probability_(0),
next_group_number_(kDefaultGroupNumber + 1),
group_(kNotFinalized),
@@ -74,30 +75,6 @@ FieldTrial::FieldTrial(const std::string& trial_name,
FieldTrial::EntropyProvider::~EntropyProvider() {
}
-void FieldTrial::UseOneTimeRandomization() {
- UseOneTimeRandomizationWithCustomSeed(0);
-}
-
-void FieldTrial::UseOneTimeRandomizationWithCustomSeed(
- uint32 randomization_seed) {
- // No need to specify randomization when the group choice was forced.
- if (forced_)
- return;
- DCHECK_EQ(group_, kNotFinalized);
- DCHECK_EQ(kDefaultGroupNumber + 1, next_group_number_);
- const EntropyProvider* entropy_provider =
- FieldTrialList::GetEntropyProviderForOneTimeRandomization();
- if (!entropy_provider) {
- NOTREACHED();
- Disable();
- return;
- }
-
- random_ = static_cast<Probability>(
- divisor_ * entropy_provider->GetEntropyForTrial(trial_name_,
- randomization_seed));
-}
-
void FieldTrial::Disable() {
DCHECK(!group_reported_);
enable_field_trial_ = false;
@@ -256,17 +233,34 @@ FieldTrialList::~FieldTrialList() {
// static
FieldTrial* FieldTrialList::FactoryGetFieldTrial(
- const std::string& name,
+ const std::string& trial_name,
FieldTrial::Probability total_probability,
const std::string& default_group_name,
const int year,
const int month,
const int day_of_month,
+ FieldTrial::RandomizationType randomization_type,
+ int* default_group_number) {
+ return FactoryGetFieldTrialWithRandomizationSeed(
+ trial_name, total_probability, default_group_name,
+ year, month, day_of_month, randomization_type, 0, default_group_number);
+}
+
+// static
+FieldTrial* FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed(
+ const std::string& trial_name,
+ FieldTrial::Probability total_probability,
+ const std::string& default_group_name,
+ const int year,
+ const int month,
+ const int day_of_month,
+ FieldTrial::RandomizationType randomization_type,
+ uint32 randomization_seed,
int* default_group_number) {
if (default_group_number)
*default_group_number = FieldTrial::kDefaultGroupNumber;
// Check if the field trial has already been created in some other way.
- FieldTrial* existing_trial = Find(name);
+ FieldTrial* existing_trial = Find(trial_name);
if (existing_trial) {
CHECK(existing_trial->forced_);
// If the default group name differs between the existing forced trial
@@ -295,8 +289,18 @@ FieldTrial* FieldTrialList::FactoryGetFieldTrial(
return existing_trial;
}
- FieldTrial* field_trial =
- new FieldTrial(name, total_probability, default_group_name);
+ double entropy_value;
+ if (randomization_type == FieldTrial::ONE_TIME_RANDOMIZED) {
+ entropy_value = GetEntropyProviderForOneTimeRandomization()->
+ GetEntropyForTrial(trial_name, randomization_seed);
+ } else {
+ DCHECK_EQ(FieldTrial::SESSION_RANDOMIZED, randomization_type);
+ DCHECK_EQ(0U, randomization_seed);
+ entropy_value = RandDouble();
+ }
+
+ FieldTrial* field_trial = new FieldTrial(trial_name, total_probability,
+ default_group_name, entropy_value);
if (GetBuildTime() > CreateTimeFromParams(year, month, day_of_month))
field_trial->Disable();
FieldTrialList::Register(field_trial);
@@ -418,7 +422,7 @@ FieldTrial* FieldTrialList::CreateFieldTrial(
return field_trial;
}
const int kTotalProbability = 100;
- field_trial = new FieldTrial(name, kTotalProbability, group_name);
+ field_trial = new FieldTrial(name, kTotalProbability, group_name, 0);
// Force the trial, which will also finalize the group choice.
field_trial->SetForced();
FieldTrialList::Register(field_trial);
diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h
index 106bf8b..08a8406 100644
--- a/base/metrics/field_trial.h
+++ b/base/metrics/field_trial.h
@@ -15,11 +15,9 @@
// States are typically generated randomly, either based on a one time
// randomization (which will yield the same results, in terms of selecting
// the client for a field trial or not, for every run of the program on a
-// given machine), or by a startup randomization (generated each time the
+// given machine), or by a session randomization (generated each time the
// application starts up, but held constant during the duration of the
-// process), or by continuous randomization across a run (where the state
-// can be recalculated again and again, many times during a process).
-// Continuous randomization is not yet implemented.
+// process).
//------------------------------------------------------------------------------
// Example: Suppose we have an experiment involving memory, such as determining
@@ -37,9 +35,10 @@
// // Note: This field trial will run in Chrome instances compiled through
// // 8 July, 2015, and after that all instances will be in "StandardMem".
// scoped_refptr<base::FieldTrial> trial(
-// base::FieldTrialList::FactoryGetFieldTrial("MemoryExperiment", 1000,
-// "StandardMem", 2015, 7, 8,
-// NULL));
+// base::FieldTrialList::FactoryGetFieldTrial(
+// "MemoryExperiment", 1000, "StandardMem", 2015, 7, 8,
+// base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
+//
// const int high_mem_group =
// trial->AppendGroup("HighMem", 20); // 2% in HighMem group.
// const int low_mem_group =
@@ -95,6 +94,17 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
public:
typedef int Probability; // Probability type for being selected in a trial.
+ // Specifies the persistence of the field trial group choice.
+ enum RandomizationType {
+ // One time randomized trials will persist the group choice between
+ // restarts, which is recommended for most trials, especially those that
+ // change user visible behavior.
+ ONE_TIME_RANDOMIZED,
+ // Session randomized trials will roll the dice to select a group on every
+ // process restart.
+ SESSION_RANDOMIZED,
+ };
+
// EntropyProvider is an interface for providing entropy for one-time
// randomized (persistent) field trials.
class BASE_EXPORT EntropyProvider {
@@ -122,21 +132,6 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
// assignment (and hence is not yet participating in the trial).
static const int kNotFinalized;
- // Changes the field trial to use one-time randomization, i.e. produce the
- // same result for the current trial on every run of this client. Must be
- // called right after construction, before any groups are added.
- void UseOneTimeRandomization();
-
- // Changes the field trial to use one-time randomization, i.e. produce the
- // same result for the current trial on every run of this client, with a
- // custom randomization seed for the trial (instead of a hash of the trial
- // name, which is used otherwise). The |randomization_seed| value should never
- // be the same for two trials, else this would result in correlated group
- // assignments. Note: Using a custom randomization seed is only supported by
- // the PermutedEntropyProvider (which is used when UMA is not enabled). Must
- // be called right after construction, before any groups are added.
- void UseOneTimeRandomizationWithCustomSeed(uint32 randomization_seed);
-
// Disables this trial, meaning it always determines the default group
// has been selected. May be called immediately after construction, or
// at any time after initialization (should not be interleaved with
@@ -201,7 +196,6 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, HashClientId);
FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, HashClientIdIsUniform);
FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, NameGroupIds);
- FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, UseOneTimeRandomization);
FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOff);
FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOn);
FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_Default);
@@ -216,9 +210,12 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
// consumers don't use it by mistake in cases where the group was forced.
static const int kDefaultGroupNumber;
+ // Creates a field trial with the specified parameters. Group assignment will
+ // be done based on |entropy_value|, which must have a range of [0, 1).
FieldTrial(const std::string& name,
Probability total_probability,
- const std::string& default_group_name);
+ const std::string& default_group_name,
+ double entropy_value);
virtual ~FieldTrial();
// Return the default group name of the FieldTrial.
@@ -350,8 +347,7 @@ class BASE_EXPORT FieldTrialList {
// then the field trial reverts to the 'default' group.
//
// Use this static method to get a startup-randomized FieldTrial or a
- // previously created forced FieldTrial. If you want a one-time randomized
- // trial, call UseOneTimeRandomization() right after creation.
+ // previously created forced FieldTrial.
static FieldTrial* FactoryGetFieldTrial(
const std::string& trial_name,
FieldTrial::Probability total_probability,
@@ -359,6 +355,25 @@ class BASE_EXPORT FieldTrialList {
const int year,
const int month,
const int day_of_month,
+ FieldTrial::RandomizationType randomization_type,
+ int* default_group_number);
+
+ // Same as FactoryGetFieldTrial(), but allows specifying a custom seed to be
+ // used on one-time randomized field trials (instead of a hash of the trial
+ // name, which is used otherwise or if |randomization_seed| has value 0). The
+ // |randomization_seed| value (other than 0) should never be the same for two
+ // trials, else this would result in correlated group assignments.
+ // Note: Using a custom randomization seed is only supported by the
+ // PermutedEntropyProvider (which is used when UMA is not enabled).
+ static FieldTrial* FactoryGetFieldTrialWithRandomizationSeed(
+ const std::string& trial_name,
+ FieldTrial::Probability total_probability,
+ const std::string& default_group_name,
+ const int year,
+ const int month,
+ const int day_of_month,
+ FieldTrial::RandomizationType randomization_type,
+ uint32 randomization_seed,
int* default_group_number);
// The Find() method can be used to test to see if a named Trial was already
@@ -427,15 +442,15 @@ class BASE_EXPORT FieldTrialList {
// Return the number of active field trials.
static size_t GetFieldTrialCount();
+ private:
+ // A map from FieldTrial names to the actual instances.
+ typedef std::map<std::string, FieldTrial*> RegistrationList;
+
// If one-time randomization is enabled, returns a weak pointer to the
// corresponding EntropyProvider. Otherwise, returns NULL.
static const FieldTrial::EntropyProvider*
GetEntropyProviderForOneTimeRandomization();
- private:
- // A map from FieldTrial names to the actual instances.
- typedef std::map<std::string, FieldTrial*> RegistrationList;
-
// Helper function should be called only while holding lock_.
FieldTrial* PreLockedFind(const std::string& name);
diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc
index 2f70f09..21be991 100644
--- a/base/metrics/field_trial_unittest.cc
+++ b/base/metrics/field_trial_unittest.cc
@@ -18,6 +18,25 @@ namespace {
// Default group name used by several tests.
const char kDefaultGroupName[] = "DefaultGroup";
+// Call FieldTrialList::FactoryGetFieldTrial() with a future expiry date.
+scoped_refptr<base::FieldTrial> CreateFieldTrial(
+ const std::string& trial_name,
+ int total_probability,
+ const std::string& default_group_name,
+ int* default_group_number) {
+ return FieldTrialList::FactoryGetFieldTrial(
+ trial_name, total_probability, default_group_name,
+ base::FieldTrialList::kNoExpirationYear, 1, 1,
+ base::FieldTrial::SESSION_RANDOMIZED, default_group_number);
+}
+
+int GetLastYear() {
+ Time last_year_time = Time::NowFromSystemTime() - TimeDelta::FromDays(365);
+ Time::Exploded exploded;
+ last_year_time.LocalExplode(&exploded);
+ return exploded.year;
+}
+
// FieldTrialList::Observer implementation for testing.
class TestFieldTrialObserver : public FieldTrialList::Observer {
public:
@@ -49,26 +68,10 @@ class TestFieldTrialObserver : public FieldTrialList::Observer {
class FieldTrialTest : public testing::Test {
public:
- FieldTrialTest() : trial_list_(NULL) {
- Time now = Time::NowFromSystemTime();
- TimeDelta one_year = TimeDelta::FromDays(365);
- Time::Exploded exploded;
-
- Time next_year_time = now + one_year;
- next_year_time.LocalExplode(&exploded);
- next_year_ = exploded.year;
-
- Time last_year_time = now - one_year;
- last_year_time.LocalExplode(&exploded);
- last_year_ = exploded.year;
- }
-
- protected:
- int next_year_;
- int last_year_;
- MessageLoop message_loop_;
+ FieldTrialTest() : trial_list_(NULL) {}
private:
+ MessageLoop message_loop_;
FieldTrialList trial_list_;
};
@@ -80,8 +83,7 @@ TEST_F(FieldTrialTest, Registration) {
EXPECT_FALSE(FieldTrialList::Find(name1));
EXPECT_FALSE(FieldTrialList::Find(name2));
- FieldTrial* trial1 = FieldTrialList::FactoryGetFieldTrial(
- name1, 10, "default name 1 test", next_year_, 12, 31, NULL);
+ FieldTrial* trial1 = CreateFieldTrial(name1, 10, "default name 1 test", NULL);
EXPECT_EQ(FieldTrial::kNotFinalized, trial1->group_);
EXPECT_EQ(name1, trial1->trial_name());
EXPECT_EQ("", trial1->group_name_internal());
@@ -91,8 +93,7 @@ TEST_F(FieldTrialTest, Registration) {
EXPECT_EQ(trial1, FieldTrialList::Find(name1));
EXPECT_FALSE(FieldTrialList::Find(name2));
- FieldTrial* trial2 = FieldTrialList::FactoryGetFieldTrial(
- name2, 10, "default name 2 test", next_year_, 12, 31, NULL);
+ FieldTrial* trial2 = CreateFieldTrial(name2, 10, "default name 2 test", NULL);
EXPECT_EQ(FieldTrial::kNotFinalized, trial2->group_);
EXPECT_EQ(name2, trial2->trial_name());
EXPECT_EQ("", trial2->group_name_internal());
@@ -116,16 +117,16 @@ TEST_F(FieldTrialTest, AbsoluteProbabilities) {
always_false[0] = i;
default_always_false[0] = i;
- FieldTrial* trial_true = FieldTrialList::FactoryGetFieldTrial(
- always_true, 10, default_always_true, next_year_, 12, 31, NULL);
+ FieldTrial* trial_true =
+ CreateFieldTrial(always_true, 10, default_always_true, NULL);
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 = FieldTrialList::FactoryGetFieldTrial(
- always_false, 10, default_always_false, next_year_, 12, 31, NULL);
+ FieldTrial* trial_false =
+ CreateFieldTrial(always_false, 10, default_always_false, NULL);
int loser_group = trial_false->AppendGroup("ALoser", 0);
EXPECT_NE(loser_group, trial_false->group());
@@ -141,8 +142,7 @@ TEST_F(FieldTrialTest, RemainingProbability) {
int default_group_number = -1;
do {
std::string name = StringPrintf("trial%d", ++counter);
- trial = FieldTrialList::FactoryGetFieldTrial(
- name, 10, winner, next_year_, 12, 31, &default_group_number);
+ trial = CreateFieldTrial(name, 10, winner, &default_group_number);
trial->AppendGroup(loser, 5); // 50% chance of not being chosen.
// If a group is not assigned, group_ will be kNotFinalized.
} while (trial->group_ != FieldTrial::kNotFinalized);
@@ -166,8 +166,7 @@ TEST_F(FieldTrialTest, FiftyFiftyProbability) {
std::string name = base::StringPrintf("FiftyFifty%d", ++counter);
std::string default_group_name = base::StringPrintf("Default FiftyFifty%d",
++counter);
- scoped_refptr<FieldTrial> trial(FieldTrialList::FactoryGetFieldTrial(
- name, 2, default_group_name, next_year_, 12, 31, NULL));
+ FieldTrial* trial = CreateFieldTrial(name, 2, default_group_name, NULL);
trial->AppendGroup("first", 1); // 50% chance of being chosen.
// If group_ is kNotFinalized, then a group assignement hasn't been done.
if (trial->group_ != FieldTrial::kNotFinalized) {
@@ -190,8 +189,7 @@ TEST_F(FieldTrialTest, MiddleProbabilities) {
for (int i = 1; i < 250; ++i) {
name[0] = i;
default_group_name[0] = i;
- FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
- name, 10, default_group_name, next_year_, 12, 31, NULL);
+ FieldTrial* trial = CreateFieldTrial(name, 10, default_group_name, NULL);
int might_win = trial->AppendGroup("MightWin", 5);
if (trial->group() == might_win) {
@@ -214,9 +212,8 @@ TEST_F(FieldTrialTest, OneWinner) {
int group_count(10);
int default_group_number = -1;
- FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
- name, group_count, default_group_name, next_year_, 12, 31,
- &default_group_number);
+ FieldTrial* trial =
+ CreateFieldTrial(name, group_count, default_group_name, NULL);
int winner_index(-2);
std::string winner_name;
@@ -247,9 +244,9 @@ TEST_F(FieldTrialTest, DisableProbability) {
// Create a field trail that has expired.
int default_group_number = -1;
- scoped_refptr<FieldTrial> trial;
- trial = FieldTrialList::FactoryGetFieldTrial(
- name, 1000000000, default_group_name, last_year_, 1, 1,
+ FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
+ name, 1000000000, default_group_name, GetLastYear(), 1, 1,
+ FieldTrial::SESSION_RANDOMIZED,
&default_group_number);
trial->AppendGroup(loser, 999999999); // 99.9999999% chance of being chosen.
@@ -262,8 +259,7 @@ TEST_F(FieldTrialTest, DisableProbability) {
TEST_F(FieldTrialTest, ActiveGroups) {
std::string no_group("No Group");
- scoped_refptr<FieldTrial> trial(FieldTrialList::FactoryGetFieldTrial(
- no_group, 10, "Default", next_year_, 12, 31, NULL));
+ FieldTrial* trial = CreateFieldTrial(no_group, 10, "Default", NULL);
// There is no winner yet, so no NameGroupId should be returned.
FieldTrial::ActiveGroup active_group;
@@ -271,8 +267,7 @@ TEST_F(FieldTrialTest, ActiveGroups) {
// Create a single winning group.
std::string one_winner("One Winner");
- trial = FieldTrialList::FactoryGetFieldTrial(
- one_winner, 10, "Default", next_year_, 12, 31, NULL);
+ trial = CreateFieldTrial(one_winner, 10, "Default", NULL);
std::string winner("Winner");
trial->AppendGroup(winner, 10);
EXPECT_FALSE(trial->GetActiveGroup(&active_group));
@@ -283,9 +278,8 @@ TEST_F(FieldTrialTest, ActiveGroups) {
EXPECT_EQ(winner, active_group.group_name);
std::string multi_group("MultiGroup");
- scoped_refptr<FieldTrial> multi_group_trial =
- FieldTrialList::FactoryGetFieldTrial(multi_group, 9, "Default",
- next_year_, 12, 31, NULL);
+ FieldTrial* multi_group_trial =
+ CreateFieldTrial(multi_group, 9, "Default", NULL);
multi_group_trial->AppendGroup("Me", 3);
multi_group_trial->AppendGroup("You", 3);
@@ -317,8 +311,7 @@ TEST_F(FieldTrialTest, ActiveGroupsNotFinalized) {
int default_group = -1;
FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
const int secondary_group = trial->AppendGroup(kSecondaryGroupName, 50);
// Before |group()| is called, |GetActiveGroup()| should return false.
@@ -350,8 +343,8 @@ TEST_F(FieldTrialTest, ActiveGroupsNotFinalized) {
TEST_F(FieldTrialTest, Save) {
std::string save_string;
- FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
- "Some name", 10, "Default some name", next_year_, 12, 31, NULL);
+ FieldTrial* trial =
+ CreateFieldTrial("Some name", 10, "Default some name", NULL);
// There is no winner yet, so no textual group name is associated with trial.
// In this case, the trial should not be included.
EXPECT_EQ("", trial->group_name_internal());
@@ -368,8 +361,7 @@ TEST_F(FieldTrialTest, Save) {
save_string.clear();
// Create a second trial and winning group.
- FieldTrial* trial2 = FieldTrialList::FactoryGetFieldTrial(
- "xxx", 10, "Default xxx", next_year_, 12, 31, NULL);
+ FieldTrial* trial2 = CreateFieldTrial("xxx", 10, "Default xxx", NULL);
trial2->AppendGroup("yyyy", 10);
// Finalize the group selection by accessing the selected group.
trial2->group();
@@ -380,8 +372,7 @@ TEST_F(FieldTrialTest, Save) {
save_string.clear();
// Create a third trial with only the default group.
- FieldTrial* trial3 = FieldTrialList::FactoryGetFieldTrial(
- "zzz", 10, "default", next_year_, 12, 31, NULL);
+ FieldTrial* trial3 = CreateFieldTrial("zzz", 10, "default", NULL);
// Finalize the group selection by accessing the selected group.
trial3->group();
@@ -419,8 +410,7 @@ TEST_F(FieldTrialTest, BogusRestore) {
}
TEST_F(FieldTrialTest, DuplicateRestore) {
- FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
- "Some name", 10, "Default some name", next_year_, 12, 31, NULL);
+ FieldTrial* trial = CreateFieldTrial("Some name", 10, "Default", NULL);
trial->AppendGroup("Winner", 10);
// Finalize the group selection by accessing the selected group.
trial->group();
@@ -527,8 +517,7 @@ TEST_F(FieldTrialTest, CreateFieldTrialIsNotActive) {
}
TEST_F(FieldTrialTest, DuplicateFieldTrial) {
- FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
- "Some_name", 10, "Default some name", next_year_, 12, 31, NULL);
+ FieldTrial* trial = CreateFieldTrial("Some_name", 10, "Default", NULL);
trial->AppendGroup("Winner", 10);
// It is OK if we redundantly specify a winner.
@@ -541,8 +530,7 @@ TEST_F(FieldTrialTest, DuplicateFieldTrial) {
}
TEST_F(FieldTrialTest, MakeName) {
- FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
- "Field Trial", 10, "Winner", next_year_, 12, 31, NULL);
+ FieldTrial* trial = CreateFieldTrial("Field Trial", 10, "Winner", NULL);
trial->group();
EXPECT_EQ("Histogram_Winner",
FieldTrial::MakeName("Histogram", "Field Trial"));
@@ -550,17 +538,15 @@ TEST_F(FieldTrialTest, MakeName) {
TEST_F(FieldTrialTest, DisableImmediately) {
int default_group_number = -1;
- FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
- "trial", 100, "default", next_year_, 12, 31, &default_group_number);
+ FieldTrial* trial =
+ CreateFieldTrial("trial", 100, "default", &default_group_number);
trial->Disable();
ASSERT_EQ("default", trial->group_name());
ASSERT_EQ(default_group_number, trial->group());
}
TEST_F(FieldTrialTest, DisableAfterInitialization) {
- FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial("trial", 100, "default",
- next_year_, 12, 31, NULL);
+ FieldTrial* trial = CreateFieldTrial("trial", 100, "default", NULL);
trial->AppendGroup("non_default", 100);
trial->Disable();
ASSERT_EQ("default", trial->group_name());
@@ -573,8 +559,8 @@ TEST_F(FieldTrialTest, ForcedFieldTrials) {
EXPECT_STREQ("Force", forced_trial->group_name().c_str());
int default_group_number = -1;
- FieldTrial* factory_trial = FieldTrialList::FactoryGetFieldTrial(
- "Use the", 1000, "default", next_year_, 12, 31, &default_group_number);
+ FieldTrial* factory_trial =
+ CreateFieldTrial("Use the", 1000, "default", &default_group_number);
EXPECT_EQ(factory_trial, forced_trial);
int chosen_group = factory_trial->AppendGroup("Force", 100);
@@ -596,8 +582,8 @@ TEST_F(FieldTrialTest, ForcedFieldTrialsDefaultGroup) {
FieldTrial* forced_trial = FieldTrialList::CreateFieldTrial("Trial Name",
"Default");
int default_group_number = -1;
- FieldTrial* factory_trial = FieldTrialList::FactoryGetFieldTrial(
- "Trial Name", 1000, "Default", next_year_, 12, 31, &default_group_number);
+ FieldTrial* factory_trial =
+ CreateFieldTrial("Trial Name", 1000, "Default", &default_group_number);
EXPECT_EQ(forced_trial, factory_trial);
int other_group = factory_trial->AppendGroup("Not Default", 100);
@@ -612,8 +598,8 @@ TEST_F(FieldTrialTest, ForcedFieldTrialsDefaultGroup) {
TEST_F(FieldTrialTest, SetForced) {
// Start by setting a trial for which we ensure a winner...
int default_group_number = -1;
- FieldTrial* forced_trial = FieldTrialList::FactoryGetFieldTrial(
- "Use the", 1, "default", next_year_, 12, 31, &default_group_number);
+ FieldTrial* forced_trial =
+ CreateFieldTrial("Use the", 1, "default", &default_group_number);
EXPECT_EQ(forced_trial, forced_trial);
int forced_group = forced_trial->AppendGroup("Force", 1);
@@ -623,8 +609,8 @@ TEST_F(FieldTrialTest, SetForced) {
forced_trial->SetForced();
// Now try to set it up differently as a hard coded registration would.
- FieldTrial* hard_coded_trial = FieldTrialList::FactoryGetFieldTrial(
- "Use the", 1, "default", next_year_, 12, 31, &default_group_number);
+ FieldTrial* hard_coded_trial =
+ CreateFieldTrial("Use the", 1, "default", &default_group_number);
EXPECT_EQ(hard_coded_trial, forced_trial);
int would_lose_group = hard_coded_trial->AppendGroup("Force", 0);
@@ -632,8 +618,8 @@ TEST_F(FieldTrialTest, SetForced) {
EXPECT_EQ(forced_group, would_lose_group);
// Same thing if we would have done it to win again.
- FieldTrial* other_hard_coded_trial = FieldTrialList::FactoryGetFieldTrial(
- "Use the", 1, "default", next_year_, 12, 31, &default_group_number);
+ FieldTrial* other_hard_coded_trial =
+ CreateFieldTrial("Use the", 1, "default", &default_group_number);
EXPECT_EQ(other_hard_coded_trial, forced_trial);
int would_win_group = other_hard_coded_trial->AppendGroup("Force", 1);
@@ -647,13 +633,10 @@ TEST_F(FieldTrialTest, SetForcedDefaultOnly) {
int default_group = -1;
FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
trial->SetForced();
- trial = FieldTrialList::FactoryGetFieldTrial(kTrialName, 100,
- kDefaultGroupName, next_year_,
- 12, 31, NULL);
+ trial = CreateFieldTrial(kTrialName, 100, kDefaultGroupName, NULL);
EXPECT_EQ(default_group, trial->group());
EXPECT_EQ(kDefaultGroupName, trial->group_name());
}
@@ -664,13 +647,10 @@ TEST_F(FieldTrialTest, SetForcedDefaultWithExtraGroup) {
int default_group = -1;
FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
trial->SetForced();
- trial = FieldTrialList::FactoryGetFieldTrial(kTrialName, 100,
- kDefaultGroupName, next_year_,
- 12, 31, NULL);
+ trial = CreateFieldTrial(kTrialName, 100, kDefaultGroupName, NULL);
const int extra_group = trial->AppendGroup("Extra", 100);
EXPECT_EQ(default_group, trial->group());
EXPECT_NE(extra_group, trial->group());
@@ -685,15 +665,13 @@ TEST_F(FieldTrialTest, SetForcedTurnFeatureOn) {
// Simulate a server-side (forced) config that turns the feature on when the
// original hard-coded config had it disabled.
FieldTrial* forced_trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, NULL);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, NULL);
forced_trial->AppendGroup(kExtraGroupName, 100);
forced_trial->SetForced();
int default_group = -1;
FieldTrial* client_trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
const int extra_group = client_trial->AppendGroup(kExtraGroupName, 0);
EXPECT_NE(default_group, extra_group);
@@ -711,15 +689,13 @@ TEST_F(FieldTrialTest, SetForcedTurnFeatureOff) {
// Simulate a server-side (forced) config that turns the feature off when the
// original hard-coded config had it enabled.
FieldTrial* forced_trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, NULL);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, NULL);
forced_trial->AppendGroup(kExtraGroupName, 0);
forced_trial->SetForced();
int default_group = -1;
FieldTrial* client_trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
const int extra_group = client_trial->AppendGroup(kExtraGroupName, 100);
EXPECT_NE(default_group, extra_group);
@@ -738,15 +714,13 @@ TEST_F(FieldTrialTest, SetForcedChangeDefault_Default) {
// Simulate a server-side (forced) config that switches which group is default
// and ensures that the non-forced code receives the correct group numbers.
FieldTrial* forced_trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kGroupAName,
- next_year_, 12, 31, NULL);
+ CreateFieldTrial(kTrialName, 100, kGroupAName, NULL);
forced_trial->AppendGroup(kGroupBName, 100);
forced_trial->SetForced();
int default_group = -1;
FieldTrial* client_trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kGroupBName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kGroupBName, &default_group);
const int extra_group = client_trial->AppendGroup(kGroupAName, 50);
EXPECT_NE(default_group, extra_group);
@@ -765,15 +739,13 @@ TEST_F(FieldTrialTest, SetForcedChangeDefault_NonDefault) {
// Simulate a server-side (forced) config that switches which group is default
// and ensures that the non-forced code receives the correct group numbers.
FieldTrial* forced_trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kGroupAName,
- next_year_, 12, 31, NULL);
+ CreateFieldTrial(kTrialName, 100, kGroupAName, NULL);
forced_trial->AppendGroup(kGroupBName, 0);
forced_trial->SetForced();
int default_group = -1;
FieldTrial* client_trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kGroupBName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kGroupBName, &default_group);
const int extra_group = client_trial->AppendGroup(kGroupAName, 50);
EXPECT_NE(default_group, extra_group);
@@ -790,8 +762,7 @@ TEST_F(FieldTrialTest, Observe) {
TestFieldTrialObserver observer;
int default_group = -1;
FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
const int secondary_group = trial->AppendGroup(kSecondaryGroupName, 50);
const int chosen_group = trial->group();
EXPECT_TRUE(chosen_group == default_group || chosen_group == secondary_group);
@@ -810,8 +781,7 @@ TEST_F(FieldTrialTest, ObserveDisabled) {
TestFieldTrialObserver observer;
int default_group = -1;
FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
trial->AppendGroup("A", 25);
trial->AppendGroup("B", 25);
trial->AppendGroup("C", 25);
@@ -835,8 +805,7 @@ TEST_F(FieldTrialTest, ObserveForcedDisabled) {
TestFieldTrialObserver observer;
int default_group = -1;
FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, &default_group);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
trial->AppendGroup("A", 25);
trial->AppendGroup("B", 25);
trial->AppendGroup("C", 25);
@@ -860,8 +829,7 @@ TEST_F(FieldTrialTest, DisabledTrialNotActive) {
ASSERT_FALSE(FieldTrialList::TrialExists(kTrialName));
FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
- next_year_, 12, 31, NULL);
+ CreateFieldTrial(kTrialName, 100, kDefaultGroupName, NULL);
trial->AppendGroup("X", 50);
trial->Disable();
@@ -883,9 +851,7 @@ TEST_F(FieldTrialTest, ExpirationYearNotExpired) {
ASSERT_FALSE(FieldTrialList::TrialExists(kTrialName));
FieldTrial* trial =
- FieldTrialList::FactoryGetFieldTrial(
- kTrialName, kProbability, kDefaultGroupName,
- FieldTrialList::kNoExpirationYear, 1, 1, NULL);
+ CreateFieldTrial(kTrialName, kProbability, kDefaultGroupName, NULL);
trial->AppendGroup(kGroupName, kProbability);
EXPECT_EQ(kGroupName, trial->group_name());
}