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

#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/predictors/loading_test_util.h"
#include "chrome/browser/preloading/preloading_prefs.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
#include "net/base/network_anonymization_key.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h"

_;
Return;
StrictMock;
DoAll;
SetArgPointee;

namespace predictors {

namespace {

// First two are preconnectable, last one is not (see SetUp()).
const char kUrl[] =;
const char kUrl2[] =;
const char kUrl3[] =;  // Non http(s) scheme to avoid
                                           // preconnect to the main frame.

class MockPreconnectManager : public PreconnectManager {};

MockPreconnectManager::MockPreconnectManager(base::WeakPtr<Delegate> delegate,
                                             Profile* profile)
    :{}

LoadingPredictorConfig CreateConfig() {}

// Creates a NetworkAnonymizationKey for a main frame navigation to URL.
net::NetworkAnonymizationKey CreateNetworkanonymization_key(
    const GURL& main_frame_url) {}

NavigationId GetNextId() {}

}  // namespace

class LoadingPredictorTest : public testing::Test {};

LoadingPredictorTest::~LoadingPredictorTest() = default;

void LoadingPredictorTest::SetUp() {}

void LoadingPredictorTest::TearDown() {}

void LoadingPredictorTest::SetPreference() {}

class LoadingPredictorPreconnectTest : public LoadingPredictorTest {};

void LoadingPredictorPreconnectTest::SetUp() {}

void LoadingPredictorPreconnectTest::TearDown() {}

void LoadingPredictorPreconnectTest::SetPreference() {}

TEST_F(LoadingPredictorTest, TestOnNavigationStarted) {}

TEST_F(LoadingPredictorTest, TestMainFrameResponseCancelsHint) {}

TEST_F(LoadingPredictorTest, TestMainFrameResponseClearsNavigations) {}

TEST_F(LoadingPredictorTest, TestMainFrameRequestDoesntCancelExternalHint) {}

TEST_F(LoadingPredictorTest, TestDuplicateHintAfterPreconnectCompleteCalled) {}

TEST_F(LoadingPredictorTest,
       TestDuplicateHintAfterPreconnectCompleteNotCalled) {}

TEST_F(LoadingPredictorTest, TestDontTrackNonPrefetchableUrls) {}

TEST_F(LoadingPredictorTest, TestDontPredictOmniboxHints) {}

TEST_F(LoadingPredictorPreconnectTest, TestHandleOmniboxHint) {}

// Checks that the predictor preconnects to an initial origin even when it
// doesn't have any historical data for this host.
TEST_F(LoadingPredictorPreconnectTest, TestAddInitialUrlToEmptyPrediction) {}

// Checks that the predictor doesn't add an initial origin to a preconnect list
// if the list already contains the origin.
TEST_F(LoadingPredictorPreconnectTest, TestAddInitialUrlMatchesPrediction) {}

// Checks that the predictor adds an initial origin to a preconnect list if the
// list doesn't contain this origin already. It may be possible if an initial
// url redirects to another host.
TEST_F(LoadingPredictorPreconnectTest, TestAddInitialUrlDoesntMatchPrediction) {}

// Checks that the predictor doesn't preconnect to a bad url.
TEST_F(LoadingPredictorPreconnectTest, TestAddInvalidInitialUrl) {}

// Checks that the predictor uses the provided prediction if there isn't an
// active hint initiated via a local prediction happening already.
TEST_F(LoadingPredictorPreconnectTest,
       TestPrepareForPageLoadPredictionProvided) {}

// Checks that the predictor does not proceed with an empty request.
TEST_F(LoadingPredictorPreconnectTest,
       TestPrepareForPageLoadPredictionWithEmptyRequestsProvided) {}

// Checks that the predictor preconnects to an initial origin even when it
// doesn't have any historical data for this host, but still allows subsequent
// calls to PrepareForPageLoad with a provided prediction.
TEST_F(LoadingPredictorPreconnectTest,
       TestPrepareForPageLoadPreconnectsUsingPredictionWhenNoLocalPrediction) {}

// Checks that the predictor uses a prediction even if there is already a local
// initiated one in flight.
TEST_F(
    LoadingPredictorPreconnectTest,
    TestPrepareForPageLoadPredictionProvidedButHasLocalPreconnectPrediction) {}

// Checks that the opaque origins will not trigger preconnect as it is treated
// as cross-origin and cannot be reused.
TEST_F(LoadingPredictorPreconnectTest, TestHandleHintWithOpaqueOrigins) {}

// Checks that the behavior of HandleHintByOrigin is expected when
// only_allow_https = true.
TEST_F(LoadingPredictorPreconnectTest, TestHandleHintWhenOnlyHttpsAllowed) {}

// Checks that HandleHintByOrigin can preresolve correctly.
TEST_F(LoadingPredictorPreconnectTest,
       TestHandleHintPreresolveWhenOnlyHttpsAllowed) {}

}  // namespace predictors