Clean up simulator tests to use public interface
Change-Id: Ibe5e6b32c81013fc7fc6467848c80e0423742cf1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3888718
Commit-Queue: Steven Holte <[email protected]>
Reviewed-by: Alexei Svitkine <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1047339}
diff --git a/components/variations/variations_seed_simulator_unittest.cc b/components/variations/variations_seed_simulator_unittest.cc
index 7e23071..a528f759 100644
--- a/components/variations/variations_seed_simulator_unittest.cc
+++ b/components/variations/variations_seed_simulator_unittest.cc
@@ -8,12 +8,15 @@
#include <map>
+#include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "base/test/mock_entropy_provider.h"
#include "base/time/time.h"
+#include "components/variations/client_filterable_state.h"
#include "components/variations/processed_study.h"
#include "components/variations/proto/study.pb.h"
#include "components/variations/variations_associated_data.h"
+#include "components/variations/variations_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace variations {
@@ -79,28 +82,21 @@
testing::ClearAllVariationParams();
}
- // Uses a VariationsSeedSimulator to simulate the differences between
- // |studies| and the current field trial state.
- VariationsSeedSimulator::Result SimulateDifferences(
- const std::vector<ProcessedStudy>& studies) {
- // Should pick the first group that has non-zero probability weight.
- base::MockEntropyProvider default_provider(0);
- // Should pick default groups, if they have non-zero probability weight.
- base::MockEntropyProvider low_provider(1.0 - 1e-8);
- VariationsSeedSimulator seed_simulator(default_provider, low_provider);
- return seed_simulator.ComputeDifferences(studies);
- }
-
// Simulates the differences between |study| and the current field trial
// state, returning a string like "1 2 3", where 1 is the number of regular
// group changes, 2 is the number of "kill best effort" group changes and 3
// is the number of "kill critical" group changes.
std::string SimulateStudyDifferences(const Study* study) {
- ProcessedStudy processed_study;
- if (!processed_study.Init(study))
- return "invalid study";
- std::vector<ProcessedStudy> studies = {processed_study};
- return ConvertSimulationResultToString(SimulateDifferences(studies));
+ VariationsSeed seed;
+ seed.add_study()->MergeFrom(*study);
+ auto client_state = CreateDummyClientFilterableState();
+ // Should pick the first group that has non-zero probability weight.
+ base::MockEntropyProvider default_provider(0);
+ // Should pick default groups, if they have non-zero probability weight.
+ base::MockEntropyProvider low_provider(1.0 - 1e-8);
+ return ConvertSimulationResultToString(
+ VariationsSeedSimulator(default_provider, low_provider)
+ .SimulateSeedStudies(seed, *client_state));
}
// Formats |result| as a string with format "1 2 3", where 1 is the number of
diff --git a/components/variations/variations_test_utils.cc b/components/variations/variations_test_utils.cc
index ae75124a..fb52708a 100644
--- a/components/variations/variations_test_utils.cc
+++ b/components/variations/variations_test_utils.cc
@@ -10,6 +10,7 @@
#include "components/metrics/clean_exit_beacon.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_service.h"
+#include "components/variations/client_filterable_state.h"
#include "components/variations/field_trial_config/fieldtrial_testing_config.h"
#include "components/variations/pref_names.h"
#include "components/variations/proto/client_variations.pb.h"
@@ -300,4 +301,16 @@
1,
};
+std::unique_ptr<ClientFilterableState> CreateDummyClientFilterableState() {
+ auto client_state = std::make_unique<ClientFilterableState>(
+ base::BindOnce([] { return false; }));
+ client_state->locale = "en-CA";
+ client_state->reference_date = base::Time::Now();
+ client_state->version = base::Version("20.0.0.0");
+ client_state->channel = Study::STABLE;
+ client_state->form_factor = Study::PHONE;
+ client_state->platform = Study::PLATFORM_ANDROID;
+ return client_state;
+}
+
} // namespace variations
diff --git a/components/variations/variations_test_utils.h b/components/variations/variations_test_utils.h
index a3c305f..ba0ec80 100644
--- a/components/variations/variations_test_utils.h
+++ b/components/variations/variations_test_utils.h
@@ -11,6 +11,7 @@
#include "base/containers/span.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/field_trial.h"
+#include "components/variations/client_filterable_state.h"
#include "components/variations/field_trial_config/fieldtrial_testing_config.h"
#include "components/variations/variations_associated_data.h"
@@ -18,6 +19,8 @@
namespace variations {
+struct ClientFilterableState;
+
// Packages signed variations seed data into a tuple for use with
// WriteSeedData(). This allows for encapsulated seed information to be created
// below for generic test seeds as well as seeds which cause crashes.
@@ -104,6 +107,10 @@
// are stored as process singleton.
void ResetVariations();
+// Create a ClientFilterableState with valid, but unimportant values.
+// Tests that actually expect specific values should set them on the result.
+std::unique_ptr<ClientFilterableState> CreateDummyClientFilterableState();
+
} // namespace variations
#endif // COMPONENTS_VARIATIONS_VARIATIONS_TEST_UTILS_H_