#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 {
namespace page_scheduler_impl_unittest {
namespace {
constexpr base::TimeDelta kEpsilon = …;
void IncrementCounter(int* counter) { … }
std::unique_ptr<PageSchedulerImpl> CreatePageScheduler(
PageScheduler::Delegate* page_scheduler_delegate,
MainThreadSchedulerImpl* scheduler,
AgentGroupScheduler& agent_group_scheduler) { … }
std::unique_ptr<FrameSchedulerImpl> CreateFrameScheduler(
PageSchedulerImpl* page_scheduler,
FrameScheduler::Delegate* delegate,
bool is_in_embedded_frame_tree,
FrameScheduler::FrameType frame_type) { … }
}
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) { … }
}
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) { … }
}
TEST_F(PageSchedulerImplTest, VirtualTime_TimerFastForwarding) { … }
TEST_F(PageSchedulerImplTest, VirtualTime_LoadingTaskFastForwarding) { … }
TEST_F(PageSchedulerImplTest,
RepeatingTimer_PageInBackground_MeansNothingForVirtualTime) { … }
TEST_F(PageSchedulerImplTest, PageBackgrounded_EnableVirtualTime) { … }
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) { … }
}
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) { … }
}
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) { … }
}
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) { … }
}
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() { … }
}
TEST_F(PageSchedulerImplTest, BackgroundTimerThrottling) { … }
TEST_F(PageSchedulerImplTest, OpenWebSocketExemptsFromBudgetThrottling) { … }
TEST_F(PageSchedulerImplTest, PageFreezeAndSetVisible) { … }
TEST_F(PageSchedulerImplTest, PageFreezeAndUnfreeze) { … }
TEST_F(PageSchedulerImplTest, AudioState) { … }
TEST_F(PageSchedulerImplTest, PageSchedulerDestroyedWhileAudioChangePending) { … }
TEST_F(PageSchedulerImplTest, AudiblePagesAreNotThrottled) { … }
TEST_F(PageSchedulerImplTest, FreezingRecentlyAudiblePage) { … }
TEST_F(PageSchedulerImplTest, FreezingAudiblePage) { … }
TEST_F(PageSchedulerImplTest, BudgetBasedThrottlingForPageScheduler) { … }
TEST_F(PageSchedulerImplTest, TestPageBackgroundedTimerSuspension) { … }
TEST_F(PageSchedulerImplTest, PageFrozenOnlyWhileAudioSilent) { … }
TEST_F(PageSchedulerImplTest, PageFrozenOnlyWhileNotVisible) { … }
}
}
}