chromium/third_party/blink/renderer/platform/scheduler/main_thread/page_scheduler_impl_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/main_thread/page_scheduler_impl.h"

#include <memory>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_param_associator.h"
#include "base/metrics/field_trial_params.h"
#include "base/task/sequence_manager/test/fake_task.h"
#include "base/task/sequence_manager/test/sequence_manager_for_test.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.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/public/common/features.h"
#include "third_party/blink/renderer/platform/scheduler/common/features.h"
#include "third_party/blink/renderer/platform/scheduler/common/task_priority.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_scheduler_impl.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_task_queue_controller.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/page_visibility_state.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

FakeTask;
FakeTaskTiming;
TaskQueue;
ElementsAre;
VirtualTimePolicy;

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

namespace {

constexpr base::TimeDelta kEpsilon =;

void IncrementCounter(int* counter) {}

// This is a wrapper around MainThreadSchedulerImpl::CreatePageScheduler, that
// returns the PageScheduler as a PageSchedulerImpl.
std::unique_ptr<PageSchedulerImpl> CreatePageScheduler(
    PageScheduler::Delegate* page_scheduler_delegate,
    MainThreadSchedulerImpl* scheduler,
    AgentGroupScheduler& agent_group_scheduler) {}

// This is a wrapper around PageSchedulerImpl::CreateFrameScheduler, that
// returns the FrameScheduler as a FrameSchedulerImpl.
std::unique_ptr<FrameSchedulerImpl> CreateFrameScheduler(
    PageSchedulerImpl* page_scheduler,
    FrameScheduler::Delegate* delegate,
    bool is_in_embedded_frame_tree,
    FrameScheduler::FrameType frame_type) {}
}  // namespace

Bucket;
UnorderedElementsAreArray;

class MockPageSchedulerDelegate : public PageScheduler::Delegate {};

class PageSchedulerImplTest : public testing::Test {};

TEST_F(PageSchedulerImplTest, TestDestructionOfFrameSchedulersBefore) {}

TEST_F(PageSchedulerImplTest, TestDestructionOfFrameSchedulersAfter) {}

namespace {

void RunRepeatingTask(scoped_refptr<base::SingleThreadTaskRunner>,
                      int* run_count,
                      base::TimeDelta delay);

base::OnceClosure MakeRepeatingTask(
    scoped_refptr<base::SingleThreadTaskRunner> task_runner,
    int* run_count,
    base::TimeDelta delay) {}

void RunRepeatingTask(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
                      int* run_count,
                      base::TimeDelta delay) {}

}  // namespace

TEST_F(PageSchedulerImplTest, RepeatingTimer_PageInForeground) {}

TEST_F(PageSchedulerImplTest, RepeatingTimer_PageInBackgroundThenForeground) {}

TEST_F(PageSchedulerImplTest, RepeatingLoadingTask_PageInBackground) {}

TEST_F(PageSchedulerImplTest, RepeatingTimers_OneBackgroundOneForeground) {}

TEST_F(PageSchedulerImplTest, IsLoadingTest) {}

namespace {

void RunVirtualTimeRecorderTask(const base::TickClock* clock,
                                MainThreadSchedulerImpl* scheduler,
                                Vector<base::TimeTicks>* out_real_times,
                                Vector<base::TimeTicks>* out_virtual_times) {}

base::OnceClosure MakeVirtualTimeRecorderTask(
    const base::TickClock* clock,
    MainThreadSchedulerImpl* scheduler,
    Vector<base::TimeTicks>* out_real_times,
    Vector<base::TimeTicks>* out_virtual_times) {}
}  // namespace

TEST_F(PageSchedulerImplTest, VirtualTime_TimerFastForwarding) {}

TEST_F(PageSchedulerImplTest, VirtualTime_LoadingTaskFastForwarding) {}

TEST_F(PageSchedulerImplTest,
       RepeatingTimer_PageInBackground_MeansNothingForVirtualTime) {}

// Check that enabling virtual time while the page is backgrounded prevents a
// page from being frozen if it wasn't already.
TEST_F(PageSchedulerImplTest, PageBackgrounded_EnableVirtualTime) {}

// Check that enabling virtual time while a backgrounded page is frozen
// unfreezes it.
TEST_F(PageSchedulerImplTest, PageFrozen_EnableVirtualTime) {}

namespace {

void RunOrderTask(int index, Vector<int>* out_run_order) {}

void DelayedRunOrderTask(
    int index,
    scoped_refptr<base::SingleThreadTaskRunner> task_runner,
    Vector<int>* out_run_order) {}
}  // namespace

