chromium/chrome/browser/navigation_predictor/navigation_predictor_unittest.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/navigation_predictor/navigation_predictor.h"

#include <map>
#include <memory>
#include <string>
#include <utility>

#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.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 "chrome/browser/page_load_metrics/observers/page_anchors_metrics_observer.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/navigation_simulator.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "navigation_predictor_metrics_document_data.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.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/public/mojom/loader/navigation_predictor.mojom-forward.h"
#include "third_party/blink/public/mojom/loader/navigation_predictor.mojom.h"
#include "url/gurl.h"

namespace {

class NavigationPredictorTest : public ChromeRenderViewHostTestHarness {};

}  // namespace

// Basic test to check the ReportNewAnchorElements method aggregates
// metric data correctly.
TEST_F(NavigationPredictorTest, ReportNewAnchorElements) {}

TEST_F(NavigationPredictorTest, ReportSameAnchorElementTwice) {}

TEST_F(NavigationPredictorTest, MedianLinkLocation) {}

// Basic test to check the ReportNewAnchorElements method can be
// called with multiple anchors at once.
TEST_F(NavigationPredictorTest, ReportNewAnchorElementsMultipleAnchors) {}

class MetricsBuilder {};

TEST_F(NavigationPredictorTest,
       ReportAnchorElementsEnteredViewportContainsImage) {}

TEST_F(NavigationPredictorTest, ReportAnchorElementsEnteredViewportIsInIframe) {}

TEST_F(NavigationPredictorTest,
       ReportAnchorElementsEnteredViewportIsURLIncrementedByOne) {}

TEST_F(NavigationPredictorTest, ReportAnchorElementsEnteredViewportSameOrigin) {}

TEST_F(NavigationPredictorTest,
       ReportAnchorElementsEnteredViewportRatioDistanceRootTop) {}

TEST_F(NavigationPredictorTest,
       ReportAnchorElementsEnteredViewportHasTextSibling) {}

TEST_F(NavigationPredictorTest, ReportAnchorElementsEnteredViewportFontSize) {}

TEST_F(NavigationPredictorTest, ReportAnchorElementsEnteredViewportIsBold) {}

TEST_F(NavigationPredictorTest, ReportAnchorElementsEnteredViewportPathLength) {}

TEST_F(NavigationPredictorTest, ReportAnchorElementsEnteredViewportPathDepth) {}

TEST_F(NavigationPredictorTest, ReportAnchorElementClick) {}

TEST_F(NavigationPredictorTest, ReportAnchorElementClickMoreThan10Clicks) {}

class MockNavigationPredictorForTesting : public NavigationPredictor {};

class NavigationPredictorUserInteractionsTest : public NavigationPredictorTest {};

TEST_F(NavigationPredictorUserInteractionsTest,
       AnchorElementEnteredAndLeftViewport) {}

TEST_F(NavigationPredictorUserInteractionsTest,
       AnchorElementPointerOverAndHover) {}

TEST_F(NavigationPredictorUserInteractionsTest, NavigationStartToClick) {}

TEST_F(NavigationPredictorUserInteractionsTest, RecordUserInteractionMetrics) {}

TEST_F(NavigationPredictorUserInteractionsTest, RecordPreloadingOnHover) {}

TEST_F(NavigationPredictorUserInteractionsTest,
       UserInteractionMetricsIsClearedAfterNavigation) {}

TEST_F(NavigationPredictorUserInteractionsTest,
       UserInteractionMetricsIgnoresNotReportedAnchorIds) {}

// TODO(crbug.com/40266872): Flaky on Android.
TEST_F(NavigationPredictorUserInteractionsTest,
       DISABLED_UserInteractionMetricsIgnoresUpdatesForInvalidUkmSourceId) {}

TEST_F(NavigationPredictorUserInteractionsTest,
       ClickOnNotSampledAnchorElement) {}

TEST_F(NavigationPredictorUserInteractionsTest,
       ProcessPointerEventUsingMLModel) {}

TEST_F(NavigationPredictorUserInteractionsTest, MLModelMaxHoverTime) {}

TEST_F(NavigationPredictorTest, RemoveAnchorElement) {}

class NavigationPredictorNewViewportFeaturesTest
    : public NavigationPredictorUserInteractionsTest {};

TEST_F(NavigationPredictorNewViewportFeaturesTest, RecordPositionMetrics) {}

TEST_F(NavigationPredictorNewViewportFeaturesTest,
       RecordPositionMetrics_NotInViewport) {}

TEST_F(NavigationPredictorNewViewportFeaturesTest,
       RecordPositionMetrics_NoDistanceFromPointerDown) {}