chromium/components/variations/service/variations_service_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/variations/service/variations_service.h"

#include <stddef.h>

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

#include "base/base64.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "base/version.h"
#include "components/metrics/clean_exit_beacon.h"
#include "components/metrics/client_info.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_state_manager.h"
#include "components/metrics/test/test_enabled_state_provider.h"
#include "components/prefs/testing_pref_service.h"
#include "components/variations/pref_names.h"
#include "components/variations/proto/study.pb.h"
#include "components/variations/proto/variations_seed.pb.h"
#include "components/variations/scoped_variations_ids_provider.h"
#include "components/variations/synthetic_trial_registry.h"
#include "components/variations/variations_seed_simulator.h"
#include "components/version_info/channel.h"
#include "components/web_resource/resource_request_allowed_notifier_test_util.h"
#include "net/base/mock_network_change_notifier.h"
#include "net/base/url_util.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.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/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace variations {
namespace {

// The below seed and signature pair were generated using the server's
// private key.
const char kBase64SeedData[] =;
const char kBase64SeedSignature[] =;

// TODO(crbug.com/40742801): Remove when fake VariationsServiceClient created.
class TestVariationsServiceClient : public VariationsServiceClient {};

// A test class used to validate expected functionality in VariationsService.
class TestVariationsService : public VariationsService {};

class TestVariationsServiceObserver : public VariationsService::Observer {};

// Constants used to create the test seed.
const char kTestSeedStudyName[] =;
const char kTestSeedExperimentName[] =;
const int kTestSeedExperimentProbability =;
const char kTestSeedSerialNumber[] =;

// Populates |seed| with simple test data. The resulting seed will contain one
// study called "test", which contains one experiment called "abc" with
// probability weight 100. |seed|'s study field will be cleared before adding
// the new study.
VariationsSeed CreateTestSeed() {}

// Serializes |seed| to protobuf binary format.
std::string SerializeSeed(const VariationsSeed& seed) {}

// Converts |list| to a string, to make it easier for debugging.
std::string ListToString(const base::Value::List& list) {}

// Adds an OK response to the test_url_loader_factory with IM headers.
void AddOKResponseWithIM(
    const GURL& interception_url,
    const std::string& body,
    const std::string& im,
    network::TestURLLoaderFactory* test_url_loader_factory) {}

}  // namespace

class VariationsServiceTest : public ::testing::Test {};

TEST_F(VariationsServiceTest, GetVariationsServerURL) {}

TEST_F(VariationsServiceTest, VariationsURLHasParams) {}

TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) {}

TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) {}

TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) {}

TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) {}

TEST_F(VariationsServiceTest, RequestGzipCompressedSeed) {}

TEST_F(VariationsServiceTest, RequestDeltaCompressedSeed) {}

TEST_F(VariationsServiceTest, InstanceManipulations) {}

TEST_F(VariationsServiceTest, CountryHeader) {}

TEST_F(VariationsServiceTest, Observer) {}

TEST_F(VariationsServiceTest, LoadPermanentConsistencyCountry) {}

TEST_F(VariationsServiceTest, GetStoredPermanentCountry) {}

TEST_F(VariationsServiceTest, OverrideStoredPermanentCountry) {}

TEST_F(VariationsServiceTest, SafeMode_StartingRequestIncrementsFetchFailures) {}

TEST_F(VariationsServiceTest, SafeMode_SuccessfulFetchClearsFailureStreaks) {}

TEST_F(VariationsServiceTest, SafeMode_NotModifiedFetchClearsFailureStreaks) {}

TEST_F(VariationsServiceTest, FieldTrialCreatorInitializedCorrectly) {}

TEST_F(VariationsServiceTest, RetryOverHTTPIfURLisSet) {}

TEST_F(VariationsServiceTest, DoNotRetryAfterARetry) {}

TEST_F(VariationsServiceTest, DoNotRetryIfInsecureURLIsHTTPS) {}

TEST_F(VariationsServiceTest, SeedStoredWhenRedirected) {}

TEST_F(VariationsServiceTest, NullResponseReceivedWithHTTPOk) {}

TEST_F(VariationsServiceTest, VariationsServiceStartsRequestOnNetworkChange) {}

// TODO(isherman): Add an integration test for saving and loading a safe seed,
// once the loading functionality is implemented on the seed store.

}  // namespace variations