OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/task_scheduler_util/common/variations_util.h" | 5 #include "components/task_scheduler_util/common/variations_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | |
11 #include "base/task_scheduler/scheduler_worker_pool_params.h" | 12 #include "base/task_scheduler/scheduler_worker_pool_params.h" |
12 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace task_scheduler_util { | 16 namespace task_scheduler_util { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 using StandbyThreadPolicy = | 20 using StandbyThreadPolicy = |
20 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; | 21 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; |
21 using ThreadPriority = base::ThreadPriority; | 22 using ThreadPriority = base::ThreadPriority; |
22 | 23 |
24 constexpr char kTaskSchedulerVariationParamsSwitch[] = | |
25 "task-scheduler-variation-params"; | |
26 | |
23 std::vector<SchedulerConstantWorkerPoolParams> GetConstantWorkerPoolParams() { | 27 std::vector<SchedulerConstantWorkerPoolParams> GetConstantWorkerPoolParams() { |
24 std::vector<SchedulerConstantWorkerPoolParams> constant_worker_pool_params; | 28 std::vector<SchedulerConstantWorkerPoolParams> constant_worker_pool_params; |
25 constant_worker_pool_params.emplace_back("Background", | 29 constant_worker_pool_params.emplace_back("Background", |
26 ThreadPriority::BACKGROUND); | 30 ThreadPriority::BACKGROUND); |
27 constant_worker_pool_params.emplace_back("BackgroundFileIO", | 31 constant_worker_pool_params.emplace_back("BackgroundFileIO", |
28 ThreadPriority::BACKGROUND); | 32 ThreadPriority::BACKGROUND); |
29 constant_worker_pool_params.emplace_back("Foreground", | 33 constant_worker_pool_params.emplace_back("Foreground", |
30 ThreadPriority::NORMAL); | 34 ThreadPriority::NORMAL); |
31 constant_worker_pool_params.emplace_back("ForegroundFileIO", | 35 constant_worker_pool_params.emplace_back("ForegroundFileIO", |
32 ThreadPriority::NORMAL); | 36 ThreadPriority::NORMAL); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 std::map<std::string, std::string> variation_params; | 142 std::map<std::string, std::string> variation_params; |
139 variation_params["Background"] = "a;b;c;d;e"; | 143 variation_params["Background"] = "a;b;c;d;e"; |
140 variation_params["BackgroundFileIO"] = "a;b;c;d;e"; | 144 variation_params["BackgroundFileIO"] = "a;b;c;d;e"; |
141 variation_params["Foreground"] = "a;b;c;d;e"; | 145 variation_params["Foreground"] = "a;b;c;d;e"; |
142 variation_params["ForegroundFileIO"] = "a;b;c;d;e"; | 146 variation_params["ForegroundFileIO"] = "a;b;c;d;e"; |
143 EXPECT_TRUE( | 147 EXPECT_TRUE( |
144 GetWorkerPoolParams(GetConstantWorkerPoolParams(), variation_params) | 148 GetWorkerPoolParams(GetConstantWorkerPoolParams(), variation_params) |
145 .empty()); | 149 .empty()); |
146 } | 150 } |
147 | 151 |
152 TEST(TaskSchedulerUtilVariationsUtilTest, CommandLine) { | |
153 std::map<std::string, std::string> in_variation_params; | |
154 in_variation_params["PrefixFoo"] = "Foo"; | |
155 in_variation_params["PrefixBar"] = "Bar"; | |
156 in_variation_params["NoPrefix"] = "NoPrefix"; | |
157 | |
158 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
159 AddVariationParamsToCommandLine(in_variation_params, "Prefix", &command_line); | |
160 const std::map<std::string, std::string> out_variation_params = | |
161 GetVariationParamsFromCommandLine(command_line); | |
162 | |
163 std::map<std::string, std::string> expected_out_variation_params; | |
164 expected_out_variation_params["PrefixFoo"] = "Foo"; | |
165 expected_out_variation_params["PrefixBar"] = "Bar"; | |
166 EXPECT_EQ(expected_out_variation_params, out_variation_params); | |
167 } | |
168 | |
169 TEST(TaskSchedulerUtilVariationsUtilTest, | |
170 CommandLineSeparatorInVariationParamsKey) { | |
171 std::map<std::string, std::string> in_variation_params; | |
172 in_variation_params["PrefixFoo"] = "Foo"; | |
173 in_variation_params["PrefixKey|"] = "Value"; | |
174 | |
175 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
176 AddVariationParamsToCommandLine(in_variation_params, "Prefix", &command_line); | |
177 EXPECT_TRUE( | |
178 command_line.GetSwitchValueASCII(kTaskSchedulerVariationParamsSwitch) | |
179 .empty()); | |
180 } | |
181 | |
182 TEST(TaskSchedulerUtilVariationsUtilTest, | |
183 CommandLineSeparatorInVariationParamsValue) { | |
184 std::map<std::string, std::string> in_variation_params; | |
185 in_variation_params["PrefixFoo"] = "Foo"; | |
186 in_variation_params["PrefixKey"] = "Value|"; | |
187 | |
188 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
189 AddVariationParamsToCommandLine(in_variation_params, "Prefix", &command_line); | |
190 EXPECT_TRUE( | |
191 command_line.GetSwitchValueASCII(kTaskSchedulerVariationParamsSwitch) | |
192 .empty()); | |
193 } | |
194 | |
195 TEST(TaskSchedulerUtilVariationsUtilTest, CommandLineInvalidSwitch) { | |
196 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
197 command_line.AppendSwitchASCII(kTaskSchedulerVariationParamsSwitch, | |
198 "one|two|three"); | |
199 EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty()); | |
200 } | |
201 | |
202 TEST(TaskSchedulerUtilVariationsUtilTest, CommandLineEmptySwitch) { | |
203 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
204 command_line.AppendSwitchASCII(kTaskSchedulerVariationParamsSwitch, ""); | |
205 EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty()); | |
206 } | |
207 | |
208 TEST(TaskSchedulerUtilVariationsUtilTest, CommandLineNoSwitch) { | |
209 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
210 EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty()); | |
211 } | |
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
| |
212 | |
148 } // namespace task_scheduler_util | 213 } // namespace task_scheduler_util |
OLD | NEW |