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

Unified Diff: third_party/WebKit/Source/platform/scheduler/test/fake_web_task_runner.cc

Issue 2266443002: Optimize posting of WTF::Closure and improve scheduler test mocks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix FakeWebTaskRunner leak Created 4 years, 4 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: third_party/WebKit/Source/platform/scheduler/test/fake_web_task_runner.cc
diff --git a/third_party/WebKit/Source/platform/scheduler/test/fake_web_task_runner.cc b/third_party/WebKit/Source/platform/scheduler/test/fake_web_task_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fb0f105cac54998df8025ddf218f5115342fa7e4
--- /dev/null
+++ b/third_party/WebKit/Source/platform/scheduler/test/fake_web_task_runner.cc
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/scheduler/test/fake_web_task_runner.h"
+
+namespace blink {
+namespace scheduler {
+
+FakeWebTaskRunner::FakeWebTaskRunner() : time_(0.0) {}
+
+FakeWebTaskRunner::~FakeWebTaskRunner() {}
+
+void FakeWebTaskRunner::setTime(double new_time) {
+ time_ = new_time;
+}
+
+void FakeWebTaskRunner::postTask(const WebTraceLocation&, Task*) {}
+
+void FakeWebTaskRunner::postDelayedTask(const WebTraceLocation&,
+ Task* task,
+ double) {
+ task_.reset(task);
+}
+
+TaskQueue::TaskHandle FakeWebTaskRunner::postCancellableDelayedTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ double delayMs) {
+ // We need to return a TaskHandle that appears valid, otherwise
+ // TimerBase::isActive will return false which breaks some tests.
+ return TaskQueue::TaskHandle(nullptr, 1);
+}
+
+bool FakeWebTaskRunner::cancelTask(const TaskQueue::TaskHandle& handle) {
+ // The FakeWebTaskRunner is typically used with platform Timer which expects
+ // cancellation to succeed.
+ return true;
+}
+
+bool FakeWebTaskRunner::runsTasksOnCurrentThread() {
+ return true;
+}
+
+std::unique_ptr<WebTaskRunner> FakeWebTaskRunner::clone() {
+ return nullptr;
+}
+
+double FakeWebTaskRunner::virtualTimeSeconds() const {
+ return time_;
+}
+
+double FakeWebTaskRunner::monotonicallyIncreasingVirtualTimeSeconds() const {
+ return time_;
+}
+
+SingleThreadTaskRunner* FakeWebTaskRunner::toSingleThreadTaskRunner() {
+ return nullptr;
+}
+
+} // namespace scheduler
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698