Commit 0b001faa authored by Viktor Semeniuk's avatar Viktor Semeniuk Committed by Commit Bot

[iOS][Password Check] Number of compromised credentials

This change displays number of compromised credentials in the Passwords
screen using plural string.

Bug: 1075494
Change-Id: Ic155353280f2f40834fef78e26a1d4b12a6477a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2301142Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Viktor Semeniuk <vsemeniuk@google.com>
Cr-Commit-Position: refs/heads/master@{#789397}
parent 1f7e8b67
...@@ -1623,11 +1623,11 @@ While in incognito, sites can't use cookies to see your browsing activity across ...@@ -1623,11 +1623,11 @@ While in incognito, sites can't use cookies to see your browsing activity across
<message name="IDS_IOS_CHECK_PASSWORDS_DESCRIPTION" desc="Description for the Password Check item in Settings" meaning="Label is shown to explain purpose of Password Check feature. This string is shown only if user didn't run Password Check before or check finished due to error without any results. [iOS only]"> <message name="IDS_IOS_CHECK_PASSWORDS_DESCRIPTION" desc="Description for the Password Check item in Settings" meaning="Label is shown to explain purpose of Password Check feature. This string is shown only if user didn't run Password Check before or check finished due to error without any results. [iOS only]">
Keep your passwords safe from security issues Keep your passwords safe from security issues
</message> </message>
<message name="IDS_IOS_CHECK_PASSWORDS_SAFE_STATE" desc="Description for the Password Check item in Settings" meaning="Label is shown when no issues were found during password check. [iOS only]"> <message name="IDS_IOS_CHECK_PASSWORDS_COMPROMISED_COUNT" desc="Displays the number of compromised passwords present in the database">
No passwords compromised {COUNT, plural,
</message> =0 {No passwords compromised}
<message name="IDS_IOS_CHECK_PASSWORDS_UNSAFE_STATE" desc="Description for the Password Check item in Settings" meaning="Label is shown when compromised credentials were found during password check. [iOS only]"> =1 {{COUNT} Password compromised}
Passwords compromised other {{COUNT} Passwords compromised}}
</message> </message>
<message name="IDS_IOS_CHECK_PASSWORDS_NOW_BUTTON" desc="Label of a button which starts Password Check [Length: 22em] [iOS only]" meaning="By clicking this button user will start checking all passwords for security issues."> <message name="IDS_IOS_CHECK_PASSWORDS_NOW_BUTTON" desc="Label of a button which starts Password Check [Length: 22em] [iOS only]" meaning="By clicking this button user will start checking all passwords for security issues.">
Check Now Check Now
......
50f9da3214aa8cc48c5c1038753cb1aa27073713
\ No newline at end of file
2ca0f184b7da1ef01735d614bb03a58467d6587e
\ No newline at end of file
681e0ec48c1ac1017594daf5aed8dc8d3cb49f81
\ No newline at end of file
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
#include "ios/chrome/grit/ios_chromium_strings.h" #include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "net/base/mac/url_conversions.h" #import "net/base/mac/url_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -972,7 +973,9 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf( ...@@ -972,7 +973,9 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
} }
case PasswordCheckStateUnSafe: { case PasswordCheckStateUnSafe: {
_passwordProblemsItem.detailText = _passwordProblemsItem.detailText =
l10n_util::GetNSString(IDS_IOS_CHECK_PASSWORDS_UNSAFE_STATE); base::SysUTF16ToNSString(l10n_util::GetPluralStringFUTF16(
IDS_IOS_CHECK_PASSWORDS_COMPROMISED_COUNT,
_passwordCheck->GetCompromisedCredentials().size()));
UIImage* unSafeIconImage = [[UIImage imageNamed:@"settings_unsafe_state"] UIImage* unSafeIconImage = [[UIImage imageNamed:@"settings_unsafe_state"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
_passwordProblemsItem.trailingImage = unSafeIconImage; _passwordProblemsItem.trailingImage = unSafeIconImage;
...@@ -983,10 +986,12 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf( ...@@ -983,10 +986,12 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
break; break;
} }
case PasswordCheckStateSafe: { case PasswordCheckStateSafe: {
DCHECK(_passwordCheck->GetCompromisedCredentials().empty());
UIImage* safeIconImage = [[UIImage imageNamed:@"settings_safe_state"] UIImage* safeIconImage = [[UIImage imageNamed:@"settings_safe_state"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
_passwordProblemsItem.detailText = _passwordProblemsItem.detailText =
l10n_util::GetNSString(IDS_IOS_CHECK_PASSWORDS_SAFE_STATE); base::SysUTF16ToNSString(l10n_util::GetPluralStringFUTF16(
IDS_IOS_CHECK_PASSWORDS_COMPROMISED_COUNT, 0));
_passwordProblemsItem.trailingImage = safeIconImage; _passwordProblemsItem.trailingImage = safeIconImage;
_passwordProblemsItem.trailingImageTintColor = _passwordProblemsItem.trailingImageTintColor =
[UIColor colorNamed:kGreenColor]; [UIColor colorNamed:kGreenColor];
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/strings/string_piece.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
...@@ -38,11 +40,14 @@ ...@@ -38,11 +40,14 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using password_manager::CompromiseType;
using password_manager::TestPasswordStore; using password_manager::TestPasswordStore;
using password_manager::MockBulkLeakCheckService; using password_manager::MockBulkLeakCheckService;
using ::testing::Return; using ::testing::Return;
...@@ -226,6 +231,23 @@ class PasswordsTableViewControllerTest ...@@ -226,6 +231,23 @@ class PasswordsTableViewControllerTest
AddPasswordForm(std::move(form)); AddPasswordForm(std::move(form));
} }
password_manager::CompromisedCredentials MakeCompromised(
base::StringPiece signon_realm,
base::StringPiece username) {
return {
std::string(signon_realm),
base::ASCIIToUTF16(username),
base::Time::Now(),
CompromiseType::kLeaked,
};
}
void AddCompromisedCredential1() {
GetTestStore().AddCompromisedCredentials(
MakeCompromised("http://www.example.com/", "test@egmail.com"));
RunUntilIdle();
}
// Deletes the item at (row, section) and wait util condition returns true or // Deletes the item at (row, section) and wait util condition returns true or
// timeout. // timeout.
bool deleteItemAndWait(int section, int row, ConditionBlock condition) { bool deleteItemAndWait(int section, int row, ConditionBlock condition) {
...@@ -237,6 +259,19 @@ class PasswordsTableViewControllerTest ...@@ -237,6 +259,19 @@ class PasswordsTableViewControllerTest
base::test::ios::kWaitForUIElementTimeout, condition); base::test::ios::kWaitForUIElementTimeout, condition);
} }
void CheckDetailItemTextWithPluralIds(int expected_text_id,
int expected_detail_text_id,
int count,
int section,
int item) {
SettingsCheckItem* cell =
static_cast<SettingsCheckItem*>(GetTableViewItem(section, item));
EXPECT_NSEQ(l10n_util::GetNSString(expected_text_id), [cell text]);
EXPECT_NSEQ(base::SysUTF16ToNSString(l10n_util::GetPluralStringFUTF16(
IDS_IOS_CHECK_PASSWORDS_COMPROMISED_COUNT, count)),
[cell detailText]);
}
void RunUntilIdle() { task_environment_.RunUntilIdle(); } void RunUntilIdle() { task_environment_.RunUntilIdle(); }
web::WebTaskEnvironment task_environment_; web::WebTaskEnvironment task_environment_;
...@@ -572,6 +607,45 @@ TEST_P(PasswordsTableViewControllerTest, PasswordCheckStateDefault) { ...@@ -572,6 +607,45 @@ TEST_P(PasswordsTableViewControllerTest, PasswordCheckStateDefault) {
EXPECT_FALSE(checkPassword.trailingImage); EXPECT_FALSE(checkPassword.trailingImage);
} }
// Test verifies safe state of password check cell.
TEST_P(PasswordsTableViewControllerTest, PasswordCheckStateSafe) {
if (!GetParam().password_check_enabled)
return;
ChangePasswordCheckState(PasswordCheckStateSafe);
CheckTextCellTextWithId(IDS_IOS_CHECK_PASSWORDS_NOW_BUTTON,
GetSectionIndex(PasswordCheck), 1);
CheckDetailItemTextWithPluralIds(IDS_IOS_CHECK_PASSWORDS,
IDS_IOS_CHECK_PASSWORDS_COMPROMISED_COUNT, 0,
GetSectionIndex(PasswordCheck), 0);
SettingsCheckItem* checkPassword =
GetTableViewItem(GetSectionIndex(PasswordCheck), 0);
EXPECT_TRUE(checkPassword.enabled);
EXPECT_TRUE(checkPassword.indicatorHidden);
EXPECT_TRUE(checkPassword.trailingImage);
}
// Test verifies unsafe state of password check cell.
TEST_P(PasswordsTableViewControllerTest, PasswordCheckStateUnSafe) {
if (!GetParam().password_check_enabled)
return;
AddSavedForm1();
AddCompromisedCredential1();
ChangePasswordCheckState(PasswordCheckStateUnSafe);
CheckTextCellTextWithId(IDS_IOS_CHECK_PASSWORDS_NOW_BUTTON,
GetSectionIndex(PasswordCheck), 1);
CheckDetailItemTextWithPluralIds(IDS_IOS_CHECK_PASSWORDS,
IDS_IOS_CHECK_PASSWORDS_COMPROMISED_COUNT, 1,
GetSectionIndex(PasswordCheck), 0);
SettingsCheckItem* checkPassword =
GetTableViewItem(GetSectionIndex(PasswordCheck), 0);
EXPECT_TRUE(checkPassword.enabled);
EXPECT_TRUE(checkPassword.indicatorHidden);
EXPECT_TRUE(checkPassword.trailingImage);
}
// Test verifies running state of password check cell. // Test verifies running state of password check cell.
TEST_P(PasswordsTableViewControllerTest, PasswordCheckStateRunning) { TEST_P(PasswordsTableViewControllerTest, PasswordCheckStateRunning) {
if (!GetParam().password_check_enabled) if (!GetParam().password_check_enabled)
......
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