summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorasvitkine <asvitkine@chromium.org>2016-03-17 10:32:00 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-17 17:33:07 +0000
commit64e9e1144919a714e4fe3aa20f040846e2d5a9aa (patch)
tree8b8f75fb55fa146c77e5f1e33ea7845a84c8d9f1 /base
parent60adcbb3ec944fa45c3b7cd0c45b38b1120e7b08 (diff)
downloadchromium_src-64e9e1144919a714e4fe3aa20f040846e2d5a9aa.zip
chromium_src-64e9e1144919a714e4fe3aa20f040846e2d5a9aa.tar.gz
chromium_src-64e9e1144919a714e4fe3aa20f040846e2d5a9aa.tar.bz2
Allow trials to associate without overriding a feature.
This adds a heuristic such that if a study only references a single feature from any of its groups, its other groups will be associated with that feature as well, for reporting only. This allows a config like 25% Enabled, 25% Disabled and 50% Default to still report the users in the default group to UMA, so that they show up in the data. More details in the code comments. BUG=587135 Review URL: https://codereview.chromium.org/1809633003 Cr-Commit-Position: refs/heads/master@{#381737}
Diffstat (limited to 'base')
-rw-r--r--base/feature_list.cc7
-rw-r--r--base/feature_list.h1
-rw-r--r--base/feature_list_unittest.cc30
3 files changed, 37 insertions, 1 deletions
diff --git a/base/feature_list.cc b/base/feature_list.cc
index d10c60b..089da64 100644
--- a/base/feature_list.cc
+++ b/base/feature_list.cc
@@ -108,6 +108,8 @@ void FeatureList::GetFeatureOverrides(std::string* enable_overrides,
case OVERRIDE_DISABLE_FEATURE:
target_list = disable_overrides;
break;
+ case OVERRIDE_USE_DEFAULT:
+ continue;
}
if (!target_list->empty())
@@ -177,7 +179,10 @@ bool FeatureList::IsFeatureEnabled(const Feature& feature) {
entry.field_trial->group();
// TODO(asvitkine) Expand this section as more support is added.
- return entry.overridden_state == OVERRIDE_ENABLE_FEATURE;
+
+ // If marked as OVERRIDE_USE_DEFAULT, simply return the default state below.
+ if (entry.overridden_state != OVERRIDE_USE_DEFAULT)
+ return entry.overridden_state == OVERRIDE_ENABLE_FEATURE;
}
// Otherwise, return the default state.
return feature.default_state == FEATURE_ENABLED_BY_DEFAULT;
diff --git a/base/feature_list.h b/base/feature_list.h
index 875d3b5..90128cf 100644
--- a/base/feature_list.h
+++ b/base/feature_list.h
@@ -91,6 +91,7 @@ class BASE_EXPORT FeatureList {
// Specifies whether a feature override enables or disables the feature.
enum OverrideState {
+ OVERRIDE_USE_DEFAULT,
OVERRIDE_DISABLE_FEATURE,
OVERRIDE_ENABLE_FEATURE,
};
diff --git a/base/feature_list_unittest.cc b/base/feature_list_unittest.cc
index 11cf179..7155e86 100644
--- a/base/feature_list_unittest.cc
+++ b/base/feature_list_unittest.cc
@@ -6,6 +6,7 @@
#include <stddef.h>
+#include <algorithm>
#include <utility>
#include "base/format_macros.h"
@@ -178,6 +179,35 @@ TEST_F(FeatureListTest, FieldTrialOverrides) {
}
}
+TEST_F(FeatureListTest, FieldTrialAssociateUseDefault) {
+ FieldTrialList field_trial_list(nullptr);
+ scoped_ptr<FeatureList> feature_list(new FeatureList);
+
+ FieldTrial* trial1 = FieldTrialList::CreateFieldTrial("TrialExample1", "A");
+ FieldTrial* trial2 = FieldTrialList::CreateFieldTrial("TrialExample2", "B");
+ feature_list->RegisterFieldTrialOverride(
+ kFeatureOnByDefaultName, FeatureList::OVERRIDE_USE_DEFAULT, trial1);
+ feature_list->RegisterFieldTrialOverride(
+ kFeatureOffByDefaultName, FeatureList::OVERRIDE_USE_DEFAULT, trial2);
+ RegisterFeatureListInstance(std::move(feature_list));
+
+ // Initially, neither trial should be active.
+ EXPECT_FALSE(FieldTrialList::IsTrialActive(trial1->trial_name()));
+ EXPECT_FALSE(FieldTrialList::IsTrialActive(trial2->trial_name()));
+
+ // Check the feature enabled state is its default.
+ EXPECT_TRUE(FeatureList::IsEnabled(kFeatureOnByDefault));
+ // The above should have activated |trial1|.
+ EXPECT_TRUE(FieldTrialList::IsTrialActive(trial1->trial_name()));
+ EXPECT_FALSE(FieldTrialList::IsTrialActive(trial2->trial_name()));
+
+ // Check the feature enabled state is its default.
+ EXPECT_FALSE(FeatureList::IsEnabled(kFeatureOffByDefault));
+ // The above should have activated |trial2|.
+ EXPECT_TRUE(FieldTrialList::IsTrialActive(trial1->trial_name()));
+ EXPECT_TRUE(FieldTrialList::IsTrialActive(trial2->trial_name()));
+}
+
TEST_F(FeatureListTest, CommandLineTakesPrecedenceOverFieldTrial) {
ClearFeatureListInstance();