File: campaigns_configuration_provider_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 4,081 bytes parent folder | download | duplicates (8)
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