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

Unified Diff: base/task_scheduler/task_tracker_unittest.cc

Issue 2531883002: TaskScheduler: Set the IO allowed bit in TaskTracker::RunTask(). (Closed)
Patch Set: rebase Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/task_scheduler/task_tracker.cc ('k') | base/test/scoped_task_scheduler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/task_tracker_unittest.cc
diff --git a/base/task_scheduler/task_tracker_unittest.cc b/base/task_scheduler/task_tracker_unittest.cc
index fee73e1f4079bd45dfa3625f52202edca6d61fa3..e1a4229022e27649ee67979fe107d41487b9699e 100644
--- a/base/task_scheduler/task_tracker_unittest.cc
+++ b/base/task_scheduler/task_tracker_unittest.cc
@@ -431,6 +431,34 @@ TEST_P(TaskSchedulerTaskTrackerTest, SingletonAllowed) {
}
}
+// Verify that AssertIOAllowed() succeeds only for a WithFileIO() task.
+TEST_P(TaskSchedulerTaskTrackerTest, IOAllowed) {
+ TaskTracker tracker;
+
+ // Unset the IO allowed bit. Expect TaskTracker to set it before running a
+ // task with the WithFileIO() trait.
+ ThreadRestrictions::SetIOAllowed(false);
+ auto task_with_file_io = MakeUnique<Task>(
+ FROM_HERE, Bind([]() {
+ // Shouldn't fail.
+ ThreadRestrictions::AssertIOAllowed();
+ }),
+ TaskTraits().WithFileIO().WithShutdownBehavior(GetParam()), TimeDelta());
+ EXPECT_TRUE(tracker.WillPostTask(task_with_file_io.get()));
+ tracker.RunTask(std::move(task_with_file_io), SequenceToken::Create());
+
+ // Set the IO allowed bit. Expect TaskTracker to unset it before running a
+ // task without the WithFileIO() trait.
+ ThreadRestrictions::SetIOAllowed(true);
+ auto task_without_file_io = MakeUnique<Task>(
+ FROM_HERE, Bind([]() {
+ EXPECT_DCHECK_DEATH({ ThreadRestrictions::AssertIOAllowed(); });
+ }),
+ TaskTraits().WithShutdownBehavior(GetParam()), TimeDelta());
+ EXPECT_TRUE(tracker.WillPostTask(task_without_file_io.get()));
+ tracker.RunTask(std::move(task_without_file_io), SequenceToken::Create());
+}
+
static void RunTaskRunnerHandleVerificationTask(
TaskTracker* tracker,
std::unique_ptr<Task> verify_task) {
« no previous file with comments | « base/task_scheduler/task_tracker.cc ('k') | base/test/scoped_task_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698