0

birch: Add "X days ago" to last active tab suggestion chip subtitle

For tabs that were last active before yesterday we now show the string
"X days ago".

Bug: b:345284203
Test: ash_unittests --gtest_filter=BirchItemTest*
Change-Id: I9e18fe3599a3d6b145824413901122f5b10e1493
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5606062
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1311537}
This commit is contained in:
James Cook
2024-06-06 20:54:50 +00:00
committed by Chromium LUCI CQ
parent 21d4953f34
commit 64b4f2ac4a
4 changed files with 34 additions and 2 deletions

@ -8259,6 +8259,12 @@ To shut down the device, press and hold the power button on the device again.
<message name="IDS_ASH_BIRCH_SELF_SHARE_SUBTITLE_SUFFIX" desc="End of the subtitle for the suggestion chip with tabs shared from other devices">
Sent from <ph name="SESSION_NAME">$1<ex>Chromebook</ex></ph>
</message>
<!-- This uses a full plural string for safety, even though the day count should be at least 2. -->
<message name="IDS_ASH_BIRCH_LAST_ACTIVE_SUBTITLE_DAYS_AGO" desc="Start of the subtitle for the suggestion chip with a last active tab used some number of days ago">
{DAYS, plural,
=1 {1 day ago}
other {# days ago}}
</message>
<message name="IDS_ASH_BIRCH_LAST_ACTIVE_SUBTITLE_YESTERDAY" desc="Subtitle for the suggestion chip with the last active tab">
Yesterday
</message>

@ -0,0 +1 @@
83750d59f83c3d8b1004b03a39c503d4cb67b4b8

@ -623,8 +623,14 @@ void BirchLastActiveItem::LoadIcon(LoadIconCallback callback) const {
// static
std::u16string BirchLastActiveItem::GetSubtitle(base::Time last_visit) {
std::u16string prefix;
if (last_visit < base::Time::Now().LocalMidnight()) {
// TODO(jamescook): Add support for more than 1 day ago.
if (last_visit < base::Time::Now().LocalMidnight() - base::Days(1)) {
// If the last visit was before yesterday, show "X days ago".
int days = (base::Time::Now() - last_visit).InDays();
prefix = l10n_util::GetPluralStringFUTF16(
IDS_ASH_BIRCH_LAST_ACTIVE_SUBTITLE_DAYS_AGO, days);
} else if (last_visit < base::Time::Now().LocalMidnight()) {
// If the last visit was yesterday show "Yesterday", which is a common case
// in the mornings.
prefix =
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_LAST_ACTIVE_SUBTITLE_YESTERDAY);
} else {

@ -483,6 +483,25 @@ TEST_F(BirchItemTest, Tab_PerformAction_Histograms) {
1);
}
TEST_F(BirchItemTest, LastActive_Subtitle_TwoDaysAgo) {
BirchLastActiveItem item(u"item", GURL("http://example.com/"),
base::Time::Now() - base::Days(2), ui::ImageModel());
EXPECT_EQ(item.subtitle(), u"2 days ago · Continue browsing");
}
TEST_F(BirchItemTest, LastActive_Subtitle_Yesterday) {
BirchLastActiveItem item(u"item", GURL("http://example.com/"),
base::Time::Now() - base::Days(1), ui::ImageModel());
EXPECT_EQ(item.subtitle(), u"Yesterday · Continue browsing");
}
TEST_F(BirchItemTest, LastActive_Subtitle_OneHourAgo) {
BirchLastActiveItem item(u"item", GURL("http://example.com/"),
base::Time::Now() - base::Hours(1),
ui::ImageModel());
EXPECT_EQ(item.subtitle(), u"1 hr ago · Continue browsing");
}
TEST_F(BirchItemTest, LastActive_PerformAction) {
BirchLastActiveItem item(u"item", GURL("http://example.com/"), base::Time(),
ui::ImageModel());