1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/l10n/time_format.h"
#include "base/files/file_path.h"
#include "base/strings/string16.h"
#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"
using base::ASCIIToUTF16;
namespace ui {
namespace {
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:
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 and 2 seconds"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1m2s_));
EXPECT_EQ(ASCIIToUTF16("2 minutes and 1 second"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_2m1s_));
EXPECT_EQ(ASCIIToUTF16("1 hour and 2 minutes"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1h2m_));
EXPECT_EQ(ASCIIToUTF16("2 hours and 1 minute"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_2h1m_));
EXPECT_EQ(ASCIIToUTF16("1 day and 2 hours"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 3, delta_1d2h_));
EXPECT_EQ(ASCIIToUTF16("2 days and 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_;
};
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 rounding behavior (detailed).
EXPECT_EQ(ASCIIToUTF16("59 seconds"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 100,
delta_59s499ms_));
EXPECT_EQ(ASCIIToUTF16("1 minute and 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 and 59 seconds"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 60,
delta_59m59s499ms_));
EXPECT_EQ(ASCIIToUTF16("1 hour and 0 minutes"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 59,
delta_59m59s499ms_));
EXPECT_EQ(ASCIIToUTF16("1 hour and 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 and 0 minutes"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
delta_59m59s500ms_));
EXPECT_EQ(ASCIIToUTF16("23 hours and 59 minutes"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 24,
delta_23h59m29s999ms_));
EXPECT_EQ(ASCIIToUTF16("1 day and 0 hours"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 23,
delta_23h59m29s999ms_));
EXPECT_EQ(ASCIIToUTF16("1 day and 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 and 0 hours"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, 2,
delta_23h59m30s_));
EXPECT_EQ(ASCIIToUTF16("1 day and 0 hours"), TimeFormat::Detailed(
TimeFormat::FORMAT_DURATION, TimeFormat::LENGTH_LONG, -1,
delta_23h59m30s_));
}
// Test strings in default code path.
TEST_F(TimeFormatTest, SimpleAndDetailedStrings) {
TestStrings();
}
// 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.
TEST_F(TimeFormatTest, RelativeDate) {
base::Time now = base::Time::Now();
base::string16 today_str = TimeFormat::RelativeDate(now, NULL);
EXPECT_EQ(ASCIIToUTF16("Today"), today_str);
base::Time yesterday = now - TimeDelta::FromDays(1);
base::string16 yesterday_str = TimeFormat::RelativeDate(yesterday, NULL);
EXPECT_EQ(ASCIIToUTF16("Yesterday"), yesterday_str);
base::Time two_days_ago = now - TimeDelta::FromDays(2);
base::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);
base::string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL);
EXPECT_TRUE(a_week_ago_str.empty());
}
} // namespace
} // namespace ui
|