chromium/third_party/blink/renderer/core/loader/interactive_detector_test.cc

// Copyright 2017 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/core/loader/interactive_detector.h"

#include "base/functional/callback_helpers.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/events/message_event.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/core/testing/scoped_mock_overlay_scrollbars.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"

namespace blink {

PageLoad;

class NetworkActivityCheckerForTest
    : public InteractiveDetector::NetworkActivityChecker {};

int NetworkActivityCheckerForTest::GetActiveConnections() {}

class InteractiveDetectorTest : public testing::Test,
                                public ScopedMockOverlayScrollbars {};

// Note: The tests currently assume kTimeToInteractiveWindowSeconds is 5
// seconds. The window size is unlikely to change, and this makes the test
// scenarios significantly easier to write.

// Note: Some of the tests are named W_X_Y_Z, where W, X, Y, Z can any of the
// following events:
// FCP: First Contentful Paint
// DCL: DomContentLoadedEnd
// FcpDetect: Detection of FCP. FCP is a presentation timestamp.
// LT: Long Task
// The name shows the ordering of these events in the test.

TEST_F(InteractiveDetectorTest, FCP_DCL_FcpDetect) {}

TEST_F(InteractiveDetectorTest, DCL_FCP_FcpDetect) {}

TEST_F(InteractiveDetectorTest, InstantDetectionAtFcpDetectIfPossible) {}

TEST_F(InteractiveDetectorTest, FcpDetectFiresAfterLateLongTask) {}

TEST_F(InteractiveDetectorTest, FCP_FcpDetect_DCL) {}

TEST_F(InteractiveDetectorTest, LongTaskBeforeFCPDoesNotAffectTTI) {}

TEST_F(InteractiveDetectorTest, DCLDoesNotResetTimer) {}

TEST_F(InteractiveDetectorTest, DCL_FCP_FcpDetect_LT) {}

TEST_F(InteractiveDetectorTest, DCL_FCP_LT_FcpDetect) {}

TEST_F(InteractiveDetectorTest, FCP_FcpDetect_LT_DCL) {}

TEST_F(InteractiveDetectorTest, DclIsMoreThan5sAfterFCP) {}

TEST_F(InteractiveDetectorTest, NetworkBusyBlocksTTIEvenWhenMainThreadQuiet) {}

// FCP is a presentation timestamp, which is computed by another process and
// thus received asynchronously by the renderer process. Therefore, there can be
// some delay between the time in which FCP occurs and the time in which FCP is
// detected by the renderer.
TEST_F(InteractiveDetectorTest, LongEnoughQuietWindowBetweenFCPAndFcpDetect) {}

TEST_F(InteractiveDetectorTest, NetworkBusyEndIsNotTTI) {}

TEST_F(InteractiveDetectorTest, LateLongTaskWithLateFCPDetection) {}

TEST_F(InteractiveDetectorTest, IntermittentNetworkBusyBlocksTTI) {}

TEST_F(InteractiveDetectorTest, InvalidatingUserInput) {}

TEST_F(InteractiveDetectorTest, TaskLongerThan5sBlocksTTI) {}

TEST_F(InteractiveDetectorTest, LongTaskAfterTTIDoesNothing) {}

// In tests for Total Blocking Time (TBT) we call SetTimeToInteractive() instead
// of allowing TimeToInteractive to occur because the computation is gated
// behind tracing being enabled, which means that they won't run by default. In
// addition, further complication stems from the fact that the vector of
// longtasks is cleared at the end of OnTimeToInteractiveDetected(). Therefore,
// the simplest solution is to manually set all of the relevant variables and
// check the correctness of the method ComputeTotalBlockingTime(). This can be
// revisited if we move TBT computations to occur outside of the trace event.
TEST_F(InteractiveDetectorTest, TotalBlockingTimeZero) {}

TEST_F(InteractiveDetectorTest, TotalBlockingTimeNonZero) {}

TEST_F(InteractiveDetectorTest, TotalBlockingSingleTask) {}

TEST_F(InteractiveDetectorTest, FirstInputDelayForClickOnMobile) {}

TEST_F(InteractiveDetectorTest,
       FirstInputDelayForClickOnDesktopWithFixEnabled) {}

}  // namespace blink