chromium/base/test/test_mock_time_task_runner.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/test/test_mock_time_task_runner.h"

#include <optional>
#include <utility>

#include "base/check_op.h"
#include "base/containers/circular_deque.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/task/single_thread_task_runner.h"

namespace base {

// A SingleThreadTaskRunner which forwards everything to its |target_|. This
// serves two purposes:
// 1) If a TaskRunner CurrentDefaultHandle owned by TestMockTimeTaskRunner were
//    to be set to point to that TestMockTimeTaskRunner, a reference cycle
//    would result. As |target_| here is a non-refcounting raw pointer, the
//    cycle is broken.
// 2) Since SingleThreadTaskRunner is ref-counted, it's quite easy for it to
//    accidentally get captured between tests in a singleton somewhere.
//    Indirecting via NonOwningProxyTaskRunner permits TestMockTimeTaskRunner
//    to be cleaned up (removing the RunLoop::Delegate in the kBoundToThread
//    mode), and to also cleanly flag any actual attempts to use the leaked
//    task runner.
class TestMockTimeTaskRunner::NonOwningProxyTaskRunner
    : public SingleThreadTaskRunner {};

// TestMockTimeTaskRunner::TestOrderedPendingTask -----------------------------

// Subclass of TestPendingTask which has a strictly monotonically increasing ID
// for every task, so that tasks posted with the same 'time to run' can be run
// in the order of being posted.
struct TestMockTimeTaskRunner::TestOrderedPendingTask
    : public base::TestPendingTask {};

TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask()
    :{}

TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask(
    TestOrderedPendingTask&&) = default;

TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask(
    const Location& location,
    OnceClosure task,
    TimeTicks post_time,
    TimeDelta delay,
    size_t ordinal,
    TestNestability nestability)
    :{}

TestMockTimeTaskRunner::TestOrderedPendingTask::~TestOrderedPendingTask() =
    default;

TestMockTimeTaskRunner::TestOrderedPendingTask&
TestMockTimeTaskRunner::TestOrderedPendingTask::operator=(
    TestOrderedPendingTask&&) = default;

// TestMockTimeTaskRunner -----------------------------------------------------

// TODO(gab): This should also set the SequenceToken for the current thread.
// Ref. TestMockTimeTaskRunner::RunsTasksInCurrentSequence().
TestMockTimeTaskRunner::ScopedContext::ScopedContext(
    scoped_refptr<TestMockTimeTaskRunner> scope)
    :{}

TestMockTimeTaskRunner::ScopedContext::~ScopedContext() = default;

bool TestMockTimeTaskRunner::TemporalOrder::operator()(
    const TestOrderedPendingTask& first_task,
    const TestOrderedPendingTask& second_task) const {}

TestMockTimeTaskRunner::TestMockTimeTaskRunner(Type type)
    :{}

TestMockTimeTaskRunner::TestMockTimeTaskRunner(Time start_time,
                                               TimeTicks start_ticks,
                                               Type type)
    :{}

TestMockTimeTaskRunner::~TestMockTimeTaskRunner() {}

void TestMockTimeTaskRunner::FastForwardBy(TimeDelta delta) {}

void TestMockTimeTaskRunner::AdvanceMockTickClock(TimeDelta delta) {}

void TestMockTimeTaskRunner::AdvanceWallClock(TimeDelta delta) {}

void TestMockTimeTaskRunner::RunUntilIdle() {}

void TestMockTimeTaskRunner::ProcessNextNTasks(int n) {}

void TestMockTimeTaskRunner::FastForwardUntilNoTasksRemain() {}

void TestMockTimeTaskRunner::ClearPendingTasks() {}

Time TestMockTimeTaskRunner::Now() const {}

TimeTicks TestMockTimeTaskRunner::NowTicks() const {}

Clock* TestMockTimeTaskRunner::GetMockClock() const {}

const TickClock* TestMockTimeTaskRunner::GetMockTickClock() const {}

base::circular_deque<TestPendingTask>
TestMockTimeTaskRunner::TakePendingTasks() {}

bool TestMockTimeTaskRunner::HasPendingTask() {}

size_t TestMockTimeTaskRunner::GetPendingTaskCount() {}

TimeDelta TestMockTimeTaskRunner::NextPendingTaskDelay() {}

void TestMockTimeTaskRunner::DetachFromThread() {}

// TODO(gab): Combine |thread_checker_| with a SequenceToken to differentiate
// between tasks running in the scope of this TestMockTimeTaskRunner and other
// task runners sharing this thread. http://crbug.com/631186
bool TestMockTimeTaskRunner::RunsTasksInCurrentSequence() const {}

bool TestMockTimeTaskRunner::PostDelayedTask(const Location& from_here,
                                             OnceClosure task,
                                             TimeDelta delay) {}

bool TestMockTimeTaskRunner::PostDelayedTaskAt(
    subtle::PostDelayedTaskPassKey,
    const Location& from_here,
    OnceClosure task,
    TimeTicks delayed_run_time,
    subtle::DelayPolicy deadline_policy) {}

bool TestMockTimeTaskRunner::PostNonNestableDelayedTask(
    const Location& from_here,
    OnceClosure task,
    TimeDelta delay) {}

void TestMockTimeTaskRunner::OnBeforeSelectingTask() {}

void TestMockTimeTaskRunner::OnAfterTimePassed() {}

void TestMockTimeTaskRunner::OnAfterTaskRun() {}

void TestMockTimeTaskRunner::ProcessTasksNoLaterThan(TimeDelta max_delta,
                                                     int limit) {}

void TestMockTimeTaskRunner::ForwardClocksUntilTickTime(TimeTicks later_ticks) {}

bool TestMockTimeTaskRunner::DequeueNextTask(const TimeTicks& reference,
                                             const TimeDelta& max_delta,
                                             TestPendingTask* next_task) {}

void TestMockTimeTaskRunner::Run(bool application_tasks_allowed,
                                 TimeDelta timeout) {}

void TestMockTimeTaskRunner::Quit() {}

void TestMockTimeTaskRunner::EnsureWorkScheduled() {}

TimeTicks TestMockTimeTaskRunner::MockClock::NowTicks() const {}

Time TestMockTimeTaskRunner::MockClock::Now() const {}

}  // namespace base