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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_SCALABLE_IPH_SCALABLE_IPH_BROWSER_TEST_BASE_H_
#define CHROME_BROWSER_ASH_SCALABLE_IPH_SCALABLE_IPH_BROWSER_TEST_BASE_H_
#include <memory>
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_mock_time_task_runner.h"
#include "chrome/browser/ash/scalable_iph/customizable_test_env_browser_test_base.h"
#include "chrome/browser/ash/scalable_iph/mock_scalable_iph_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/ash/components/scalable_iph/logger.h"
#include "chromeos/ash/components/scalable_iph/scalable_iph.h"
#include "chromeos/services/network_config/public/cpp/fake_cros_network_config.h"
#include "components/feature_engagement/test/mock_tracker.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/browser_context.h"
namespace ash {
class ScalableIphBrowserTestBase : public CustomizableTestEnvBrowserTestBase {
public:
static constexpr char kTestNotificationId[] = "test_notification_id";
static constexpr char kTestNotificationTitle[] = "Test Notification Title";
static constexpr char kTestNotificationBodyText[] =
"Test Notification Body Text";
static constexpr char kTestNotificationButtonText[] =
"Test Notification Button Text";
static constexpr char kTestBubbleId[] = "test_bubble_id";
static constexpr char kTestBubbleTitle[] = "Test Bubble Title";
static constexpr char kTestBubbleText[] = "Test Bubble Text";
static constexpr char kTestBubbleButtonText[] = "Test Bubble Button Text";
static constexpr char kTestBubbleIconString[] = "GoogleDocsIcon";
static constexpr char kTestButtonActionTypeOpenChrome[] = "OpenChrome";
static constexpr char kTestButtonActionTypeOpenGoogleDocs[] =
"OpenGoogleDocs";
static constexpr char kTestButtonActionEvent[] =
"TestScalableIphTimerBasedOneEventUsed";
static constexpr char kTestActionEventName[] =
"name:TestScalableIphTimerBasedOneEventUsed;comparator:any;window:365;"
"storage:365";
ScalableIphBrowserTestBase();
~ScalableIphBrowserTestBase() override;
// CustomizableTestEnvBrowserTestBase:
void SetUp() override;
void SetUpInProcessBrowserTestFixture() override;
void SetUpBrowserContextKeyedServices(
content::BrowserContext* context) override;
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
protected:
using MockTrackerFactoryMethod =
base::RepeatingCallback<std::unique_ptr<KeyedService>(
content::BrowserContext*)>;
// Returns a function to create a `MockTracker`. For using real tracker, you
// can return a null callback.
virtual MockTrackerFactoryMethod GetMockTrackerFactoryMethod();
// Set up fake tracker initialization behaviors to the passed mock tracker.
static std::unique_ptr<feature_engagement::test::MockTracker>
SetUpFakeInitializationCalls(
std::unique_ptr<feature_engagement::test::MockTracker> mock_tracker);
void SetUpMocks();
// Allow sub-classes to initialize scoped feature list with different values.
// TODO(b/297565024): Abstract this as we initialize more than just IPH
// configs in this method.
// `InitializeScopedFeatureList` is the top level function for initializing
// scoped feature list of this test.
// - Override `AppendUiParams` if you only want to customize UI params.
// - Override `AppendTestSpecificFeatures` if you only want to customize other
// feature flags in this test.
virtual void InitializeScopedFeatureList();
virtual void AppendUiParams(base::FieldTrialParams& params);
virtual void AppendTestSpecificFeatures(
std::vector<base::test::FeatureRefAndParams>& enabled_features,
std::vector<base::test::FeatureRef>& disabled_features) {}
void AppendVersionNumber(base::FieldTrialParams& params,
const base::Feature& feature,
const std::string& version_number);
void AppendVersionNumber(base::FieldTrialParams& params,
const base::Feature& feature);
virtual void AppendVersionNumber(base::FieldTrialParams& params);
void AppendFakeUiParamsNotification(base::FieldTrialParams& params,
bool has_body_text,
const base::Feature& feature);
void AppendFakeUiParamsBubble(base::FieldTrialParams& params);
static std::string FullyQualified(const base::Feature& feature,
const std::string& param_name);
feature_engagement::test::MockTracker* mock_tracker() {
return mock_tracker_;
}
test::MockScalableIphDelegate* mock_delegate() { return mock_delegate_; }
scoped_refptr<base::TestMockTimeTaskRunner> task_runner() {
return task_runner_;
}
bool IsMockDelegateCreatedFor(Profile* profile);
void ShutdownScalableIph();
void AddOnlineNetwork();
void EnableTestIphFeatures(
const std::vector<raw_ptr<const base::Feature, VectorExperimental>>
test_iph_features);
void EnableTestIphFeature();
const base::Feature& TestIphFeature() const;
// Triggers a conditions check with a fake event. Note that this will make the
// count of the five min time tick or unlocked event incorrect if you are
// testing it.
void TriggerConditionsCheckWithAFakeEvent(
scalable_iph::ScalableIph::Event event);
// Returns a user context of primary user.
ash::UserContext GetPrimaryUserContext();
// Returns a user context of secondary user. Note that `enable_multi_user_`
// has to be true to use this method.
ash::UserContext GetSecondaryUserContext();
// A sub-class might override this from `InitializeScopedFeatureList`.
base::test::ScopedFeatureList scoped_feature_list_;
// Set false in the constructor to disable `ash::features::kScalableIph`.
bool enable_scalable_iph_ = true;
// Set false in the constructor to disable `ash::features::kScalableIphDebug`.
bool enable_scalable_iph_debug_ = true;
// Set false in the constructor to not enforce scalable IPH set-up.
// If `enable_scalable_iph_` is set to false, this should also be false.
bool setup_scalable_iph_ = true;
// Set true in the constructor to enable multi user in this test case.
bool enable_multi_user_ = false;
// Manta service eligibility is set automatically depending on
// `SessionUserType`. `force_disable_manta_service=true` force-disables the
// service regardless of `UserSessionType`.
bool force_disable_manta_service_ = false;
private:
static void SetTestingFactories(
MockTrackerFactoryMethod mock_tracker_factory_method,
content::BrowserContext* browser_context);
static std::unique_ptr<KeyedService> CreateMockTracker(
content::BrowserContext* browser_context);
static std::unique_ptr<scalable_iph::ScalableIphDelegate> CreateMockDelegate(
Profile* profile,
scalable_iph::Logger* logger);
static void SetCanUseMantaService(content::BrowserContext* browser_context);
chromeos::network_config::FakeCrosNetworkConfig fake_cros_network_config_;
scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
MockTrackerFactoryMethod mock_tracker_factory_method_;
raw_ptr<feature_engagement::test::MockTracker> mock_tracker_ = nullptr;
raw_ptr<test::MockScalableIphDelegate> mock_delegate_ = nullptr;
};
} // namespace ash
#endif // CHROME_BROWSER_ASH_SCALABLE_IPH_SCALABLE_IPH_BROWSER_TEST_BASE_H_
|