chromium/components/permissions/prediction_service/prediction_service_unittest.cc

// Copyright 2020 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/permissions/prediction_service/prediction_service.h"

#include <memory>
#include <optional>
#include <vector>

#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_request_enums.h"
#include "components/permissions/prediction_service/prediction_common.h"
#include "components/permissions/prediction_service/prediction_request_features.h"
#include "components/permissions/prediction_service/prediction_service_messages.pb.h"
#include "components/permissions/request_type.h"
#include "google/protobuf/message_lite.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"

namespace {
// Helper common requests and responses. All of these are for the NOTIFICATION
// type.

// A request that has all counts 0. With user gesture.
permissions::PredictionRequestFeatures kFeaturesAllCountsZero =;
// A request that has all counts 5 expect for "grants" which are 6. Without user
// gesture.
const permissions::PredictionRequestFeatures kFeaturesCountsNeedingRounding =;
// A request that has all counts 50. With user gesture.
const permissions::PredictionRequestFeatures kFeaturesEvenCountsOver100 =;
// A request that has all counts 100. With user gesture.
const permissions::PredictionRequestFeatures kFeaturesEvenCountsOver100Alt =;
// A request that has generic counts 50, and notification counts 0. Without user
// gesture.
const permissions::PredictionRequestFeatures kFeaturesDifferentCounts =;

// A proto request that has all ratios and total counts 0. With user gesture.
permissions::GeneratePredictionsRequest kRequestAllCountsZero;
// A proto request that has all ratios 0.24 (~5/21) except for "grants" which
// are 0.29 (~6/21). Without user gesture.
permissions::GeneratePredictionsRequest kRequestRoundedCounts;
// A proto request that has all ratios .25 and total count 100. With user
// gesture.
permissions::GeneratePredictionsRequest kRequestEqualCountsTotal20;
// A proot request that has generic ratios .25 and total count 100 and
// notifications ratios and counts 0. Without user gesture.
permissions::GeneratePredictionsRequest kRequestDifferentCounts;

// A response that has a likelihood of DiscretizedLikelihood::LIKELY.
permissions::GeneratePredictionsResponse kResponseLikely;

// A response that has a likelihood of DiscretizedLikelihood::UNLIKELY.
permissions::GeneratePredictionsResponse kResponseUnlikely;

void InitializeProtoHelperObjects() {}

}  // namespace

namespace permissions {
class PredictionServiceTest : public testing::Test {};

TEST_F(PredictionServiceTest, BuiltProtoRequestIsCorrect) {}

TEST_F(PredictionServiceTest, ResponsesAreCorrect) {}

// Test that the Web Prediction Service url can be overridden via feature params
// and command line, and the fallback logic in case the provided url is not
// valid.
TEST_F(PredictionServiceTest, FeatureParamAndCommandLineCanOverrideDefaultUrl) {}

TEST_F(PredictionServiceTest,
       FeatureEnabledWithNoFeatureParamFallsBackOnDefault) {}

TEST_F(PredictionServiceTest, HandleSimultaneousRequests) {}

TEST_F(PredictionServiceTest, InvalidResponse) {}

TEST_F(PredictionServiceTest, PromptCountsAreBucketed) {}

}  // namespace permissions