#include "content/browser/preloading/preloading_decider.h"
#include <vector>
#include "base/strings/strcat.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/preloading/prefetch/prefetch_document_manager.h"
#include "content/browser/preloading/prefetch/prefetch_features.h"
#include "content/browser/preloading/prefetch/prefetch_service.h"
#include "content/browser/preloading/prefetcher.h"
#include "content/browser/preloading/preloading.h"
#include "content/browser/preloading/preloading_confidence.h"
#include "content/browser/preloading/preloading_data_impl.h"
#include "content/browser/preloading/preloading_trigger_type_impl.h"
#include "content/browser/preloading/prerenderer.h"
#include "content/common/features.h"
#include "content/public/browser/anchor_element_preconnect_delegate.h"
#include "content/public/common/content_client.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_renderer_host.h"
#include "content/test/test_content_browser_client.h"
#include "content/test/test_web_contents.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/preloading/anchor_element_interaction_host.mojom.h"
#include "third_party/blink/public/mojom/speculation_rules/speculation_rules.mojom-shared.h"
namespace content {
namespace {
class MockAnchorElementPreconnector : public AnchorElementPreconnectDelegate { … };
class TestPrefetchService : public PrefetchService { … };
class MockPrerenderer : public Prerenderer { … };
class ScopedMockPrerenderer { … };
class MockContentBrowserClient : public TestContentBrowserClient { … };
enum class EventType { … };
class PreloadingDeciderTest : public RenderViewHostTestHarness { … };
TEST_F(PreloadingDeciderTest, DefaultEagernessCandidatesStartOnStandby) { … }
class PreloadingDeciderPointerEventHeuristicsTest
: public PreloadingDeciderTest,
public ::testing::WithParamInterface<
std::tuple<EventType, blink::mojom::SpeculationEagerness>> { … };
TEST_P(PreloadingDeciderPointerEventHeuristicsTest,
PrefetchOnPointerEventHeuristics) { … }
TEST_P(PreloadingDeciderPointerEventHeuristicsTest,
PrerenderOnPointerEventHeuristics) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(PreloadingDeciderTest, CanOverridePointerDownEagerness) { … }
TEST_F(PreloadingDeciderTest, CanOverridePointerHoverEagerness) { … }
TEST_F(PreloadingDeciderTest, UmaRecallStats) { … }
class PreloadingDeciderWithParameterizedSpeculationActionTest
: public PreloadingDeciderTest,
public ::testing::WithParamInterface<blink::mojom::SpeculationAction> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(PreloadingDeciderWithParameterizedSpeculationActionTest,
CandidateWithMultipleEagernessValues) { … }
TEST_P(PreloadingDeciderWithParameterizedSpeculationActionTest,
CandidateCanBeReprefetchedAfterDiscard) { … }
TEST_F(PreloadingDeciderTest, ProcessCandidates_EagerCandidateRemoval) { … }
TEST_F(PreloadingDeciderTest, ProcessCandidates_NonEagerCandidateRemoval) { … }
TEST_F(PreloadingDeciderTest,
ProcessCandidates_SecondCandidateWithSameUrlKeepsPrefetchAlive) { … }
TEST_F(PreloadingDeciderTest,
OnPointerHoverWithMotionEstimatorIsRecordedToUMA) { … }
class PreloadingDeciderMLModelTest
: public PreloadingDeciderTest,
public ::testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(PreloadingDeciderMLModelTest, OnPreloadingHeuristicsModelDone) { … }
TEST_P(PreloadingDeciderMLModelTest, UseHoverHeuristicWhenNoMLModelPresent) { … }
class PreloadingDeciderMLModelActiveTest : public PreloadingDeciderTest { … };
TEST_F(PreloadingDeciderMLModelActiveTest,
ModelEnactsModeratePrefetchCandidate) { … }
TEST_F(PreloadingDeciderMLModelActiveTest,
ModelEnactsModeratePrerenderCandidate) { … }
TEST_F(PreloadingDeciderMLModelActiveTest,
ModelPrerendersCandidateOverPrefetch) { … }
TEST_F(PreloadingDeciderMLModelActiveTest, ModelConfidenceThreshold) { … }
TEST_F(PreloadingDeciderMLModelActiveTest, ModelNoPreconnectFallback) { … }
TEST_F(PreloadingDeciderMLModelActiveTest, ModelSupersedesHoverHeuristic) { … }
}
}