chromium/base/metrics/field_trial_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.

#include "base/metrics/field_trial.h"

#include <stddef.h>

#include <string_view>
#include <utility>

#include "base/base_switches.h"
#include "base/build_time.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial_list_including_low_anonymity.h"
#include "base/metrics/field_trial_param_associator.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/gtest_util.h"
#include "base/test/mock_entropy_provider.h"
#include "base/test/multiprocess_test.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_shared_memory_util.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"

#if BUILDFLAG(USE_BLINK)
#include "base/process/launch.h"
#endif

#if BUILDFLAG(IS_POSIX)
#include "base/files/platform_file.h"
#include "base/posix/global_descriptors.h"
#endif

#if BUILDFLAG(IS_MAC)
#include "base/mac/mach_port_rendezvous.h"
#endif

namespace base {

namespace {

// Default group name used by several tests.
const char kDefaultGroupName[] =;

// Call FieldTrialList::FactoryGetFieldTrial().
scoped_refptr<FieldTrial> CreateFieldTrial(
    const std::string& trial_name,
    int total_probability,
    const std::string& default_group_name,
    bool is_low_anonymity = false) {}

// A FieldTrialList::Observer implementation which stores the trial name and
// group name received via OnFieldTrialGroupFinalized() for later inspection.
class TestFieldTrialObserver : public FieldTrialList::Observer {};

// A FieldTrialList::Observer implementation which accesses the group of a
// FieldTrial from OnFieldTrialGroupFinalized(). Used to test reentrancy.
class FieldTrialObserverAccessingGroup : public FieldTrialList::Observer {};

std::string MockEscapeQueryParamValue(const std::string& input) {}

}  // namespace

// Same as |TestFieldTrialObserver|, but registers for low anonymity field
// trials too.
class TestFieldTrialObserverIncludingLowAnonymity
    : public FieldTrialList::Observer {};

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

MATCHER(CompareActiveGroupToFieldTrial, "") {}

// Test registration, and also check that destructors are called for trials.
TEST_F(FieldTrialTest, Registration) {}

TEST_F(FieldTrialTest, AbsoluteProbabilities) {}

TEST_F(FieldTrialTest, SmallProbabilities_49) {}

TEST_F(FieldTrialTest, SmallProbabilities_51) {}

TEST_F(FieldTrialTest, MiddleProbabilities_49) {}

TEST_F(FieldTrialTest, MiddleProbabilities_51) {}

// AppendGroup after finalization should not change the winner.
TEST_F(FieldTrialTest, OneWinner) {}

TEST_F(FieldTrialTest, ActiveGroups) {}

TEST_F(FieldTrialTest, ActiveGroupsNotFinalized) {}

TEST_F(FieldTrialTest, GetGroupNameWithoutActivation) {}

TEST_F(FieldTrialTest, SaveAll) {}

TEST_F(FieldTrialTest, Restore) {}

TEST_F(FieldTrialTest, RestoreNotEndingWithSlash) {}

TEST_F(FieldTrialTest, BogusRestore) {}

TEST_F(FieldTrialTest, DuplicateRestore) {}

TEST_F(FieldTrialTest, CreateTrialsFromStringNotActive) {}

TEST_F(FieldTrialTest, CreateTrialsFromStringForceActivation) {}

TEST_F(FieldTrialTest, CreateTrialsFromStringNotActiveObserver) {}

TEST_F(FieldTrialTest, CreateFieldTrial) {}

TEST_F(FieldTrialTest, CreateFieldTrialIsNotActive) {}

TEST_F(FieldTrialTest, DuplicateFieldTrial) {}

TEST_F(FieldTrialTest, ForcedFieldTrials) {}

TEST_F(FieldTrialTest, ForcedFieldTrialsDefaultGroup) {}

TEST_F(FieldTrialTest, SetForced) {}

TEST_F(FieldTrialTest, SetForcedDefaultOnly) {}

TEST_F(FieldTrialTest, SetForcedDefaultWithExtraGroup) {}

TEST_F(FieldTrialTest, SetForcedTurnFeatureOn) {}

TEST_F(FieldTrialTest, SetForcedTurnFeatureOff) {}

TEST_F(FieldTrialTest, SetForcedChangeDefault_Default) {}

TEST_F(FieldTrialTest, SetForcedChangeDefault_NonDefault) {}

TEST_F(FieldTrialTest, Observe) {}

// Verify that no hang occurs when a FieldTrial group is selected from a
// FieldTrialList::Observer::OnFieldTrialGroupFinalized() notification. If the
// FieldTrialList's lock is held when observers are notified, this test will
// hang due to reentrant lock acquisition when selecting the FieldTrial group.
TEST_F(FieldTrialTest, ObserveReentrancy) {}

TEST_F(FieldTrialTest, NotDisabled) {}

TEST_F(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes) {}

TEST_F(FieldTrialTest, DoesNotSurpassTotalProbability) {}

TEST_F(FieldTrialTest, CreateSimulatedFieldTrial) {}

TEST(FieldTrialTestWithoutList, StatesStringFormat) {}

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

TEST_F(FieldTrialListTest, InstantiateAllocator) {}

TEST_F(FieldTrialListTest, AddTrialsToAllocator) {}

TEST_F(FieldTrialListTest, DoNotAddSimulatedFieldTrialsToAllocator) {}

TEST_F(FieldTrialListTest, AssociateFieldTrialParams) {}

TEST_F(FieldTrialListTest, ClearParamsFromSharedMemory) {}

TEST_F(FieldTrialListTest, DumpAndFetchFromSharedMemory) {}

#if BUILDFLAG(USE_BLINK)

#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)
constexpr GlobalDescriptors::Key kFDKey =;
#endif

BASE_FEATURE();
BASE_FEATURE();
BASE_FEATURE();

MULTIPROCESS_TEST_MAIN(CreateTrialsInChildProcess) {}

#if !BUILDFLAG(IS_IOS)
TEST_F(FieldTrialListTest, PassFieldTrialSharedMemoryOnCommandLine) {}
#endif

// Verify that the field trial shared memory handle is really read-only, and
// does not allow writable mappings.
TEST_F(FieldTrialListTest, CheckReadOnlySharedMemoryRegion) {}
#endif  // BUILDFLAG(USE_BLINK)

TEST_F(FieldTrialListTest, TestGetRandomizedFieldTrialCount) {}

TEST_F(FieldTrialTest, TestAllParamsToString) {}

TEST_F(FieldTrialTest, GetActiveFieldTrialGroups_LowAnonymity) {}

TEST_F(FieldTrialTest, ObserveIncludingLowAnonymity) {}

TEST_F(FieldTrialTest, ParseFieldTrialsString) {}

TEST_F(FieldTrialTest, ParseFieldTrialsStringTwoStudies) {}

TEST_F(FieldTrialTest, ParseFieldTrialsStringEmpty) {}

TEST_F(FieldTrialTest, ParseFieldTrialsStringInvalid) {}

TEST_F(FieldTrialTest, BuildFieldTrialStateString) {}

}  // namespace base