Use ScopedFieldTrials in FieldTrialsTest Resetting the global state between runs was previously handled by a RAII type, but the semantics of that type changed to remove this behavior in [1]. [1] https://webrtc-review.googlesource.com/c/src/+/276269 Bug: webrtc:14731, webrtc:14705 Change-Id: I8425cb71f49ea000434d500e0b3978324e4c3195 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/285782 Commit-Queue: Emil Lundmark <lndmrk@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38800}
diff --git a/api/BUILD.gn b/api/BUILD.gn index dfb2aa1..7d76433 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn
@@ -1367,6 +1367,7 @@ "../rtc_base/containers:flat_set", "../rtc_base/task_utils:repeating_task", "../system_wrappers:field_trial", + "../test:field_trial", "../test:fileutils", "../test:rtc_expect_death", "../test:test_support",
diff --git a/api/field_trials_unittest.cc b/api/field_trials_unittest.cc index 7366775..804b52a 100644 --- a/api/field_trials_unittest.cc +++ b/api/field_trials_unittest.cc
@@ -17,6 +17,7 @@ #include "api/transport/field_trial_based_config.h" #include "rtc_base/containers/flat_set.h" #include "system_wrappers/include/field_trial.h" +#include "test/field_trial.h" #include "test/gmock.h" #include "test/gtest.h" @@ -29,7 +30,7 @@ using ::testing::NotNull; using ::webrtc::field_trial::FieldTrialsAllowedInScopeForTesting; -using ::webrtc::field_trial::InitFieldTrialsFromString; +using ::webrtc::test::ScopedFieldTrials; TEST(FieldTrialsTest, EmptyStringHasNoEffect) { FieldTrialsAllowedInScopeForTesting k({"MyCoolTrial"}); @@ -54,8 +55,7 @@ TEST(FieldTrialsTest, FieldTrialsDoesNotReadGlobalString) { FieldTrialsAllowedInScopeForTesting k({"MyCoolTrial", "MyUncoolTrial"}); - static constexpr char s[] = "MyCoolTrial/Enabled/MyUncoolTrial/Disabled/"; - InitFieldTrialsFromString(s); + ScopedFieldTrials g("MyCoolTrial/Enabled/MyUncoolTrial/Disabled/"); FieldTrials f(""); f.RegisterKeysForTesting({"MyCoolTrial", "MyUncoolTrial"}); @@ -72,7 +72,7 @@ TEST(FieldTrialsTest, FieldTrialsRestoresGlobalStringAfterDestruction) { static constexpr char s[] = "SomeString/Enabled/"; - InitFieldTrialsFromString(s); + ScopedFieldTrials g(s); { FieldTrials f("SomeOtherString/Enabled/"); EXPECT_STREQ(webrtc::field_trial::GetFieldTrialString(), @@ -140,8 +140,7 @@ TEST(FieldTrialsTest, FieldTrialBasedConfigReadsGlobalString) { FieldTrialsAllowedInScopeForTesting k({"MyCoolTrial", "MyUncoolTrial"}); - static constexpr char s[] = "MyCoolTrial/Enabled/MyUncoolTrial/Disabled/"; - InitFieldTrialsFromString(s); + ScopedFieldTrials g("MyCoolTrial/Enabled/MyUncoolTrial/Disabled/"); FieldTrialBasedConfig f; f.RegisterKeysForTesting({"MyCoolTrial", "MyUncoolTrial"});