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

Unified Diff: base/test/test_simple_task_runner.cc

Issue 2657013002: Introduce ThreadTaskRunnerHandle::OverrideForTesting and TestMockTimeTaskRunner::ScopedContext. (Closed)
Patch Set: fix RecentTabHelperTest crash? Created 3 years, 10 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/test_simple_task_runner.cc
diff --git a/base/test/test_simple_task_runner.cc b/base/test/test_simple_task_runner.cc
index e7779184f390c3b83a1fa4a6b4ae22faeaef9aea..090a72e96adf0f0c8ae4445f1965a6c1b31bb7ed 100644
--- a/base/test/test_simple_task_runner.cc
+++ b/base/test/test_simple_task_runner.cc
@@ -5,6 +5,8 @@
#include "base/test/test_simple_task_runner.h"
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "base/threading/thread_task_runner_handle.h"
namespace base {
@@ -34,6 +36,9 @@ bool TestSimpleTaskRunner::PostNonNestableDelayedTask(
return true;
}
+// TODO(gab): Use SequenceToken here to differentiate between tasks running in
+// the scope of this TestSimpleTaskRunner and other task runners sharing this
+// thread. http://crbug.com/631186
bool TestSimpleTaskRunner::RunsTasksOnCurrentThread() const {
return thread_ref_ == PlatformThread::CurrentRef();
}
@@ -78,6 +83,14 @@ void TestSimpleTaskRunner::RunPendingTasks() {
tasks_to_run.swap(pending_tasks_);
}
+ // Multiple test task runners can share the same thread for determinism in
+ // unit tests. Make sure this TestSimpleTaskRunner's tasks run in its scope.
+ ScopedClosureRunner undo_override;
+ if (!ThreadTaskRunnerHandle::IsSet() ||
+ ThreadTaskRunnerHandle::Get() != this) {
+ undo_override = ThreadTaskRunnerHandle::OverrideForTesting(this);
+ }
+
for (auto& task : tasks_to_run)
std::move(task.task).Run();
}

Powered by Google App Engine
This is Rietveld 408576698