Commit d7b3298d authored by harrisonsean's avatar harrisonsean Committed by Commit Bot

[iOS][Safety Check] Add mediator tests

Added Tests:
StartingCheckPutsChecksInRunningState
CheckStartButtonDefaultUI
ClickingCancelTakesChecksToPrevious
CheckStartButtonCancelUI
TimestampSetIfIssueFound
SafeBrowsingEnabledReturnsSafeState
SafeBrowsingSafeUI
SafeBrowsingDisabledReturnsInfoState
SafeBrowsingUnSafeUI
SafeBrowsingManagedUI
PasswordCheckSafeCheck
PasswordCheckSafeUI
PasswordCheckUnSafeCheck
PasswordCheckUnSafeUI
PasswordCheckErrorCheck
PasswordCheckErrorUI
OmahaRespondsUpToDate
UpdateCheckUpToDateUI
OmahaRespondsOutOfDateAndUpdatesInfobarTime
UpdateCheckOutOfDateUI
OmahaRespondsError
UpdateCheckOmahaErrorUI
UpdateCheckNetErrorUI
UpdateCheckManagedUI
UpdateCheckChannelUI

Bug: 1078782
Change-Id: I61d155817bc13b96fb581fa4a77426ac56deae6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436530
Commit-Queue: Sean Harrison <harrisonsean@chromium.org>
Reviewed-by: default avatarViktor Semeniuk <vsemeniuk@google.com>
Cr-Commit-Position: refs/heads/master@{#813001}
parent 7843b3b3
......@@ -83,13 +83,32 @@ source_set("unit_tests") {
sources = [ "safety_check_mediator_unittest.mm" ]
deps = [
":safety_check",
":safety_check_ui",
"//base/test:test_support",
"//components/password_manager/core/browser:test_support",
"//components/password_manager/core/common",
"//components/prefs:test_support",
"//components/safe_browsing/core:features",
"//components/safe_browsing/core/common:safe_browsing_prefs",
"//components/strings",
"//components/sync_preferences:test_support",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/passwords",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/signin:test_support",
"//ios/chrome/browser/sync",
"//ios/chrome/browser/sync:test_support",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/settings/cells",
"//ios/chrome/browser/ui/settings/utils",
"//ios/chrome/browser/ui/table_view:test_support",
"//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/browser/upgrade",
"//ios/chrome/browser/upgrade:public",
"//ios/chrome/common",
"//ios/chrome/test:test_support",
"//ios/web/public/test",
"//testing/gtest",
......
......@@ -29,4 +29,62 @@ extern NSString* const kSafeBrowsingSafetyCheckStringURL;
// issue.
extern NSString* const kTimestampOfLastIssueFoundKey;
// Enum with all possible states of the update check.
typedef NS_ENUM(NSInteger, UpdateCheckRowStates) {
// When the user is up to date.
UpdateCheckRowStateUpToDate,
// When the check has not been run yet.
UpdateCheckRowStateDefault,
// When the user is out of date.
UpdateCheckRowStateOutOfDate,
// When the user is managed.
UpdateCheckRowStateManaged,
// When the check is running.
UpdateCheckRowStateRunning,
// When Omaha encountered an error.
UpdateCheckRowStateOmahaError,
// When there is a connectivity issue.
UpdateCheckRowStateNetError,
// When the device is on a non-supported channel.
UpdateCheckRowStateChannel,
};
// Enum with all possible states of the password check.
typedef NS_ENUM(NSInteger, PasswordCheckRowStates) {
// When no compromised passwords were detected.
PasswordCheckRowStateSafe,
// When user has compromised passwords.
PasswordCheckRowStateUnSafe,
// When check has not been run yet.
PasswordCheckRowStateDefault,
// When password check is running.
PasswordCheckRowStateRunning,
// When user has no passwords and check can't be performed.
PasswordCheckRowStateDisabled,
// When password check failed due to network issues, quota limit or others.
PasswordCheckRowStateError,
};
// Enum with all possible states of the Safe Browsing check.
typedef NS_ENUM(NSInteger, SafeBrowsingCheckRowStates) {
// When check was not run yet.
SafeBrowsingCheckRowStateDefault,
// When Safe Browsing is managed by admin.
SafeBrowsingCheckRowStateManaged,
// When the Safe Browsing check is running.
SafeBrowsingCheckRowStateRunning,
// When Safe Browsing is enabled.
SafeBrowsingCheckRowStateSafe,
// When Safe Browsing is disabled.
SafeBrowsingCheckRowStateUnsafe,
};
// Enum with all possible states of the button to start the check.
typedef NS_ENUM(NSInteger, CheckStartStates) {
// When the check is not running.
CheckStartStateDefault,
// When the check is running.
CheckStartStateCancel,
};
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_SAFETY_CHECK_SAFETY_CHECK_CONSTANTS_H_
......@@ -78,7 +78,7 @@ constexpr char kSafetyCheckInteractions[] = "Settings.SafetyCheck.Interactions";
typedef NSArray<TableViewItem*>* ItemArray;
typedef NS_ENUM(NSInteger, ItemType) {
typedef NS_ENUM(NSInteger, SafteyCheckItemType) {
// CheckTypes section.
UpdateItemType = kItemTypeEnumZero,
PasswordItemType,
......@@ -89,64 +89,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
TimestampFooterItem,
};
// Enum with all possible states of the update check.
typedef NS_ENUM(NSInteger, UpdateCheckRowStates) {
// When the user is up to date.
UpdateCheckRowStateUpToDate,
// When the check has not been run yet.
UpdateCheckRowStateDefault,
// When the user is out of date.
UpdateCheckRowStateOutOfDate,
// When the user is managed.
UpdateCheckRowStateManaged,
// When the check is running.
UpdateCheckRowStateRunning,
// When Omaha encountered an error.
UpdateCheckRowStateOmahaError,
// When there is a connectivity issue.
UpdateCheckRowStateNetError,
// When the device is on a non-supported channel.
UpdateCheckRowStateChannel,
};
// Enum with all possible states of the password check.
typedef NS_ENUM(NSInteger, PasswordCheckRowStates) {
// When no compromised passwords were detected.
PasswordCheckRowStateSafe,
// When user has compromised passwords.
PasswordCheckRowStateUnSafe,
// When check has not been run yet.
PasswordCheckRowStateDefault,
// When password check is running.
PasswordCheckRowStateRunning,
// When user has no passwords and check can't be performed.
PasswordCheckRowStateDisabled,
// When password check failed due to network issues, quota limit or others.
PasswordCheckRowStateError,
};
// Enum with all possible states of the Safe Browsing check.
typedef NS_ENUM(NSInteger, SafeBrowsingCheckRowStates) {
// When check was not run yet.
SafeBrowsingCheckRowStateDefault,
// When Safe Browsing is managed by admin.
SafeBrowsingCheckRowStateManaged,
// When the Safe Browsing check is running.
SafeBrowsingCheckRowStateRunning,
// When Safe Browsing is enabled.
SafeBrowsingCheckRowStateSafe,
// When Safe Browsing is disabled.
SafeBrowsingCheckRowStateUnsafe,
};
// Enum with all possible states of the button to start the check.
typedef NS_ENUM(NSInteger, CheckStartStates) {
// When the check is not running.
CheckStartStateDefault,
// When the check is running.
CheckStartStateCancel,
};
} // namespace
@interface SafetyCheckMediator () <BooleanObserver, PasswordCheckObserver> {
......@@ -376,7 +318,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
#pragma mark - SafetyCheckServiceDelegate
- (void)didSelectItem:(TableViewItem*)item {
ItemType type = static_cast<ItemType>(item.type);
SafteyCheckItemType type = static_cast<SafteyCheckItemType>(item.type);
switch (type) {
// Few selections are handled here explicitly, but all states are laid out
// to have one location that shows all actions that are taken from the
......@@ -449,7 +391,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
}
- (BOOL)isItemWithErrorInfo:(TableViewItem*)item {
ItemType type = static_cast<ItemType>(item.type);
SafteyCheckItemType type = static_cast<SafteyCheckItemType>(item.type);
return (type != CheckStartItemType);
}
......@@ -490,7 +432,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
// Computes the text needed for a popover on |itemType| if available.
- (NSAttributedString*)getPopoverInfoForType:(NSInteger)itemType {
ItemType type = static_cast<ItemType>(itemType);
SafteyCheckItemType type = static_cast<SafteyCheckItemType>(itemType);
switch (type) {
case PasswordItemType:
return [self passwordCheckErrorInfo];
......@@ -552,7 +494,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
: PasswordCheckRowStateUnSafe;
case PasswordCheckState::kCanceled:
case PasswordCheckState::kIdle: {
if (noCompromisedPasswords) {
if (!noCompromisedPasswords) {
base::UmaHistogramEnumeration(
kSafetyCheckMetricsPasswords,
safety_check::SafetyCheck::PasswordsStatus::kCompromisedExist);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment