chromium/chrome/browser/predictors/loading_predictor_tab_helper_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/predictors/loading_predictor_tab_helper.h"

#include "base/memory/raw_ptr.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/optimization_guide/mock_optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/predictors/loading_predictor.h"
#include "chrome/browser/predictors/loading_test_util.h"
#include "chrome/browser/predictors/predictors_enums.h"
#include "chrome/browser/predictors/predictors_features.h"
#include "chrome/browser/sessions/session_tab_helper_factory.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/variations/scoped_variations_ids_provider.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/test/navigation_simulator.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"

_;
An;
ByRef;
DoAll;
Eq;
Invoke;
Mock;
NiceMock;
Return;
SaveArg;
StrictMock;
WithArg;

namespace predictors {

class MockLoadingDataCollector : public LoadingDataCollector {};

MockLoadingDataCollector::MockLoadingDataCollector(
    const LoadingPredictorConfig& config)
    :{}

class LoadingPredictorTabHelperTest : public ChromeRenderViewHostTestHarness {};

void LoadingPredictorTabHelperTest::SetUp() {}

void LoadingPredictorTabHelperTest::TearDown() {}

void LoadingPredictorTabHelperTest::
    NavigateAndCommitInMainFrameAndVerifyMetrics(const std::string& url) {}

SessionID LoadingPredictorTabHelperTest::GetTabID() {}

void LoadingPredictorTabHelperTest::NavigateAndCommitInFrame(
    const std::string& url,
    content::RenderFrameHost* rfh) {}

// Tests that a main frame navigation is correctly recorded by the
// LoadingDataCollector.
TEST_F(LoadingPredictorTabHelperTest, MainFrameNavigation) {}

// Tests that an old and new navigation ids are correctly set if a navigation
// has redirects.
TEST_F(LoadingPredictorTabHelperTest, MainFrameNavigationWithRedirects) {}

// Tests that a subframe navigation is not recorded.
TEST_F(LoadingPredictorTabHelperTest, SubframeNavigation) {}

// Tests that a failed navigation is correctly recorded.
TEST_F(LoadingPredictorTabHelperTest, MainFrameNavigationFailed) {}

// Tests that a same document navigation is not recorded.
TEST_F(LoadingPredictorTabHelperTest, MainFrameNavigationSameDocument) {}

// Tests that document on load completed is recorded with correct navigation
// id.
TEST_F(LoadingPredictorTabHelperTest, DocumentOnLoadCompleted) {}

// Tests that a resource load is correctly recorded.
TEST_F(LoadingPredictorTabHelperTest, ResourceLoadComplete) {}

// Tests that a resource loaded in a subframe is not recorded.
TEST_F(LoadingPredictorTabHelperTest, ResourceLoadCompleteInSubFrame) {}

// Tests that a resource load from the memory cache is correctly recorded.
TEST_F(LoadingPredictorTabHelperTest, LoadResourceFromMemoryCache) {}

class LoadingPredictorTabHelperOptimizationGuideDeciderTest
    : public LoadingPredictorTabHelperTest {};

// Tests that document on load completed is recorded with correct navigation
// id and that optimization guide is not consulted when from same-origin.
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderTest,
       DocumentOnLoadCompletedOptimizationGuideSameOrigin) {}

// Tests that document on load completed is recorded.
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderTest,
       DocumentOnLoadCompletedOptimizationGuide) {}

// Tests that page destruction is recorded with the correct navigation id and
// optimization guide prediction.
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderTest,
       PageDestroyedOptimizationGuide) {}

// Tests that predictions are recorded correctly when they come after the
// navigation commits.
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderTest,
       PageDestroyedOptimizationGuidePredictionComesAfterCommit) {}

// Tests that predictions are recorded correctly when they arrive after a
// redirect.
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderTest,
       PageDestroyedOptimizationGuidePredictionArrivedAfterRedirect) {}

// Tests that page destruction is recorded with correct navigation id and
// optimization guide prediction when the prediction has not arrived.
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderTest,
       PageDestroyedOptimizationGuidePredictionHasNotArrived) {}

// Tests that page destroyed is recorded with correct navigation id and
// optimization guide prediction and does not crash if callback comes after
// everything has been recorded.
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderTest,
       PageDestroyedOptimizationGuidePredictionComesAfterPageDestroyed) {}

// Tests that page destruction is recorded with correct navigation and
// optimization guide prediction with no prediction..
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderTest,
       PageDestroyedOptimizationGuidePredictionArrivedNoPrediction) {}

// Tests that page destruction is recorded with correct navigation id and
// optimization guide prediction with no prediction..
TEST_F(
    LoadingPredictorTabHelperOptimizationGuideDeciderTest,
    PageDestroyedOptimizationGuidePredictionArrivedNoLoadingPredictorMetadata) {}

class LoadingPredictorTabHelperOptimizationGuideDeciderWithPrefetchTest
    : public LoadingPredictorTabHelperOptimizationGuideDeciderTest {};

// Tests that page destruction is recorded with correct navigation id and
// optimization guide prediction.
TEST_F(LoadingPredictorTabHelperOptimizationGuideDeciderWithPrefetchTest,
       PageDestroyedOptimizationGuide) {}

class TestLoadingDataCollector : public LoadingDataCollector {};

TestLoadingDataCollector::TestLoadingDataCollector(
    const LoadingPredictorConfig& config)
    :{}

class LoadingPredictorTabHelperTestCollectorTest
    : public LoadingPredictorTabHelperTest {};

void LoadingPredictorTabHelperTestCollectorTest::SetUp() {}

// Tests that a resource load is correctly recorded with the correct priority.
TEST_F(LoadingPredictorTabHelperTestCollectorTest, ResourceLoadComplete) {}

class LoadingPredictorTabHelperTestCollectorFencedFramesTest
    : public LoadingPredictorTabHelperTestCollectorTest {};

TEST_F(LoadingPredictorTabHelperTestCollectorFencedFramesTest,
       DoNotRecordResourceLoadComplete) {}

}  // namespace predictors