Chromium Code Reviews| 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 0763526a1094b3a8e490929233df8da8575ec43c..e16a75e87f4d992a8cc7287af99fa2a1a6692062 100644 |
| --- a/components/task_scheduler_util/common/variations_util_unittest.cc |
| +++ b/components/task_scheduler_util/common/variations_util_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include <string> |
| #include <vector> |
| +#include "base/command_line.h" |
| #include "base/task_scheduler/scheduler_worker_pool_params.h" |
| #include "base/threading/platform_thread.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -20,6 +21,9 @@ using StandbyThreadPolicy = |
| base::SchedulerWorkerPoolParams::StandbyThreadPolicy; |
| using ThreadPriority = base::ThreadPriority; |
| +constexpr char kTaskSchedulerVariationParamsSwitch[] = |
| + "task-scheduler-variation-params"; |
| + |
| std::vector<SchedulerConstantWorkerPoolParams> GetConstantWorkerPoolParams() { |
| std::vector<SchedulerConstantWorkerPoolParams> constant_worker_pool_params; |
| constant_worker_pool_params.emplace_back("Background", |
| @@ -145,4 +149,65 @@ TEST(TaskSchedulerUtilVariationsUtilTest, InvalidParameters) { |
| .empty()); |
| } |
| +TEST(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"; |
| + |
| + base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| + AddVariationParamsToCommandLine(in_variation_params, "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); |
| +} |
| + |
| +TEST(TaskSchedulerUtilVariationsUtilTest, |
| + CommandLineSeparatorInVariationParamsKey) { |
| + std::map<std::string, std::string> in_variation_params; |
| + in_variation_params["PrefixFoo"] = "Foo"; |
| + in_variation_params["PrefixKey|"] = "Value"; |
| + |
| + base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| + AddVariationParamsToCommandLine(in_variation_params, "Prefix", &command_line); |
| + EXPECT_TRUE( |
| + command_line.GetSwitchValueASCII(kTaskSchedulerVariationParamsSwitch) |
| + .empty()); |
| +} |
| + |
| +TEST(TaskSchedulerUtilVariationsUtilTest, |
| + CommandLineSeparatorInVariationParamsValue) { |
| + std::map<std::string, std::string> in_variation_params; |
| + in_variation_params["PrefixFoo"] = "Foo"; |
| + in_variation_params["PrefixKey"] = "Value|"; |
| + |
| + base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| + AddVariationParamsToCommandLine(in_variation_params, "Prefix", &command_line); |
| + EXPECT_TRUE( |
| + command_line.GetSwitchValueASCII(kTaskSchedulerVariationParamsSwitch) |
| + .empty()); |
| +} |
| + |
| +TEST(TaskSchedulerUtilVariationsUtilTest, CommandLineInvalidSwitch) { |
| + base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| + command_line.AppendSwitchASCII(kTaskSchedulerVariationParamsSwitch, |
| + "one|two|three"); |
| + EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty()); |
| +} |
| + |
| +TEST(TaskSchedulerUtilVariationsUtilTest, CommandLineEmptySwitch) { |
| + base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| + command_line.AppendSwitchASCII(kTaskSchedulerVariationParamsSwitch, ""); |
| + EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty()); |
| +} |
| + |
| +TEST(TaskSchedulerUtilVariationsUtilTest, CommandLineNoSwitch) { |
| + base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| + EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty()); |
| +} |
|
gab
2016/12/12 17:33:33
I wouldn't bother testing all invalid inputs. I th
gab
2017/01/05 18:40:05
ping
fdoray
2017/01/06 17:29:03
~ done. I think you didn't correctly understand th
|
| + |
| } // namespace task_scheduler_util |