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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/child/worker_scheduler_impl_unittest.cc

Issue 2967013002: Be explicit about namespace testing to not mix it with blink::testing (Closed)
Patch Set: Dropped mojo parts that need another review. Created 3 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "platform/scheduler/child/worker_scheduler_impl.h" 5 #include "platform/scheduler/child/worker_scheduler_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/test/simple_test_tick_clock.h" 12 #include "base/test/simple_test_tick_clock.h"
13 #include "cc/test/ordered_simple_task_runner.h" 13 #include "cc/test/ordered_simple_task_runner.h"
14 #include "platform/scheduler/base/test_time_source.h" 14 #include "platform/scheduler/base/test_time_source.h"
15 #include "platform/scheduler/child/scheduler_tqm_delegate_for_test.h" 15 #include "platform/scheduler/child/scheduler_tqm_delegate_for_test.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using testing::ElementsAreArray; 19 using ::testing::ElementsAreArray;
20 20
21 namespace blink { 21 namespace blink {
22 namespace scheduler { 22 namespace scheduler {
23 23
24 namespace { 24 namespace {
25 void NopTask() {} 25 void NopTask() {}
26 26
27 int TimeTicksToIntMs(const base::TimeTicks& time) { 27 int TimeTicksToIntMs(const base::TimeTicks& time) {
28 return static_cast<int>((time - base::TimeTicks()).InMilliseconds()); 28 return static_cast<int>((time - base::TimeTicks()).InMilliseconds());
29 } 29 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 timeline_->push_back(base::StringPrintf( 83 timeline_->push_back(base::StringPrintf(
84 "IsNotQuiescent @ %d", TimeTicksToIntMs(clock_->NowTicks()))); 84 "IsNotQuiescent @ %d", TimeTicksToIntMs(clock_->NowTicks())));
85 } 85 }
86 WorkerSchedulerImpl::IsNotQuiescent(); 86 WorkerSchedulerImpl::IsNotQuiescent();
87 } 87 }
88 88
89 base::SimpleTestTickClock* clock_; // NOT OWNED 89 base::SimpleTestTickClock* clock_; // NOT OWNED
90 std::vector<std::string>* timeline_; // NOT OWNED 90 std::vector<std::string>* timeline_; // NOT OWNED
91 }; 91 };
92 92
93 class WorkerSchedulerImplTest : public testing::Test { 93 class WorkerSchedulerImplTest : public ::testing::Test {
94 public: 94 public:
95 WorkerSchedulerImplTest() 95 WorkerSchedulerImplTest()
96 : clock_(new base::SimpleTestTickClock()), 96 : clock_(new base::SimpleTestTickClock()),
97 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_.get(), true)), 97 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_.get(), true)),
98 main_task_runner_(SchedulerTqmDelegateForTest::Create( 98 main_task_runner_(SchedulerTqmDelegateForTest::Create(
99 mock_task_runner_, 99 mock_task_runner_,
100 base::WrapUnique(new TestTimeSource(clock_.get())))), 100 base::WrapUnique(new TestTimeSource(clock_.get())))),
101 scheduler_( 101 scheduler_(
102 new WorkerSchedulerImplForTest(main_task_runner_, clock_.get())), 102 new WorkerSchedulerImplForTest(main_task_runner_, clock_.get())),
103 timeline_(nullptr) { 103 timeline_(nullptr) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 }; 183 };
184 184
185 TEST_F(WorkerSchedulerImplTest, TestPostDefaultTask) { 185 TEST_F(WorkerSchedulerImplTest, TestPostDefaultTask) {
186 Init(); 186 Init();
187 187
188 std::vector<std::string> run_order; 188 std::vector<std::string> run_order;
189 PostTestTasks(&run_order, "D1 D2 D3 D4"); 189 PostTestTasks(&run_order, "D1 D2 D3 D4");
190 190
191 RunUntilIdle(); 191 RunUntilIdle();
192 EXPECT_THAT(run_order, 192 EXPECT_THAT(run_order,
193 testing::ElementsAre(std::string("D1"), std::string("D2"), 193 ::testing::ElementsAre(std::string("D1"), std::string("D2"),
194 std::string("D3"), std::string("D4"))); 194 std::string("D3"), std::string("D4")));
195 } 195 }
196 196
197 TEST_F(WorkerSchedulerImplTest, TestPostIdleTask) { 197 TEST_F(WorkerSchedulerImplTest, TestPostIdleTask) {
198 Init(); 198 Init();
199 199
200 std::vector<std::string> run_order; 200 std::vector<std::string> run_order;
201 PostTestTasks(&run_order, "I1"); 201 PostTestTasks(&run_order, "I1");
202 202
203 RunUntilIdle(); 203 RunUntilIdle();
204 EXPECT_THAT(run_order, testing::ElementsAre(std::string("I1"))); 204 EXPECT_THAT(run_order, ::testing::ElementsAre(std::string("I1")));
205 } 205 }
206 206
207 TEST_F(WorkerSchedulerImplTest, TestPostDefaultAndIdleTasks) { 207 TEST_F(WorkerSchedulerImplTest, TestPostDefaultAndIdleTasks) {
208 Init(); 208 Init();
209 209
210 std::vector<std::string> run_order; 210 std::vector<std::string> run_order;
211 PostTestTasks(&run_order, "I1 D2 D3 D4"); 211 PostTestTasks(&run_order, "I1 D2 D3 D4");
212 212
213 RunUntilIdle(); 213 RunUntilIdle();
214 EXPECT_THAT(run_order, 214 EXPECT_THAT(run_order,
215 testing::ElementsAre(std::string("D2"), std::string("D3"), 215 ::testing::ElementsAre(std::string("D2"), std::string("D3"),
216 std::string("D4"), std::string("I1"))); 216 std::string("D4"), std::string("I1")));
217 } 217 }
218 218
219 TEST_F(WorkerSchedulerImplTest, TestPostDefaultDelayedAndIdleTasks) { 219 TEST_F(WorkerSchedulerImplTest, TestPostDefaultDelayedAndIdleTasks) {
220 Init(); 220 Init();
221 221
222 std::vector<std::string> run_order; 222 std::vector<std::string> run_order;
223 PostTestTasks(&run_order, "I1 D2 D3 D4"); 223 PostTestTasks(&run_order, "I1 D2 D3 D4");
224 224
225 default_task_runner_->PostDelayedTask( 225 default_task_runner_->PostDelayedTask(
226 FROM_HERE, base::Bind(&AppendToVectorTestTask, &run_order, "DELAYED"), 226 FROM_HERE, base::Bind(&AppendToVectorTestTask, &run_order, "DELAYED"),
227 base::TimeDelta::FromMilliseconds(1000)); 227 base::TimeDelta::FromMilliseconds(1000));
228 228
229 RunUntilIdle(); 229 RunUntilIdle();
230 EXPECT_THAT(run_order, 230 EXPECT_THAT(run_order,
231 testing::ElementsAre(std::string("D2"), std::string("D3"), 231 ::testing::ElementsAre(std::string("D2"), std::string("D3"),
232 std::string("D4"), std::string("I1"), 232 std::string("D4"), std::string("I1"),
233 std::string("DELAYED"))); 233 std::string("DELAYED")));
234 } 234 }
235 235
236 TEST_F(WorkerSchedulerImplTest, TestIdleTaskWhenIsNotQuiescent) { 236 TEST_F(WorkerSchedulerImplTest, TestIdleTaskWhenIsNotQuiescent) {
237 std::vector<std::string> timeline; 237 std::vector<std::string> timeline;
238 RecordTimelineEvents(&timeline); 238 RecordTimelineEvents(&timeline);
239 Init(); 239 Init();
240 240
241 timeline.push_back("Post default task"); 241 timeline.push_back("Post default task");
242 // Post a delayed task timed to occur mid way during the long idle period. 242 // Post a delayed task timed to occur mid way during the long idle period.
243 default_task_runner_->PostTask( 243 default_task_runner_->PostTask(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 default_task_runner_->PostDelayedTask( 319 default_task_runner_->PostDelayedTask(
320 FROM_HERE, base::Bind(&NopTask), base::TimeDelta::FromMilliseconds(1000)); 320 FROM_HERE, base::Bind(&NopTask), base::TimeDelta::FromMilliseconds(1000));
321 RunUntilIdle(); 321 RunUntilIdle();
322 322
323 std::vector<std::string> run_order; 323 std::vector<std::string> run_order;
324 PostTestTasks(&run_order, "I1 I2 D3"); 324 PostTestTasks(&run_order, "I1 I2 D3");
325 325
326 RunUntilIdle(); 326 RunUntilIdle();
327 EXPECT_THAT(run_order, 327 EXPECT_THAT(run_order,
328 testing::ElementsAre(std::string("D3"), std::string("I1"), 328 ::testing::ElementsAre(std::string("D3"), std::string("I1"),
329 std::string("I2"))); 329 std::string("I2")));
330 } 330 }
331 331
332 void PostIdleTask(std::vector<std::string>* timeline, 332 void PostIdleTask(std::vector<std::string>* timeline,
333 base::SimpleTestTickClock* clock, 333 base::SimpleTestTickClock* clock,
334 SingleThreadIdleTaskRunner* idle_task_runner) { 334 SingleThreadIdleTaskRunner* idle_task_runner) {
335 timeline->push_back(base::StringPrintf("run PostIdleTask @ %d", 335 timeline->push_back(base::StringPrintf("run PostIdleTask @ %d",
336 TimeTicksToIntMs(clock->NowTicks()))); 336 TimeTicksToIntMs(clock->NowTicks())));
337 337
338 idle_task_runner->PostIdleTask(FROM_HERE, 338 idle_task_runner->PostIdleTask(FROM_HERE,
339 base::Bind(&TimelineIdleTestTask, timeline)); 339 base::Bind(&TimelineIdleTestTask, timeline));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 "Post RecordTimelineTask", 394 "Post RecordTimelineTask",
395 "RunUntilIdle begin @ 385", 395 "RunUntilIdle begin @ 385",
396 "run RecordTimelineTask @ 385", 396 "run RecordTimelineTask @ 385",
397 "RunUntilIdle end @ 385"}; 397 "RunUntilIdle end @ 385"};
398 398
399 EXPECT_THAT(timeline, ElementsAreArray(expected_timeline)); 399 EXPECT_THAT(timeline, ElementsAreArray(expected_timeline));
400 } 400 }
401 401
402 } // namespace scheduler 402 } // namespace scheduler
403 } // namespace blink 403 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698