OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base/task_queue_manager.h" | 5 #include "components/scheduler/base/task_queue_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 for (size_t i = 0; i < 3; i++) | 146 for (size_t i = 0; i < 3; i++) |
147 runners_.push_back(manager_->NewTaskQueue(TaskQueue::Spec("test_queue"))); | 147 runners_.push_back(manager_->NewTaskQueue(TaskQueue::Spec("test_queue"))); |
148 | 148 |
149 runners_[0]->PostTask(FROM_HERE, base::Bind(&NopTask)); | 149 runners_[0]->PostTask(FROM_HERE, base::Bind(&NopTask)); |
150 runners_[0]->PostTask(FROM_HERE, base::Bind(&NopTask)); | 150 runners_[0]->PostTask(FROM_HERE, base::Bind(&NopTask)); |
151 runners_[1]->PostTask(FROM_HERE, base::Bind(&NopTask)); | 151 runners_[1]->PostTask(FROM_HERE, base::Bind(&NopTask)); |
152 runners_[1]->PostTask(FROM_HERE, base::Bind(&NopTask)); | 152 runners_[1]->PostTask(FROM_HERE, base::Bind(&NopTask)); |
153 runners_[2]->PostTask(FROM_HERE, base::Bind(&NopTask)); | 153 runners_[2]->PostTask(FROM_HERE, base::Bind(&NopTask)); |
154 runners_[2]->PostTask(FROM_HERE, base::Bind(&NopTask)); | 154 runners_[2]->PostTask(FROM_HERE, base::Bind(&NopTask)); |
155 | 155 |
156 message_loop_->RunUntilIdle(); | 156 base::RunLoop().RunUntilIdle(); |
157 // We need to call Now for the beginning of the first task, and then the end | 157 // We need to call Now for the beginning of the first task, and then the end |
158 // of every task after. We reuse the end time of one task for the start time | 158 // of every task after. We reuse the end time of one task for the start time |
159 // of the next task. In this case, there were 6 tasks, so we expect 7 calls to | 159 // of the next task. In this case, there were 6 tasks, so we expect 7 calls to |
160 // Now. | 160 // Now. |
161 EXPECT_EQ(7, test_count_uses_time_source->now_calls_count()); | 161 EXPECT_EQ(7, test_count_uses_time_source->now_calls_count()); |
162 } | 162 } |
163 | 163 |
164 TEST_F(TaskQueueManagerTest, | 164 TEST_F(TaskQueueManagerTest, |
165 NowNotCalledForNestedTasks) { | 165 NowNotCalledForNestedTasks) { |
166 message_loop_.reset(new base::MessageLoop()); | 166 message_loop_.reset(new base::MessageLoop()); |
(...skipping 14 matching lines...) Expand all Loading... |
181 for (int i = 0; i <= 6; ++i) { | 181 for (int i = 0; i <= 6; ++i) { |
182 tasks_to_post_from_nested_loop.push_back( | 182 tasks_to_post_from_nested_loop.push_back( |
183 std::make_pair(base::Bind(&NopTask), true)); | 183 std::make_pair(base::Bind(&NopTask), true)); |
184 } | 184 } |
185 | 185 |
186 runners_[0]->PostTask( | 186 runners_[0]->PostTask( |
187 FROM_HERE, base::Bind(&PostFromNestedRunloop, message_loop_.get(), | 187 FROM_HERE, base::Bind(&PostFromNestedRunloop, message_loop_.get(), |
188 base::RetainedRef(runners_[0]), | 188 base::RetainedRef(runners_[0]), |
189 base::Unretained(&tasks_to_post_from_nested_loop))); | 189 base::Unretained(&tasks_to_post_from_nested_loop))); |
190 | 190 |
191 message_loop_->RunUntilIdle(); | 191 base::RunLoop().RunUntilIdle(); |
192 // We need to call Now twice, to measure the start and end of the outermost | 192 // We need to call Now twice, to measure the start and end of the outermost |
193 // task. We shouldn't call it for any of the nested tasks. | 193 // task. We shouldn't call it for any of the nested tasks. |
194 EXPECT_EQ(2, test_count_uses_time_source->now_calls_count()); | 194 EXPECT_EQ(2, test_count_uses_time_source->now_calls_count()); |
195 } | 195 } |
196 | 196 |
197 void NullTask() {} | 197 void NullTask() {} |
198 | 198 |
199 void TestTask(EnqueueOrder value, std::vector<EnqueueOrder>* out_result) { | 199 void TestTask(EnqueueOrder value, std::vector<EnqueueOrder>* out_result) { |
200 out_result->push_back(value); | 200 out_result->push_back(value); |
201 } | 201 } |
(...skipping 25 matching lines...) Expand all Loading... |
227 EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4, 5, 6)); | 227 EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4, 5, 6)); |
228 } | 228 } |
229 | 229 |
230 TEST_F(TaskQueueManagerTest, NonNestableTaskPosting) { | 230 TEST_F(TaskQueueManagerTest, NonNestableTaskPosting) { |
231 InitializeWithRealMessageLoop(1u); | 231 InitializeWithRealMessageLoop(1u); |
232 | 232 |
233 std::vector<EnqueueOrder> run_order; | 233 std::vector<EnqueueOrder> run_order; |
234 runners_[0]->PostNonNestableTask(FROM_HERE, | 234 runners_[0]->PostNonNestableTask(FROM_HERE, |
235 base::Bind(&TestTask, 1, &run_order)); | 235 base::Bind(&TestTask, 1, &run_order)); |
236 | 236 |
237 message_loop_->RunUntilIdle(); | 237 base::RunLoop().RunUntilIdle(); |
238 EXPECT_THAT(run_order, ElementsAre(1)); | 238 EXPECT_THAT(run_order, ElementsAre(1)); |
239 } | 239 } |
240 | 240 |
241 TEST_F(TaskQueueManagerTest, NonNestableTaskExecutesInExpectedOrder) { | 241 TEST_F(TaskQueueManagerTest, NonNestableTaskExecutesInExpectedOrder) { |
242 InitializeWithRealMessageLoop(1u); | 242 InitializeWithRealMessageLoop(1u); |
243 | 243 |
244 std::vector<EnqueueOrder> run_order; | 244 std::vector<EnqueueOrder> run_order; |
245 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); | 245 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); |
246 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); | 246 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); |
247 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 3, &run_order)); | 247 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 3, &run_order)); |
248 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 4, &run_order)); | 248 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 4, &run_order)); |
249 runners_[0]->PostNonNestableTask(FROM_HERE, | 249 runners_[0]->PostNonNestableTask(FROM_HERE, |
250 base::Bind(&TestTask, 5, &run_order)); | 250 base::Bind(&TestTask, 5, &run_order)); |
251 | 251 |
252 message_loop_->RunUntilIdle(); | 252 base::RunLoop().RunUntilIdle(); |
253 EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4, 5)); | 253 EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4, 5)); |
254 } | 254 } |
255 | 255 |
256 TEST_F(TaskQueueManagerTest, NonNestableTaskDoesntExecuteInNestedLoop) { | 256 TEST_F(TaskQueueManagerTest, NonNestableTaskDoesntExecuteInNestedLoop) { |
257 InitializeWithRealMessageLoop(1u); | 257 InitializeWithRealMessageLoop(1u); |
258 | 258 |
259 std::vector<EnqueueOrder> run_order; | 259 std::vector<EnqueueOrder> run_order; |
260 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); | 260 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); |
261 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); | 261 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); |
262 | 262 |
263 std::vector<std::pair<base::Closure, bool>> tasks_to_post_from_nested_loop; | 263 std::vector<std::pair<base::Closure, bool>> tasks_to_post_from_nested_loop; |
264 tasks_to_post_from_nested_loop.push_back( | 264 tasks_to_post_from_nested_loop.push_back( |
265 std::make_pair(base::Bind(&TestTask, 3, &run_order), false)); | 265 std::make_pair(base::Bind(&TestTask, 3, &run_order), false)); |
266 tasks_to_post_from_nested_loop.push_back( | 266 tasks_to_post_from_nested_loop.push_back( |
267 std::make_pair(base::Bind(&TestTask, 4, &run_order), true)); | 267 std::make_pair(base::Bind(&TestTask, 4, &run_order), true)); |
268 tasks_to_post_from_nested_loop.push_back( | 268 tasks_to_post_from_nested_loop.push_back( |
269 std::make_pair(base::Bind(&TestTask, 5, &run_order), true)); | 269 std::make_pair(base::Bind(&TestTask, 5, &run_order), true)); |
270 | 270 |
271 runners_[0]->PostTask( | 271 runners_[0]->PostTask( |
272 FROM_HERE, base::Bind(&PostFromNestedRunloop, message_loop_.get(), | 272 FROM_HERE, base::Bind(&PostFromNestedRunloop, message_loop_.get(), |
273 base::RetainedRef(runners_[0]), | 273 base::RetainedRef(runners_[0]), |
274 base::Unretained(&tasks_to_post_from_nested_loop))); | 274 base::Unretained(&tasks_to_post_from_nested_loop))); |
275 | 275 |
276 message_loop_->RunUntilIdle(); | 276 base::RunLoop().RunUntilIdle(); |
277 // Note we expect task 3 to run last because it's non-nestable. | 277 // Note we expect task 3 to run last because it's non-nestable. |
278 EXPECT_THAT(run_order, ElementsAre(1, 2, 4, 5, 3)); | 278 EXPECT_THAT(run_order, ElementsAre(1, 2, 4, 5, 3)); |
279 } | 279 } |
280 | 280 |
281 TEST_F(TaskQueueManagerTest, QueuePolling) { | 281 TEST_F(TaskQueueManagerTest, QueuePolling) { |
282 Initialize(1u); | 282 Initialize(1u); |
283 | 283 |
284 std::vector<EnqueueOrder> run_order; | 284 std::vector<EnqueueOrder> run_order; |
285 EXPECT_FALSE(runners_[0]->HasPendingImmediateWork()); | 285 EXPECT_FALSE(runners_[0]->HasPendingImmediateWork()); |
286 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); | 286 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 TEST_F(TaskQueueManagerTest, PostFromThread) { | 635 TEST_F(TaskQueueManagerTest, PostFromThread) { |
636 InitializeWithRealMessageLoop(1u); | 636 InitializeWithRealMessageLoop(1u); |
637 | 637 |
638 std::vector<EnqueueOrder> run_order; | 638 std::vector<EnqueueOrder> run_order; |
639 base::Thread thread("TestThread"); | 639 base::Thread thread("TestThread"); |
640 thread.Start(); | 640 thread.Start(); |
641 thread.task_runner()->PostTask( | 641 thread.task_runner()->PostTask( |
642 FROM_HERE, base::Bind(&PostTaskToRunner, runners_[0], &run_order)); | 642 FROM_HERE, base::Bind(&PostTaskToRunner, runners_[0], &run_order)); |
643 thread.Stop(); | 643 thread.Stop(); |
644 | 644 |
645 message_loop_->RunUntilIdle(); | 645 base::RunLoop().RunUntilIdle(); |
646 EXPECT_THAT(run_order, ElementsAre(1)); | 646 EXPECT_THAT(run_order, ElementsAre(1)); |
647 } | 647 } |
648 | 648 |
649 void RePostingTestTask(scoped_refptr<base::SingleThreadTaskRunner> runner, | 649 void RePostingTestTask(scoped_refptr<base::SingleThreadTaskRunner> runner, |
650 int* run_count) { | 650 int* run_count) { |
651 (*run_count)++; | 651 (*run_count)++; |
652 runner->PostTask(FROM_HERE, Bind(&RePostingTestTask, | 652 runner->PostTask(FROM_HERE, Bind(&RePostingTestTask, |
653 base::Unretained(runner.get()), run_count)); | 653 base::Unretained(runner.get()), run_count)); |
654 } | 654 } |
655 | 655 |
(...skipping 19 matching lines...) Expand all Loading... |
675 tasks_to_post_from_nested_loop.push_back( | 675 tasks_to_post_from_nested_loop.push_back( |
676 std::make_pair(base::Bind(&TestTask, 1, &run_order), true)); | 676 std::make_pair(base::Bind(&TestTask, 1, &run_order), true)); |
677 | 677 |
678 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 0, &run_order)); | 678 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 0, &run_order)); |
679 runners_[0]->PostTask( | 679 runners_[0]->PostTask( |
680 FROM_HERE, base::Bind(&PostFromNestedRunloop, message_loop_.get(), | 680 FROM_HERE, base::Bind(&PostFromNestedRunloop, message_loop_.get(), |
681 base::RetainedRef(runners_[0]), | 681 base::RetainedRef(runners_[0]), |
682 base::Unretained(&tasks_to_post_from_nested_loop))); | 682 base::Unretained(&tasks_to_post_from_nested_loop))); |
683 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); | 683 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); |
684 | 684 |
685 message_loop_->RunUntilIdle(); | 685 base::RunLoop().RunUntilIdle(); |
686 | 686 |
687 EXPECT_THAT(run_order, ElementsAre(0, 2, 1)); | 687 EXPECT_THAT(run_order, ElementsAre(0, 2, 1)); |
688 } | 688 } |
689 | 689 |
690 TEST_F(TaskQueueManagerTest, WorkBatching) { | 690 TEST_F(TaskQueueManagerTest, WorkBatching) { |
691 Initialize(1u); | 691 Initialize(1u); |
692 | 692 |
693 manager_->SetWorkBatchSize(2); | 693 manager_->SetWorkBatchSize(2); |
694 | 694 |
695 std::vector<EnqueueOrder> run_order; | 695 std::vector<EnqueueOrder> run_order; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 | 865 |
866 manager_->SetWorkBatchSize(2); | 866 manager_->SetWorkBatchSize(2); |
867 manager_->AddTaskObserver(&observer); | 867 manager_->AddTaskObserver(&observer); |
868 | 868 |
869 std::vector<EnqueueOrder> run_order; | 869 std::vector<EnqueueOrder> run_order; |
870 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); | 870 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); |
871 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); | 871 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); |
872 | 872 |
873 EXPECT_CALL(observer, WillProcessTask(_)).Times(2); | 873 EXPECT_CALL(observer, WillProcessTask(_)).Times(2); |
874 EXPECT_CALL(observer, DidProcessTask(_)).Times(2); | 874 EXPECT_CALL(observer, DidProcessTask(_)).Times(2); |
875 message_loop_->RunUntilIdle(); | 875 base::RunLoop().RunUntilIdle(); |
876 } | 876 } |
877 | 877 |
878 TEST_F(TaskQueueManagerTest, TaskObserverRemoving) { | 878 TEST_F(TaskQueueManagerTest, TaskObserverRemoving) { |
879 InitializeWithRealMessageLoop(1u); | 879 InitializeWithRealMessageLoop(1u); |
880 MockTaskObserver observer; | 880 MockTaskObserver observer; |
881 manager_->SetWorkBatchSize(2); | 881 manager_->SetWorkBatchSize(2); |
882 manager_->AddTaskObserver(&observer); | 882 manager_->AddTaskObserver(&observer); |
883 manager_->RemoveTaskObserver(&observer); | 883 manager_->RemoveTaskObserver(&observer); |
884 | 884 |
885 std::vector<EnqueueOrder> run_order; | 885 std::vector<EnqueueOrder> run_order; |
886 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); | 886 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); |
887 | 887 |
888 EXPECT_CALL(observer, WillProcessTask(_)).Times(0); | 888 EXPECT_CALL(observer, WillProcessTask(_)).Times(0); |
889 EXPECT_CALL(observer, DidProcessTask(_)).Times(0); | 889 EXPECT_CALL(observer, DidProcessTask(_)).Times(0); |
890 | 890 |
891 message_loop_->RunUntilIdle(); | 891 base::RunLoop().RunUntilIdle(); |
892 } | 892 } |
893 | 893 |
894 void RemoveObserverTask(TaskQueueManager* manager, | 894 void RemoveObserverTask(TaskQueueManager* manager, |
895 base::MessageLoop::TaskObserver* observer) { | 895 base::MessageLoop::TaskObserver* observer) { |
896 manager->RemoveTaskObserver(observer); | 896 manager->RemoveTaskObserver(observer); |
897 } | 897 } |
898 | 898 |
899 TEST_F(TaskQueueManagerTest, TaskObserverRemovingInsideTask) { | 899 TEST_F(TaskQueueManagerTest, TaskObserverRemovingInsideTask) { |
900 InitializeWithRealMessageLoop(1u); | 900 InitializeWithRealMessageLoop(1u); |
901 MockTaskObserver observer; | 901 MockTaskObserver observer; |
902 manager_->SetWorkBatchSize(3); | 902 manager_->SetWorkBatchSize(3); |
903 manager_->AddTaskObserver(&observer); | 903 manager_->AddTaskObserver(&observer); |
904 | 904 |
905 runners_[0]->PostTask( | 905 runners_[0]->PostTask( |
906 FROM_HERE, base::Bind(&RemoveObserverTask, manager_.get(), &observer)); | 906 FROM_HERE, base::Bind(&RemoveObserverTask, manager_.get(), &observer)); |
907 | 907 |
908 EXPECT_CALL(observer, WillProcessTask(_)).Times(1); | 908 EXPECT_CALL(observer, WillProcessTask(_)).Times(1); |
909 EXPECT_CALL(observer, DidProcessTask(_)).Times(0); | 909 EXPECT_CALL(observer, DidProcessTask(_)).Times(0); |
910 message_loop_->RunUntilIdle(); | 910 base::RunLoop().RunUntilIdle(); |
911 } | 911 } |
912 | 912 |
913 TEST_F(TaskQueueManagerTest, QueueTaskObserverAdding) { | 913 TEST_F(TaskQueueManagerTest, QueueTaskObserverAdding) { |
914 InitializeWithRealMessageLoop(2u); | 914 InitializeWithRealMessageLoop(2u); |
915 MockTaskObserver observer; | 915 MockTaskObserver observer; |
916 | 916 |
917 manager_->SetWorkBatchSize(2); | 917 manager_->SetWorkBatchSize(2); |
918 runners_[0]->AddTaskObserver(&observer); | 918 runners_[0]->AddTaskObserver(&observer); |
919 | 919 |
920 std::vector<EnqueueOrder> run_order; | 920 std::vector<EnqueueOrder> run_order; |
921 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); | 921 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); |
922 runners_[1]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); | 922 runners_[1]->PostTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order)); |
923 | 923 |
924 EXPECT_CALL(observer, WillProcessTask(_)).Times(1); | 924 EXPECT_CALL(observer, WillProcessTask(_)).Times(1); |
925 EXPECT_CALL(observer, DidProcessTask(_)).Times(1); | 925 EXPECT_CALL(observer, DidProcessTask(_)).Times(1); |
926 message_loop_->RunUntilIdle(); | 926 base::RunLoop().RunUntilIdle(); |
927 } | 927 } |
928 | 928 |
929 TEST_F(TaskQueueManagerTest, QueueTaskObserverRemoving) { | 929 TEST_F(TaskQueueManagerTest, QueueTaskObserverRemoving) { |
930 InitializeWithRealMessageLoop(1u); | 930 InitializeWithRealMessageLoop(1u); |
931 MockTaskObserver observer; | 931 MockTaskObserver observer; |
932 manager_->SetWorkBatchSize(2); | 932 manager_->SetWorkBatchSize(2); |
933 runners_[0]->AddTaskObserver(&observer); | 933 runners_[0]->AddTaskObserver(&observer); |
934 runners_[0]->RemoveTaskObserver(&observer); | 934 runners_[0]->RemoveTaskObserver(&observer); |
935 | 935 |
936 std::vector<EnqueueOrder> run_order; | 936 std::vector<EnqueueOrder> run_order; |
937 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); | 937 runners_[0]->PostTask(FROM_HERE, base::Bind(&TestTask, 1, &run_order)); |
938 | 938 |
939 EXPECT_CALL(observer, WillProcessTask(_)).Times(0); | 939 EXPECT_CALL(observer, WillProcessTask(_)).Times(0); |
940 EXPECT_CALL(observer, DidProcessTask(_)).Times(0); | 940 EXPECT_CALL(observer, DidProcessTask(_)).Times(0); |
941 | 941 |
942 message_loop_->RunUntilIdle(); | 942 base::RunLoop().RunUntilIdle(); |
943 } | 943 } |
944 | 944 |
945 void RemoveQueueObserverTask(scoped_refptr<TaskQueue> queue, | 945 void RemoveQueueObserverTask(scoped_refptr<TaskQueue> queue, |
946 base::MessageLoop::TaskObserver* observer) { | 946 base::MessageLoop::TaskObserver* observer) { |
947 queue->RemoveTaskObserver(observer); | 947 queue->RemoveTaskObserver(observer); |
948 } | 948 } |
949 | 949 |
950 TEST_F(TaskQueueManagerTest, QueueTaskObserverRemovingInsideTask) { | 950 TEST_F(TaskQueueManagerTest, QueueTaskObserverRemovingInsideTask) { |
951 InitializeWithRealMessageLoop(1u); | 951 InitializeWithRealMessageLoop(1u); |
952 MockTaskObserver observer; | 952 MockTaskObserver observer; |
953 runners_[0]->AddTaskObserver(&observer); | 953 runners_[0]->AddTaskObserver(&observer); |
954 | 954 |
955 runners_[0]->PostTask( | 955 runners_[0]->PostTask( |
956 FROM_HERE, base::Bind(&RemoveQueueObserverTask, runners_[0], &observer)); | 956 FROM_HERE, base::Bind(&RemoveQueueObserverTask, runners_[0], &observer)); |
957 | 957 |
958 EXPECT_CALL(observer, WillProcessTask(_)).Times(1); | 958 EXPECT_CALL(observer, WillProcessTask(_)).Times(1); |
959 EXPECT_CALL(observer, DidProcessTask(_)).Times(0); | 959 EXPECT_CALL(observer, DidProcessTask(_)).Times(0); |
960 message_loop_->RunUntilIdle(); | 960 base::RunLoop().RunUntilIdle(); |
961 } | 961 } |
962 | 962 |
963 TEST_F(TaskQueueManagerTest, ThreadCheckAfterTermination) { | 963 TEST_F(TaskQueueManagerTest, ThreadCheckAfterTermination) { |
964 Initialize(1u); | 964 Initialize(1u); |
965 EXPECT_TRUE(runners_[0]->RunsTasksOnCurrentThread()); | 965 EXPECT_TRUE(runners_[0]->RunsTasksOnCurrentThread()); |
966 manager_.reset(); | 966 manager_.reset(); |
967 EXPECT_TRUE(runners_[0]->RunsTasksOnCurrentThread()); | 967 EXPECT_TRUE(runners_[0]->RunsTasksOnCurrentThread()); |
968 } | 968 } |
969 | 969 |
970 TEST_F(TaskQueueManagerTest, TimeDomain_NextScheduledRunTime) { | 970 TEST_F(TaskQueueManagerTest, TimeDomain_NextScheduledRunTime) { |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 InitializeWithRealMessageLoop(1u); | 1254 InitializeWithRealMessageLoop(1u); |
1255 manager_->SetWorkBatchSize(2); | 1255 manager_->SetWorkBatchSize(2); |
1256 | 1256 |
1257 bool was_nested = true; | 1257 bool was_nested = true; |
1258 base::RunLoop run_loop; | 1258 base::RunLoop run_loop; |
1259 runners_[0]->PostTask(FROM_HERE, base::Bind(&PostAndQuitFromNestedRunloop, | 1259 runners_[0]->PostTask(FROM_HERE, base::Bind(&PostAndQuitFromNestedRunloop, |
1260 base::Unretained(&run_loop), | 1260 base::Unretained(&run_loop), |
1261 base::RetainedRef(runners_[0]), | 1261 base::RetainedRef(runners_[0]), |
1262 base::Unretained(&was_nested))); | 1262 base::Unretained(&was_nested))); |
1263 | 1263 |
1264 message_loop_->RunUntilIdle(); | 1264 base::RunLoop().RunUntilIdle(); |
1265 EXPECT_FALSE(was_nested); | 1265 EXPECT_FALSE(was_nested); |
1266 } | 1266 } |
1267 | 1267 |
1268 class SequenceNumberCapturingTaskObserver | 1268 class SequenceNumberCapturingTaskObserver |
1269 : public base::MessageLoop::TaskObserver { | 1269 : public base::MessageLoop::TaskObserver { |
1270 public: | 1270 public: |
1271 // MessageLoop::TaskObserver overrides. | 1271 // MessageLoop::TaskObserver overrides. |
1272 void WillProcessTask(const base::PendingTask& pending_task) override {} | 1272 void WillProcessTask(const base::PendingTask& pending_task) override {} |
1273 void DidProcessTask(const base::PendingTask& pending_task) override { | 1273 void DidProcessTask(const base::PendingTask& pending_task) override { |
1274 sequence_numbers_.push_back(pending_task.sequence_num); | 1274 sequence_numbers_.push_back(pending_task.sequence_num); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 // nested run loop does not trigger the pumping of an on-wakeup queue. | 1414 // nested run loop does not trigger the pumping of an on-wakeup queue. |
1415 InitializeWithRealMessageLoop(2u); | 1415 InitializeWithRealMessageLoop(2u); |
1416 runners_[1]->SetPumpPolicy(TaskQueue::PumpPolicy::AFTER_WAKEUP); | 1416 runners_[1]->SetPumpPolicy(TaskQueue::PumpPolicy::AFTER_WAKEUP); |
1417 | 1417 |
1418 std::vector<EnqueueOrder> run_order; | 1418 std::vector<EnqueueOrder> run_order; |
1419 runners_[0]->PostTask( | 1419 runners_[0]->PostTask( |
1420 FROM_HERE, | 1420 FROM_HERE, |
1421 base::Bind(&PostTestTasksFromNestedMessageLoop, message_loop_.get(), | 1421 base::Bind(&PostTestTasksFromNestedMessageLoop, message_loop_.get(), |
1422 runners_[0], runners_[1], base::Unretained(&run_order))); | 1422 runners_[0], runners_[1], base::Unretained(&run_order))); |
1423 | 1423 |
1424 message_loop_->RunUntilIdle(); | 1424 base::RunLoop().RunUntilIdle(); |
1425 ASSERT_THAT(run_order, ElementsAre(1)); | 1425 ASSERT_THAT(run_order, ElementsAre(1)); |
1426 } | 1426 } |
1427 | 1427 |
1428 namespace { | 1428 namespace { |
1429 | 1429 |
1430 class MockObserver : public TaskQueueManager::Observer { | 1430 class MockObserver : public TaskQueueManager::Observer { |
1431 public: | 1431 public: |
1432 MOCK_METHOD1(OnUnregisterTaskQueue, | 1432 MOCK_METHOD1(OnUnregisterTaskQueue, |
1433 void(const scoped_refptr<TaskQueue>& queue)); | 1433 void(const scoped_refptr<TaskQueue>& queue)); |
1434 MOCK_METHOD2(OnTriedToExecuteBlockedTask, | 1434 MOCK_METHOD2(OnTriedToExecuteBlockedTask, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 base::Bind(&internal::TaskQueueImpl::UnregisterTaskQueue, | 1512 base::Bind(&internal::TaskQueueImpl::UnregisterTaskQueue, |
1513 base::Unretained(task_queue.get())), true)); | 1513 base::Unretained(task_queue.get())), true)); |
1514 tasks_to_post_from_nested_loop.push_back( | 1514 tasks_to_post_from_nested_loop.push_back( |
1515 std::make_pair(base::Bind(&HasOneRefTask, base::Unretained(&log), | 1515 std::make_pair(base::Bind(&HasOneRefTask, base::Unretained(&log), |
1516 base::Unretained(task_queue.get())), | 1516 base::Unretained(task_queue.get())), |
1517 true)); | 1517 true)); |
1518 runners_[0]->PostTask( | 1518 runners_[0]->PostTask( |
1519 FROM_HERE, base::Bind(&PostFromNestedRunloop, message_loop_.get(), | 1519 FROM_HERE, base::Bind(&PostFromNestedRunloop, message_loop_.get(), |
1520 base::RetainedRef(runners_[0]), | 1520 base::RetainedRef(runners_[0]), |
1521 base::Unretained(&tasks_to_post_from_nested_loop))); | 1521 base::Unretained(&tasks_to_post_from_nested_loop))); |
1522 message_loop_->RunUntilIdle(); | 1522 base::RunLoop().RunUntilIdle(); |
1523 | 1523 |
1524 // Add a final call to HasOneRefTask. This gives the manager a chance to | 1524 // Add a final call to HasOneRefTask. This gives the manager a chance to |
1525 // release its reference, and checks that it has. | 1525 // release its reference, and checks that it has. |
1526 runners_[0]->PostTask(FROM_HERE, | 1526 runners_[0]->PostTask(FROM_HERE, |
1527 base::Bind(&HasOneRefTask, base::Unretained(&log), | 1527 base::Bind(&HasOneRefTask, base::Unretained(&log), |
1528 base::Unretained(task_queue.get()))); | 1528 base::Unretained(task_queue.get()))); |
1529 message_loop_->RunUntilIdle(); | 1529 base::RunLoop().RunUntilIdle(); |
1530 | 1530 |
1531 EXPECT_THAT(log, ElementsAre(false, false, true)); | 1531 EXPECT_THAT(log, ElementsAre(false, false, true)); |
1532 } | 1532 } |
1533 | 1533 |
1534 TEST_F(TaskQueueManagerTest, TimeDomainsAreIndependant) { | 1534 TEST_F(TaskQueueManagerTest, TimeDomainsAreIndependant) { |
1535 Initialize(2u); | 1535 Initialize(2u); |
1536 | 1536 |
1537 base::TimeTicks start_time = manager_->delegate()->NowTicks(); | 1537 base::TimeTicks start_time = manager_->delegate()->NowTicks(); |
1538 std::unique_ptr<VirtualTimeDomain> domain_a( | 1538 std::unique_ptr<VirtualTimeDomain> domain_a( |
1539 new VirtualTimeDomain(nullptr, start_time)); | 1539 new VirtualTimeDomain(nullptr, start_time)); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 tasks_to_post_from_nested_loop.push_back( | 1890 tasks_to_post_from_nested_loop.push_back( |
1891 std::make_pair(base::Bind(&CurrentlyExecutingTaskQueueTestTask, | 1891 std::make_pair(base::Bind(&CurrentlyExecutingTaskQueueTestTask, |
1892 manager_.get(), &task_sources), | 1892 manager_.get(), &task_sources), |
1893 queue2)); | 1893 queue2)); |
1894 | 1894 |
1895 queue0->PostTask( | 1895 queue0->PostTask( |
1896 FROM_HERE, base::Bind(&RunloopCurrentlyExecutingTaskQueueTestTask, | 1896 FROM_HERE, base::Bind(&RunloopCurrentlyExecutingTaskQueueTestTask, |
1897 message_loop_.get(), manager_.get(), &task_sources, | 1897 message_loop_.get(), manager_.get(), &task_sources, |
1898 &tasks_to_post_from_nested_loop)); | 1898 &tasks_to_post_from_nested_loop)); |
1899 | 1899 |
1900 message_loop_->RunUntilIdle(); | 1900 base::RunLoop().RunUntilIdle(); |
1901 EXPECT_THAT(task_sources, ElementsAre(queue0, queue1, queue2, queue0)); | 1901 EXPECT_THAT(task_sources, ElementsAre(queue0, queue1, queue2, queue0)); |
1902 EXPECT_EQ(nullptr, manager_->currently_executing_task_queue()); | 1902 EXPECT_EQ(nullptr, manager_->currently_executing_task_queue()); |
1903 } | 1903 } |
1904 | 1904 |
1905 void OnTraceDataCollected(base::Closure quit_closure, | 1905 void OnTraceDataCollected(base::Closure quit_closure, |
1906 base::trace_event::TraceResultBuffer* buffer, | 1906 base::trace_event::TraceResultBuffer* buffer, |
1907 const scoped_refptr<base::RefCountedString>& json, | 1907 const scoped_refptr<base::RefCountedString>& json, |
1908 bool has_more_events) { | 1908 bool has_more_events) { |
1909 buffer->AddFragment(json->data()); | 1909 buffer->AddFragment(json->data()); |
1910 if (!has_more_events) | 1910 if (!has_more_events) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1951 InitializeWithRealMessageLoop(1u); | 1951 InitializeWithRealMessageLoop(1u); |
1952 TaskQueue* queue = runners_[0].get(); | 1952 TaskQueue* queue = runners_[0].get(); |
1953 | 1953 |
1954 StartTracing(); | 1954 StartTracing(); |
1955 { | 1955 { |
1956 base::trace_event::BlameContext blame_context("cat", "name", "type", | 1956 base::trace_event::BlameContext blame_context("cat", "name", "type", |
1957 "scope", 0, nullptr); | 1957 "scope", 0, nullptr); |
1958 blame_context.Initialize(); | 1958 blame_context.Initialize(); |
1959 queue->SetBlameContext(&blame_context); | 1959 queue->SetBlameContext(&blame_context); |
1960 queue->PostTask(FROM_HERE, base::Bind(&NopTask)); | 1960 queue->PostTask(FROM_HERE, base::Bind(&NopTask)); |
1961 message_loop_->RunUntilIdle(); | 1961 base::RunLoop().RunUntilIdle(); |
1962 } | 1962 } |
1963 StopTracing(); | 1963 StopTracing(); |
1964 std::unique_ptr<trace_analyzer::TraceAnalyzer> analyzer = | 1964 std::unique_ptr<trace_analyzer::TraceAnalyzer> analyzer = |
1965 CreateTraceAnalyzer(); | 1965 CreateTraceAnalyzer(); |
1966 | 1966 |
1967 trace_analyzer::TraceEventVector events; | 1967 trace_analyzer::TraceEventVector events; |
1968 Query q = Query::EventPhaseIs(TRACE_EVENT_PHASE_ENTER_CONTEXT) || | 1968 Query q = Query::EventPhaseIs(TRACE_EVENT_PHASE_ENTER_CONTEXT) || |
1969 Query::EventPhaseIs(TRACE_EVENT_PHASE_LEAVE_CONTEXT); | 1969 Query::EventPhaseIs(TRACE_EVENT_PHASE_LEAVE_CONTEXT); |
1970 analyzer->FindEvents(q, &events); | 1970 analyzer->FindEvents(q, &events); |
1971 | 1971 |
1972 EXPECT_EQ(2u, events.size()); | 1972 EXPECT_EQ(2u, events.size()); |
1973 } | 1973 } |
1974 | 1974 |
1975 } // namespace scheduler | 1975 } // namespace scheduler |
OLD | NEW |