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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 scheduler_->GetMaxConcurrentTasksWithTraitsDeprecated( | 315 scheduler_->GetMaxConcurrentTasksWithTraitsDeprecated( |
316 TaskTraits().WithPriority(TaskPriority::USER_VISIBLE).MayBlock())); | 316 TaskTraits().WithPriority(TaskPriority::USER_VISIBLE).MayBlock())); |
317 EXPECT_EQ(4, scheduler_->GetMaxConcurrentTasksWithTraitsDeprecated( | 317 EXPECT_EQ(4, scheduler_->GetMaxConcurrentTasksWithTraitsDeprecated( |
318 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING))); | 318 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING))); |
319 EXPECT_EQ( | 319 EXPECT_EQ( |
320 12, | 320 12, |
321 scheduler_->GetMaxConcurrentTasksWithTraitsDeprecated( | 321 scheduler_->GetMaxConcurrentTasksWithTraitsDeprecated( |
322 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING).MayBlock())); | 322 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING).MayBlock())); |
323 } | 323 } |
324 | 324 |
| 325 // Verify that the RunsTasksOnCurrentThread() method of a SequencedTaskRunner |
| 326 // returns false when called from a task that isn't part of the sequence. |
| 327 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) { |
| 328 auto single_thread_task_runner = |
| 329 scheduler_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); |
| 330 auto sequenced_task_runner = |
| 331 scheduler_->CreateSequencedTaskRunnerWithTraits(TaskTraits()); |
| 332 |
| 333 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
| 334 WaitableEvent::InitialState::NOT_SIGNALED); |
| 335 single_thread_task_runner->PostTask( |
| 336 FROM_HERE, |
| 337 Bind( |
| 338 [](scoped_refptr<TaskRunner> sequenced_task_runner, |
| 339 WaitableEvent* task_ran) { |
| 340 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); |
| 341 task_ran->Signal(); |
| 342 }, |
| 343 sequenced_task_runner, Unretained(&task_ran))); |
| 344 task_ran.Wait(); |
| 345 } |
| 346 |
| 347 // Verify that the RunsTasksOnCurrentThread() method of a SingleThreadTaskRunner |
| 348 // returns false when called from a task that isn't part of the sequence. |
| 349 TEST_F(TaskSchedulerImplTest, SingleThreadRunsTasksOnCurrentThread) { |
| 350 auto sequenced_task_runner = |
| 351 scheduler_->CreateSequencedTaskRunnerWithTraits(TaskTraits()); |
| 352 auto single_thread_task_runner = |
| 353 scheduler_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); |
| 354 |
| 355 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
| 356 WaitableEvent::InitialState::NOT_SIGNALED); |
| 357 sequenced_task_runner->PostTask( |
| 358 FROM_HERE, |
| 359 Bind( |
| 360 [](scoped_refptr<TaskRunner> single_thread_task_runner, |
| 361 WaitableEvent* task_ran) { |
| 362 EXPECT_FALSE(single_thread_task_runner->RunsTasksOnCurrentThread()); |
| 363 task_ran->Signal(); |
| 364 }, |
| 365 single_thread_task_runner, Unretained(&task_ran))); |
| 366 task_ran.Wait(); |
| 367 } |
| 368 |
325 } // namespace internal | 369 } // namespace internal |
326 } // namespace base | 370 } // namespace base |
OLD | NEW |