chromium/components/optimization_guide/core/prediction_manager_unittest.cc

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

#include "components/optimization_guide/core/prediction_manager.h"

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

#include "base/base64.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/leveldb_proto/testing/fake_db.h"
#include "components/optimization_guide/core/model_util.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/optimization_guide/core/optimization_guide_logger.h"
#include "components/optimization_guide/core/optimization_guide_prefs.h"
#include "components/optimization_guide/core/optimization_guide_store.h"
#include "components/optimization_guide/core/optimization_guide_switches.h"
#include "components/optimization_guide/core/optimization_guide_test_util.h"
#include "components/optimization_guide/core/optimization_guide_util.h"
#include "components/optimization_guide/core/optimization_target_model_observer.h"
#include "components/optimization_guide/core/prediction_model_download_manager.h"
#include "components/optimization_guide/core/prediction_model_fetcher.h"
#include "components/optimization_guide/core/prediction_model_fetcher_impl.h"
#include "components/optimization_guide/core/prediction_model_store.h"
#include "components/optimization_guide/core/proto_database_provider_test_base.h"
#include "components/optimization_guide/proto/hint_cache.pb.h"
#include "components/optimization_guide/proto/models.pb.h"
#include "components/prefs/testing_pref_service.h"
#include "components/variations/scoped_variations_ids_provider.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/page_transition_types.h"

FakeDB;

namespace {

// Retry delay is 2 minutes to allow for fetch retry delay + some random delay
// to pass.
constexpr int kTestFetchRetryDelaySecs =;
// 24 hours + random fetch delay.
constexpr int kUpdateFetchModelAndFeaturesTimeSecs =;

constexpr char kTestLocale[] =;

}  // namespace

namespace optimization_guide {

proto::PredictionModel CreatePredictionModelForGetModelsResponse(
    proto::OptimizationTarget optimization_target) {}

std::unique_ptr<proto::GetModelsResponse> BuildGetModelsResponse(
    std::set<proto::OptimizationTarget> optimization_targets) {}

proto::ModelCacheKey GetTestModelCacheKey() {}

class FakeOptimizationTargetModelObserver
    : public OptimizationTargetModelObserver {};

class FakePredictionModelDownloadManager
    : public PredictionModelDownloadManager {};

enum class PredictionModelFetcherEndState {};

void RunGetModelsCallback(
    ModelsFetchedCallback callback,
    std::unique_ptr<proto::GetModelsResponse> get_models_response) {}

// A mock class implementation of PredictionModelFetcherImpl.
class TestPredictionModelFetcher : public PredictionModelFetcherImpl {};


class TestPredictionManager : public PredictionManager {};

class TestPredictionModelStore : public PredictionModelStore {};

class PredictionManagerTestBase : public ProtoDatabaseProviderTestBase {};

class PredictionManagerRemoteFetchingDisabledTest
    : public PredictionManagerTestBase {};

TEST_F(PredictionManagerRemoteFetchingDisabledTest, RemoteFetchingDisabled) {}

class PredictionManagerModelDownloadingDisabledTest
    : public PredictionManagerTestBase {};

TEST_F(PredictionManagerModelDownloadingDisabledTest,
       ModelDownloadingDisabledShouldNotFetch) {}

class PredictionManagerTest : public PredictionManagerTestBase {};

TEST_F(PredictionManagerTest, RemoteFetchingPrefDisabled) {}

TEST_F(PredictionManagerTest, RemoteFetchingPrefEnabledAndThenDisabled) {}

TEST_F(PredictionManagerTest, AddObserverForOptimizationTargetModel) {}

TEST_F(PredictionManagerTest,
       AddObserverForOptimizationTargetModelAddAnotherObserverForSameTarget) {}

// See crbug/1227996.
#if !BUILDFLAG(IS_WIN)
TEST_F(PredictionManagerTest,
       AddObserverForOptimizationTargetModelCommandLineOverride) {}
#endif

TEST_F(PredictionManagerTest,
       NoPredictionModelForRegisteredOptimizationTarget) {}

// Tests the opt target observer valid re-registrations, i.e., adding, removing
// and then re-adding an observer for the same opt target.
TEST_F(PredictionManagerTest, OptimizationTargetModelObserverReRegistrations) {}

TEST_F(PredictionManagerTest, UpdatePredictionModelsWithInvalidModel) {}

TEST_F(PredictionManagerTest, UpdateModelFileWithSameVersion) {}

TEST_F(PredictionManagerTest, DownloadManagerUnavailableShouldNotFetch) {}

TEST_F(PredictionManagerTest, UpdateModelWithDownloadUrl) {}

TEST_F(PredictionManagerTest, UpdateModelForUnregisteredTargetOnModelReady) {}

TEST_F(PredictionManagerTest,
       StoreInitializedAfterOptimizationTargetRegistered) {}

TEST_F(PredictionManagerTest,
       StoreInitializedBeforeOptimizationTargetRegistered) {}

TEST_F(PredictionManagerTest, ModelFetcherTimerRetryDelay) {}

TEST_F(PredictionManagerTest, ModelFetcherTimerFetchSucceeds) {}

TEST_F(PredictionManagerTest, ModelRemovedWhenMissingInGetModelsResponse) {}

}  // namespace optimization_guide