Chromium Code Reviews| Index: chrome/common/time_format_unittest.cc |
| diff --git a/chrome/common/time_format_unittest.cc b/chrome/common/time_format_unittest.cc |
| index 31976e3bd40838f24bf9f31e7429f12b64f3b351..87cf6fcb5b9c66fe4ad5e20bf42eeb51a2061c4f 100644 |
| --- a/chrome/common/time_format_unittest.cc |
| +++ b/chrome/common/time_format_unittest.cc |
| @@ -2,38 +2,18 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include <time.h> |
| +#include "chrome/common/time_format.h" |
|
Paweł Hajdan Jr.
2011/10/18 09:59:35
nit: I don't think we put that header first in uni
tfarina
2011/10/18 16:00:53
Some says we should format like this (sky). Althou
|
| -#include "base/basictypes.h" |
| #include "base/string16.h" |
| #include "base/time.h" |
| #include "base/utf_string_conversions.h" |
| -#include "chrome/common/time_format.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -using base::Time; |
| -using base::TimeDelta; |
| - |
| -TEST(TimeFormat, RelativeDate) { |
| - Time now = Time::Now(); |
| - string16 today_str = TimeFormat::RelativeDate(now, NULL); |
| - EXPECT_EQ(ASCIIToUTF16("Today"), today_str); |
| - |
| - Time yesterday = now - TimeDelta::FromDays(1); |
| - string16 yesterday_str = TimeFormat::RelativeDate(yesterday, NULL); |
| - EXPECT_EQ(ASCIIToUTF16("Yesterday"), yesterday_str); |
| - |
| - Time two_days_ago = now - TimeDelta::FromDays(2); |
| - string16 two_days_ago_str = TimeFormat::RelativeDate(two_days_ago, NULL); |
| - EXPECT_TRUE(two_days_ago_str.empty()); |
| +namespace { |
| - Time a_week_ago = now - TimeDelta::FromDays(7); |
| - string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); |
| - EXPECT_TRUE(a_week_ago_str.empty()); |
| -} |
| +using base::TimeDelta; |
| -namespace { |
| -void TestTimeFormats(const TimeDelta delta, const char* expected_ascii) { |
| +void TestTimeFormats(const TimeDelta& delta, const char* expected_ascii) { |
| string16 expected = ASCIIToUTF16(expected_ascii); |
| string16 expected_left = expected + ASCIIToUTF16(" left"); |
| string16 expected_ago = expected + ASCIIToUTF16(" ago"); |
| @@ -42,8 +22,6 @@ void TestTimeFormats(const TimeDelta delta, const char* expected_ascii) { |
| EXPECT_EQ(expected_ago, TimeFormat::TimeElapsed(delta)); |
| } |
| -} // namespace |
| - |
| TEST(TimeFormat, FormatTime) { |
| const TimeDelta one_day = TimeDelta::FromDays(1); |
| const TimeDelta three_days = TimeDelta::FromDays(3); |
| @@ -69,3 +47,23 @@ TEST(TimeFormat, FormatTime) { |
| TestTimeFormats(three_days, "3 days"); |
| TestTimeFormats(three_days + four_hours, "3 days"); |
| } |
| + |
| +TEST(TimeFormat, RelativeDate) { |
|
Paweł Hajdan Jr.
2011/10/18 09:59:35
nit: Why are you moving this?
tfarina
2011/10/18 16:00:53
I think my idea was because of the order of the me
|
| + base::Time now = base::Time::Now(); |
| + string16 today_str = TimeFormat::RelativeDate(now, NULL); |
| + EXPECT_EQ(ASCIIToUTF16("Today"), today_str); |
| + |
| + base::Time yesterday = now - TimeDelta::FromDays(1); |
| + string16 yesterday_str = TimeFormat::RelativeDate(yesterday, NULL); |
| + EXPECT_EQ(ASCIIToUTF16("Yesterday"), yesterday_str); |
| + |
| + base::Time two_days_ago = now - TimeDelta::FromDays(2); |
| + string16 two_days_ago_str = TimeFormat::RelativeDate(two_days_ago, NULL); |
| + EXPECT_TRUE(two_days_ago_str.empty()); |
| + |
| + base::Time a_week_ago = now - TimeDelta::FromDays(7); |
| + string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); |
| + EXPECT_TRUE(a_week_ago_str.empty()); |
| +} |
| + |
| +} // namespace |