1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/ash/components/growth/campaigns_configuration_provider.h"
#include "base/feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace growth {
namespace {
using feature_engagement::ANY;
using feature_engagement::Comparator;
using feature_engagement::EQUAL;
using feature_engagement::EventConfig;
using feature_engagement::FeatureConfig;
using feature_engagement::LESS_THAN;
BASE_FEATURE(kTestFeatureValid,
"IPH_GrowthFramework",
base::FEATURE_DISABLED_BY_DEFAULT);
BASE_FEATURE(kTestFeatureInvalid,
"GrowthGramework",
base::FEATURE_DISABLED_BY_DEFAULT);
constexpr char kEventUsedKey[] = "event_used";
constexpr char kEventTriggerKey[] = "event_trigger";
constexpr char kEvent1Key[] = "event_1";
constexpr char kEventImpressionKey[] = "event_impression";
constexpr char kEventDismissalKey[] = "event_dismissal";
constexpr char kEventUsedParam[] =
"name:ChromeOSAshGrowthCampaigns_EventUsed;comparator:any;window:1;storage:"
"1";
constexpr char kEventTriggerParam[] =
"name:ChromeOSAshGrowthCampaigns_EventTrigger;comparator:any;window:1;"
"storage:1";
constexpr char kEventImpressionParam[] =
"name:ChromeOSAshGrowthCampaigns_Impression_CampaignId_100;comparator:<3;"
"window:365;storage:365";
constexpr char kEventDismissalParam[] =
"name:ChromeOSAshGrowthCampaigns_Dismissed_CampaignId_100;comparator:<1;"
"window:365;storage:365";
constexpr char kEvent1Param[] =
"name:ChromeOSAshGrowthCampaigns_Impression_CampaignId_100;comparator:==0;"
"window:365;storage:365";
} // namespace
class CampaignsConfigurationProviderTest : public testing::Test {
protected:
CampaignsConfigurationProvider provider_;
};
TEST_F(CampaignsConfigurationProviderTest, HasPrefixValidFeature) {
const auto prefixes =
provider_.MaybeProvideAllowedEventPrefixes(kTestFeatureValid);
EXPECT_EQ(1u, prefixes.size());
EXPECT_TRUE(prefixes.contains("ChromeOSAshGrowthCampaigns_"));
}
TEST_F(CampaignsConfigurationProviderTest, NoPrefixInvalidFeature) {
const auto prefixes =
provider_.MaybeProvideAllowedEventPrefixes(kTestFeatureInvalid);
EXPECT_EQ(0u, prefixes.size());
}
TEST_F(CampaignsConfigurationProviderTest, SetConfigWithInvalidFeature) {
std::map<std::string, std::string> params;
FeatureConfig config;
provider_.SetConfig(params);
provider_.MaybeProvideFeatureConfiguration(
kTestFeatureInvalid, config, /*known_features=*/{}, /*known_groups=*/{});
EXPECT_FALSE(config.valid);
}
TEST_F(CampaignsConfigurationProviderTest, SetConfigWithValidFeature) {
std::map<std::string, std::string> params;
params[kEventUsedKey] = kEventUsedParam;
params[kEventTriggerKey] = kEventTriggerParam;
params[kEventImpressionKey] = kEventImpressionParam;
params[kEventDismissalKey] = kEventDismissalParam;
params[kEvent1Key] = kEvent1Param;
FeatureConfig expected;
expected.valid = true;
expected.used = EventConfig("ChromeOSAshGrowthCampaigns_EventUsed",
Comparator(ANY, 0), 1, 1);
expected.trigger = EventConfig("ChromeOSAshGrowthCampaigns_EventTrigger",
Comparator(ANY, 0), 1, 1);
expected.event_configs.insert(
EventConfig("ChromeOSAshGrowthCampaigns_Impression_CampaignId_100",
Comparator(LESS_THAN, 3), 365, 365));
expected.event_configs.insert(
EventConfig("ChromeOSAshGrowthCampaigns_Dismissed_CampaignId_100",
Comparator(LESS_THAN, 1), 365, 365));
expected.event_configs.insert(
EventConfig("ChromeOSAshGrowthCampaigns_Impression_CampaignId_100",
Comparator(EQUAL, 0), 365, 365));
FeatureConfig config;
provider_.SetConfig(params);
provider_.MaybeProvideFeatureConfiguration(
kTestFeatureValid, config, /*known_features=*/{}, /*known_groups=*/{});
EXPECT_EQ(expected, config);
}
} // namespace growth
|