Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Unified Diff: ui/base/l10n/time_format_unittest.cc

Issue 147443007: Add support for localized time strings with two units, eg. "2 hours 17 minutes" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Tony's comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/l10n/time_format.cc ('k') | ui/base/strings/ui_strings.grd » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/l10n/time_format_unittest.cc
diff --git a/ui/base/l10n/time_format_unittest.cc b/ui/base/l10n/time_format_unittest.cc
index 4d6dbb7d154197e95547a7ec3f9bceeaef6badd6..69f8b4e94ac10b7e2df683c4b97746688f0126fa 100644
--- a/ui/base/l10n/time_format_unittest.cc
+++ b/ui/base/l10n/time_format_unittest.cc
@@ -9,6 +9,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/formatter.h"
#include "ui/base/resource/resource_bundle.h"
using base::ASCIIToUTF16;
@@ -20,6 +21,59 @@ using base::TimeDelta;
class TimeFormatTest : public ::testing::Test {
public:
+ TimeFormatTest() :
+ delta_0s_(TimeDelta::FromSeconds(0)),
+ delta_1ms_(TimeDelta::FromMilliseconds(1)),
+ delta_499ms_(TimeDelta::FromMilliseconds(499)),
+ delta_500ms_(TimeDelta::FromMilliseconds(500)),
+ delta_999ms_(TimeDelta::FromMilliseconds(999)),
+ delta_1s_(TimeDelta::FromSeconds(1)),
+ delta_1s499ms_(delta_1s_ + delta_499ms_),
+ delta_1s500ms_(delta_1s_ + delta_500ms_),
+ delta_2s_(TimeDelta::FromSeconds(2)),
+ delta_29s_(TimeDelta::FromSeconds(29)),
+ delta_30s_(TimeDelta::FromSeconds(30)),
+ delta_59s_(TimeDelta::FromSeconds(59)),
+ delta_59s499ms_(delta_59s_ + delta_499ms_),
+ delta_59s500ms_(delta_59s_ + delta_500ms_),
+ delta_1m_(TimeDelta::FromMinutes(1)),
+ delta_1m2s_(delta_1m_ + delta_2s_),
+ delta_1m29s999ms_(delta_1m_ + delta_29s_ + delta_999ms_),
+ delta_1m30s_(delta_1m_ + delta_30s_),
+ delta_2m_(TimeDelta::FromMinutes(2)),
+ delta_2m1s_(delta_2m_ + delta_1s_),
+ delta_29m_(TimeDelta::FromMinutes(29)),
+ delta_30m_(TimeDelta::FromMinutes(30)),
+ delta_59m_(TimeDelta::FromMinutes(59)),
+ delta_59m29s999ms_(delta_59m_ + delta_29s_ + delta_999ms_),
+ delta_59m30s_(delta_59m_ + delta_30s_),
+ delta_59m59s499ms_(delta_59m_ + delta_59s_ + delta_499ms_),
+ delta_59m59s500ms_(delta_59m_ + delta_59s_ + delta_500ms_),
+ delta_1h_(TimeDelta::FromHours(1)),
+ delta_1h2m_(delta_1h_ + delta_2m_),
+ delta_1h29m59s999ms_(delta_1h_ + delta_29m_ + delta_59s_ + delta_999ms_),
+ delta_1h30m_(delta_1h_ + delta_30m_),
+ delta_2h_(TimeDelta::FromHours(2)),
+ delta_2h1m_(delta_2h_ + delta_1m_),
+ delta_11h_(TimeDelta::FromHours(11)),
+ delta_12h_(TimeDelta::FromHours(12)),
+ delta_23h_(TimeDelta::FromHours(23)),
+ delta_23h29m59s999ms_(delta_23h_ + delta_29m_ + delta_59s_ +
+ delta_999ms_),
+ delta_23h30m_(delta_23h_ + delta_30m_),
+ delta_23h59m29s999ms_(delta_23h_ + delta_59m_ + delta_29s_ +
+ delta_999ms_),
+ delta_23h59m30s_(delta_23h_ + delta_59m_ + delta_30s_),
+ delta_1d_(TimeDelta::FromDays(1)),
+ delta_1d2h_(delta_1d_ + delta_2h_),
+ delta_1d11h59m59s999ms_(delta_1d_ + delta_11h_ + delta_59m_ + delta_29s_ +
+ delta_999ms_),
+ delta_1d12h_(delta_1d_ + delta_12h_),
+ delta_2d_(TimeDelta::FromDays(2)),
+ delta_2d1h_(delta_2d_ + delta_1h_)
+ {}
+
+ protected:
static void SetUpTestCase() {
LoadLocale(ui::ResourceBundle::GetSharedInstance()
.GetLocaleFilePath("en-US", true));
@@ -29,6 +83,153 @@ class TimeFormatTest : public ::testing::Test {
LoadLocale(base::FilePath());
}
+ void TestStrings() {
+ // Test English strings (simple, singular).
+ EXPECT_EQ(ASCIIToUTF16("1 sec"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1s_));
+ EXPECT_EQ(ASCIIToUTF16("1 min"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1m_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1h_));
+ EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1d_));
+ EXPECT_EQ(ASCIIToUTF16("1 second"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_1s_));
+ EXPECT_EQ(ASCIIToUTF16("1 minute"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_1m_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_1h_));
+ EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_1d_));
+ EXPECT_EQ(ASCIIToUTF16("1 sec left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_1s_));
+ EXPECT_EQ(ASCIIToUTF16("1 min left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_1m_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_1h_));
+ EXPECT_EQ(ASCIIToUTF16("1 day left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_1d_));
+ EXPECT_EQ(ASCIIToUTF16("1 second left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_1s_));
+ EXPECT_EQ(ASCIIToUTF16("1 minute left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_1m_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_1h_));
+ EXPECT_EQ(ASCIIToUTF16("1 day left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_1d_));
+ EXPECT_EQ(ASCIIToUTF16("1 sec ago"), TimeFormat::Simple(
+ TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_1s_));
+ EXPECT_EQ(ASCIIToUTF16("1 min ago"), TimeFormat::Simple(
+ TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_1m_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour ago"), TimeFormat::Simple(
+ TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_1h_));
+ EXPECT_EQ(ASCIIToUTF16("1 day ago"), TimeFormat::Simple(
+ TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_1d_));
+
+ // Test English strings (simple, plural).
+ EXPECT_EQ(ASCIIToUTF16("2 secs"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_2s_));
+ EXPECT_EQ(ASCIIToUTF16("2 mins"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_2m_));
+ EXPECT_EQ(ASCIIToUTF16("2 hours"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_2h_));
+ EXPECT_EQ(ASCIIToUTF16("2 days"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_2d_));
+ EXPECT_EQ(ASCIIToUTF16("2 seconds"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_2s_));
+ EXPECT_EQ(ASCIIToUTF16("2 minutes"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_2m_));
+ EXPECT_EQ(ASCIIToUTF16("2 hours"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_2h_));
+ EXPECT_EQ(ASCIIToUTF16("2 days"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_2d_));
+ EXPECT_EQ(ASCIIToUTF16("2 secs left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_2s_));
+ EXPECT_EQ(ASCIIToUTF16("2 mins left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_2m_));
+ EXPECT_EQ(ASCIIToUTF16("2 hours left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_2h_));
+ EXPECT_EQ(ASCIIToUTF16("2 days left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_2d_));
+ EXPECT_EQ(ASCIIToUTF16("2 seconds left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_2s_));
+ EXPECT_EQ(ASCIIToUTF16("2 minutes left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_2m_));
+ EXPECT_EQ(ASCIIToUTF16("2 hours left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_2h_));
+ EXPECT_EQ(ASCIIToUTF16("2 days left"), TimeFormat::Simple(
+ TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_2d_));
+ EXPECT_EQ(ASCIIToUTF16("2 secs ago"), TimeFormat::Simple(
+ TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_2s_));
+ EXPECT_EQ(ASCIIToUTF16("2 mins ago"), TimeFormat::Simple(
+ TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_2m_));
+ EXPECT_EQ(ASCIIToUTF16("2 hours ago"), TimeFormat::Simple(
+ TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_2h_));
+ EXPECT_EQ(ASCIIToUTF16("2 days ago"), TimeFormat::Simple(
+ TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_2d_));
+
+ // Test English strings (detailed, singular and plural).
+ EXPECT_EQ(ASCIIToUTF16("1 minute 2 seconds"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1m2s_));
+ EXPECT_EQ(ASCIIToUTF16("2 minutes 1 second"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_2m1s_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour 2 minutes"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1h2m_));
+ EXPECT_EQ(ASCIIToUTF16("2 hours 1 minute"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_2h1m_));
+ EXPECT_EQ(ASCIIToUTF16("1 day 2 hours"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1d2h_));
+ EXPECT_EQ(ASCIIToUTF16("2 days 1 hour"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_2d1h_));
+ }
+
+ TimeDelta delta_0s_;
+ TimeDelta delta_1ms_;
+ TimeDelta delta_499ms_;
+ TimeDelta delta_500ms_;
+ TimeDelta delta_999ms_;
+ TimeDelta delta_1s_;
+ TimeDelta delta_1s499ms_;
+ TimeDelta delta_1s500ms_;
+ TimeDelta delta_2s_;
+ TimeDelta delta_29s_;
+ TimeDelta delta_30s_;
+ TimeDelta delta_59s_;
+ TimeDelta delta_59s499ms_;
+ TimeDelta delta_59s500ms_;
+ TimeDelta delta_1m_;
+ TimeDelta delta_1m2s_;
+ TimeDelta delta_1m29s999ms_;
+ TimeDelta delta_1m30s_;
+ TimeDelta delta_2m_;
+ TimeDelta delta_2m1s_;
+ TimeDelta delta_29m_;
+ TimeDelta delta_30m_;
+ TimeDelta delta_59m_;
+ TimeDelta delta_59m29s999ms_;
+ TimeDelta delta_59m30s_;
+ TimeDelta delta_59m59s499ms_;
+ TimeDelta delta_59m59s500ms_;
+ TimeDelta delta_1h_;
+ TimeDelta delta_1h2m_;
+ TimeDelta delta_1h29m59s999ms_;
+ TimeDelta delta_1h30m_;
+ TimeDelta delta_2h_;
+ TimeDelta delta_2h1m_;
+ TimeDelta delta_11h_;
+ TimeDelta delta_12h_;
+ TimeDelta delta_23h_;
+ TimeDelta delta_23h29m59s999ms_;
+ TimeDelta delta_23h30m_;
+ TimeDelta delta_23h59m29s999ms_;
+ TimeDelta delta_23h59m30s_;
+ TimeDelta delta_1d_;
+ TimeDelta delta_1d2h_;
+ TimeDelta delta_1d11h59m59s999ms_;
+ TimeDelta delta_1d12h_;
+ TimeDelta delta_2d_;
+ TimeDelta delta_2d1h_;
+
private:
static void LoadLocale(const base::FilePath& file_path) {
ui::ResourceBundle::GetSharedInstance().OverrideLocalePakForTest(file_path);
@@ -36,74 +237,111 @@ class TimeFormatTest : public ::testing::Test {
}
};
-void TestTimeFormats(const TimeDelta& delta, const char* expected_ascii) {
- base::string16 expected = ASCIIToUTF16(expected_ascii);
- base::string16 expected_left = expected + ASCIIToUTF16(" left");
- base::string16 expected_ago = expected + ASCIIToUTF16(" ago");
- EXPECT_EQ(expected, TimeFormat::TimeDurationShort(delta));
- EXPECT_EQ(expected_left, TimeFormat::TimeRemaining(delta));
- EXPECT_EQ(expected_ago, TimeFormat::TimeElapsed(delta));
-}
+TEST_F(TimeFormatTest, SimpleAndDetailedRounding) {
+ // Test rounding behavior (simple).
+ EXPECT_EQ(ASCIIToUTF16("0 secs"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_0s_));
+ EXPECT_EQ(ASCIIToUTF16("0 secs"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_499ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 sec"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_500ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 sec"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1s499ms_));
+ EXPECT_EQ(ASCIIToUTF16("2 secs"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1s500ms_));
+ EXPECT_EQ(ASCIIToUTF16("59 secs"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_59s499ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 min"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_59s500ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 min"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
+ delta_1m29s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("2 mins"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1m30s_));
+ EXPECT_EQ(ASCIIToUTF16("59 mins"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
+ delta_59m29s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_59m30s_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
+ delta_1h29m59s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("2 hours"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1h30m_));
+ EXPECT_EQ(ASCIIToUTF16("23 hours"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
+ delta_23h29m59s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_23h30m_));
+ EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
+ delta_1d11h59m59s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("2 days"), TimeFormat::Simple(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1d12h_));
-TEST_F(TimeFormatTest, FormatTime) {
- const TimeDelta one_day = TimeDelta::FromDays(1);
- const TimeDelta one_hour = TimeDelta::FromHours(1);
- const TimeDelta one_min = TimeDelta::FromMinutes(1);
- const TimeDelta one_second = TimeDelta::FromSeconds(1);
- const TimeDelta one_millisecond = TimeDelta::FromMilliseconds(1);
- const TimeDelta zero = TimeDelta::FromMilliseconds(0);
-
- TestTimeFormats(zero, "0 secs");
- TestTimeFormats(499 * one_millisecond, "0 secs");
- TestTimeFormats(500 * one_millisecond, "1 sec");
- TestTimeFormats(1 * one_second + 499 * one_millisecond, "1 sec");
- TestTimeFormats(1 * one_second + 500 * one_millisecond, "2 secs");
- TestTimeFormats(59 * one_second + 499 * one_millisecond, "59 secs");
- TestTimeFormats(59 * one_second + 500 * one_millisecond, "1 min");
- TestTimeFormats(1 * one_min + 30 * one_second - one_millisecond, "1 min");
- TestTimeFormats(1 * one_min + 30 * one_second, "2 mins");
- TestTimeFormats(59 * one_min + 30 * one_second - one_millisecond, "59 mins");
- TestTimeFormats(59 * one_min + 30 * one_second, "1 hour");
- TestTimeFormats(1 * one_hour + 30 * one_min - one_millisecond, "1 hour");
- TestTimeFormats(1 * one_hour + 30 * one_min, "2 hours");
- TestTimeFormats(23 * one_hour + 30 * one_min - one_millisecond, "23 hours");
- TestTimeFormats(23 * one_hour + 30 * one_min, "1 day");
- TestTimeFormats(1 * one_day + 12 * one_hour - one_millisecond, "1 day");
- TestTimeFormats(1 * one_day + 12 * one_hour, "2 days");
+ // Test rounding behavior (detailed).
+ EXPECT_EQ(ASCIIToUTF16("59 seconds"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 100,
+ delta_59s499ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 minute 0 seconds"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
+ delta_59s500ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 minute"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
+ delta_59s500ms_));
+ EXPECT_EQ(ASCIIToUTF16("59 minutes 59 seconds"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 60,
+ delta_59m59s499ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour 0 minutes"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 59,
+ delta_59m59s499ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour 0 minutes"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
+ delta_59m59s499ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
+ delta_59m59s499ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
+ delta_59m59s500ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 hour 0 minutes"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
+ delta_59m59s500ms_));
+ EXPECT_EQ(ASCIIToUTF16("23 hours 59 minutes"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 24,
+ delta_23h59m29s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 day 0 hours"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 23,
+ delta_23h59m29s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 day 0 hours"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
+ delta_23h59m29s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
+ delta_23h59m29s999ms_));
+ EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
+ delta_23h59m30s_));
+ EXPECT_EQ(ASCIIToUTF16("1 day 0 hours"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
+ delta_23h59m30s_));
+ EXPECT_EQ(ASCIIToUTF16("1 day 0 hours"), TimeFormat::Detailed(
+ TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, -1,
+ delta_23h59m30s_));
}
-void TestRemainingLong(const TimeDelta& delta, const std::string& expected) {
- EXPECT_EQ(TimeFormat::TimeRemainingLong(delta), ASCIIToUTF16(expected));
+// Test strings in default code path.
+TEST_F(TimeFormatTest, SimpleAndDetailedStrings) {
+ TestStrings();
}
-TEST_F(TimeFormatTest, TimeRemainingLong) {
- const TimeDelta one_day(TimeDelta::FromDays(1));
- const TimeDelta one_hour(TimeDelta::FromHours(1));
- const TimeDelta one_min(TimeDelta::FromMinutes(1));
- const TimeDelta one_second(TimeDelta::FromSeconds(1));
- const TimeDelta one_millisecond(TimeDelta::FromMilliseconds(1));
- const TimeDelta zero(TimeDelta::FromMilliseconds(0));
-
- TestRemainingLong(zero, "0 seconds left");
- TestRemainingLong(499 * one_millisecond, "0 seconds left");
- TestRemainingLong(500 * one_millisecond, "1 second left");
- TestRemainingLong(one_second + 499 * one_millisecond, "1 second left");
- TestRemainingLong(one_second + 500 * one_millisecond, "2 seconds left");
- TestRemainingLong(59 * one_second + 499 * one_millisecond, "59 seconds left");
- TestRemainingLong(59 * one_second + 500 * one_millisecond, "1 minute left");
- TestRemainingLong(one_min + 30 * one_second - one_millisecond,
- "1 minute left");
- TestRemainingLong(one_min + 30 * one_second, "2 minutes left");
- TestRemainingLong(59 * one_min + 30 * one_second - one_millisecond,
- "59 minutes left");
- TestRemainingLong(59 * one_min + 30 * one_second, "1 hour left");
- TestRemainingLong(one_hour + 30 * one_min - one_millisecond, "1 hour left");
- TestRemainingLong(one_hour + 30 * one_min, "2 hours left");
- TestRemainingLong(23 * one_hour + 30 * one_min - one_millisecond,
- "23 hours left");
- TestRemainingLong(23 * one_hour + 30 * one_min, "1 day left");
- TestRemainingLong(one_day + 12 * one_hour - one_millisecond, "1 day left");
- TestRemainingLong(one_day + 12 * one_hour, "2 days left");
+// Test strings in fallback path in case of translator error.
+TEST_F(TimeFormatTest, SimpleAndDetailedStringFallback) {
+ formatter_force_fallback = true;
+ g_container.Get().ResetForTesting();
+ TestStrings();
+ formatter_force_fallback = false;
+ g_container.Get().ResetForTesting();
}
// crbug.com/159388: This test fails when daylight savings time ends.
« no previous file with comments | « ui/base/l10n/time_format.cc ('k') | ui/base/strings/ui_strings.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698