Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / l10n / time_format_unittest.cc
blob5e2face2485902822732ea4c6a5c915ea9db9d59
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/l10n/time_format.h"
7 #include "base/files/file_path.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/base/l10n/formatter.h"
14 using base::ASCIIToUTF16;
16 namespace ui {
17 namespace {
19 using base::TimeDelta;
21 class TimeFormatTest : public ::testing::Test {
22 public:
23 TimeFormatTest() :
24 delta_0s_(TimeDelta::FromSeconds(0)),
25 delta_1ms_(TimeDelta::FromMilliseconds(1)),
26 delta_499ms_(TimeDelta::FromMilliseconds(499)),
27 delta_500ms_(TimeDelta::FromMilliseconds(500)),
28 delta_999ms_(TimeDelta::FromMilliseconds(999)),
29 delta_1s_(TimeDelta::FromSeconds(1)),
30 delta_1s499ms_(delta_1s_ + delta_499ms_),
31 delta_1s500ms_(delta_1s_ + delta_500ms_),
32 delta_2s_(TimeDelta::FromSeconds(2)),
33 delta_29s_(TimeDelta::FromSeconds(29)),
34 delta_30s_(TimeDelta::FromSeconds(30)),
35 delta_59s_(TimeDelta::FromSeconds(59)),
36 delta_59s499ms_(delta_59s_ + delta_499ms_),
37 delta_59s500ms_(delta_59s_ + delta_500ms_),
38 delta_1m_(TimeDelta::FromMinutes(1)),
39 delta_1m2s_(delta_1m_ + delta_2s_),
40 delta_1m29s999ms_(delta_1m_ + delta_29s_ + delta_999ms_),
41 delta_1m30s_(delta_1m_ + delta_30s_),
42 delta_2m_(TimeDelta::FromMinutes(2)),
43 delta_2m1s_(delta_2m_ + delta_1s_),
44 delta_29m_(TimeDelta::FromMinutes(29)),
45 delta_30m_(TimeDelta::FromMinutes(30)),
46 delta_59m_(TimeDelta::FromMinutes(59)),
47 delta_59m29s999ms_(delta_59m_ + delta_29s_ + delta_999ms_),
48 delta_59m30s_(delta_59m_ + delta_30s_),
49 delta_59m59s499ms_(delta_59m_ + delta_59s_ + delta_499ms_),
50 delta_59m59s500ms_(delta_59m_ + delta_59s_ + delta_500ms_),
51 delta_1h_(TimeDelta::FromHours(1)),
52 delta_1h2m_(delta_1h_ + delta_2m_),
53 delta_1h29m59s999ms_(delta_1h_ + delta_29m_ + delta_59s_ + delta_999ms_),
54 delta_1h30m_(delta_1h_ + delta_30m_),
55 delta_2h_(TimeDelta::FromHours(2)),
56 delta_2h1m_(delta_2h_ + delta_1m_),
57 delta_11h_(TimeDelta::FromHours(11)),
58 delta_12h_(TimeDelta::FromHours(12)),
59 delta_23h_(TimeDelta::FromHours(23)),
60 delta_23h29m59s999ms_(delta_23h_ + delta_29m_ + delta_59s_ +
61 delta_999ms_),
62 delta_23h30m_(delta_23h_ + delta_30m_),
63 delta_23h59m29s999ms_(delta_23h_ + delta_59m_ + delta_29s_ +
64 delta_999ms_),
65 delta_23h59m30s_(delta_23h_ + delta_59m_ + delta_30s_),
66 delta_1d_(TimeDelta::FromDays(1)),
67 delta_1d2h_(delta_1d_ + delta_2h_),
68 delta_1d11h59m59s999ms_(delta_1d_ + delta_11h_ + delta_59m_ + delta_29s_ +
69 delta_999ms_),
70 delta_1d12h_(delta_1d_ + delta_12h_),
71 delta_2d_(TimeDelta::FromDays(2)),
72 delta_2d1h_(delta_2d_ + delta_1h_)
75 protected:
76 void TestStrings() {
77 // Test English strings (simple, singular).
78 EXPECT_EQ(ASCIIToUTF16("1 sec"), TimeFormat::Simple(
79 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1s_));
80 EXPECT_EQ(ASCIIToUTF16("1 min"), TimeFormat::Simple(
81 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1m_));
82 EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Simple(
83 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1h_));
84 EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Simple(
85 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1d_));
86 EXPECT_EQ(ASCIIToUTF16("1 second"), TimeFormat::Simple(
87 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_1s_));
88 EXPECT_EQ(ASCIIToUTF16("1 minute"), TimeFormat::Simple(
89 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_1m_));
90 EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Simple(
91 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_1h_));
92 EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Simple(
93 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_1d_));
94 EXPECT_EQ(ASCIIToUTF16("1 sec left"), TimeFormat::Simple(
95 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_1s_));
96 EXPECT_EQ(ASCIIToUTF16("1 min left"), TimeFormat::Simple(
97 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_1m_));
98 EXPECT_EQ(ASCIIToUTF16("1 hour left"), TimeFormat::Simple(
99 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_1h_));
100 EXPECT_EQ(ASCIIToUTF16("1 day left"), TimeFormat::Simple(
101 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_1d_));
102 EXPECT_EQ(ASCIIToUTF16("1 second left"), TimeFormat::Simple(
103 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_1s_));
104 EXPECT_EQ(ASCIIToUTF16("1 minute left"), TimeFormat::Simple(
105 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_1m_));
106 EXPECT_EQ(ASCIIToUTF16("1 hour left"), TimeFormat::Simple(
107 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_1h_));
108 EXPECT_EQ(ASCIIToUTF16("1 day left"), TimeFormat::Simple(
109 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_1d_));
110 EXPECT_EQ(ASCIIToUTF16("1 sec ago"), TimeFormat::Simple(
111 TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_1s_));
112 EXPECT_EQ(ASCIIToUTF16("1 min ago"), TimeFormat::Simple(
113 TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_1m_));
114 EXPECT_EQ(ASCIIToUTF16("1 hour ago"), TimeFormat::Simple(
115 TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_1h_));
116 EXPECT_EQ(ASCIIToUTF16("1 day ago"), TimeFormat::Simple(
117 TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_1d_));
119 // Test English strings (simple, plural).
120 EXPECT_EQ(ASCIIToUTF16("2 secs"), TimeFormat::Simple(
121 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_2s_));
122 EXPECT_EQ(ASCIIToUTF16("2 mins"), TimeFormat::Simple(
123 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_2m_));
124 EXPECT_EQ(ASCIIToUTF16("2 hours"), TimeFormat::Simple(
125 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_2h_));
126 EXPECT_EQ(ASCIIToUTF16("2 days"), TimeFormat::Simple(
127 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_2d_));
128 EXPECT_EQ(ASCIIToUTF16("2 seconds"), TimeFormat::Simple(
129 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_2s_));
130 EXPECT_EQ(ASCIIToUTF16("2 minutes"), TimeFormat::Simple(
131 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_2m_));
132 EXPECT_EQ(ASCIIToUTF16("2 hours"), TimeFormat::Simple(
133 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_2h_));
134 EXPECT_EQ(ASCIIToUTF16("2 days"), TimeFormat::Simple(
135 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, delta_2d_));
136 EXPECT_EQ(ASCIIToUTF16("2 secs left"), TimeFormat::Simple(
137 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_2s_));
138 EXPECT_EQ(ASCIIToUTF16("2 mins left"), TimeFormat::Simple(
139 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_2m_));
140 EXPECT_EQ(ASCIIToUTF16("2 hours left"), TimeFormat::Simple(
141 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_2h_));
142 EXPECT_EQ(ASCIIToUTF16("2 days left"), TimeFormat::Simple(
143 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_SHORT, delta_2d_));
144 EXPECT_EQ(ASCIIToUTF16("2 seconds left"), TimeFormat::Simple(
145 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_2s_));
146 EXPECT_EQ(ASCIIToUTF16("2 minutes left"), TimeFormat::Simple(
147 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_2m_));
148 EXPECT_EQ(ASCIIToUTF16("2 hours left"), TimeFormat::Simple(
149 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_2h_));
150 EXPECT_EQ(ASCIIToUTF16("2 days left"), TimeFormat::Simple(
151 TimeFormat::FORMAT_REMAINING, TimeFormat::LENGTH_LONG, delta_2d_));
152 EXPECT_EQ(ASCIIToUTF16("2 secs ago"), TimeFormat::Simple(
153 TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_2s_));
154 EXPECT_EQ(ASCIIToUTF16("2 mins ago"), TimeFormat::Simple(
155 TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_2m_));
156 EXPECT_EQ(ASCIIToUTF16("2 hours ago"), TimeFormat::Simple(
157 TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_2h_));
158 EXPECT_EQ(ASCIIToUTF16("2 days ago"), TimeFormat::Simple(
159 TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_SHORT, delta_2d_));
161 // Test English strings (detailed, singular and plural).
162 EXPECT_EQ(ASCIIToUTF16("1 minute and 2 seconds"), TimeFormat::Detailed(
163 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1m2s_));
164 EXPECT_EQ(ASCIIToUTF16("2 minutes and 1 second"), TimeFormat::Detailed(
165 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_2m1s_));
166 EXPECT_EQ(ASCIIToUTF16("1 hour and 2 minutes"), TimeFormat::Detailed(
167 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1h2m_));
168 EXPECT_EQ(ASCIIToUTF16("2 hours and 1 minute"), TimeFormat::Detailed(
169 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_2h1m_));
170 EXPECT_EQ(ASCIIToUTF16("1 day and 2 hours"), TimeFormat::Detailed(
171 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1d2h_));
172 EXPECT_EQ(ASCIIToUTF16("2 days and 1 hour"), TimeFormat::Detailed(
173 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_2d1h_));
176 TimeDelta delta_0s_;
177 TimeDelta delta_1ms_;
178 TimeDelta delta_499ms_;
179 TimeDelta delta_500ms_;
180 TimeDelta delta_999ms_;
181 TimeDelta delta_1s_;
182 TimeDelta delta_1s499ms_;
183 TimeDelta delta_1s500ms_;
184 TimeDelta delta_2s_;
185 TimeDelta delta_29s_;
186 TimeDelta delta_30s_;
187 TimeDelta delta_59s_;
188 TimeDelta delta_59s499ms_;
189 TimeDelta delta_59s500ms_;
190 TimeDelta delta_1m_;
191 TimeDelta delta_1m2s_;
192 TimeDelta delta_1m29s999ms_;
193 TimeDelta delta_1m30s_;
194 TimeDelta delta_2m_;
195 TimeDelta delta_2m1s_;
196 TimeDelta delta_29m_;
197 TimeDelta delta_30m_;
198 TimeDelta delta_59m_;
199 TimeDelta delta_59m29s999ms_;
200 TimeDelta delta_59m30s_;
201 TimeDelta delta_59m59s499ms_;
202 TimeDelta delta_59m59s500ms_;
203 TimeDelta delta_1h_;
204 TimeDelta delta_1h2m_;
205 TimeDelta delta_1h29m59s999ms_;
206 TimeDelta delta_1h30m_;
207 TimeDelta delta_2h_;
208 TimeDelta delta_2h1m_;
209 TimeDelta delta_11h_;
210 TimeDelta delta_12h_;
211 TimeDelta delta_23h_;
212 TimeDelta delta_23h29m59s999ms_;
213 TimeDelta delta_23h30m_;
214 TimeDelta delta_23h59m29s999ms_;
215 TimeDelta delta_23h59m30s_;
216 TimeDelta delta_1d_;
217 TimeDelta delta_1d2h_;
218 TimeDelta delta_1d11h59m59s999ms_;
219 TimeDelta delta_1d12h_;
220 TimeDelta delta_2d_;
221 TimeDelta delta_2d1h_;
224 TEST_F(TimeFormatTest, SimpleAndDetailedRounding) {
225 // Test rounding behavior (simple).
226 EXPECT_EQ(ASCIIToUTF16("0 secs"), TimeFormat::Simple(
227 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_0s_));
228 EXPECT_EQ(ASCIIToUTF16("0 secs"), TimeFormat::Simple(
229 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_499ms_));
230 EXPECT_EQ(ASCIIToUTF16("1 sec"), TimeFormat::Simple(
231 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_500ms_));
232 EXPECT_EQ(ASCIIToUTF16("1 sec"), TimeFormat::Simple(
233 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1s499ms_));
234 EXPECT_EQ(ASCIIToUTF16("2 secs"), TimeFormat::Simple(
235 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1s500ms_));
236 EXPECT_EQ(ASCIIToUTF16("59 secs"), TimeFormat::Simple(
237 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_59s499ms_));
238 EXPECT_EQ(ASCIIToUTF16("1 min"), TimeFormat::Simple(
239 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_59s500ms_));
240 EXPECT_EQ(ASCIIToUTF16("1 min"), TimeFormat::Simple(
241 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
242 delta_1m29s999ms_));
243 EXPECT_EQ(ASCIIToUTF16("2 mins"), TimeFormat::Simple(
244 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1m30s_));
245 EXPECT_EQ(ASCIIToUTF16("59 mins"), TimeFormat::Simple(
246 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
247 delta_59m29s999ms_));
248 EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Simple(
249 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_59m30s_));
250 EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Simple(
251 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
252 delta_1h29m59s999ms_));
253 EXPECT_EQ(ASCIIToUTF16("2 hours"), TimeFormat::Simple(
254 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1h30m_));
255 EXPECT_EQ(ASCIIToUTF16("23 hours"), TimeFormat::Simple(
256 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
257 delta_23h29m59s999ms_));
258 EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Simple(
259 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_23h30m_));
260 EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Simple(
261 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT,
262 delta_1d11h59m59s999ms_));
263 EXPECT_EQ(ASCIIToUTF16("2 days"), TimeFormat::Simple(
264 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_SHORT, delta_1d12h_));
266 // Test rounding behavior (detailed).
267 EXPECT_EQ(ASCIIToUTF16("59 seconds"), TimeFormat::Detailed(
268 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 100,
269 delta_59s499ms_));
270 EXPECT_EQ(ASCIIToUTF16("1 minute and 0 seconds"), TimeFormat::Detailed(
271 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
272 delta_59s500ms_));
273 EXPECT_EQ(ASCIIToUTF16("1 minute"), TimeFormat::Detailed(
274 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
275 delta_59s500ms_));
276 EXPECT_EQ(ASCIIToUTF16("59 minutes and 59 seconds"), TimeFormat::Detailed(
277 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 60,
278 delta_59m59s499ms_));
279 EXPECT_EQ(ASCIIToUTF16("1 hour and 0 minutes"), TimeFormat::Detailed(
280 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 59,
281 delta_59m59s499ms_));
282 EXPECT_EQ(ASCIIToUTF16("1 hour and 0 minutes"), TimeFormat::Detailed(
283 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
284 delta_59m59s499ms_));
285 EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Detailed(
286 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
287 delta_59m59s499ms_));
288 EXPECT_EQ(ASCIIToUTF16("1 hour"), TimeFormat::Detailed(
289 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
290 delta_59m59s500ms_));
291 EXPECT_EQ(ASCIIToUTF16("1 hour and 0 minutes"), TimeFormat::Detailed(
292 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
293 delta_59m59s500ms_));
294 EXPECT_EQ(ASCIIToUTF16("23 hours and 59 minutes"), TimeFormat::Detailed(
295 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 24,
296 delta_23h59m29s999ms_));
297 EXPECT_EQ(ASCIIToUTF16("1 day and 0 hours"), TimeFormat::Detailed(
298 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 23,
299 delta_23h59m29s999ms_));
300 EXPECT_EQ(ASCIIToUTF16("1 day and 0 hours"), TimeFormat::Detailed(
301 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
302 delta_23h59m29s999ms_));
303 EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Detailed(
304 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
305 delta_23h59m29s999ms_));
306 EXPECT_EQ(ASCIIToUTF16("1 day"), TimeFormat::Detailed(
307 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 1,
308 delta_23h59m30s_));
309 EXPECT_EQ(ASCIIToUTF16("1 day and 0 hours"), TimeFormat::Detailed(
310 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
311 delta_23h59m30s_));
312 EXPECT_EQ(ASCIIToUTF16("1 day and 0 hours"), TimeFormat::Detailed(
313 TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, -1,
314 delta_23h59m30s_));
317 // Test strings in default code path.
318 TEST_F(TimeFormatTest, SimpleAndDetailedStrings) {
319 TestStrings();
322 // Test strings in fallback path in case of translator error.
323 TEST_F(TimeFormatTest, SimpleAndDetailedStringFallback) {
324 formatter_force_fallback = true;
325 g_container.Get().ResetForTesting();
326 TestStrings();
327 formatter_force_fallback = false;
328 g_container.Get().ResetForTesting();
331 // crbug.com/159388: This test fails when daylight savings time ends.
332 TEST_F(TimeFormatTest, RelativeDate) {
333 base::Time now = base::Time::Now();
334 base::string16 today_str = TimeFormat::RelativeDate(now, NULL);
335 EXPECT_EQ(ASCIIToUTF16("Today"), today_str);
337 base::Time yesterday = now - TimeDelta::FromDays(1);
338 base::string16 yesterday_str = TimeFormat::RelativeDate(yesterday, NULL);
339 EXPECT_EQ(ASCIIToUTF16("Yesterday"), yesterday_str);
341 base::Time two_days_ago = now - TimeDelta::FromDays(2);
342 base::string16 two_days_ago_str =
343 TimeFormat::RelativeDate(two_days_ago, NULL);
344 EXPECT_TRUE(two_days_ago_str.empty());
346 base::Time a_week_ago = now - TimeDelta::FromDays(7);
347 base::string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL);
348 EXPECT_TRUE(a_week_ago_str.empty());
351 } // namespace
352 } // namespace ui