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

Side by Side Diff: base/i18n/time_formatting_unittest.cc

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Enable unittest on android for time_formatting Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/i18n/time_formatting.h" 5 #include "base/i18n/time_formatting.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 TimeFormatShortDateAndTime(time)); 217 TimeFormatShortDateAndTime(time));
218 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), 218 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time),
219 TimeFormatShortDateAndTimeWithTimeZone(time)); 219 TimeFormatShortDateAndTimeWithTimeZone(time));
220 EXPECT_EQ(ASCIIToUTF16("April 2011"), TimeFormatMonthAndYear(time)); 220 EXPECT_EQ(ASCIIToUTF16("April 2011"), TimeFormatMonthAndYear(time));
221 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), 221 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"),
222 TimeFormatFriendlyDateAndTime(time)); 222 TimeFormatFriendlyDateAndTime(time));
223 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), 223 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"),
224 TimeFormatFriendlyDate(time)); 224 TimeFormatFriendlyDate(time));
225 } 225 }
226 226
227 TEST(TimeFormattingTest, TimeFormatWithPatternUS) {
228 test::ScopedRestoreICUDefaultLocale restore_locale;
jungshik at Google 2017/01/27 21:51:35 Thank you for finding this :-). With this(ScopedR
jiahuiguo 2017/02/03 07:11:17 Cool, grouped them into one test.
229
230 Time time;
231 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time));
232
233 i18n::SetICUDefaultLocale("en_US");
234 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatWithPattern(time, "yMMMd"));
235 EXPECT_EQ(ASCIIToUTF16("April 30, 3:42:07 PM"),
236 TimeFormatWithPattern(time, "MMMMdjmmss"));
237 }
238
239 TEST(TimeFormattingTest, TimeFormatWithPatternGB) {
240 test::ScopedRestoreICUDefaultLocale restore_locale;
241
242 Time time;
243 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time));
244
245 i18n::SetICUDefaultLocale("en_GB");
246 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatWithPattern(time, "yMMMd"));
247 EXPECT_EQ(ASCIIToUTF16("30 April, 15:42:07"),
248 TimeFormatWithPattern(time, "MMMMdjmmss"));
249 }
250
251 TEST(TimeFormattingTest, TimeFormatWithPatternJP) {
252 test::ScopedRestoreICUDefaultLocale restore_locale;
253
254 Time time;
255 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time));
256
257 i18n::SetICUDefaultLocale("ja_JP");
258 EXPECT_EQ(WideToUTF16(L"2011年4月30日"),
259 TimeFormatWithPattern(time, "yMMMd"));
jungshik at Google 2017/01/27 21:43:30 An alternative would be EXPET_EQ(u8"2011年4月30日",
jiahuiguo 2017/02/03 07:11:17 Done.
260 EXPECT_EQ(WideToUTF16(L"4月30日") + ASCIIToUTF16(" 15:42:07"),
261 TimeFormatWithPattern(time, "MMMMdjmmss"));
262 }
263
227 TEST(TimeFormattingTest, TimeDurationFormat) { 264 TEST(TimeFormattingTest, TimeDurationFormat) {
228 test::ScopedRestoreICUDefaultLocale restore_locale; 265 test::ScopedRestoreICUDefaultLocale restore_locale;
229 TimeDelta delta = TimeDelta::FromMinutes(15 * 60 + 42); 266 TimeDelta delta = TimeDelta::FromMinutes(15 * 60 + 42);
230 267
231 // US English. 268 // US English.
232 i18n::SetICUDefaultLocale("en_US"); 269 i18n::SetICUDefaultLocale("en_US");
233 EXPECT_EQ(ASCIIToUTF16("15 hours, 42 minutes"), 270 EXPECT_EQ(ASCIIToUTF16("15 hours, 42 minutes"),
234 TimeDurationFormat(delta, DURATION_WIDTH_WIDE)); 271 TimeDurationFormat(delta, DURATION_WIDTH_WIDE));
235 EXPECT_EQ(ASCIIToUTF16("15 hr, 42 min"), 272 EXPECT_EQ(ASCIIToUTF16("15 hr, 42 min"),
236 TimeDurationFormat(delta, DURATION_WIDTH_SHORT)); 273 TimeDurationFormat(delta, DURATION_WIDTH_SHORT));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 Time end_time; 368 Time end_time;
332 EXPECT_TRUE(Time::FromLocalExploded(kTestIntervalEndTimeExploded, &end_time)); 369 EXPECT_TRUE(Time::FromLocalExploded(kTestIntervalEndTimeExploded, &end_time));
333 370
334 EXPECT_EQ( 371 EXPECT_EQ(
335 WideToUTF16(L"Saturday, April 30 – Saturday, May 28"), 372 WideToUTF16(L"Saturday, April 30 – Saturday, May 28"),
336 DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY)); 373 DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY));
337 } 374 }
338 375
339 } // namespace 376 } // namespace
340 } // namespace base 377 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698