chromium/components/variations/entropy_provider_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/entropy_provider.h"

#include <stddef.h>
#include <stdint.h>

#include <cmath>
#include <limits>
#include <memory>
#include <numeric>

#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/uuid.h"
#include "components/variations/hashing.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace variations {

namespace {

// Size of the low entropy source for testing.
const uint32_t kMaxLowEntropySize =;

// Field trial names used in unit tests.
const char* const kTestTrialNames[] =;

// Computes the Chi-Square statistic for |values| assuming they follow a uniform
// distribution, where each entry has expected value |expected_value|.
//
// The Chi-Square statistic is defined as Sum((O-E)^2/E) where O is the observed
// value and E is the expected value.
double ComputeChiSquare(const std::vector<int>& values,
                        double expected_value) {}

// Computes SHA1-based entropy for the given |trial_name| based on
// |entropy_source|
double GenerateSHA1Entropy(const std::string& entropy_source,
                           const std::string& trial_name) {}

// Generates normalized MurmurHash-based entropy for the given |trial_name|
// based on |entropy_source| which must be in the range [0, entropy_max).
double GenerateNormalizedMurmurHashEntropy(ValueInRange entropy_source,
                                           const std::string& trial_name) {}

// Helper interface for testing used to generate entropy values for a given
// field trial. Unlike EntropyProvider, which keeps the low/high entropy source
// value constant and generates entropy for different trial names, instances
// of TrialEntropyGenerator keep the trial name constant and generate low/high
// entropy source values internally to produce each output entropy value.
class TrialEntropyGenerator {};

// An TrialEntropyGenerator that uses the SHA1EntropyProvider with the high
// entropy source (random UUID with 128 bits of entropy + 13 additional bits of
// entropy corresponding to a low entropy source).
class SHA1EntropyGenerator : public TrialEntropyGenerator {};

// An TrialEntropyGenerator that uses the normalized MurmurHash entropy provider
// algorithm, using 13-bit low entropy source values.
class NormalizedMurmurHashEntropyGenerator : public TrialEntropyGenerator {};

// Tests uniformity of a given |entropy_generator| using the Chi-Square Goodness
// of Fit Test.
void PerformEntropyUniformityTest(
    const std::string& trial_name,
    const TrialEntropyGenerator& entropy_generator) {}

}  // namespace

TEST(EntropyProviderTest, UseOneTimeRandomizationSHA1) {}

TEST(EntropyProviderTest, UseOneTimeRandomizationNormalizedMurmurHash) {}

TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedSHA1) {}

TEST(EntropyProviderTest,
     UseOneTimeRandomizationWithCustomSeedNormalizedMurmurHash) {}

TEST(EntropyProviderTest, SHA1Entropy) {}

TEST(EntropyProviderTest, NormalizedMurmurHashEntropy) {}

TEST(EntropyProviderTest, NormalizedMurmurHashEntropyProviderResults) {}

TEST(EntropyProviderTest, SHA1EntropyIsUniform) {}

TEST(EntropyProviderTest, NormalizedMurmurHashEntropyIsUniform) {}

TEST(EntropyProviderTest, InstantiationWithLimitedEntropyRandomizationSource) {}

TEST(EntropyProviderTest,
     InstantiationWithLimitedEntropyRandomizationSourceAsEmptyString) {}

}  // namespace variations