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

Unified Diff: base/test/scoped_task_environment.h

Issue 2891363005: Add ScopedTaskEnvironment::ExecutionControlMode. (Closed)
Patch Set: self-review Created 3 years, 7 months 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
Index: base/test/scoped_task_environment.h
diff --git a/base/test/scoped_task_environment.h b/base/test/scoped_task_environment.h
index f46b516d7c16ddea6d7a6b710fd9a7832045dc29..6156c21537cab850680119852432b1232ec3009d 100644
--- a/base/test/scoped_task_environment.h
+++ b/base/test/scoped_task_environment.h
@@ -26,7 +26,9 @@ namespace test {
// RunLoop::Run(UntilIdle) or ScopedTaskEnvironment::RunUntilIdle is called on
// the thread where the ScopedTaskEnvironment lives.
//
-// Tasks posted through base/task_scheduler/post_task.h run on dedicated threads
+// Tasks posted through base/task_scheduler/post_task.h run on dedicated
+// threads. If ExecutionControlMode is QUEUED, they run when RunUntilIdle() or
+// ~ScopedTaskEnvironment is called. If ExecutionControlMode is ASYNC, they run
// as they are posted.
//
// All methods of ScopedTaskEnvironment must be called from the same thread.
@@ -61,8 +63,17 @@ class ScopedTaskEnvironment {
IO,
};
+ enum class ExecutionControlMode {
gab 2017/05/23 15:26:13 I'd say "ExecutionMode" is enough (especially beca
fdoray 2017/05/25 19:17:34 Done.
+ // Tasks are queued and executed when RunUntilIdle() is called.
gab 2017/05/23 15:26:13 only executed ^^^^ is explicitly called ^^^^^^
fdoray 2017/05/25 19:17:34 Done.
+ QUEUED,
+ // Tasks run as they are posted.
gab 2017/05/23 15:26:13 + "RunUntilIdle() can still be used to block until
fdoray 2017/05/25 19:17:33 Done.
+ ASYNC,
+ };
+
ScopedTaskEnvironment(
- MainThreadType main_thread_type = MainThreadType::DEFAULT);
+ MainThreadType main_thread_type = MainThreadType::DEFAULT,
+ ExecutionControlMode execution_control_mode =
+ ExecutionControlMode::ASYNC);
// Waits until no undelayed TaskScheduler tasks remain. Then, unregisters the
// TaskScheduler and the (Thread|Sequenced)TaskRunnerHandle.
@@ -71,11 +82,15 @@ class ScopedTaskEnvironment {
// Returns a TaskRunner that schedules tasks on the main thread.
scoped_refptr<base::SingleThreadTaskRunner> GetMainThreadTaskRunner();
- // Synchronously runs (Thread|Sequenced)TaskRunnerHandle tasks until no
- // undelayed (Thread|Sequenced)TaskRunnerHandle or TaskScheduler tasks remain.
+ // Runs tasks until both the (Thread|Sequenced)TaskRunnerHandle and the
+ // TaskScheduler queues are empty.
void RunUntilIdle();
private:
+ class TestTaskTracker;
+
+ const ExecutionControlMode execution_control_mode_;
+
// Note: |message_loop_| is an implementation detail and will be replaced in
// the future, do NOT rely on the presence of a MessageLoop beyond
// (Thread|Sequenced)TaskRunnerHandle and RunLoop.
@@ -83,6 +98,9 @@ class ScopedTaskEnvironment {
const TaskScheduler* task_scheduler_ = nullptr;
+ // Owned by |task_scheduler_|.
+ TestTaskTracker* const task_tracker_;
+
DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment);
};

Powered by Google App Engine
This is Rietveld 408576698