Commit 35f89c57 authored by Alexei Svitkine's avatar Alexei Svitkine Committed by Commit Bot

Make ScopedFeatureList a no-op if Init*() is never called on it.

Previously, it would clobber state when going out of scope, which
is undesirable.

Bug: 854812
Change-Id: I2fd2859b28eed5e8247361da3b105068b348813b
Reviewed-on: https://chromium-review.googlesource.com/1112481Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569752}
parent d15bcae0
......@@ -85,10 +85,15 @@ void OverrideFeatures(const std::string& features,
ScopedFeatureList::ScopedFeatureList() = default;
ScopedFeatureList::~ScopedFeatureList() {
if (field_trial_override_)
// If one of the Init() functions was never called, don't reset anything.
if (!init_called_)
return;
if (field_trial_override_) {
base::FieldTrialParamAssociator::GetInstance()->ClearParamsForTesting(
field_trial_override_->trial_name(),
field_trial_override_->group_name());
}
FeatureList::ClearInstanceForTesting();
if (original_feature_list_)
......@@ -106,6 +111,7 @@ void ScopedFeatureList::InitWithFeatureList(
DCHECK(!original_feature_list_);
original_feature_list_ = FeatureList::ClearInstanceForTesting();
FeatureList::SetInstance(std::move(feature_list));
init_called_ = true;
}
void ScopedFeatureList::InitFromCommandLine(
......
......@@ -110,6 +110,7 @@ class ScopedFeatureList final {
void InitAndEnableFeatureWithFieldTrialOverride(const Feature& feature,
FieldTrial* trial);
bool init_called_ = false;
std::unique_ptr<FeatureList> original_feature_list_;
scoped_refptr<FieldTrial> field_trial_override_;
std::unique_ptr<base::FieldTrialList> field_trial_list_;
......
......@@ -293,5 +293,16 @@ TEST_F(ScopedFeatureListTest, FeatureOverrideKeepsOtherExistingDefaultFeature) {
}
}
TEST_F(ScopedFeatureListTest, ScopedFeatureListIsNoopWhenNotInitialized) {
test::ScopedFeatureList feature_list1;
feature_list1.InitFromCommandLine("*TestFeature1", std::string());
// A ScopedFeatureList on which Init() is not called should not reset things
// when going out of scope.
{ test::ScopedFeatureList feature_list2; }
ExpectFeatures("*TestFeature1", std::string());
}
} // namespace test
} // namespace base
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment