Index: components/scheduler/child/worker_scheduler_impl_unittest.cc |
diff --git a/components/scheduler/child/worker_scheduler_impl_unittest.cc b/components/scheduler/child/worker_scheduler_impl_unittest.cc |
index c9f34dbcb4fc10b5ea14e16df98ba82f4a8d039f..2518ae3972c9369d07d154fd1a736b3fef861787 100644 |
--- a/components/scheduler/child/worker_scheduler_impl_unittest.cc |
+++ b/components/scheduler/child/worker_scheduler_impl_unittest.cc |
@@ -26,13 +26,6 @@ int TimeTicksToIntMs(const base::TimeTicks& time) { |
return static_cast<int>((time - base::TimeTicks()).InMilliseconds()); |
} |
-void WakeUpTask(std::vector<std::string>* timeline, cc::TestNowSource* clock) { |
- if (timeline) { |
- timeline->push_back(base::StringPrintf("run WakeUpTask @ %d", |
- TimeTicksToIntMs(clock->Now()))); |
- } |
-} |
- |
void RecordTimelineTask(std::vector<std::string>* timeline, |
cc::TestNowSource* clock) { |
timeline->push_back(base::StringPrintf("run RecordTimelineTask @ %d", |
@@ -144,17 +137,6 @@ class WorkerSchedulerImplTest : public testing::Test { |
} |
} |
- void InitAndPostDelayedWakeupTask() { |
- Init(); |
- // WorkerSchedulerImpl::Init causes a delayed task to be posted on the |
- // after wakeup control runner. We need a task to wake the system up |
- // AFTER the delay for this has expired. |
- default_task_runner_->PostDelayedTask( |
- FROM_HERE, base::Bind(&WakeUpTask, base::Unretained(timeline_), |
- base::Unretained(clock_.get())), |
- base::TimeDelta::FromMilliseconds(100)); |
- } |
- |
// Helper for posting several tasks of specific types. |task_descriptor| is a |
// string with space delimited task identifiers. The first letter of each |
// task identifier specifies the task type: |
@@ -202,7 +184,7 @@ class WorkerSchedulerImplTest : public testing::Test { |
}; |
TEST_F(WorkerSchedulerImplTest, TestPostDefaultTask) { |
- InitAndPostDelayedWakeupTask(); |
+ Init(); |
std::vector<std::string> run_order; |
PostTestTasks(&run_order, "D1 D2 D3 D4"); |
@@ -214,7 +196,7 @@ TEST_F(WorkerSchedulerImplTest, TestPostDefaultTask) { |
} |
TEST_F(WorkerSchedulerImplTest, TestPostIdleTask) { |
- InitAndPostDelayedWakeupTask(); |
+ Init(); |
std::vector<std::string> run_order; |
PostTestTasks(&run_order, "I1"); |
@@ -223,17 +205,8 @@ TEST_F(WorkerSchedulerImplTest, TestPostIdleTask) { |
EXPECT_THAT(run_order, testing::ElementsAre(std::string("I1"))); |
} |
-TEST_F(WorkerSchedulerImplTest, TestPostIdleTask_NoWakeup) { |
- Init(); |
- std::vector<std::string> run_order; |
- PostTestTasks(&run_order, "I1"); |
- |
- RunUntilIdle(); |
- EXPECT_TRUE(run_order.empty()); |
-} |
- |
TEST_F(WorkerSchedulerImplTest, TestPostDefaultAndIdleTasks) { |
- InitAndPostDelayedWakeupTask(); |
+ Init(); |
std::vector<std::string> run_order; |
PostTestTasks(&run_order, "I1 D2 D3 D4"); |
@@ -244,22 +217,8 @@ TEST_F(WorkerSchedulerImplTest, TestPostDefaultAndIdleTasks) { |
std::string("D4"), std::string("I1"))); |
} |
-TEST_F(WorkerSchedulerImplTest, TestPostIdleTaskWithWakeupNeeded_NoWakeup) { |
- InitAndPostDelayedWakeupTask(); |
- |
- RunUntilIdle(); |
- // The delayed call to EnableLongIdlePeriod happened and it posted a call to |
- // EnableLongIdlePeriod on the after wakeup control queue. |
- |
- std::vector<std::string> run_order; |
- PostTestTasks(&run_order, "I1"); |
- |
- RunUntilIdle(); |
- EXPECT_TRUE(run_order.empty()); |
-} |
- |
TEST_F(WorkerSchedulerImplTest, TestPostDefaultDelayedAndIdleTasks) { |
- InitAndPostDelayedWakeupTask(); |
+ Init(); |
std::vector<std::string> run_order; |
PostTestTasks(&run_order, "I1 D2 D3 D4"); |
@@ -275,17 +234,46 @@ TEST_F(WorkerSchedulerImplTest, TestPostDefaultDelayedAndIdleTasks) { |
std::string("DELAYED"))); |
} |
+TEST_F(WorkerSchedulerImplTest, TestIdleTaskWhenIsNotQuiescent) { |
+ std::vector<std::string> timeline; |
+ RecordTimelineEvents(&timeline); |
+ Init(); |
+ |
+ timeline.push_back("Post default task"); |
+ // Post a delayed task timed to occur mid way during the long idle period. |
+ default_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&RecordTimelineTask, base::Unretained(&timeline), |
+ base::Unretained(clock_.get()))); |
+ RunUntilIdle(); |
+ |
+ timeline.push_back("Post idle task"); |
+ idle_task_runner_->PostIdleTask(FROM_HERE, |
+ base::Bind(&TimelineIdleTestTask, &timeline)); |
+ |
+ RunUntilIdle(); |
+ |
+ std::string expected_timeline[] = {"CanEnterLongIdlePeriod @ 5", |
+ "Post default task", |
+ "run RecordTimelineTask @ 5", |
+ "Post idle task", |
+ "IsNotQuiescent @ 5", |
+ "CanEnterLongIdlePeriod @ 305", |
+ "run TimelineIdleTestTask deadline 355"}; |
+ |
+ EXPECT_THAT(timeline, ElementsAreArray(expected_timeline)); |
+} |
+ |
TEST_F(WorkerSchedulerImplTest, TestIdleDeadlineWithPendingDelayedTask) { |
std::vector<std::string> timeline; |
RecordTimelineEvents(&timeline); |
- InitAndPostDelayedWakeupTask(); |
+ Init(); |
timeline.push_back("Post delayed and idle tasks"); |
// Post a delayed task timed to occur mid way during the long idle period. |
default_task_runner_->PostDelayedTask( |
FROM_HERE, base::Bind(&RecordTimelineTask, base::Unretained(&timeline), |
base::Unretained(clock_.get())), |
- base::TimeDelta::FromMilliseconds(420)); |
+ base::TimeDelta::FromMilliseconds(20)); |
idle_task_runner_->PostIdleTask(FROM_HERE, |
base::Bind(&TimelineIdleTestTask, &timeline)); |
@@ -294,11 +282,9 @@ TEST_F(WorkerSchedulerImplTest, TestIdleDeadlineWithPendingDelayedTask) { |
std::string expected_timeline[] = { |
"CanEnterLongIdlePeriod @ 5", |
"Post delayed and idle tasks", |
- "IsNotQuiescent @ 105", |
- "CanEnterLongIdlePeriod @ 405", |
- "run TimelineIdleTestTask deadline 425", // Note the short 20ms deadline. |
- "CanEnterLongIdlePeriod @ 425", |
- "run RecordTimelineTask @ 425"}; |
+ "CanEnterLongIdlePeriod @ 5", |
+ "run TimelineIdleTestTask deadline 25", // Note the short 20ms deadline. |
+ "run RecordTimelineTask @ 25"}; |
EXPECT_THAT(timeline, ElementsAreArray(expected_timeline)); |
} |
@@ -307,14 +293,14 @@ TEST_F(WorkerSchedulerImplTest, |
TestIdleDeadlineWithPendingDelayedTaskFarInTheFuture) { |
std::vector<std::string> timeline; |
RecordTimelineEvents(&timeline); |
- InitAndPostDelayedWakeupTask(); |
+ Init(); |
timeline.push_back("Post delayed and idle tasks"); |
// Post a delayed task timed to occur well after the long idle period. |
default_task_runner_->PostDelayedTask( |
FROM_HERE, base::Bind(&RecordTimelineTask, base::Unretained(&timeline), |
base::Unretained(clock_.get())), |
- base::TimeDelta::FromMilliseconds(1000)); |
+ base::TimeDelta::FromMilliseconds(500)); |
idle_task_runner_->PostIdleTask(FROM_HERE, |
base::Bind(&TimelineIdleTestTask, &timeline)); |
@@ -323,43 +309,19 @@ TEST_F(WorkerSchedulerImplTest, |
std::string expected_timeline[] = { |
"CanEnterLongIdlePeriod @ 5", |
"Post delayed and idle tasks", |
- "IsNotQuiescent @ 105", |
- "CanEnterLongIdlePeriod @ 405", |
- "run TimelineIdleTestTask deadline 455", // Note the full 50ms deadline. |
- "CanEnterLongIdlePeriod @ 455", |
- "run RecordTimelineTask @ 1005"}; |
+ "CanEnterLongIdlePeriod @ 5", |
+ "run TimelineIdleTestTask deadline 55", // Note the full 50ms deadline. |
+ "run RecordTimelineTask @ 505"}; |
EXPECT_THAT(timeline, ElementsAreArray(expected_timeline)); |
} |
-TEST_F(WorkerSchedulerImplTest, |
- TestPostIdleTaskAfterRunningUntilIdle_NoWakeUp) { |
- InitAndPostDelayedWakeupTask(); |
- |
- default_task_runner_->PostDelayedTask( |
- FROM_HERE, base::Bind(&NopTask), base::TimeDelta::FromMilliseconds(1000)); |
- RunUntilIdle(); |
- |
- // The delayed call to EnableLongIdlePeriod happened and it posted a call to |
- // EnableLongIdlePeriod on the after wakeup control queue. Without an other |
- // non-idle task posted, the idle tasks won't run. |
- std::vector<std::string> run_order; |
- PostTestTasks(&run_order, "I1 I2"); |
- |
- RunUntilIdle(); |
- EXPECT_TRUE(run_order.empty()); |
-} |
- |
-TEST_F(WorkerSchedulerImplTest, |
- TestPostIdleTaskAfterRunningUntilIdle_WithWakeUp) { |
- InitAndPostDelayedWakeupTask(); |
+TEST_F(WorkerSchedulerImplTest, TestPostIdleTaskAfterRunningUntilIdle) { |
+ Init(); |
default_task_runner_->PostDelayedTask( |
FROM_HERE, base::Bind(&NopTask), base::TimeDelta::FromMilliseconds(1000)); |
RunUntilIdle(); |
- // The delayed call to EnableLongIdlePeriod happened and it posted a call to |
- // EnableLongIdlePeriod on the after wakeup control queue. Without an other |
- // non-idle task posted, the idle tasks won't run. |
std::vector<std::string> run_order; |
PostTestTasks(&run_order, "I1 I2 D3"); |
@@ -417,8 +379,7 @@ TEST_F(WorkerSchedulerImplTest, TestLongIdlePeriodTimeline) { |
"IsNotQuiescent @ 55", // NOTE we have to wait for quiescence. |
"CanEnterLongIdlePeriod @ 355", |
"run TimelineIdleTestTask deadline 405", |
- "CanEnterLongIdlePeriod @ 405", |
- "RunUntilIdle end @ 455"}; |
+ "RunUntilIdle end @ 355"}; |
EXPECT_THAT(timeline, ElementsAreArray(expected_timeline)); |
} |