Commit 8a09ec16 authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Do not instantiate base::FieldTrialList explicitly in tests

Recent patches introduced the initialization of FieldTrialList as part
of the test suite, hence it's no longer necessary to do so explicitly.

This patch addresses unit tests related to metrics and variations.

Bug: 1018667
Change-Id: If091b24ca3a4943841228d850c0166c14ffb3db8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884730Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715142}
parent a71bbbb8
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/scoped_field_trial_list_resetter.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace base { namespace base {
...@@ -143,6 +144,7 @@ TEST_F(FeatureListTest, FieldTrialOverrides) { ...@@ -143,6 +144,7 @@ TEST_F(FeatureListTest, FieldTrialOverrides) {
const auto& test_case = test_cases[i]; const auto& test_case = test_cases[i];
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]", i)); SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]", i));
test::ScopedFieldTrialListResetter resetter;
FieldTrialList field_trial_list(nullptr); FieldTrialList field_trial_list(nullptr);
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
...@@ -176,7 +178,6 @@ TEST_F(FeatureListTest, FieldTrialOverrides) { ...@@ -176,7 +178,6 @@ TEST_F(FeatureListTest, FieldTrialOverrides) {
} }
TEST_F(FeatureListTest, FieldTrialAssociateUseDefault) { TEST_F(FeatureListTest, FieldTrialAssociateUseDefault) {
FieldTrialList field_trial_list(nullptr);
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
FieldTrial* trial1 = FieldTrialList::CreateFieldTrial("TrialExample1", "A"); FieldTrial* trial1 = FieldTrialList::CreateFieldTrial("TrialExample1", "A");
...@@ -206,7 +207,6 @@ TEST_F(FeatureListTest, FieldTrialAssociateUseDefault) { ...@@ -206,7 +207,6 @@ TEST_F(FeatureListTest, FieldTrialAssociateUseDefault) {
} }
TEST_F(FeatureListTest, CommandLineEnableTakesPrecedenceOverFieldTrial) { TEST_F(FeatureListTest, CommandLineEnableTakesPrecedenceOverFieldTrial) {
FieldTrialList field_trial_list(nullptr);
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
// The feature is explicitly enabled on the command-line. // The feature is explicitly enabled on the command-line.
...@@ -229,7 +229,6 @@ TEST_F(FeatureListTest, CommandLineEnableTakesPrecedenceOverFieldTrial) { ...@@ -229,7 +229,6 @@ TEST_F(FeatureListTest, CommandLineEnableTakesPrecedenceOverFieldTrial) {
} }
TEST_F(FeatureListTest, CommandLineDisableTakesPrecedenceOverFieldTrial) { TEST_F(FeatureListTest, CommandLineDisableTakesPrecedenceOverFieldTrial) {
FieldTrialList field_trial_list(nullptr);
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
// The feature is explicitly disabled on the command-line. // The feature is explicitly disabled on the command-line.
...@@ -252,7 +251,6 @@ TEST_F(FeatureListTest, CommandLineDisableTakesPrecedenceOverFieldTrial) { ...@@ -252,7 +251,6 @@ TEST_F(FeatureListTest, CommandLineDisableTakesPrecedenceOverFieldTrial) {
} }
TEST_F(FeatureListTest, IsFeatureOverriddenFromCommandLine) { TEST_F(FeatureListTest, IsFeatureOverriddenFromCommandLine) {
FieldTrialList field_trial_list(nullptr);
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
// No features are overridden from the command line yet // No features are overridden from the command line yet
...@@ -326,6 +324,7 @@ TEST_F(FeatureListTest, AssociateReportingFieldTrial) { ...@@ -326,6 +324,7 @@ TEST_F(FeatureListTest, AssociateReportingFieldTrial) {
test_case.enable_features, test_case.enable_features,
test_case.disable_features)); test_case.disable_features));
test::ScopedFieldTrialListResetter resetter;
FieldTrialList field_trial_list(nullptr); FieldTrialList field_trial_list(nullptr);
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
feature_list->InitializeFromCommandLine(test_case.enable_features, feature_list->InitializeFromCommandLine(test_case.enable_features,
...@@ -410,7 +409,6 @@ TEST_F(FeatureListTest, InitializeFromCommandLineThenRegisterExtraOverrides) { ...@@ -410,7 +409,6 @@ TEST_F(FeatureListTest, InitializeFromCommandLineThenRegisterExtraOverrides) {
} }
TEST_F(FeatureListTest, GetFeatureOverrides) { TEST_F(FeatureListTest, GetFeatureOverrides) {
FieldTrialList field_trial_list(nullptr);
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
feature_list->InitializeFromCommandLine("A,X", "D"); feature_list->InitializeFromCommandLine("A,X", "D");
...@@ -445,7 +443,6 @@ TEST_F(FeatureListTest, GetFeatureOverrides) { ...@@ -445,7 +443,6 @@ TEST_F(FeatureListTest, GetFeatureOverrides) {
} }
TEST_F(FeatureListTest, GetFeatureOverrides_UseDefault) { TEST_F(FeatureListTest, GetFeatureOverrides_UseDefault) {
FieldTrialList field_trial_list(nullptr);
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
feature_list->InitializeFromCommandLine("A,X", "D"); feature_list->InitializeFromCommandLine("A,X", "D");
...@@ -465,7 +462,6 @@ TEST_F(FeatureListTest, GetFeatureOverrides_UseDefault) { ...@@ -465,7 +462,6 @@ TEST_F(FeatureListTest, GetFeatureOverrides_UseDefault) {
} }
TEST_F(FeatureListTest, GetFieldTrial) { TEST_F(FeatureListTest, GetFieldTrial) {
FieldTrialList field_trial_list(nullptr);
FieldTrial* trial = FieldTrialList::CreateFieldTrial("Trial", "Group"); FieldTrial* trial = FieldTrialList::CreateFieldTrial("Trial", "Group");
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
feature_list->RegisterFieldTrialOverride( feature_list->RegisterFieldTrialOverride(
...@@ -478,7 +474,6 @@ TEST_F(FeatureListTest, GetFieldTrial) { ...@@ -478,7 +474,6 @@ TEST_F(FeatureListTest, GetFieldTrial) {
} }
TEST_F(FeatureListTest, InitializeFromCommandLine_WithFieldTrials) { TEST_F(FeatureListTest, InitializeFromCommandLine_WithFieldTrials) {
FieldTrialList field_trial_list(nullptr);
FieldTrialList::CreateFieldTrial("Trial", "Group"); FieldTrialList::CreateFieldTrial("Trial", "Group");
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
feature_list->InitializeFromCommandLine("A,OffByDefault<Trial,X", "D"); feature_list->InitializeFromCommandLine("A,OffByDefault<Trial,X", "D");
...@@ -491,7 +486,6 @@ TEST_F(FeatureListTest, InitializeFromCommandLine_WithFieldTrials) { ...@@ -491,7 +486,6 @@ TEST_F(FeatureListTest, InitializeFromCommandLine_WithFieldTrials) {
} }
TEST_F(FeatureListTest, InitializeFromCommandLine_UseDefault) { TEST_F(FeatureListTest, InitializeFromCommandLine_UseDefault) {
FieldTrialList field_trial_list(nullptr);
FieldTrialList::CreateFieldTrial("T1", "Group"); FieldTrialList::CreateFieldTrial("T1", "Group");
FieldTrialList::CreateFieldTrial("T2", "Group"); FieldTrialList::CreateFieldTrial("T2", "Group");
auto feature_list = std::make_unique<FeatureList>(); auto feature_list = std::make_unique<FeatureList>();
...@@ -578,7 +572,6 @@ TEST_F(FeatureListTest, StoreAndRetrieveFeaturesFromSharedMemory) { ...@@ -578,7 +572,6 @@ TEST_F(FeatureListTest, StoreAndRetrieveFeaturesFromSharedMemory) {
} }
TEST_F(FeatureListTest, StoreAndRetrieveAssociatedFeaturesFromSharedMemory) { TEST_F(FeatureListTest, StoreAndRetrieveAssociatedFeaturesFromSharedMemory) {
FieldTrialList field_trial_list(nullptr);
std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
// Create some overrides. // Create some overrides.
......
...@@ -30,7 +30,7 @@ scoped_refptr<FieldTrial> CreateFieldTrial( ...@@ -30,7 +30,7 @@ scoped_refptr<FieldTrial> CreateFieldTrial(
class FieldTrialParamsTest : public ::testing::Test { class FieldTrialParamsTest : public ::testing::Test {
public: public:
FieldTrialParamsTest() : field_trial_list_(nullptr) {} FieldTrialParamsTest() = default;
~FieldTrialParamsTest() override { ~FieldTrialParamsTest() override {
// Ensure that the maps are cleared between tests, since they are stored as // Ensure that the maps are cleared between tests, since they are stored as
...@@ -48,7 +48,6 @@ class FieldTrialParamsTest : public ::testing::Test { ...@@ -48,7 +48,6 @@ class FieldTrialParamsTest : public ::testing::Test {
} }
private: private:
FieldTrialList field_trial_list_;
test::ScopedFeatureList scoped_feature_list_; test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(FieldTrialParamsTest); DISALLOW_COPY_AND_ASSIGN(FieldTrialParamsTest);
......
...@@ -106,6 +106,9 @@ class FieldTrialTest : public ::testing::Test { ...@@ -106,6 +106,9 @@ class FieldTrialTest : public ::testing::Test {
private: private:
test::TaskEnvironment task_environment_; test::TaskEnvironment task_environment_;
// The test suite instantiates a FieldTrialList but for the purpose of these
// tests it's cleaner to start from scratch.
test::ScopedFieldTrialListResetter trial_list_resetter_;
FieldTrialList trial_list_; FieldTrialList trial_list_;
DISALLOW_COPY_AND_ASSIGN(FieldTrialTest); DISALLOW_COPY_AND_ASSIGN(FieldTrialTest);
...@@ -1132,6 +1135,10 @@ TEST_F(FieldTrialTest, CreateSimulatedFieldTrial) { ...@@ -1132,6 +1135,10 @@ TEST_F(FieldTrialTest, CreateSimulatedFieldTrial) {
TEST(FieldTrialTestWithoutList, StatesStringFormat) { TEST(FieldTrialTestWithoutList, StatesStringFormat) {
std::string save_string; std::string save_string;
// The test suite instantiates a FieldTrialList but for the purpose of these
// tests it's cleaner to start from scratch.
test::ScopedFieldTrialListResetter trial_list_resetter_;
// Scoping the first FieldTrialList, as we need another one to test the // Scoping the first FieldTrialList, as we need another one to test the
// importing function. // importing function.
{ {
...@@ -1176,6 +1183,16 @@ TEST(FieldTrialDeathTest, OneTimeRandomizedTrialWithoutFieldTrialList) { ...@@ -1176,6 +1183,16 @@ TEST(FieldTrialDeathTest, OneTimeRandomizedTrialWithoutFieldTrialList) {
""); "");
} }
class FieldTrialListTest : public ::testing::Test {
public:
FieldTrialListTest() = default;
private:
// The test suite instantiates a FieldTrialList but for the purpose of these
// tests it's cleaner to start from scratch.
test::ScopedFieldTrialListResetter trial_list_resetter_;
};
#if defined(OS_FUCHSIA) #if defined(OS_FUCHSIA)
// TODO(crbug.com/752368): This is flaky on Fuchsia. // TODO(crbug.com/752368): This is flaky on Fuchsia.
#define MAYBE_TestCopyFieldTrialStateToFlags \ #define MAYBE_TestCopyFieldTrialStateToFlags \
...@@ -1183,7 +1200,7 @@ TEST(FieldTrialDeathTest, OneTimeRandomizedTrialWithoutFieldTrialList) { ...@@ -1183,7 +1200,7 @@ TEST(FieldTrialDeathTest, OneTimeRandomizedTrialWithoutFieldTrialList) {
#else #else
#define MAYBE_TestCopyFieldTrialStateToFlags TestCopyFieldTrialStateToFlags #define MAYBE_TestCopyFieldTrialStateToFlags TestCopyFieldTrialStateToFlags
#endif #endif
TEST(FieldTrialListTest, MAYBE_TestCopyFieldTrialStateToFlags) { TEST_F(FieldTrialListTest, MAYBE_TestCopyFieldTrialStateToFlags) {
constexpr char kFieldTrialHandleSwitch[] = "test-field-trial-handle"; constexpr char kFieldTrialHandleSwitch[] = "test-field-trial-handle";
constexpr char kEnableFeaturesSwitch[] = "test-enable-features"; constexpr char kEnableFeaturesSwitch[] = "test-enable-features";
constexpr char kDisableFeaturesSwitch[] = "test-disable-features"; constexpr char kDisableFeaturesSwitch[] = "test-disable-features";
...@@ -1213,7 +1230,7 @@ TEST(FieldTrialListTest, MAYBE_TestCopyFieldTrialStateToFlags) { ...@@ -1213,7 +1230,7 @@ TEST(FieldTrialListTest, MAYBE_TestCopyFieldTrialStateToFlags) {
EXPECT_EQ("C", command_line.GetSwitchValueASCII(kDisableFeaturesSwitch)); EXPECT_EQ("C", command_line.GetSwitchValueASCII(kDisableFeaturesSwitch));
} }
TEST(FieldTrialListTest, InstantiateAllocator) { TEST_F(FieldTrialListTest, InstantiateAllocator) {
FieldTrialList field_trial_list(nullptr); FieldTrialList field_trial_list(nullptr);
FieldTrialList::CreateFieldTrial("Trial1", "Group1"); FieldTrialList::CreateFieldTrial("Trial1", "Group1");
...@@ -1230,16 +1247,14 @@ TEST(FieldTrialListTest, InstantiateAllocator) { ...@@ -1230,16 +1247,14 @@ TEST(FieldTrialListTest, InstantiateAllocator) {
EXPECT_EQ(used, new_used); EXPECT_EQ(used, new_used);
} }
TEST(FieldTrialListTest, AddTrialsToAllocator) { TEST_F(FieldTrialListTest, AddTrialsToAllocator) {
std::string save_string; std::string save_string;
base::ReadOnlySharedMemoryRegion shm_region; base::ReadOnlySharedMemoryRegion shm_region;
// Scoping the first FieldTrialList, as we need another one to test that it // Scoping the first FieldTrialList, as we need another one to test that it
// matches. // matches.
{ {
test::ScopedFeatureList scoped_feature_list; FieldTrialList field_trial_list1(nullptr);
scoped_feature_list.Init();
FieldTrialList::CreateFieldTrial("Trial1", "Group1"); FieldTrialList::CreateFieldTrial("Trial1", "Group1");
FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
FieldTrialList::AllStatesToString(&save_string, false); FieldTrialList::AllStatesToString(&save_string, false);
...@@ -1257,12 +1272,11 @@ TEST(FieldTrialListTest, AddTrialsToAllocator) { ...@@ -1257,12 +1272,11 @@ TEST(FieldTrialListTest, AddTrialsToAllocator) {
EXPECT_EQ(save_string, check_string); EXPECT_EQ(save_string, check_string);
} }
TEST(FieldTrialListTest, DoNotAddSimulatedFieldTrialsToAllocator) { TEST_F(FieldTrialListTest, DoNotAddSimulatedFieldTrialsToAllocator) {
constexpr char kTrialName[] = "trial"; constexpr char kTrialName[] = "trial";
base::ReadOnlySharedMemoryRegion shm_region; base::ReadOnlySharedMemoryRegion shm_region;
{ {
test::ScopedFeatureList scoped_feature_list; FieldTrialList field_trial_list1(nullptr);
scoped_feature_list.Init();
// Create a simulated trial and a real trial and call group() on them, which // Create a simulated trial and a real trial and call group() on them, which
// should only add the real trial to the field trial allocator. // should only add the real trial to the field trial allocator.
...@@ -1294,9 +1308,8 @@ TEST(FieldTrialListTest, DoNotAddSimulatedFieldTrialsToAllocator) { ...@@ -1294,9 +1308,8 @@ TEST(FieldTrialListTest, DoNotAddSimulatedFieldTrialsToAllocator) {
ASSERT_EQ(check_string.find("Simulated"), std::string::npos); ASSERT_EQ(check_string.find("Simulated"), std::string::npos);
} }
TEST(FieldTrialListTest, AssociateFieldTrialParams) { TEST_F(FieldTrialListTest, AssociateFieldTrialParams) {
test::ScopedFeatureList scoped_feature_list; FieldTrialList field_trial_list(nullptr);
scoped_feature_list.Init();
std::string trial_name("Trial1"); std::string trial_name("Trial1");
std::string group_name("Group1"); std::string group_name("Group1");
...@@ -1333,14 +1346,13 @@ TEST(FieldTrialListTest, AssociateFieldTrialParams) { ...@@ -1333,14 +1346,13 @@ TEST(FieldTrialListTest, AssociateFieldTrialParams) {
#else #else
#define MAYBE_ClearParamsFromSharedMemory ClearParamsFromSharedMemory #define MAYBE_ClearParamsFromSharedMemory ClearParamsFromSharedMemory
#endif #endif
TEST(FieldTrialListTest, MAYBE_ClearParamsFromSharedMemory) { TEST_F(FieldTrialListTest, MAYBE_ClearParamsFromSharedMemory) {
std::string trial_name("Trial1"); std::string trial_name("Trial1");
std::string group_name("Group1"); std::string group_name("Group1");
base::ReadOnlySharedMemoryRegion shm_region; base::ReadOnlySharedMemoryRegion shm_region;
{ {
test::ScopedFeatureList scoped_feature_list; FieldTrialList field_trial_list1(nullptr);
scoped_feature_list.Init();
// Create a field trial with some params. // Create a field trial with some params.
FieldTrial* trial = FieldTrial* trial =
...@@ -1382,7 +1394,7 @@ TEST(FieldTrialListTest, MAYBE_ClearParamsFromSharedMemory) { ...@@ -1382,7 +1394,7 @@ TEST(FieldTrialListTest, MAYBE_ClearParamsFromSharedMemory) {
EXPECT_EQ("*Trial1/Group1/", check_string); EXPECT_EQ("*Trial1/Group1/", check_string);
} }
TEST(FieldTrialListTest, DumpAndFetchFromSharedMemory) { TEST_F(FieldTrialListTest, DumpAndFetchFromSharedMemory) {
std::string trial_name("Trial1"); std::string trial_name("Trial1");
std::string group_name("Group1"); std::string group_name("Group1");
...@@ -1459,7 +1471,7 @@ MULTIPROCESS_TEST_MAIN(SerializeSharedMemoryRegionMetadata) { ...@@ -1459,7 +1471,7 @@ MULTIPROCESS_TEST_MAIN(SerializeSharedMemoryRegionMetadata) {
return 0; return 0;
} }
TEST(FieldTrialListTest, SerializeSharedMemoryRegionMetadata) { TEST_F(FieldTrialListTest, SerializeSharedMemoryRegionMetadata) {
base::MappedReadOnlyRegion shm = base::MappedReadOnlyRegion shm =
base::ReadOnlySharedMemoryRegion::Create(4 << 10); base::ReadOnlySharedMemoryRegion::Create(4 << 10);
ASSERT_TRUE(shm.IsValid()); ASSERT_TRUE(shm.IsValid());
...@@ -1506,13 +1518,10 @@ TEST(FieldTrialListTest, SerializeSharedMemoryRegionMetadata) { ...@@ -1506,13 +1518,10 @@ TEST(FieldTrialListTest, SerializeSharedMemoryRegionMetadata) {
// crbug.com/752368 // crbug.com/752368
#if !defined(OS_NACL) && !defined(OS_FUCHSIA) && \ #if !defined(OS_NACL) && !defined(OS_FUCHSIA) && \
!(defined(OS_MACOSX) && !defined(OS_IOS)) !(defined(OS_MACOSX) && !defined(OS_IOS))
TEST(FieldTrialListTest, CheckReadOnlySharedMemoryRegion) { TEST_F(FieldTrialListTest, CheckReadOnlySharedMemoryRegion) {
FieldTrialList field_trial_list(nullptr); FieldTrialList field_trial_list(nullptr);
FieldTrialList::CreateFieldTrial("Trial1", "Group1"); FieldTrialList::CreateFieldTrial("Trial1", "Group1");
test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.Init();
FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
base::ReadOnlySharedMemoryRegion region = base::ReadOnlySharedMemoryRegion region =
......
...@@ -114,7 +114,6 @@ TEST_F(ScopedFeatureListTest, EnableWithFeatureParameters) { ...@@ -114,7 +114,6 @@ TEST_F(ScopedFeatureListTest, EnableWithFeatureParameters) {
} }
TEST_F(ScopedFeatureListTest, OverrideWithFeatureParameters) { TEST_F(ScopedFeatureListTest, OverrideWithFeatureParameters) {
FieldTrialList field_trial_list(nullptr);
scoped_refptr<FieldTrial> trial = scoped_refptr<FieldTrial> trial =
FieldTrialList::CreateFieldTrial("foo", "bar"); FieldTrialList::CreateFieldTrial("foo", "bar");
const char kParam[] = "param_1"; const char kParam[] = "param_1";
...@@ -185,7 +184,6 @@ TEST_F(ScopedFeatureListTest, OverrideWithFeatureParameters) { ...@@ -185,7 +184,6 @@ TEST_F(ScopedFeatureListTest, OverrideWithFeatureParameters) {
} }
TEST_F(ScopedFeatureListTest, OverrideMultipleFeaturesWithParameters) { TEST_F(ScopedFeatureListTest, OverrideMultipleFeaturesWithParameters) {
FieldTrialList field_trial_list(nullptr);
scoped_refptr<FieldTrial> trial1 = scoped_refptr<FieldTrial> trial1 =
FieldTrialList::CreateFieldTrial("foo1", "bar1"); FieldTrialList::CreateFieldTrial("foo1", "bar1");
const char kParam[] = "param_1"; const char kParam[] = "param_1";
...@@ -344,7 +342,6 @@ TEST_F(ScopedFeatureListTest, FeatureOverrideFeatureWithEnabledFieldTrial) { ...@@ -344,7 +342,6 @@ TEST_F(ScopedFeatureListTest, FeatureOverrideFeatureWithEnabledFieldTrial) {
test::ScopedFeatureList feature_list1; test::ScopedFeatureList feature_list1;
std::unique_ptr<FeatureList> feature_list(new FeatureList); std::unique_ptr<FeatureList> feature_list(new FeatureList);
FieldTrialList field_trial_list(nullptr);
FieldTrial* trial = FieldTrialList::CreateFieldTrial("TrialExample", "A"); FieldTrial* trial = FieldTrialList::CreateFieldTrial("TrialExample", "A");
feature_list->RegisterFieldTrialOverride( feature_list->RegisterFieldTrialOverride(
kTestFeature1.name, FeatureList::OVERRIDE_ENABLE_FEATURE, trial); kTestFeature1.name, FeatureList::OVERRIDE_ENABLE_FEATURE, trial);
...@@ -361,7 +358,6 @@ TEST_F(ScopedFeatureListTest, FeatureOverrideFeatureWithDisabledFieldTrial) { ...@@ -361,7 +358,6 @@ TEST_F(ScopedFeatureListTest, FeatureOverrideFeatureWithDisabledFieldTrial) {
test::ScopedFeatureList feature_list1; test::ScopedFeatureList feature_list1;
std::unique_ptr<FeatureList> feature_list(new FeatureList); std::unique_ptr<FeatureList> feature_list(new FeatureList);
FieldTrialList field_trial_list(nullptr);
FieldTrial* trial = FieldTrialList::CreateFieldTrial("TrialExample", "A"); FieldTrial* trial = FieldTrialList::CreateFieldTrial("TrialExample", "A");
feature_list->RegisterFieldTrialOverride( feature_list->RegisterFieldTrialOverride(
kTestFeature1.name, FeatureList::OVERRIDE_DISABLE_FEATURE, trial); kTestFeature1.name, FeatureList::OVERRIDE_DISABLE_FEATURE, trial);
......
...@@ -54,7 +54,7 @@ std::pair<std::string, std::string> MakeStringPair(const std::string& a, ...@@ -54,7 +54,7 @@ std::pair<std::string, std::string> MakeStringPair(const std::string& a,
TEST(ChildProcessFieldTrialSyncerTest, FieldTrialState) { TEST(ChildProcessFieldTrialSyncerTest, FieldTrialState) {
base::test::SingleThreadTaskEnvironment task_environment; base::test::SingleThreadTaskEnvironment task_environment;
base::FieldTrialList field_trial_list(nullptr);
// We don't use the descriptor here anyways so it's ok to pass -1. // We don't use the descriptor here anyways so it's ok to pass -1.
base::FieldTrialList::CreateTrialsFromCommandLine( base::FieldTrialList::CreateTrialsFromCommandLine(
*base::CommandLine::ForCurrentProcess(), "field_trial_handle_switch", -1); *base::CommandLine::ForCurrentProcess(), "field_trial_handle_switch", -1);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/test/scoped_field_trial_list_resetter.h"
#include "components/variations/hashing.h" #include "components/variations/hashing.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -177,6 +178,7 @@ void PerformEntropyUniformityTest( ...@@ -177,6 +178,7 @@ void PerformEntropyUniformityTest(
} // namespace } // namespace
TEST(EntropyProviderTest, UseOneTimeRandomizationSHA1) { TEST(EntropyProviderTest, UseOneTimeRandomizationSHA1) {
base::test::ScopedFieldTrialListResetter resetter;
// Simply asserts that two trials using one-time randomization // Simply asserts that two trials using one-time randomization
// that have different names, normally generate different results. // that have different names, normally generate different results.
// //
...@@ -206,6 +208,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationSHA1) { ...@@ -206,6 +208,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationSHA1) {
} }
TEST(EntropyProviderTest, UseOneTimeRandomizationNormalizedMurmurHash) { TEST(EntropyProviderTest, UseOneTimeRandomizationNormalizedMurmurHash) {
base::test::ScopedFieldTrialListResetter resetter;
// Simply asserts that two trials using one-time randomization // Simply asserts that two trials using one-time randomization
// that have different names, normally generate different results. // that have different names, normally generate different results.
// //
...@@ -236,6 +239,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationNormalizedMurmurHash) { ...@@ -236,6 +239,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationNormalizedMurmurHash) {
} }
TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedSHA1) { TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedSHA1) {
base::test::ScopedFieldTrialListResetter resetter;
// Ensures that two trials with different names but the same custom seed used // Ensures that two trials with different names but the same custom seed used
// for one time randomization produce the same group assignments. // for one time randomization produce the same group assignments.
base::FieldTrialList field_trial_list( base::FieldTrialList field_trial_list(
...@@ -263,6 +267,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedSHA1) { ...@@ -263,6 +267,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedSHA1) {
TEST(EntropyProviderTest, TEST(EntropyProviderTest,
UseOneTimeRandomizationWithCustomSeedNormalizedMurmurHash) { UseOneTimeRandomizationWithCustomSeedNormalizedMurmurHash) {
base::test::ScopedFieldTrialListResetter resetter;
// Ensures that two trials with different names but the same custom seed used // Ensures that two trials with different names but the same custom seed used
// for one time randomization produce the same group assignments. // for one time randomization produce the same group assignments.
base::FieldTrialList field_trial_list( base::FieldTrialList field_trial_list(
......
...@@ -52,7 +52,7 @@ class TestOverrideStringCallback { ...@@ -52,7 +52,7 @@ class TestOverrideStringCallback {
class FieldTrialUtilTest : public ::testing::Test { class FieldTrialUtilTest : public ::testing::Test {
public: public:
FieldTrialUtilTest() : field_trial_list_(nullptr) {} FieldTrialUtilTest() {}
~FieldTrialUtilTest() override { ~FieldTrialUtilTest() override {
// Ensure that the maps are cleared between tests, since they are stored as // Ensure that the maps are cleared between tests, since they are stored as
...@@ -75,7 +75,6 @@ class FieldTrialUtilTest : public ::testing::Test { ...@@ -75,7 +75,6 @@ class FieldTrialUtilTest : public ::testing::Test {
} }
protected: protected:
base::FieldTrialList field_trial_list_;
TestOverrideStringCallback override_callback_; TestOverrideStringCallback override_callback_;
DISALLOW_COPY_AND_ASSIGN(FieldTrialUtilTest); DISALLOW_COPY_AND_ASSIGN(FieldTrialUtilTest);
......
...@@ -21,7 +21,6 @@ TEST(VariationsCommandLineTest, TestGetVariationsCommandLine) { ...@@ -21,7 +21,6 @@ TEST(VariationsCommandLineTest, TestGetVariationsCommandLine) {
std::string enable_feature_list = "feature1<trial1"; std::string enable_feature_list = "feature1<trial1";
std::string disable_feature_list = "feature2<trial2"; std::string disable_feature_list = "feature2<trial2";
base::FieldTrialList field_trial_list(nullptr);
AssociateParamsFromString(param_list); AssociateParamsFromString(param_list);
base::FieldTrialList::CreateTrialsFromString(trial_list, base::FieldTrialList::CreateTrialsFromString(trial_list,
std::set<std::string>()); std::set<std::string>());
...@@ -36,4 +35,4 @@ TEST(VariationsCommandLineTest, TestGetVariationsCommandLine) { ...@@ -36,4 +35,4 @@ TEST(VariationsCommandLineTest, TestGetVariationsCommandLine) {
EXPECT_NE(output.find(disable_feature_list), std::string::npos); EXPECT_NE(output.find(disable_feature_list), std::string::npos);
} }
} // namespace variations } // namespace variations
\ No newline at end of file
...@@ -268,7 +268,7 @@ class TestVariationsFieldTrialCreator : public VariationsFieldTrialCreator { ...@@ -268,7 +268,7 @@ class TestVariationsFieldTrialCreator : public VariationsFieldTrialCreator {
class FieldTrialCreatorTest : public ::testing::Test { class FieldTrialCreatorTest : public ::testing::Test {
protected: protected:
FieldTrialCreatorTest() : field_trial_list_(nullptr) { FieldTrialCreatorTest() {
VariationsService::RegisterPrefs(prefs_.registry()); VariationsService::RegisterPrefs(prefs_.registry());
global_feature_list_ = base::FeatureList::ClearInstanceForTesting(); global_feature_list_ = base::FeatureList::ClearInstanceForTesting();
} }
...@@ -288,9 +288,6 @@ class FieldTrialCreatorTest : public ::testing::Test { ...@@ -288,9 +288,6 @@ class FieldTrialCreatorTest : public ::testing::Test {
// The global feature list, which is ignored by tests in this suite. // The global feature list, which is ignored by tests in this suite.
std::unique_ptr<base::FeatureList> global_feature_list_; std::unique_ptr<base::FeatureList> global_feature_list_;
// A local FieldTrialList to hold any field trials created in this suite.
base::FieldTrialList field_trial_list_;
DISALLOW_COPY_AND_ASSIGN(FieldTrialCreatorTest); DISALLOW_COPY_AND_ASSIGN(FieldTrialCreatorTest);
}; };
......
...@@ -21,7 +21,7 @@ namespace { ...@@ -21,7 +21,7 @@ namespace {
class SyntheticTrialRegistryTest : public ::testing::Test { class SyntheticTrialRegistryTest : public ::testing::Test {
public: public:
SyntheticTrialRegistryTest() : field_trial_list_(nullptr) { InitCrashKeys(); } SyntheticTrialRegistryTest() { InitCrashKeys(); }
~SyntheticTrialRegistryTest() override { ClearCrashKeysInstanceForTesting(); } ~SyntheticTrialRegistryTest() override { ClearCrashKeysInstanceForTesting(); }
// Returns true if there is a synthetic trial in the given vector that matches // Returns true if there is a synthetic trial in the given vector that matches
...@@ -49,8 +49,6 @@ class SyntheticTrialRegistryTest : public ::testing::Test { ...@@ -49,8 +49,6 @@ class SyntheticTrialRegistryTest : public ::testing::Test {
private: private:
base::test::SingleThreadTaskEnvironment task_environment_; base::test::SingleThreadTaskEnvironment task_environment_;
base::FieldTrialList field_trial_list_;
DISALLOW_COPY_AND_ASSIGN(SyntheticTrialRegistryTest); DISALLOW_COPY_AND_ASSIGN(SyntheticTrialRegistryTest);
}; };
......
...@@ -36,7 +36,7 @@ scoped_refptr<base::FieldTrial> CreateFieldTrial( ...@@ -36,7 +36,7 @@ scoped_refptr<base::FieldTrial> CreateFieldTrial(
class VariationsAssociatedDataTest : public ::testing::Test { class VariationsAssociatedDataTest : public ::testing::Test {
public: public:
VariationsAssociatedDataTest() : field_trial_list_(nullptr) {} VariationsAssociatedDataTest() {}
~VariationsAssociatedDataTest() override { ~VariationsAssociatedDataTest() override {
// Ensure that the maps are cleared between tests, since they are stored as // Ensure that the maps are cleared between tests, since they are stored as
...@@ -45,8 +45,6 @@ class VariationsAssociatedDataTest : public ::testing::Test { ...@@ -45,8 +45,6 @@ class VariationsAssociatedDataTest : public ::testing::Test {
} }
private: private:
base::FieldTrialList field_trial_list_;
DISALLOW_COPY_AND_ASSIGN(VariationsAssociatedDataTest); DISALLOW_COPY_AND_ASSIGN(VariationsAssociatedDataTest);
}; };
......
...@@ -30,7 +30,7 @@ std::string GetNumExperimentsCrashKey() { ...@@ -30,7 +30,7 @@ std::string GetNumExperimentsCrashKey() {
class VariationsCrashKeysTest : public ::testing::Test { class VariationsCrashKeysTest : public ::testing::Test {
public: public:
VariationsCrashKeysTest() : field_trial_list_(nullptr) { VariationsCrashKeysTest() {
crash_reporter::ResetCrashKeysForTesting(); crash_reporter::ResetCrashKeysForTesting();
crash_reporter::InitializeCrashKeysForTesting(); crash_reporter::InitializeCrashKeysForTesting();
} }
...@@ -44,8 +44,6 @@ class VariationsCrashKeysTest : public ::testing::Test { ...@@ -44,8 +44,6 @@ class VariationsCrashKeysTest : public ::testing::Test {
private: private:
base::test::SingleThreadTaskEnvironment task_environment_; base::test::SingleThreadTaskEnvironment task_environment_;
base::FieldTrialList field_trial_list_;
DISALLOW_COPY_AND_ASSIGN(VariationsCrashKeysTest); DISALLOW_COPY_AND_ASSIGN(VariationsCrashKeysTest);
}; };
......
...@@ -43,8 +43,12 @@ scoped_refptr<base::FieldTrial> CreateTrialAndAssociateId( ...@@ -43,8 +43,12 @@ scoped_refptr<base::FieldTrial> CreateTrialAndAssociateId(
VariationID id) { VariationID id) {
scoped_refptr<base::FieldTrial> trial( scoped_refptr<base::FieldTrial> trial(
base::FieldTrialList::CreateFieldTrial(trial_name, default_group_name)); base::FieldTrialList::CreateFieldTrial(trial_name, default_group_name));
EXPECT_TRUE(trial);
AssociateGoogleVariationID(key, trial->trial_name(), trial->group_name(), id); if (trial) {
AssociateGoogleVariationID(key, trial->trial_name(), trial->group_name(),
id);
}
return trial; return trial;
} }
...@@ -123,7 +127,6 @@ TEST_F(VariationsHttpHeaderProviderTest, ForceVariationIds_Invalid) { ...@@ -123,7 +127,6 @@ TEST_F(VariationsHttpHeaderProviderTest, ForceVariationIds_Invalid) {
TEST_F(VariationsHttpHeaderProviderTest, OnFieldTrialGroupFinalized) { TEST_F(VariationsHttpHeaderProviderTest, OnFieldTrialGroupFinalized) {
base::test::SingleThreadTaskEnvironment task_environment; base::test::SingleThreadTaskEnvironment task_environment;
base::FieldTrialList field_trial_list(nullptr);
VariationsHttpHeaderProvider provider; VariationsHttpHeaderProvider provider;
provider.InitVariationIDsCacheIfNeeded(); provider.InitVariationIDsCacheIfNeeded();
...@@ -172,7 +175,6 @@ TEST_F(VariationsHttpHeaderProviderTest, OnFieldTrialGroupFinalized) { ...@@ -172,7 +175,6 @@ TEST_F(VariationsHttpHeaderProviderTest, OnFieldTrialGroupFinalized) {
TEST_F(VariationsHttpHeaderProviderTest, GetVariationsString) { TEST_F(VariationsHttpHeaderProviderTest, GetVariationsString) {
base::test::SingleThreadTaskEnvironment task_environment; base::test::SingleThreadTaskEnvironment task_environment;
base::FieldTrialList field_trial_list(nullptr);
CreateTrialAndAssociateId("t1", "g1", GOOGLE_WEB_PROPERTIES, 123); CreateTrialAndAssociateId("t1", "g1", GOOGLE_WEB_PROPERTIES, 123);
CreateTrialAndAssociateId("t2", "g2", GOOGLE_WEB_PROPERTIES, 124); CreateTrialAndAssociateId("t2", "g2", GOOGLE_WEB_PROPERTIES, 124);
...@@ -186,8 +188,6 @@ TEST_F(VariationsHttpHeaderProviderTest, GetVariationsString) { ...@@ -186,8 +188,6 @@ TEST_F(VariationsHttpHeaderProviderTest, GetVariationsString) {
TEST_F(VariationsHttpHeaderProviderTest, GetVariationsVector) { TEST_F(VariationsHttpHeaderProviderTest, GetVariationsVector) {
base::test::SingleThreadTaskEnvironment task_environment; base::test::SingleThreadTaskEnvironment task_environment;
base::FieldTrialList field_trial_list(nullptr);
CreateTrialAndAssociateId("t1", "g1", GOOGLE_WEB_PROPERTIES, 121); CreateTrialAndAssociateId("t1", "g1", GOOGLE_WEB_PROPERTIES, 121);
CreateTrialAndAssociateId("t2", "g2", GOOGLE_WEB_PROPERTIES, 122); CreateTrialAndAssociateId("t2", "g2", GOOGLE_WEB_PROPERTIES, 122);
CreateTrialAndAssociateId("t3", "g3", GOOGLE_WEB_PROPERTIES_TRIGGER, 123); CreateTrialAndAssociateId("t3", "g3", GOOGLE_WEB_PROPERTIES_TRIGGER, 123);
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
...@@ -57,7 +56,7 @@ void SetupAndFinalizeTrial(const std::string& trial_name, ...@@ -57,7 +56,7 @@ void SetupAndFinalizeTrial(const std::string& trial_name,
class VariationsIdCollectionTest : public ::testing::Test { class VariationsIdCollectionTest : public ::testing::Test {
public: public:
VariationsIdCollectionTest() : field_trial_list_(nullptr) {} VariationsIdCollectionTest() {}
~VariationsIdCollectionTest() override { testing::ClearAllVariationIDs(); } ~VariationsIdCollectionTest() override { testing::ClearAllVariationIDs(); }
...@@ -75,7 +74,6 @@ class VariationsIdCollectionTest : public ::testing::Test { ...@@ -75,7 +74,6 @@ class VariationsIdCollectionTest : public ::testing::Test {
private: private:
base::test::SingleThreadTaskEnvironment task_environment_; base::test::SingleThreadTaskEnvironment task_environment_;
base::FieldTrialList field_trial_list_;
std::unique_ptr<VariationsIdCollection> collection_; std::unique_ptr<VariationsIdCollection> collection_;
std::vector<VariationID> new_ids_; std::vector<VariationID> new_ids_;
}; };
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "base/test/scoped_field_trial_list_resetter.h"
namespace base { namespace base {
class CommandLine; class CommandLine;
...@@ -88,6 +89,7 @@ class VariationParamsManager { ...@@ -88,6 +89,7 @@ class VariationParamsManager {
base::CommandLine* command_line); base::CommandLine* command_line);
private: private:
base::test::ScopedFieldTrialListResetter field_trial_list_resetter_;
std::unique_ptr<base::FieldTrialList> field_trial_list_; std::unique_ptr<base::FieldTrialList> field_trial_list_;
std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_;
......
...@@ -71,7 +71,7 @@ Study_Experiment_Param* AddExperimentParam(const std::string& param_name, ...@@ -71,7 +71,7 @@ Study_Experiment_Param* AddExperimentParam(const std::string& param_name,
class VariationsSeedSimulatorTest : public ::testing::Test { class VariationsSeedSimulatorTest : public ::testing::Test {
public: public:
VariationsSeedSimulatorTest() : field_trial_list_(nullptr) {} VariationsSeedSimulatorTest() {}
~VariationsSeedSimulatorTest() override { ~VariationsSeedSimulatorTest() override {
// Ensure that the maps are cleared between tests, since they are stored as // Ensure that the maps are cleared between tests, since they are stored as
...@@ -128,8 +128,6 @@ class VariationsSeedSimulatorTest : public ::testing::Test { ...@@ -128,8 +128,6 @@ class VariationsSeedSimulatorTest : public ::testing::Test {
} }
private: private:
base::FieldTrialList field_trial_list_;
DISALLOW_COPY_AND_ASSIGN(VariationsSeedSimulatorTest); DISALLOW_COPY_AND_ASSIGN(VariationsSeedSimulatorTest);
}; };
......
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