chromium/third_party/blink/renderer/platform/scheduler/common/throttling/task_queue_throttler_unittest.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 "third_party/blink/renderer/platform/scheduler/common/throttling/task_queue_throttler.h"

#include <stddef.h>

#include <memory>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/task/common/lazy_now.h"
#include "base/task/sequence_manager/sequence_manager.h"
#include "base/task/sequence_manager/task_queue.h"
#include "base/task/sequence_manager/test/sequence_manager_for_test.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/time/time.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/scheduler/common/auto_advancing_virtual_time_domain.h"
#include "third_party/blink/renderer/platform/scheduler/common/throttling/budget_pool.h"
#include "third_party/blink/renderer/platform/scheduler/common/throttling/cpu_time_budget_pool.h"
#include "third_party/blink/renderer/platform/scheduler/common/throttling/wake_up_budget_pool.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"

namespace blink {
namespace scheduler {
// To avoid symbol collisions in jumbo builds.
namespace task_queue_throttler_unittest {

LazyNow;
TestMockTimeTaskRunner;
TimeTicks;
TaskQueue;
ElementsAre;

void NopTask() {}

void AddOneTask(size_t* count) {}

void RunTenTimesTask(size_t* count, TaskQueue* timer_queue) {}

Deque<base::TimeDelta> MakeTaskDurations(wtf_size_t size,
                                         base::TimeDelta duration) {}

class TaskQueueThrottlerTest : public testing::Test {};

// Advances mock clock every time we call NowTicks() from the scheduler.
class AutoAdvancingProxyClock : public base::TickClock {};

class TaskQueueThrottlerWithAutoAdvancingTimeTest
    : public TaskQueueThrottlerTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

namespace {

// Round up time to milliseconds to deal with autoadvancing time.
// TODO(altimin): round time only when autoadvancing time is enabled.
base::TimeDelta RoundTimeToMilliseconds(base::TimeDelta time) {}

base::TimeTicks RoundTimeToMilliseconds(base::TimeTicks time) {}

void TestTask(Vector<base::TimeTicks>* run_times,
              scoped_refptr<TestMockTimeTaskRunner> task_runner) {}

void ExpensiveTestTask(Vector<base::TimeTicks>* run_times,
                       scoped_refptr<TestMockTimeTaskRunner> task_runner) {}

void RecordThrottling(Vector<base::TimeDelta>* reported_throttling_times,
                      base::TimeDelta throttling_duration) {}
}  // namespace

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, TimerAlignment) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       TimerAlignment_Unthrottled) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, Refcount) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, WakeUpForNonDelayedTask) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, WakeUpForDelayedTask) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       SingleThrottledTaskPumpedAndRunWithNoExtraneousMessageLoopTasks) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       SingleFutureThrottledTaskPumpedAndRunWithNoExtraneousMessageLoopTasks) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       TwoFutureThrottledTaskPumpedAndRunWithNoExtraneousMessageLoopTasks) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       TaskDelayIsBasedOnRealTime) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       DoubleIncrementDoubleDecrement) {}

TEST_F(TaskQueueThrottlerTest, TimeBasedThrottling) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       EnableAndDisableCPUTimeBudgetPool) {}

TEST_F(TaskQueueThrottlerTest, ImmediateTasksTimeBudgetThrottling) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       TwoQueuesTimeBudgetThrottling) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       DisabledTimeBudgetDoesNotAffectThrottledQueues) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       TimeBudgetThrottlingDoesNotAffectUnthrottledQueues) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, MaxThrottlingDelay) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       EnableAndDisableThrottling) {}

TEST_F(TaskQueueThrottlerTest, ReportThrottling) {}

TEST_F(TaskQueueThrottlerTest, GrantAdditionalBudget) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       AddQueueThrottlerToBudgetPoolWhenThrottlingDisabled) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       DisabledQueueThenEnabledQueue) {}

TEST_F(TaskQueueThrottlerTest, TwoBudgetPools) {}

namespace {

void RunChainedTask(Deque<base::TimeDelta> task_durations,
                    TaskQueue* queue,
                    scoped_refptr<TestMockTimeTaskRunner> task_runner,
                    Vector<base::TimeTicks>* run_times,
                    base::TimeDelta delay) {}
}  // namespace

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       WakeUpBasedThrottling_ChainedTasks_Instantaneous) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       WakeUpBasedThrottling_ImmediateTasks_Fast) {}

TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest,
       WakeUpBasedThrottling_DelayedTasks) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_MultiplePoolsWithDifferentIntervalsOneEmpty) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_MultiplePoolsWithDifferentIntervals) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_MultiplePoolsWithUnalignedWakeUps) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_MultiplePoolsWithAllignedAndUnalignedWakeUps) {}

TEST_F(TaskQueueThrottlerTest, WakeUpBasedThrottling_EnableDisableThrottling) {}

TEST_F(TaskQueueThrottlerTest, WakeUpBasedThrottling_LowAlignedWakeUps) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_UnalignedWakeUps_MultipleTasks) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_IncreaseWakeUpIntervalBeforeWakeUp) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_DecreaseWakeUpIntervalBeforeWakeUp) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_IncreaseWakeUpIntervalDuringWakeUp) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottling_DecreaseWakeUpIntervalDuringWakeUp) {}

TEST_F(TaskQueueThrottlerTest, WakeUpBasedThrottlingWithCPUBudgetThrottling) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottlingWithCPUBudgetThrottling_OnAndOff) {}

TEST_F(TaskQueueThrottlerTest,
       WakeUpBasedThrottlingWithCPUBudgetThrottling_ChainedFastTasks) {}

}  // namespace task_queue_throttler_unittest
}  // namespace scheduler
}  // namespace blink