#include "components/segmentation_platform/internal/data_collection/training_data_collector_impl.h"
#include <map>
#include <string_view>
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/metrics_hashes.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/prefs/testing_pref_service.h"
#include "components/segmentation_platform/internal/constants.h"
#include "components/segmentation_platform/internal/data_collection/training_data_collector.h"
#include "components/segmentation_platform/internal/database/cached_result_provider.h"
#include "components/segmentation_platform/internal/database/cached_result_writer.h"
#include "components/segmentation_platform/internal/database/client_result_prefs.h"
#include "components/segmentation_platform/internal/database/config_holder.h"
#include "components/segmentation_platform/internal/database/mock_signal_storage_config.h"
#include "components/segmentation_platform/internal/database/test_segment_info_database.h"
#include "components/segmentation_platform/internal/execution/processing/feature_list_query_processor.h"
#include "components/segmentation_platform/internal/execution/processing/mock_feature_list_query_processor.h"
#include "components/segmentation_platform/internal/metadata/metadata_utils.h"
#include "components/segmentation_platform/internal/mock_ukm_data_manager.h"
#include "components/segmentation_platform/internal/platform_options.h"
#include "components/segmentation_platform/internal/proto/model_prediction.pb.h"
#include "components/segmentation_platform/internal/segmentation_ukm_helper.h"
#include "components/segmentation_platform/internal/selection/segmentation_result_prefs.h"
#include "components/segmentation_platform/internal/signals/mock_histogram_signal_handler.h"
#include "components/segmentation_platform/internal/signals/mock_user_action_signal_handler.h"
#include "components/segmentation_platform/internal/stats.h"
#include "components/segmentation_platform/public/config.h"
#include "components/segmentation_platform/public/features.h"
#include "components/segmentation_platform/public/local_state_helper.h"
#include "components/segmentation_platform/public/model_provider.h"
#include "components/segmentation_platform/public/proto/model_metadata.pb.h"
#include "components/segmentation_platform/public/proto/segmentation_platform.pb.h"
#include "components/segmentation_platform/public/proto/types.pb.h"
#include "components/segmentation_platform/public/segmentation_platform_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace segmentation_platform {
namespace {
RunOnceCallback;
RunOnceCallbackRepeatedly;
_;
NiceMock;
Return;
Segmentation_ModelExecution;
constexpr auto kTestOptimizationTarget0 = …;
constexpr auto kTestOptimizationTarget1 = …;
constexpr auto kTestOptimizationTarget2 = …;
constexpr char kHistogramName0[] = …;
constexpr char kHistogramName1[] = …;
constexpr char kSegmentationKey[] = …;
constexpr char kSegmentationKey2[] = …;
constexpr int64_t kModelVersion = …;
constexpr int kSample = …;
constexpr DecisionType kOnDemandDecisionType = …;
constexpr DecisionType kPeriodicDecisionType = …;
class MockModelManager : public ModelManager { … };
class TrainingDataCollectorImplTest
: public ::testing::Test,
public ::testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(TrainingDataCollectorImplTest, NoSegment) { … }
TEST_P(TrainingDataCollectorImplTest, IrrelevantHistogramNotReported) { … }
TEST_P(TrainingDataCollectorImplTest, SignalCollectionRequirementNotMet) { … }
TEST_P(TrainingDataCollectorImplTest, ModelUpdatedRecently) { … }
TEST_P(TrainingDataCollectorImplTest, PartialOutputNotAllowed) { … }
TEST_P(TrainingDataCollectorImplTest,
ContinuousCollectionOnStartupWithoutUploadTensor) { … }
TEST_P(TrainingDataCollectorImplTest, ContinuousCollectionOnStartupNoDelay) { … }
TEST_P(TrainingDataCollectorImplTest,
OnDemandModelsDoNotTriggerPeriodicCollection) { … }
TEST_P(TrainingDataCollectorImplTest,
ReportCollectedContinuousTrainingData_LegacyConfig) { … }
TEST_P(TrainingDataCollectorImplTest,
ReportCollectedContinuousTrainingData_MultiOutputConfig) { … }
TEST_P(TrainingDataCollectorImplTest, ContinuousWithExactPredictionNotSet) { … }
TEST_P(TrainingDataCollectorImplTest, ContinuousWithExactPrediction) { … }
TEST_P(TrainingDataCollectorImplTest, ContinuousWithFlexibleObservation) { … }
TEST_P(TrainingDataCollectorImplTest, ContinuousWithDelay) { … }
TEST_P(TrainingDataCollectorImplTest,
NoImmediateDataCollectionAfterLastCollection) { … }
TEST_P(TrainingDataCollectorImplTest, NoDataCollectionIfUkmAllowedPrefNotSet) { … }
TEST_P(TrainingDataCollectorImplTest, DataCollectionWithEnumHistogramTrigger) { … }
TEST_P(TrainingDataCollectorImplTest, DataCollectionWithUserActionTrigger) { … }
TEST_P(TrainingDataCollectorImplTest,
DataCollectionWithTriggerWithoutUploadTensor) { … }
TEST_P(TrainingDataCollectorImplTest,
DataCollectionWithUMATrigger_MultipleModels) { … }
TEST_P(TrainingDataCollectorImplTest, DataCollectionWithTimeTrigger) { … }
TEST_P(TrainingDataCollectorImplTest, DataCollectionWithStoreToDisk) { … }
TEST_P(TrainingDataCollectorImplTest, DataCollectionWithTriggerAPI) { … }
TEST_P(TrainingDataCollectorImplTest,
DataCollectionTriggerAPIWithoutUploadTensor) { … }
TEST_P(TrainingDataCollectorImplTest,
DataCollectionWithTriggerAPIForPreferredSegment) { … }
TEST_P(TrainingDataCollectorImplTest,
DataCollectionSkippedWhenInputProcessingFails) { … }
}
}