summaryrefslogtreecommitdiff
path: root/chromium/components/feature_engagement/internal/never_condition_validator_unittest.cc
blob: f693570225a2a050d74efbfbc5ecb5252fe86782 (plain)
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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/feature_engagement/internal/never_condition_validator.h"

#include <string>

#include "base/feature_list.h"
#include "components/feature_engagement/internal/event_model.h"
#include "components/feature_engagement/internal/never_availability_model.h"
#include "components/feature_engagement/internal/noop_display_lock_controller.h"
#include "components/feature_engagement/internal/proto/feature_event.pb.h"
#include "components/feature_engagement/public/configuration.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace feature_engagement {

namespace {

const base::Feature kNeverTestFeatureFoo{"test_foo",
                                         base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kNeverTestFeatureBar{"test_bar",
                                         base::FEATURE_DISABLED_BY_DEFAULT};

// A EventModel that is always postive to show in-product help.
class NeverTestEventModel : public EventModel {
 public:
  NeverTestEventModel() = default;

  void Initialize(OnModelInitializationFinished callback,
                  uint32_t current_day) override {}

  bool IsReady() const override { return true; }

  const Event* GetEvent(const std::string& event_name) const override {
    return nullptr;
  }

  uint32_t GetEventCount(const std::string& event_name,
                         uint32_t current_day,
                         uint32_t window_size) const override {
    return 0;
  }

  void IncrementEvent(const std::string& event_name, uint32_t day) override {}

 private:
  DISALLOW_COPY_AND_ASSIGN(NeverTestEventModel);
};

class NeverConditionValidatorTest : public ::testing::Test {
 public:
  NeverConditionValidatorTest() = default;

 protected:
  NeverTestEventModel event_model_;
  NeverAvailabilityModel availability_model_;
  NoopDisplayLockController display_lock_controller_;
  NeverConditionValidator validator_;

 private:
  DISALLOW_COPY_AND_ASSIGN(NeverConditionValidatorTest);
};

}  // namespace

TEST_F(NeverConditionValidatorTest, ShouldNeverMeetConditions) {
  EXPECT_FALSE(validator_
                   .MeetsConditions(kNeverTestFeatureFoo, FeatureConfig(),
                                    event_model_, availability_model_,
                                    display_lock_controller_, 0u)
                   .NoErrors());
  EXPECT_FALSE(validator_
                   .MeetsConditions(kNeverTestFeatureBar, FeatureConfig(),
                                    event_model_, availability_model_,
                                    display_lock_controller_, 0u)
                   .NoErrors());
}

}  // namespace feature_engagement