| 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 60ad3b4109ecc0cdafd9ceeaf0792ffeca693554..f12015556a3f26b2ee6615792b46c065a61132d6 100644
|
| --- a/ui/base/l10n/time_format_unittest.cc
|
| +++ b/ui/base/l10n/time_format_unittest.cc
|
| @@ -18,16 +18,20 @@ namespace {
|
|
|
| using base::TimeDelta;
|
|
|
| -class TimeFormatTest : public ::testing::Test {
|
| - public:
|
| - static void SetUpTestCase() {
|
| +class TimeFormatTests : public ::testing::Test {
|
| + protected:
|
| + TimeFormatTests()
|
| + : one_day(TimeDelta::FromDays(1)),
|
| + one_hour(TimeDelta::FromHours(1)),
|
| + one_min(TimeDelta::FromMinutes(1)),
|
| + one_second(TimeDelta::FromSeconds(1)),
|
| + one_millisecond(TimeDelta::FromMilliseconds(1)),
|
| + zero(TimeDelta::FromMilliseconds(0)) {
|
| LoadLocale(ui::ResourceBundle::GetSharedInstance()
|
| .GetLocaleFilePath("en-US", true));
|
| }
|
| -
|
| - static void TearDownTestCase() {
|
| - LoadLocale(base::FilePath());
|
| - }
|
| + ~TimeFormatTests() { LoadLocale(base::FilePath()); }
|
| + TimeDelta one_day, one_hour, one_min, one_second, one_millisecond, zero;
|
|
|
| private:
|
| static void LoadLocale(const base::FilePath& file_path) {
|
| @@ -36,44 +40,135 @@ 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));
|
| +void TestElapsed(const TimeDelta& delta, const std::string& expected) {
|
| + EXPECT_EQ(TimeFormat::TimeElapsed(delta), ASCIIToUTF16(expected));
|
| +}
|
| +
|
| +TEST_F(TimeFormatTests, TimeElapsed) {
|
| + TestElapsed(zero, "0 secs ago");
|
| + TestElapsed(499 * one_millisecond, "0 secs ago");
|
| + TestElapsed(500 * one_millisecond, "1 sec ago");
|
| + TestElapsed(one_second + 499 * one_millisecond, "1 sec ago");
|
| + TestElapsed(one_second + 500 * one_millisecond, "2 secs ago");
|
| + TestElapsed(59 * one_second + 499 * one_millisecond, "59 secs ago");
|
| + TestElapsed(59 * one_second + 500 * one_millisecond, "1 min ago");
|
| + TestElapsed(one_min + 30 * one_second - one_millisecond, "1 min ago");
|
| + TestElapsed(one_min + 30 * one_second, "2 mins ago");
|
| + TestElapsed(59 * one_min + 30 * one_second - one_millisecond, "59 mins ago");
|
| + TestElapsed(59 * one_min + 30 * one_second, "1 hour ago");
|
| + TestElapsed(one_hour + 30 * one_min - one_millisecond, "1 hour ago");
|
| + TestElapsed(one_hour + 30 * one_min, "2 hours ago");
|
| + TestElapsed(23 * one_hour + 30 * one_min - one_millisecond, "23 hours ago");
|
| + TestElapsed(23 * one_hour + 30 * one_min, "1 day ago");
|
| + TestElapsed(one_day + 12 * one_hour - one_millisecond, "1 day ago");
|
| + TestElapsed(one_day + 12 * one_hour, "2 days ago");
|
| +}
|
| +
|
| +void TestRemaining(const TimeDelta& delta, const std::string& expected) {
|
| + EXPECT_EQ(TimeFormat::TimeRemaining(delta), ASCIIToUTF16(expected));
|
| +}
|
| +
|
| +TEST_F(TimeFormatTests, TimeRemaining) {
|
| + TestRemaining(zero, "0 secs left");
|
| + TestRemaining(499 * one_millisecond, "0 secs left");
|
| + TestRemaining(500 * one_millisecond, "1 sec left");
|
| + TestRemaining(one_second + 499 * one_millisecond, "1 sec left");
|
| + TestRemaining(one_second + 500 * one_millisecond, "2 secs left");
|
| + TestRemaining(59 * one_second + 499 * one_millisecond, "59 secs left");
|
| + TestRemaining(59 * one_second + 500 * one_millisecond, "1 min left");
|
| + TestRemaining(one_min + 30 * one_second - one_millisecond, "1 min left");
|
| + TestRemaining(one_min + 30 * one_second, "2 mins left");
|
| + TestRemaining(59 * one_min + 30 * one_second - one_millisecond,
|
| + "59 mins left");
|
| + TestRemaining(59 * one_min + 30 * one_second, "1 hour left");
|
| + TestRemaining(one_hour + 30 * one_min - one_millisecond, "1 hour left");
|
| + TestRemaining(one_hour + 30 * one_min, "2 hours left");
|
| + TestRemaining(23 * one_hour + 30 * one_min - one_millisecond,
|
| + "23 hours left");
|
| + TestRemaining(23 * one_hour + 30 * one_min, "1 day left");
|
| + TestRemaining(one_day + 12 * one_hour - one_millisecond, "1 day left");
|
| + TestRemaining(one_day + 12 * one_hour, "2 days left");
|
| +}
|
| +
|
| +void TestRemainingLong(const TimeDelta& delta, const std::string& expected) {
|
| + EXPECT_EQ(TimeFormat::TimeRemainingLong(delta), ASCIIToUTF16(expected));
|
| +}
|
| +
|
| +TEST_F(TimeFormatTests, TimeRemainingLong) {
|
| + TestRemainingLong(zero, "0 secs left");
|
| + TestRemainingLong(499 * one_millisecond, "0 secs left");
|
| + TestRemainingLong(500 * one_millisecond, "1 sec left");
|
| + TestRemainingLong(one_second + 499 * one_millisecond, "1 sec left");
|
| + TestRemainingLong(one_second + 500 * one_millisecond, "2 secs left");
|
| + TestRemainingLong(59 * one_second + 499 * one_millisecond, "59 secs 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");
|
| +}
|
| +
|
| +void TestDurationShort(const TimeDelta& delta, const std::string& expected) {
|
| + EXPECT_EQ(TimeFormat::TimeDurationShort(delta), ASCIIToUTF16(expected));
|
| +}
|
| +
|
| +TEST_F(TimeFormatTests, TimeDurationShort) {
|
| + TestDurationShort(zero, "0 secs");
|
| + TestDurationShort(499 * one_millisecond, "0 secs");
|
| + TestDurationShort(500 * one_millisecond, "1 sec");
|
| + TestDurationShort(one_second + 499 * one_millisecond, "1 sec");
|
| + TestDurationShort(one_second + 500 * one_millisecond, "2 secs");
|
| + TestDurationShort(59 * one_second + 499 * one_millisecond, "59 secs");
|
| + TestDurationShort(59 * one_second + 500 * one_millisecond, "1 min");
|
| + TestDurationShort(one_min + 30 * one_second - one_millisecond, "1 min");
|
| + TestDurationShort(one_min + 30 * one_second, "2 mins");
|
| + TestDurationShort(59 * one_min + 30 * one_second - one_millisecond,
|
| + "59 mins");
|
| + TestDurationShort(59 * one_min + 30 * one_second, "1 hour");
|
| + TestDurationShort(one_hour + 30 * one_min - one_millisecond, "1 hour");
|
| + TestDurationShort(one_hour + 30 * one_min, "2 hours");
|
| + TestDurationShort(23 * one_hour + 30 * one_min - one_millisecond, "23 hours");
|
| + TestDurationShort(23 * one_hour + 30 * one_min, "1 day");
|
| + TestDurationShort(one_day + 12 * one_hour - one_millisecond, "1 day");
|
| + TestDurationShort(one_day + 12 * one_hour, "2 days");
|
| +}
|
| +
|
| +void TestDurationLong(const TimeDelta& delta, const std::string& expected) {
|
| + EXPECT_EQ(TimeFormat::TimeDurationLong(delta), ASCIIToUTF16(expected));
|
| }
|
|
|
| -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_F(TimeFormatTests, TimeDurationLong) {
|
| + TestDurationLong(zero, "0 seconds");
|
| + TestDurationLong(499 * one_millisecond, "0 seconds");
|
| + TestDurationLong(500 * one_millisecond, "1 second");
|
| + TestDurationLong(one_second + 499 * one_millisecond, "1 second");
|
| + TestDurationLong(one_second + 500 * one_millisecond, "2 seconds");
|
| + TestDurationLong(59 * one_second + 499 * one_millisecond, "59 seconds");
|
| + TestDurationLong(59 * one_second + 500 * one_millisecond, "1 minute");
|
| + TestDurationLong(one_min + 30 * one_second - one_millisecond, "1 minute");
|
| + TestDurationLong(one_min + 30 * one_second, "2 minutes");
|
| + TestDurationLong(59 * one_min + 30 * one_second - one_millisecond,
|
| + "59 minutes");
|
| + TestDurationLong(59 * one_min + 30 * one_second, "1 hour");
|
| + TestDurationLong(one_hour + 30 * one_min - one_millisecond, "1 hour");
|
| + TestDurationLong(one_hour + 30 * one_min, "2 hours");
|
| + TestDurationLong(23 * one_hour + 30 * one_min - one_millisecond, "23 hours");
|
| + TestDurationLong(23 * one_hour + 30 * one_min, "1 day");
|
| + TestDurationLong(one_day + 12 * one_hour - one_millisecond, "1 day");
|
| + TestDurationLong(one_day + 12 * one_hour, "2 days");
|
| }
|
|
|
| // crbug.com/159388: This test fails when daylight savings time ends.
|
| -TEST_F(TimeFormatTest, RelativeDate) {
|
| +TEST_F(TimeFormatTests, RelativeDate) {
|
| base::Time now = base::Time::Now();
|
| base::string16 today_str = TimeFormat::RelativeDate(now, NULL);
|
| EXPECT_EQ(ASCIIToUTF16("Today"), today_str);
|
|
|