Commit 66343390 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Improve Time Formatting for Password Check

This change improves the formatting of elapsed time since a compromised
password was found. Time deltas smaller than a minute are now shown as
"Just now", while deltas exceeding 30 and 365 days are formatted with
months and years, respectively.

Bug: 1047726
Change-Id: Ic08bf80ac300724a64fe304e032936ee0968b6b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095298Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748273}
parent a8edfaa9
...@@ -332,6 +332,9 @@ ...@@ -332,6 +332,9 @@
<message name="IDS_SETTINGS_CHECK_PASSWORDS_AGAIN" desc="Button to start bulk password check manually in passwords check section."> <message name="IDS_SETTINGS_CHECK_PASSWORDS_AGAIN" desc="Button to start bulk password check manually in passwords check section.">
Check again Check again
</message> </message>
<message name="IDS_SETTINGS_PASSWORDS_JUST_NOW" desc="Label shown when a compromised credential was found less than a minute ago">
Just now
</message>
<message name="IDS_SETTINGS_COMPROMISED_PASSWORDS" desc="Title for list of compromised credentials after passwords bulk check."> <message name="IDS_SETTINGS_COMPROMISED_PASSWORDS" desc="Title for list of compromised credentials after passwords bulk check.">
Compromised passwords Compromised passwords
</message> </message>
......
c72fcd2625754a7a383ccd2885c322bb1b100f00
\ No newline at end of file
...@@ -206,9 +206,16 @@ PasswordCheckDelegate::GetCompromisedCredentialsInfo() { ...@@ -206,9 +206,16 @@ PasswordCheckDelegate::GetCompromisedCredentialsInfo() {
api_credential.username = base::UTF16ToUTF8(credential.username); api_credential.username = base::UTF16ToUTF8(credential.username);
api_credential.compromise_time = api_credential.compromise_time =
credential.create_time.ToJsTimeIgnoringNull(); credential.create_time.ToJsTimeIgnoringNull();
api_credential.elapsed_time_since_compromise = base::UTF16ToUTF8( base::TimeDelta elapsed_time = base::Time::Now() - credential.create_time;
TimeFormat::Simple(TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_LONG, if (elapsed_time < base::TimeDelta::FromMinutes(1)) {
base::Time::Now() - credential.create_time)); api_credential.elapsed_time_since_compromise =
l10n_util::GetStringUTF8(IDS_SETTINGS_PASSWORDS_JUST_NOW);
} else {
api_credential.elapsed_time_since_compromise =
base::UTF16ToUTF8(TimeFormat::SimpleWithMonthAndYear(
TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_LONG, elapsed_time,
true));
}
api_credential.compromise_type = api_credential.compromise_type =
ConvertCompromiseType(credential.compromise_type); ConvertCompromiseType(credential.compromise_type);
credentials_info.compromised_credentials.push_back( credentials_info.compromised_credentials.push_back(
......
...@@ -272,6 +272,49 @@ TEST_F(PasswordCheckDelegateTest, GetCompromisedCredentialsInfoOrders) { ...@@ -272,6 +272,49 @@ TEST_F(PasswordCheckDelegateTest, GetCompromisedCredentialsInfoOrders) {
api::passwords_private::COMPROMISE_TYPE_LEAKED))); api::passwords_private::COMPROMISE_TYPE_LEAKED)));
} }
// Verifies that the formatted timestamp associated with a compromised
// credential covers the "Just now" cases (less than a minute ago), as well as
// months and years.
TEST_F(PasswordCheckDelegateTest, GetCompromisedCredentialsHandlesTimes) {
store().AddLogin(MakeSavedPassword(kExampleCom, kUsername1));
store().AddLogin(MakeSavedPassword(kExampleCom, kUsername2));
store().AddLogin(MakeSavedPassword(kExampleOrg, kUsername1));
store().AddLogin(MakeSavedPassword(kExampleOrg, kUsername2));
store().AddCompromisedCredentials(
MakeCompromised(kExampleCom, kUsername1, base::TimeDelta::FromSeconds(59),
CompromiseType::kLeaked));
store().AddCompromisedCredentials(
MakeCompromised(kExampleCom, kUsername2, base::TimeDelta::FromSeconds(60),
CompromiseType::kLeaked));
store().AddCompromisedCredentials(
MakeCompromised(kExampleOrg, kUsername1, base::TimeDelta::FromDays(100),
CompromiseType::kLeaked));
store().AddCompromisedCredentials(
MakeCompromised(kExampleOrg, kUsername2, base::TimeDelta::FromDays(800),
CompromiseType::kLeaked));
RunUntilIdle();
EXPECT_THAT(
delegate().GetCompromisedCredentialsInfo().compromised_credentials,
ElementsAre(ExpectCompromisedCredential(
"example.com", kExampleCom, kUsername1,
base::TimeDelta::FromSeconds(59), "Just now",
api::passwords_private::COMPROMISE_TYPE_LEAKED),
ExpectCompromisedCredential(
"example.com", kExampleCom, kUsername2,
base::TimeDelta::FromSeconds(60), "1 minute ago",
api::passwords_private::COMPROMISE_TYPE_LEAKED),
ExpectCompromisedCredential(
"example.org", kExampleOrg, kUsername1,
base::TimeDelta::FromDays(100), "3 months ago",
api::passwords_private::COMPROMISE_TYPE_LEAKED),
ExpectCompromisedCredential(
"example.org", kExampleOrg, kUsername2,
base::TimeDelta::FromDays(800), "2 years ago",
api::passwords_private::COMPROMISE_TYPE_LEAKED)));
}
TEST_F(PasswordCheckDelegateTest, GetCompromisedCredentialsInfoInjectsAndroid) { TEST_F(PasswordCheckDelegateTest, GetCompromisedCredentialsInfoInjectsAndroid) {
store().AddLogin(MakeSavedPassword(kExampleCom, kUsername1)); store().AddLogin(MakeSavedPassword(kExampleCom, kUsername1));
store().AddLogin(MakeSavedAndroidPassword(kExampleApp, kUsername2, store().AddLogin(MakeSavedAndroidPassword(kExampleApp, kUsername2,
......
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