blob: ffe78f637e12ee91552bf180731aa04ca46637cc [file] [log] [blame]
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_APP_TESTS_HOOK_H_
#define IOS_CHROME_APP_TESTS_HOOK_H_
#include <memory>
#import <optional>
class PrefService;
class ProfileIOS;
class ProfileOAuth2TokenServiceDelegate;
class ProfileOAuth2TokenService;
class ShareKitService;
class SystemIdentityManager;
class TrustedVaultClientBackend;
namespace base {
class TimeDelta;
} // namespace base
namespace collaboration {
class CollaborationService;
} // namespace collaboration
namespace data_sharing {
class DataSharingService;
} // namespace data_sharing
namespace drive {
class DriveService;
} // namespace drive
namespace feature_engagement {
class FeatureActivation;
} // namespace feature_engagement
namespace policy {
class ConfigurationPolicyProvider;
} // namespace policy
namespace password_manager {
class BulkLeakCheckServiceInterface;
class RecipientsFetcher;
} // namespace password_manager
namespace plus_addresses {
class PlusAddressService;
} // namespace plus_addresses
namespace tab_groups {
class TabGroupSyncService;
} // namespace tab_groups
namespace tests_hook {
// Returns true if app group access should be disabled as tests don't have the
// required entitlements.
// This is used by internal code.
bool DisableAppGroupAccess();
// Returns true if client-side field trials should be disabled, so
// that their associated base::Features always use the default
// behavior, avoiding unexpected randomness during testing.
bool DisableClientSideFieldTrials();
// Returns true if ContentSuggestions should be disabled to allow other tests to
// run unimpeded.
bool DisableContentSuggestions();
// Returns true if Discover feed should be disabled to allow tests to run
// without it.
bool DisableDiscoverFeed();
// Returns true if the first run UI, which would interfere with many tests,
// should by default be skipped. Note that even in a target where this function
// returns `false`, that's just a default, and individual tests may still enable
// the first run UI.
bool DisableDefaultFirstRun();
// Returns true if the geolocation should be disabled to avoid the user location
// prompt displaying for the omnibox.
bool DisableGeolocation();
// Returns true if the Promo Manager should avoid displaying promos
// on app startup to allow tests to run unimpeded.
bool DisablePromoManagerDisplayingPromo();
// Returns true if the search engine choice view, which would interfere with
// many tests, should by default be skipped. Note that even in a target where
// this function returns `false`, that's just a default, and individual tests
// may still enable this view.
bool DisableDefaultSearchEngineChoice();
// Returns a token service that can be installed as a fake identity management
// service that bridges iOS SSO library and Chrome account info when testing.
// May return nullptr.
std::unique_ptr<ProfileOAuth2TokenService> GetOverriddenTokenService(
PrefService* user_prefs,
std::unique_ptr<ProfileOAuth2TokenServiceDelegate> delegate);
// Returns true if the upgrade sign-in promo should be disabled to allow other
// tests to run unimpeded.
bool DisableUpgradeSigninPromo();
// Returns true if the update service should be disabled so that the update
// infobar won't be shown during testing.
bool DisableUpdateService();
// Returns true if any app launch promos should delay themselves so EGTests
// can start before checking if the promo appears.
bool DelayAppLaunchPromos();
// Returns true if the data for discarded session should never be deleted.
// This is a workaround because during EG tests, the application delegate
// method -application:didDiscardSceneSessions: may be called with a list
// of identifiers that contains identifiers of UIScene that are active.
bool NeverPurgeDiscardedSessionsData();
// Returns a policy provider that should be installed as the platform policy
// provider when testing. May return nullptr.
policy::ConfigurationPolicyProvider* GetOverriddenPlatformPolicyProvider();
// Whether a phone backup/restore state should be simulated for testing purpose.
// Uses`experimental_flags::SimulatePostDeviceRestore()` to check whether this
// feature should be enabled due to experimental feature.
bool SimulatePostDeviceRestore();
// Allows overriding the SystemIdentityManager factory. The real factory will
// be used if this hook returns null.
std::unique_ptr<SystemIdentityManager> CreateSystemIdentityManager();
// Allows overriding the TrustedVaultClientBackend factory. The real factory
// will be used if this hook returns null.
std::unique_ptr<TrustedVaultClientBackend> CreateTrustedVaultClientBackend();
// Allows overriding the TabGroupSyncService factory. The real factory will be
// used if this hook returns null.
std::unique_ptr<tab_groups::TabGroupSyncService> CreateTabGroupSyncService(
ProfileIOS* profile);
// Allows additional test setup for the DataSharingService.
void DataSharingServiceHooks(
data_sharing::DataSharingService* data_sharing_service);
// Allows overriding the ShareKitService factory. The real factory will be
// used if this hook returns null.
std::unique_ptr<ShareKitService> CreateShareKitService(
data_sharing::DataSharingService* data_sharing_service,
collaboration::CollaborationService* collaboration_service,
tab_groups::TabGroupSyncService* sync_service);
// Returns a bulk leak check service that should be used when testing. The real
// factory will be used if this hook returns a nullptr.
std::unique_ptr<password_manager::BulkLeakCheckServiceInterface>
GetOverriddenBulkLeakCheckService();
// Returns a plus address service that should be used when testing. The real
// factory will be used if this hook returns a nullptr.
std::unique_ptr<plus_addresses::PlusAddressService>
GetOverriddenPlusAddressService();
// Returns a recipients fetcher instance that should be used in EG tests. The
// real instance will be used if this hook returns a nullptr.
std::unique_ptr<password_manager::RecipientsFetcher>
GetOverriddenRecipientsFetcher();
// Global integration tests setup.
void SetUpTestsIfPresent();
// Runs the integration tests. This is not used by EarlGrey-based integration
// tests.
void RunTestsIfPresent();
// Signal that the app has successfully launched. Only used by performance
// tests.
void SignalAppLaunched();
// Minimum duration of password checks. The password check UI displays checks as
// in progress for at least this duration in order to avoid updating the UI too
// fast and making it flicker. Test targets do not have an artificial minimum
// duration as it can make test flaky.
base::TimeDelta PasswordCheckMinimumDuration();
// Duration for snackbars. If the value is 0, the default value from
// -[MDCSnackbarMessage duration] should not be updated.
base::TimeDelta GetOverriddenSnackbarDuration();
// Returns a Drive service instance that should be used in EG tests. The real
// instance will be used if this hook returns a nullptr.
std::unique_ptr<drive::DriveService> GetOverriddenDriveService();
// Override the Feature Engagement Tracker used in tests with a demo version.
feature_engagement::FeatureActivation FETDemoModeOverride();
// If the given argv contains `-EGTestWipeProfile`, deletes the
// contents of the `Library` directory at the start of `main()`. This
// simulates launching the application with a fresh profile.
void WipeProfileIfRequested(int argc, char* argv[]);
} // namespace tests_hook
#endif // IOS_CHROME_APP_TESTS_HOOK_H_