Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Unified Diff: components/task_scheduler_util/common/variations_util_unittest.cc

Issue 2568793003: Control TaskScheduler initialization params in renderers via field trial. (Closed)
Patch Set: self-review Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/task_scheduler_util/common/variations_util_unittest.cc
diff --git a/components/task_scheduler_util/common/variations_util_unittest.cc b/components/task_scheduler_util/common/variations_util_unittest.cc
index 386d0b0163c0b015ab572786c6db4299302f3985..361caf1c3a7b2a3bcee9e04b7162f791c0209d75 100644
--- a/components/task_scheduler_util/common/variations_util_unittest.cc
+++ b/components/task_scheduler_util/common/variations_util_unittest.cc
@@ -8,8 +8,12 @@
#include <string>
#include <vector>
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "base/metrics/field_trial.h"
#include "base/task_scheduler/scheduler_worker_pool_params.h"
#include "base/threading/platform_thread.h"
+#include "components/variations/variations_associated_data.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace task_scheduler_util {
@@ -20,6 +24,11 @@ using StandbyThreadPolicy =
base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
using ThreadPriority = base::ThreadPriority;
+constexpr char kFieldTrialName[] = "BrowserScheduler";
+constexpr char kFieldTrialTestGroup[] = "Test";
+constexpr char kTaskSchedulerVariationParamsSwitch[] =
+ "task-scheduler-variation-params";
+
std::vector<SchedulerImmutableWorkerPoolParams> GetImmutableWorkerPoolParams() {
std::vector<SchedulerImmutableWorkerPoolParams> constant_worker_pool_params;
constant_worker_pool_params.emplace_back("Background",
@@ -33,9 +42,25 @@ std::vector<SchedulerImmutableWorkerPoolParams> GetImmutableWorkerPoolParams() {
return constant_worker_pool_params;
}
+class TaskSchedulerUtilVariationsUtilTest : public testing::Test {
+ public:
+ TaskSchedulerUtilVariationsUtilTest() : field_trial_list_(nullptr) {}
+ ~TaskSchedulerUtilVariationsUtilTest() override {
+ // Ensure that the maps are cleared between tests, since they are stored as
+ // process singletons.
+ variations::testing::ClearAllVariationIDs();
+ variations::testing::ClearAllVariationParams();
+ }
+
+ private:
+ base::FieldTrialList field_trial_list_;
gab 2017/01/06 17:41:09 = nullptr; (and make constructor = default;)
fdoray 2017/01/06 18:10:39 Doesn't work. nullptr is an argument for the const
+
+ DISALLOW_COPY_AND_ASSIGN(TaskSchedulerUtilVariationsUtilTest);
+};
+
} // namespace
-TEST(TaskSchedulerUtilVariationsUtilTest, OrderingParams5) {
+TEST_F(TaskSchedulerUtilVariationsUtilTest, OrderingParams5) {
std::map<std::string, std::string> variation_params;
variation_params["Background"] = "1;1;1;0;42";
variation_params["BackgroundFileIO"] = "2;2;1;0;52";
@@ -75,7 +100,7 @@ TEST(TaskSchedulerUtilVariationsUtilTest, OrderingParams5) {
params_vector[3].suggested_reclaim_time());
}
-TEST(TaskSchedulerUtilVariationsUtilTest, OrderingParams6) {
+TEST_F(TaskSchedulerUtilVariationsUtilTest, OrderingParams6) {
std::map<std::string, std::string> variation_params;
variation_params["Background"] = "1;1;1;0;42;lazy";
variation_params["BackgroundFileIO"] = "2;2;1;0;52;one";
@@ -117,13 +142,13 @@ TEST(TaskSchedulerUtilVariationsUtilTest, OrderingParams6) {
params_vector[3].suggested_reclaim_time());
}
-TEST(TaskSchedulerUtilVariationsUtilTest, NoData) {
+TEST_F(TaskSchedulerUtilVariationsUtilTest, NoData) {
EXPECT_TRUE(GetWorkerPoolParams(GetImmutableWorkerPoolParams(),
std::map<std::string, std::string>())
.empty());
}
-TEST(TaskSchedulerUtilVariationsUtilTest, IncompleteParameters) {
+TEST_F(TaskSchedulerUtilVariationsUtilTest, IncompleteParameters) {
std::map<std::string, std::string> variation_params;
variation_params["Background"] = "1;1;1;0";
variation_params["BackgroundFileIO"] = "2;2;1;0";
@@ -134,7 +159,7 @@ TEST(TaskSchedulerUtilVariationsUtilTest, IncompleteParameters) {
.empty());
}
-TEST(TaskSchedulerUtilVariationsUtilTest, InvalidParameters) {
+TEST_F(TaskSchedulerUtilVariationsUtilTest, InvalidParameters) {
std::map<std::string, std::string> variation_params;
variation_params["Background"] = "a;b;c;d;e";
variation_params["BackgroundFileIO"] = "a;b;c;d;e";
@@ -145,4 +170,71 @@ TEST(TaskSchedulerUtilVariationsUtilTest, InvalidParameters) {
.empty());
}
+// Verify that AddVariationParamsToCommandLine() serializes BrowserScheduler
+// variation params that start with the specified prefix to the command line and
+// that GetVariationParamsFromCommandLine() correctly deserializes them.
+TEST_F(TaskSchedulerUtilVariationsUtilTest, CommandLine) {
+ std::map<std::string, std::string> in_variation_params;
+ in_variation_params["PrefixFoo"] = "Foo";
+ in_variation_params["PrefixBar"] = "Bar";
+ in_variation_params["NoPrefix"] = "NoPrefix";
+ ASSERT_TRUE(variations::AssociateVariationParams(
+ kFieldTrialName, kFieldTrialTestGroup, in_variation_params));
+
+ base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
+ AddVariationParamsToCommandLine("Prefix", &command_line);
+ const std::map<std::string, std::string> out_variation_params =
+ GetVariationParamsFromCommandLine(command_line);
+
+ std::map<std::string, std::string> expected_out_variation_params;
+ expected_out_variation_params["PrefixFoo"] = "Foo";
+ expected_out_variation_params["PrefixBar"] = "Bar";
+ EXPECT_EQ(expected_out_variation_params, out_variation_params);
+}
+
+// Verify that AddVariationParamsToCommandLine() doesn't add anything to the
+// command line when a BrowserScheduler variation param key contains |. A key
+// that contains | wouldn't be deserialized correctly by
+// GetVariationParamsFromCommandLine().
+TEST_F(TaskSchedulerUtilVariationsUtilTest,
+ CommandLineSeparatorInVariationParamsKey) {
+ std::map<std::string, std::string> in_variation_params;
+ in_variation_params["PrefixFoo"] = "Foo";
+ in_variation_params["PrefixKey|"] = "Value";
+ ASSERT_TRUE(variations::AssociateVariationParams(
+ kFieldTrialName, kFieldTrialTestGroup, in_variation_params));
+
+ base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
+ AddVariationParamsToCommandLine("Prefix", &command_line);
+ EXPECT_TRUE(
+ command_line.GetSwitchValueASCII(kTaskSchedulerVariationParamsSwitch)
+ .empty());
+}
+
+// Verify that AddVariationParamsToCommandLine() doesn't add anything to the
+// command line when a BrowserScheduler variation param value contains |. A
+// value that contains | wouldn't be deserialized correctly by
+// GetVariationParamsFromCommandLine().
+TEST_F(TaskSchedulerUtilVariationsUtilTest,
+ CommandLineSeparatorInVariationParamsValue) {
+ std::map<std::string, std::string> in_variation_params;
+ in_variation_params["PrefixFoo"] = "Foo";
+ in_variation_params["PrefixKey"] = "Value|";
+ ASSERT_TRUE(variations::AssociateVariationParams(
+ kFieldTrialName, kFieldTrialTestGroup, in_variation_params));
+
+ base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
+ AddVariationParamsToCommandLine("Prefix", &command_line);
+ EXPECT_TRUE(
+ command_line.GetSwitchValueASCII(kTaskSchedulerVariationParamsSwitch)
+ .empty());
+}
+
+// Verify that GetVariationParamsFromCommandLine() returns an empty map when the
+// command line doesn't have a --task-scheduler-variation-params switch.
+TEST_F(TaskSchedulerUtilVariationsUtilTest, CommandLineNoSwitch) {
+ base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
+ EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty());
+}
+
} // namespace task_scheduler_util

Powered by Google App Engine
This is Rietveld 408576698