Chromium Code Reviews| Index: base/task_scheduler/task_scheduler_impl_unittest.cc |
| diff --git a/base/task_scheduler/task_scheduler_impl_unittest.cc b/base/task_scheduler/task_scheduler_impl_unittest.cc |
| index 250aae5909f1fe0a298b2b03aa77adbff0d82921..97f5e39e4c8eb365c6dea9fc28609fdaea11a51e 100644 |
| --- a/base/task_scheduler/task_scheduler_impl_unittest.cc |
| +++ b/base/task_scheduler/task_scheduler_impl_unittest.cc |
| @@ -6,6 +6,7 @@ |
| #include <stddef.h> |
| +#include <limits> |
| #include <utility> |
| #include <vector> |
| @@ -14,6 +15,9 @@ |
| #include "base/callback.h" |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_piece.h" |
| +#include "base/strings/string_util.h" |
| #include "base/synchronization/waitable_event.h" |
| #include "base/task_scheduler/task_traits.h" |
| #include "base/task_scheduler/test_task_factory.h" |
| @@ -75,6 +79,34 @@ void VerifyTaskEnvironement(const TaskTraits& traits) { |
| // !ENABLE_THREAD_RESTRICTIONS, even when |traits| don't allow file I/O. |
| EXPECT_EQ(traits.with_file_io(), GetIOAllowed()); |
| #endif |
| + |
| + // Verify that the thread the task is running on is named as expected |
| + // (appropriate prefix label and index for its traits). |
| + std::string expected_thread_name = "TaskScheduler"; |
| + expected_thread_name += traits.priority() == TaskPriority::BACKGROUND |
| + ? "Background" |
| + : "Foreground"; |
| + if (traits.with_file_io()) |
| + expected_thread_name += "FileIO"; |
| + expected_thread_name += "Worker"; |
| + |
| + const std::string actual_thread_name(PlatformThread::GetName()); |
| + EXPECT_TRUE(StartsWith(actual_thread_name, expected_thread_name, |
| + CompareCase::SENSITIVE)); |
| + |
| + size_t thread_index_in_pool = std::numeric_limits<size_t>::max(); |
| + EXPECT_TRUE(base::StringToSizeT( |
| + StringPiece(actual_thread_name).substr(expected_thread_name.size()), |
| + &thread_index_in_pool)); |
| + if (traits.priority() == TaskPriority::BACKGROUND) { |
|
fdoray
2016/05/04 19:04:32
I would remove lines 101-109 because we shouldn't
gab
2016/05/04 21:00:02
Done.
|
| + EXPECT_EQ(0U, thread_index_in_pool); |
| + } else if (traits.priority() == TaskPriority::BACKGROUND) { |
| + EXPECT_GE(thread_index_in_pool, 0U); |
| + EXPECT_LT(thread_index_in_pool, 4U); |
| + } else { |
| + EXPECT_GE(thread_index_in_pool, 0U); |
| + EXPECT_LT(thread_index_in_pool, 12U); |
| + } |
| } |
| void VerifyTaskEnvironementAndSignalEvent(const TaskTraits& traits, |