File: feature_promo_controller_test_base.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (110 lines) | stat: -rw-r--r-- 4,295 bytes parent folder | download | duplicates (6)
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
// 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 "components/user_education/test/feature_promo_controller_test_base.h"

#include <optional>

#include "base/feature_list.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "components/feature_engagement/public/tracker.h"
#include "components/user_education/common/feature_promo/feature_promo_result.h"
#include "components/user_education/common/feature_promo/feature_promo_session_policy.h"
#include "components/user_education/common/tutorial/tutorial_service.h"
#include "components/user_education/test/test_help_bubble.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"

namespace user_education::test {

BASE_FEATURE(kTestIPHFocusHelpBubbleScreenReaderPromoFeature,
             "TEST_IPH_FocusHelpBubbleScreenReaderPromo",
             base::FEATURE_ENABLED_BY_DEFAULT);

DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(FeaturePromoControllerTestBase,
                                      kAnchorElementId);

// static
const ui::ElementContext FeaturePromoControllerTestBase::kAnchorElementContext(
    1);

// static
constexpr char
    FeaturePromoControllerTestBase::kTestFocusHelpBubbleAcceleratorPromoRead[];

FeaturePromoControllerTestBase::TestTutorialService::~TestTutorialService() =
    default;

std::u16string
FeaturePromoControllerTestBase::TestTutorialService::GetBodyIconAltText(
    bool is_last_step) const {
  return u"Body Icon Alt Text";
}

FeaturePromoControllerTestBase::FeaturePromoControllerTestBase() {
  storage_service_.set_clock_for_testing(task_environment_.GetMockClock());
}

FeaturePromoControllerTestBase::~FeaturePromoControllerTestBase() = default;

void FeaturePromoControllerTestBase::SetTrackerResult(bool success) {
  EXPECT_CALL(tracker_, IsInitialized).WillRepeatedly(testing::Return(success));
  EXPECT_CALL(tracker_, AddOnInitializedCallback)
      .WillRepeatedly([success](
                          feature_engagement::Tracker::OnInitializedCallback
                              callback) {
        base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
            FROM_HERE,
            base::BindOnce(
                [](feature_engagement::Tracker::OnInitializedCallback callback,
                   bool success) { std::move(callback).Run(success); },
                std::move(callback), success));
      });
}

TestHelpBubble* FeaturePromoControllerTestBase::GetHelpBubble(
    std::optional<ui::ElementContext> context) const {
  auto* const el =
      context
          ? ui::ElementTracker::GetElementTracker()->GetFirstMatchingElement(
                TestHelpBubble::kElementId, *context)
          : ui::ElementTracker::GetElementTracker()->GetElementInAnyContext(
                TestHelpBubble::kElementId);
  return el ? el->AsA<TestHelpBubbleElement>()->bubble() : nullptr;
}

void FeaturePromoControllerTestBase::SetUp() {
  using Info = FeaturePromoSessionPolicy::PromoPriorityInfo;

  session_policy_.Init(nullptr, &storage_service_);
  messaging_controller_.Init(session_provider_, storage_service_);
  promo_controller_ = CreateController();
  help_bubble_factory_registry_.MaybeRegister<TestHelpBubbleFactory>();
  anchor_element_.Show();
  EXPECT_CALL(session_policy_, CanShowPromo)
      .WillRepeatedly([](Info to_show, std::optional<Info> current) {
        return FeaturePromoSessionPolicy().CanShowPromo(to_show, current);
      });
  EXPECT_CALL(tracker_, ShouldTriggerHelpUI)
      .WillRepeatedly(testing::Return(true));
  EXPECT_CALL(tracker_, WouldTriggerHelpUI)
      .WillRepeatedly(testing::Return(true));
  EXPECT_CALL(tracker_, NotifyEvent).Times(testing::AnyNumber());
#if !BUILDFLAG(IS_ANDROID)
  EXPECT_CALL(tracker_, NotifyUsedEvent).Times(testing::AnyNumber());
  EXPECT_CALL(tracker_, ListEvents)
      .WillRepeatedly(
          testing::Return(feature_engagement::Tracker::EventList()));
#endif
  EXPECT_CALL(tracker_, Dismissed).Times(testing::AnyNumber());
  SetTrackerResult(true);
}

void FeaturePromoControllerTestBase::TearDown() {
  promo_controller_.reset();
}

}  // namespace user_education::test