TEST_F(PageSchedulerImplTest, VirtualTime_NotAllowedToAdvance) {}

TEST_F(PageSchedulerImplTest, VirtualTime_AllowedToAdvance) {}

TEST_F(PageSchedulerImplTest, RepeatingTimer_PageInBackground) {}

TEST_F(PageSchedulerImplTest, VirtualTimeSettings_NewFrameScheduler) {}

namespace {

template <typename T>
base::OnceClosure MakeDeletionTask(T* obj) {}

}  // namespace

TEST_F(PageSchedulerImplTest, DeleteFrameSchedulers_InTask) {}

TEST_F(PageSchedulerImplTest, DeletePageScheduler_InTask) {}

TEST_F(PageSchedulerImplTest, DeleteThrottledQueue_InTask) {}

TEST_F(PageSchedulerImplTest, VirtualTimePauseCount_DETERMINISTIC_LOADING) {}

TEST_F(PageSchedulerImplTest,
       WebScopedVirtualTimePauser_DETERMINISTIC_LOADING) {}

namespace {

void RecordVirtualTime(MainThreadSchedulerImpl* scheduler,
                       base::TimeTicks* out) {}

void PauseAndUnpauseVirtualTime(MainThreadSchedulerImpl* scheduler,
                                FrameSchedulerImpl* frame_scheduler,
                                base::TimeTicks* paused,
                                base::TimeTicks* unpaused) {}

}  // namespace

TEST_F(PageSchedulerImplTest,
       WebScopedVirtualTimePauserWithInterleavedTasks_DETERMINISTIC_LOADING) {}

TEST_F(PageSchedulerImplTest,
       MultipleWebScopedVirtualTimePausers_DETERMINISTIC_LOADING) {}

TEST_F(PageSchedulerImplTest, NestedMessageLoop_DETERMINISTIC_LOADING) {}

TEST_F(PageSchedulerImplTest, PauseTimersWhileVirtualTimeIsPaused) {}

TEST_F(PageSchedulerImplTest, VirtualTimeBudgetExhaustedCallback) {}

namespace {
void RepostingTask(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
                   int max_count,
                   int* count) {}

void DelayedTask(int* count_in, int* count_out) {}

}  // namespace

TEST_F(PageSchedulerImplTest, MaxVirtualTimeTaskStarvationCountOneHundred) {}

TEST_F(PageSchedulerImplTest,
       MaxVirtualTimeTaskStarvationCountOneHundredNestedMessageLoop) {}

TEST_F(PageSchedulerImplTest, MaxVirtualTimeTaskStarvationCountZero) {}

namespace {

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

void InitializeTrialParams() {}

}  // namespace

TEST_F(PageSchedulerImplTest, BackgroundTimerThrottling) {}

TEST_F(PageSchedulerImplTest, OpenWebSocketExemptsFromBudgetThrottling) {}

// Verify that freezing a page prevents tasks in its task queues from running.
// Then, verify that making the page visible unfreezes it and allows tasks in
// its task queues to run.
TEST_F(PageSchedulerImplTest, PageFreezeAndSetVisible) {}

// Same as before, but unfreeze the page explicitly instead of making it
// visible.
TEST_F(PageSchedulerImplTest, PageFreezeAndUnfreeze) {}

TEST_F(PageSchedulerImplTest, AudioState) {}

TEST_F(PageSchedulerImplTest, PageSchedulerDestroyedWhileAudioChangePending) {}

TEST_F(PageSchedulerImplTest, AudiblePagesAreNotThrottled) {}

// Regression test for crbug.com/1431695. Test freezing and state changes work
// correctly if the OnAudioSilent timer fires after the page is frozen.
TEST_F(PageSchedulerImplTest, FreezingRecentlyAudiblePage) {}

// Regression test for crbug.com/1431695. Test freezing and state changes work
// correctly if the AudioStateChanged notification occurs after the page is
// frozen.
TEST_F(PageSchedulerImplTest, FreezingAudiblePage) {}

TEST_F(PageSchedulerImplTest, BudgetBasedThrottlingForPageScheduler) {}

TEST_F(PageSchedulerImplTest, TestPageBackgroundedTimerSuspension) {}

TEST_F(PageSchedulerImplTest, PageFrozenOnlyWhileAudioSilent) {}

TEST_F(PageSchedulerImplTest, PageFrozenOnlyWhileNotVisible) {}

}  // namespace page_scheduler_impl_unittest
}  // namespace scheduler
}  // namespace blink