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

Side by Side Diff: components/scheduler/child/idle_helper_unittest.cc

Issue 1432263002: (reland) Adds TimeDomains to the TaskQueueManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix thread_hop_task DCHECK Created 5 years, 1 month 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 "components/scheduler/child/idle_helper.h" 5 #include "components/scheduler/child/idle_helper.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "cc/test/ordered_simple_task_runner.h" 9 #include "cc/test/ordered_simple_task_runner.h"
10 #include "components/scheduler/base/real_time_domain.h"
10 #include "components/scheduler/base/task_queue.h" 11 #include "components/scheduler/base/task_queue.h"
11 #include "components/scheduler/base/task_queue_manager.h" 12 #include "components/scheduler/base/task_queue_manager.h"
12 #include "components/scheduler/base/test_time_source.h" 13 #include "components/scheduler/base/test_time_source.h"
13 #include "components/scheduler/child/scheduler_helper.h" 14 #include "components/scheduler/child/scheduler_helper.h"
14 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h" 15 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h"
15 #include "components/scheduler/child/scheduler_tqm_delegate_impl.h" 16 #include "components/scheduler/child/scheduler_tqm_delegate_impl.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using testing::_; 20 using testing::_;
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 838
838 TEST_F(IdleHelperTest, TestLongIdlePeriodPaused) { 839 TEST_F(IdleHelperTest, TestLongIdlePeriodPaused) {
839 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); 840 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true);
840 std::vector<base::TimeTicks> actual_deadlines; 841 std::vector<base::TimeTicks> actual_deadlines;
841 int run_count = 0; 842 int run_count = 0;
842 843
843 // If there are no idle tasks posted we should start in the paused state. 844 // If there are no idle tasks posted we should start in the paused state.
844 idle_helper_->EnableLongIdlePeriod(); 845 idle_helper_->EnableLongIdlePeriod();
845 CheckIdlePeriodStateIs("in_long_idle_period_paused"); 846 CheckIdlePeriodStateIs("in_long_idle_period_paused");
846 // There shouldn't be any delayed tasks posted by the idle helper when paused. 847 // There shouldn't be any delayed tasks posted by the idle helper when paused.
847 EXPECT_EQ(base::TimeTicks(), 848 base::TimeTicks next_pending_delayed_task;
848 scheduler_helper_->NextPendingDelayedTaskRunTime()); 849 EXPECT_FALSE(scheduler_helper_->real_time_domain()->NextScheduledRunTime(
850 &next_pending_delayed_task));
849 851
850 // Posting a task should transition us to the an active state. 852 // Posting a task should transition us to the an active state.
851 max_idle_task_reposts = 2; 853 max_idle_task_reposts = 2;
852 base::TimeTicks clock_before(clock_->NowTicks()); 854 base::TimeTicks clock_before(clock_->NowTicks());
853 base::TimeDelta idle_task_runtime(base::TimeDelta::FromMilliseconds(10)); 855 base::TimeDelta idle_task_runtime(base::TimeDelta::FromMilliseconds(10));
854 idle_task_runner_->PostIdleTask( 856 idle_task_runner_->PostIdleTask(
855 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask, 857 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask,
856 idle_task_runner_, &run_count, clock_.get(), 858 idle_task_runner_, &run_count, clock_.get(),
857 idle_task_runtime, &actual_deadlines)); 859 idle_task_runtime, &actual_deadlines));
858 RunUntilIdle(); 860 RunUntilIdle();
859 EXPECT_EQ(2, run_count); 861 EXPECT_EQ(2, run_count);
860 EXPECT_THAT( 862 EXPECT_THAT(
861 actual_deadlines, 863 actual_deadlines,
862 testing::ElementsAre( 864 testing::ElementsAre(
863 clock_before + maximum_idle_period_duration(), 865 clock_before + maximum_idle_period_duration(),
864 clock_before + idle_task_runtime + maximum_idle_period_duration())); 866 clock_before + idle_task_runtime + maximum_idle_period_duration()));
865 867
866 // Once all task have been run we should go back to the paused state. 868 // Once all task have been run we should go back to the paused state.
867 CheckIdlePeriodStateIs("in_long_idle_period_paused"); 869 CheckIdlePeriodStateIs("in_long_idle_period_paused");
868 EXPECT_EQ(base::TimeTicks(), 870 EXPECT_FALSE(scheduler_helper_->real_time_domain()->NextScheduledRunTime(
869 scheduler_helper_->NextPendingDelayedTaskRunTime()); 871 &next_pending_delayed_task));
870 872
871 idle_helper_->EndIdlePeriod(); 873 idle_helper_->EndIdlePeriod();
872 CheckIdlePeriodStateIs("not_in_idle_period"); 874 CheckIdlePeriodStateIs("not_in_idle_period");
873 } 875 }
874 876
875 TEST_F(IdleHelperTest, TestLongIdlePeriodWhenShutdown) { 877 TEST_F(IdleHelperTest, TestLongIdlePeriodWhenShutdown) {
876 base::TimeTicks deadline_in_task; 878 base::TimeTicks deadline_in_task;
877 int run_count = 0; 879 int run_count = 0;
878 880
879 idle_task_runner_->PostIdleTask( 881 idle_task_runner_->PostIdleTask(
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 EXPECT_EQ(0, run_count); 1138 EXPECT_EQ(0, run_count);
1137 1139
1138 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), 1140 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask),
1139 more_than_min_deadline_duration); 1141 more_than_min_deadline_duration);
1140 idle_helper_->EnableLongIdlePeriod(); 1142 idle_helper_->EnableLongIdlePeriod();
1141 RunUntilIdle(); 1143 RunUntilIdle();
1142 EXPECT_EQ(1, run_count); 1144 EXPECT_EQ(1, run_count);
1143 } 1145 }
1144 1146
1145 } // namespace scheduler 1147 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/child/idle_helper.cc ('k') | components/scheduler/child/scheduler_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698