#include "chrome/browser/chrome_browser_field_trials.h"
#include <memory>
#include "base/feature_list.h"
#include "components/prefs/testing_pref_service.h"
#include "components/ukm/ukm_recorder_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
TEST(ChromeBrowserFieldTrialsTest, SamplingTrials) {
TestingPrefServiceSimple local_state;
ChromeBrowserFieldTrials chrome_browser_field_trials(&local_state);
const char kSamplingTrialName[] = "MetricsAndCrashSampling";
#if BUILDFLAG(IS_ANDROID)
const char kPostFREFixSamplingTrialName[] =
"PostFREFixMetricsAndCrashSampling";
#endif
const char kUkmSamplingTrialName[] = "UkmSamplingRate";
EXPECT_FALSE(base::FieldTrialList::TrialExists(kSamplingTrialName));
#if BUILDFLAG(IS_ANDROID)
EXPECT_FALSE(base::FieldTrialList::TrialExists(kPostFREFixSamplingTrialName));
#endif
EXPECT_FALSE(base::FieldTrialList::TrialExists(kUkmSamplingTrialName));
variations::EntropyProviders entropy_providers(
"client_id", {0, 8000},
std::string_view());
auto feature_list = std::make_unique<base::FeatureList>();
chrome_browser_field_trials.SetUpClientSideFieldTrials(
false, entropy_providers, feature_list.get());
EXPECT_TRUE(base::FieldTrialList::TrialExists(kSamplingTrialName));
#if BUILDFLAG(IS_ANDROID)
EXPECT_TRUE(base::FieldTrialList::TrialExists(kPostFREFixSamplingTrialName));
#endif
EXPECT_TRUE(base::FieldTrialList::TrialExists(kUkmSamplingTrialName));
chrome_browser_field_trials.SetUpClientSideFieldTrials(
false, entropy_providers, feature_list.get());
}
#endif