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

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

Issue 2701993002: DO NOT COMMIT: Results of running new (proposed) clang-format on Blink (Closed)
Patch Set: Created 3 years, 10 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/idle_helper.h" 5 #include "platform/scheduler/child/idle_helper.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 void RepostingUpdateClockIdleTestTask( 87 void RepostingUpdateClockIdleTestTask(
88 SingleThreadIdleTaskRunner* idle_task_runner, 88 SingleThreadIdleTaskRunner* idle_task_runner,
89 int* run_count, 89 int* run_count,
90 base::SimpleTestTickClock* clock, 90 base::SimpleTestTickClock* clock,
91 base::TimeDelta advance_time, 91 base::TimeDelta advance_time,
92 std::vector<base::TimeTicks>* deadlines, 92 std::vector<base::TimeTicks>* deadlines,
93 base::TimeTicks deadline) { 93 base::TimeTicks deadline) {
94 if ((*run_count + 1) < max_idle_task_reposts) { 94 if ((*run_count + 1) < max_idle_task_reposts) {
95 idle_task_runner->PostIdleTask( 95 idle_task_runner->PostIdleTask(
96 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask, 96 FROM_HERE,
97 base::Unretained(idle_task_runner), run_count, 97 base::Bind(&RepostingUpdateClockIdleTestTask,
98 clock, advance_time, deadlines)); 98 base::Unretained(idle_task_runner), run_count, clock,
99 advance_time, deadlines));
99 } 100 }
100 deadlines->push_back(deadline); 101 deadlines->push_back(deadline);
101 (*run_count)++; 102 (*run_count)++;
102 clock->Advance(advance_time); 103 clock->Advance(advance_time);
103 } 104 }
104 105
105 void RepeatingTask(base::SingleThreadTaskRunner* task_runner, 106 void RepeatingTask(base::SingleThreadTaskRunner* task_runner,
106 int num_repeats, 107 int num_repeats,
107 base::TimeDelta delay) { 108 base::TimeDelta delay) {
108 if (num_repeats > 1) { 109 if (num_repeats > 1) {
109 task_runner->PostDelayedTask( 110 task_runner->PostDelayedTask(
110 FROM_HERE, base::Bind(&RepeatingTask, base::Unretained(task_runner), 111 FROM_HERE,
111 num_repeats - 1, delay), 112 base::Bind(&RepeatingTask, base::Unretained(task_runner),
113 num_repeats - 1, delay),
112 delay); 114 delay);
113 } 115 }
114 } 116 }
115 117
116 void UpdateClockIdleTestTask(base::SimpleTestTickClock* clock, 118 void UpdateClockIdleTestTask(base::SimpleTestTickClock* clock,
117 int* run_count, 119 int* run_count,
118 base::TimeTicks set_time, 120 base::TimeTicks set_time,
119 base::TimeTicks deadline) { 121 base::TimeTicks deadline) {
120 clock->Advance(set_time - clock->NowTicks()); 122 clock->Advance(set_time - clock->NowTicks());
121 (*run_count)++; 123 (*run_count)++;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 static base::TimeDelta minimum_idle_period_duration() { 275 static base::TimeDelta minimum_idle_period_duration() {
274 return base::TimeDelta::FromMilliseconds( 276 return base::TimeDelta::FromMilliseconds(
275 IdleHelper::kMinimumIdlePeriodDurationMillis); 277 IdleHelper::kMinimumIdlePeriodDurationMillis);
276 } 278 }
277 279
278 base::TimeTicks CurrentIdleTaskDeadline() { 280 base::TimeTicks CurrentIdleTaskDeadline() {
279 return idle_helper_->CurrentIdleTaskDeadline(); 281 return idle_helper_->CurrentIdleTaskDeadline();
280 } 282 }
281 283
282 void CheckIdlePeriodStateIs(const char* expected) { 284 void CheckIdlePeriodStateIs(const char* expected) {
283 EXPECT_STREQ(expected, IdleHelper::IdlePeriodStateToString( 285 EXPECT_STREQ(expected,
284 idle_helper_->SchedulerIdlePeriodState())); 286 IdleHelper::IdlePeriodStateToString(
287 idle_helper_->SchedulerIdlePeriodState()));
285 } 288 }
286 289
287 const scoped_refptr<TaskQueue>& idle_queue() const { 290 const scoped_refptr<TaskQueue>& idle_queue() const {
288 return idle_helper_->idle_queue_; 291 return idle_helper_->idle_queue_;
289 } 292 }
290 293
291 std::unique_ptr<base::SimpleTestTickClock> clock_; 294 std::unique_ptr<base::SimpleTestTickClock> clock_;
292 // Only one of mock_task_runner_ or message_loop_ will be set. 295 // Only one of mock_task_runner_ or message_loop_ will be set.
293 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 296 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
294 std::unique_ptr<base::MessageLoop> message_loop_; 297 std::unique_ptr<base::MessageLoop> message_loop_;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 FROM_HERE, 522 FROM_HERE,
520 base::Bind(&IdleHelperWithMessageLoopTest::PostFromNestedRunloop, 523 base::Bind(&IdleHelperWithMessageLoopTest::PostFromNestedRunloop,
521 base::Unretained(this), 524 base::Unretained(this),
522 base::Unretained(&tasks_to_post_from_nested_loop))); 525 base::Unretained(&tasks_to_post_from_nested_loop)));
523 526
524 idle_helper_->StartIdlePeriod( 527 idle_helper_->StartIdlePeriod(
525 IdleHelper::IdlePeriodState::IN_SHORT_IDLE_PERIOD, clock_->NowTicks(), 528 IdleHelper::IdlePeriodState::IN_SHORT_IDLE_PERIOD, clock_->NowTicks(),
526 clock_->NowTicks() + base::TimeDelta::FromMilliseconds(10)); 529 clock_->NowTicks() + base::TimeDelta::FromMilliseconds(10));
527 RunUntilIdle(); 530 RunUntilIdle();
528 // Note we expect task 3 to run last because it's non-nestable. 531 // Note we expect task 3 to run last because it's non-nestable.
529 EXPECT_THAT(order, testing::ElementsAre(std::string("1"), std::string("2"), 532 EXPECT_THAT(
530 std::string("4"), std::string("5"), 533 order,
531 std::string("3"))); 534 testing::ElementsAre(std::string("1"), std::string("2"), std::string("4"),
535 std::string("5"), std::string("3")));
532 } 536 }
533 537
534 TEST_F(IdleHelperTestWithIdlePeriodObserver, TestLongIdlePeriod) { 538 TEST_F(IdleHelperTestWithIdlePeriodObserver, TestLongIdlePeriod) {
535 base::TimeTicks expected_deadline = 539 base::TimeTicks expected_deadline =
536 clock_->NowTicks() + maximum_idle_period_duration(); 540 clock_->NowTicks() + maximum_idle_period_duration();
537 base::TimeTicks deadline_in_task; 541 base::TimeTicks deadline_in_task;
538 int run_count = 0; 542 int run_count = 0;
539 543
540 idle_task_runner_->PostIdleTask( 544 idle_task_runner_->PostIdleTask(
541 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 545 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 // Run a repeating task so we're deemed to be busy for the next 400ms. 956 // Run a repeating task so we're deemed to be busy for the next 400ms.
953 default_task_runner_->PostTask( 957 default_task_runner_->PostTask(
954 FROM_HERE, 958 FROM_HERE,
955 base::Bind(&RepeatingTask, base::Unretained(default_task_runner_.get()), 959 base::Bind(&RepeatingTask, base::Unretained(default_task_runner_.get()),
956 10, base::TimeDelta::FromMilliseconds(40))); 960 10, base::TimeDelta::FromMilliseconds(40)));
957 961
958 int run_count = 0; 962 int run_count = 0;
959 // In this scenario EnableLongIdlePeriod deems us not to be quiescent 5x in 963 // In this scenario EnableLongIdlePeriod deems us not to be quiescent 5x in
960 // a row. 964 // a row.
961 base::TimeTicks expected_deadline = 965 base::TimeTicks expected_deadline =
962 clock_->NowTicks() + base::TimeDelta::FromMilliseconds( 966 clock_->NowTicks() +
963 5 * kQuiescenceDelayMs + kLongIdlePeriodMs); 967 base::TimeDelta::FromMilliseconds(5 * kQuiescenceDelayMs +
968 kLongIdlePeriodMs);
964 base::TimeTicks deadline_in_task; 969 base::TimeTicks deadline_in_task;
965 idle_task_runner_->PostIdleTask( 970 idle_task_runner_->PostIdleTask(
966 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 971 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
967 972
968 idle_helper_->EnableLongIdlePeriod(); 973 idle_helper_->EnableLongIdlePeriod();
969 RunUntilIdle(); 974 RunUntilIdle();
970 EXPECT_EQ(1, run_count); 975 EXPECT_EQ(1, run_count);
971 EXPECT_EQ(expected_deadline, deadline_in_task); 976 EXPECT_EQ(expected_deadline, deadline_in_task);
972 } 977 }
973 978
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 expected_deadline); 1118 expected_deadline);
1114 EXPECT_EQ(1u, idle_queue()->GetNumberOfPendingTasks()); 1119 EXPECT_EQ(1u, idle_queue()->GetNumberOfPendingTasks());
1115 RunUntilIdle(); 1120 RunUntilIdle();
1116 1121
1117 EXPECT_EQ(1, run_count); 1122 EXPECT_EQ(1, run_count);
1118 EXPECT_EQ(expected_deadline, deadline_in_task); 1123 EXPECT_EQ(expected_deadline, deadline_in_task);
1119 } 1124 }
1120 1125
1121 } // namespace scheduler 1126 } // namespace scheduler
1122 } // namespace blink 1127 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698