OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/task_scheduler/task_scheduler_impl.h" | 5 #include "base/task_scheduler/task_scheduler_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } // namespace | 235 } // namespace |
236 | 236 |
237 // Verifies that a Task posted via PostDelayedTaskWithTraits with parameterized | 237 // Verifies that a Task posted via PostDelayedTaskWithTraits with parameterized |
238 // TaskTraits and no delay runs on a thread with the expected priority and I/O | 238 // TaskTraits and no delay runs on a thread with the expected priority and I/O |
239 // restrictions. The ExecutionMode parameter is ignored by this test. | 239 // restrictions. The ExecutionMode parameter is ignored by this test. |
240 TEST_P(TaskSchedulerImplTest, PostDelayedTaskWithTraitsNoDelay) { | 240 TEST_P(TaskSchedulerImplTest, PostDelayedTaskWithTraitsNoDelay) { |
241 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, | 241 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
242 WaitableEvent::InitialState::NOT_SIGNALED); | 242 WaitableEvent::InitialState::NOT_SIGNALED); |
243 scheduler_->PostDelayedTaskWithTraits( | 243 scheduler_->PostDelayedTaskWithTraits( |
244 FROM_HERE, GetParam().traits, | 244 FROM_HERE, GetParam().traits, |
245 Bind(&VerifyTaskEnvironmentAndSignalEvent, GetParam().traits, | 245 BindOnce(&VerifyTaskEnvironmentAndSignalEvent, GetParam().traits, |
246 Unretained(&task_ran)), | 246 Unretained(&task_ran)), |
247 TimeDelta()); | 247 TimeDelta()); |
248 task_ran.Wait(); | 248 task_ran.Wait(); |
249 } | 249 } |
250 | 250 |
251 // Verifies that a Task posted via PostDelayedTaskWithTraits with parameterized | 251 // Verifies that a Task posted via PostDelayedTaskWithTraits with parameterized |
252 // TaskTraits and a non-zero delay runs on a thread with the expected priority | 252 // TaskTraits and a non-zero delay runs on a thread with the expected priority |
253 // and I/O restrictions after the delay expires. The ExecutionMode parameter is | 253 // and I/O restrictions after the delay expires. The ExecutionMode parameter is |
254 // ignored by this test. | 254 // ignored by this test. |
255 TEST_P(TaskSchedulerImplTest, PostDelayedTaskWithTraitsWithDelay) { | 255 TEST_P(TaskSchedulerImplTest, PostDelayedTaskWithTraitsWithDelay) { |
256 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, | 256 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
257 WaitableEvent::InitialState::NOT_SIGNALED); | 257 WaitableEvent::InitialState::NOT_SIGNALED); |
258 scheduler_->PostDelayedTaskWithTraits( | 258 scheduler_->PostDelayedTaskWithTraits( |
259 FROM_HERE, GetParam().traits, | 259 FROM_HERE, GetParam().traits, |
260 Bind(&VerifyTimeAndTaskEnvironmentAndSignalEvent, GetParam().traits, | 260 BindOnce(&VerifyTimeAndTaskEnvironmentAndSignalEvent, GetParam().traits, |
261 TimeTicks::Now() + TestTimeouts::tiny_timeout(), | 261 TimeTicks::Now() + TestTimeouts::tiny_timeout(), |
262 Unretained(&task_ran)), | 262 Unretained(&task_ran)), |
263 TestTimeouts::tiny_timeout()); | 263 TestTimeouts::tiny_timeout()); |
264 task_ran.Wait(); | 264 task_ran.Wait(); |
265 } | 265 } |
266 | 266 |
267 // Verifies that Tasks posted via a TaskRunner with parameterized TaskTraits and | 267 // Verifies that Tasks posted via a TaskRunner with parameterized TaskTraits and |
268 // ExecutionMode run on a thread with the expected priority and I/O restrictions | 268 // ExecutionMode run on a thread with the expected priority and I/O restrictions |
269 // and respect the characteristics of their ExecutionMode. | 269 // and respect the characteristics of their ExecutionMode. |
270 TEST_P(TaskSchedulerImplTest, PostTasksViaTaskRunner) { | 270 TEST_P(TaskSchedulerImplTest, PostTasksViaTaskRunner) { |
271 test::TestTaskFactory factory( | 271 test::TestTaskFactory factory( |
272 CreateTaskRunnerWithTraitsAndExecutionMode( | 272 CreateTaskRunnerWithTraitsAndExecutionMode( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) { | 331 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) { |
332 auto single_thread_task_runner = | 332 auto single_thread_task_runner = |
333 scheduler_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); | 333 scheduler_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); |
334 auto sequenced_task_runner = | 334 auto sequenced_task_runner = |
335 scheduler_->CreateSequencedTaskRunnerWithTraits(TaskTraits()); | 335 scheduler_->CreateSequencedTaskRunnerWithTraits(TaskTraits()); |
336 | 336 |
337 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, | 337 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
338 WaitableEvent::InitialState::NOT_SIGNALED); | 338 WaitableEvent::InitialState::NOT_SIGNALED); |
339 single_thread_task_runner->PostTask( | 339 single_thread_task_runner->PostTask( |
340 FROM_HERE, | 340 FROM_HERE, |
341 Bind( | 341 BindOnce( |
342 [](scoped_refptr<TaskRunner> sequenced_task_runner, | 342 [](scoped_refptr<TaskRunner> sequenced_task_runner, |
343 WaitableEvent* task_ran) { | 343 WaitableEvent* task_ran) { |
344 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); | 344 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); |
345 task_ran->Signal(); | 345 task_ran->Signal(); |
346 }, | 346 }, |
347 sequenced_task_runner, Unretained(&task_ran))); | 347 sequenced_task_runner, Unretained(&task_ran))); |
348 task_ran.Wait(); | 348 task_ran.Wait(); |
349 } | 349 } |
350 | 350 |
351 // Verify that the RunsTasksOnCurrentThread() method of a SingleThreadTaskRunner | 351 // Verify that the RunsTasksOnCurrentThread() method of a SingleThreadTaskRunner |
352 // returns false when called from a task that isn't part of the sequence. | 352 // returns false when called from a task that isn't part of the sequence. |
353 TEST_F(TaskSchedulerImplTest, SingleThreadRunsTasksOnCurrentThread) { | 353 TEST_F(TaskSchedulerImplTest, SingleThreadRunsTasksOnCurrentThread) { |
354 auto sequenced_task_runner = | 354 auto sequenced_task_runner = |
355 scheduler_->CreateSequencedTaskRunnerWithTraits(TaskTraits()); | 355 scheduler_->CreateSequencedTaskRunnerWithTraits(TaskTraits()); |
356 auto single_thread_task_runner = | 356 auto single_thread_task_runner = |
357 scheduler_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); | 357 scheduler_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); |
358 | 358 |
359 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, | 359 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
360 WaitableEvent::InitialState::NOT_SIGNALED); | 360 WaitableEvent::InitialState::NOT_SIGNALED); |
361 sequenced_task_runner->PostTask( | 361 sequenced_task_runner->PostTask( |
362 FROM_HERE, | 362 FROM_HERE, |
363 Bind( | 363 BindOnce( |
364 [](scoped_refptr<TaskRunner> single_thread_task_runner, | 364 [](scoped_refptr<TaskRunner> single_thread_task_runner, |
365 WaitableEvent* task_ran) { | 365 WaitableEvent* task_ran) { |
366 EXPECT_FALSE(single_thread_task_runner->RunsTasksOnCurrentThread()); | 366 EXPECT_FALSE(single_thread_task_runner->RunsTasksOnCurrentThread()); |
367 task_ran->Signal(); | 367 task_ran->Signal(); |
368 }, | 368 }, |
369 single_thread_task_runner, Unretained(&task_ran))); | 369 single_thread_task_runner, Unretained(&task_ran))); |
370 task_ran.Wait(); | 370 task_ran.Wait(); |
371 } | 371 } |
372 | 372 |
373 #if defined(OS_WIN) | 373 #if defined(OS_WIN) |
(...skipping 15 matching lines...) Expand all Loading... |
389 } | 389 } |
390 task_ran->Signal(); | 390 task_ran->Signal(); |
391 }, | 391 }, |
392 com_sta_task_runner, Unretained(&task_ran))); | 392 com_sta_task_runner, Unretained(&task_ran))); |
393 task_ran.Wait(); | 393 task_ran.Wait(); |
394 } | 394 } |
395 #endif // defined(OS_WIN) | 395 #endif // defined(OS_WIN) |
396 | 396 |
397 } // namespace internal | 397 } // namespace internal |
398 } // namespace base | 398 } // namespace base |
OLD | NEW |