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

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

Issue 827123004: The Certificate Web UI incorrectly formats the issued and expires dates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Rebase on ToT Created 5 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
« no previous file with comments | « base/i18n/time_formatting.cc ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h" 10 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/icu/source/common/unicode/uversion.h" 12 #include "third_party/icu/source/common/unicode/uversion.h"
13 #include "third_party/icu/source/i18n/unicode/calendar.h"
14 #include "third_party/icu/source/i18n/unicode/timezone.h"
12 15
13 namespace base { 16 namespace base {
14 namespace { 17 namespace {
15 18
16 const Time::Exploded kTestDateTimeExploded = { 19 const Time::Exploded kTestDateTimeExploded = {
17 2011, 4, 6, 30, // Sat, Apr 30, 2011 20 2011, 4, 6, 30, // Sat, Apr 30, 2011
18 15, 42, 7, 0 // 15:42:07.000 21 15, 42, 7, 0 // 15:42:07.000
19 }; 22 };
20 23
24 base::string16 GetShortTimeZone() {
25 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
26 // This code shamelessly taken from
27 // src/chrome/browser/chromeos/system/timezone_util.cc.
28 int raw_offset, dst_offset;
29 UErrorCode status;
30 zone->getOffset(icu::Calendar::getNow(), false, raw_offset, dst_offset,
31 status);
32 icu::UnicodeString name;
33 zone->getDisplayName(true, icu::TimeZone::SHORT, name);
34 return base::string16(name.getBuffer(), name.length());
35 }
36
21 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) { 37 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) {
22 // Test for a locale defaulted to 12h clock. 38 // Test for a locale defaulted to 12h clock.
23 // As an instance, we use third_party/icu/source/data/locales/en.txt. 39 // As an instance, we use third_party/icu/source/data/locales/en.txt.
24 i18n::SetICUDefaultLocale("en_US"); 40 i18n::SetICUDefaultLocale("en_US");
25 41
26 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 42 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
27 string16 clock24h(ASCIIToUTF16("15:42")); 43 string16 clock24h(ASCIIToUTF16("15:42"));
28 string16 clock12h_pm(ASCIIToUTF16("3:42 PM")); 44 string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
29 string16 clock12h(ASCIIToUTF16("3:42")); 45 string16 clock12h(ASCIIToUTF16("3:42"));
30 46
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy". 138 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy".
123 i18n::SetICUDefaultLocale("en_US"); 139 i18n::SetICUDefaultLocale("en_US");
124 140
125 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 141 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
126 142
127 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); 143 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time));
128 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); 144 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time));
129 145
130 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"), 146 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"),
131 TimeFormatShortDateAndTime(time)); 147 TimeFormatShortDateAndTime(time));
148 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(),
149 TimeFormatShortDateAndTimeWithTimeZone(time));
132 150
133 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), 151 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"),
134 TimeFormatFriendlyDateAndTime(time)); 152 TimeFormatFriendlyDateAndTime(time));
135 153
136 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), 154 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"),
137 TimeFormatFriendlyDate(time)); 155 TimeFormatFriendlyDate(time));
138 } 156 }
139 157
140 TEST(TimeFormattingTest, TimeFormatDateGB) { 158 TEST(TimeFormattingTest, TimeFormatDateGB) {
141 // See third_party/icu/source/data/locales/en_GB.txt. 159 // See third_party/icu/source/data/locales/en_GB.txt.
142 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". 160 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy".
143 i18n::SetICUDefaultLocale("en_GB"); 161 i18n::SetICUDefaultLocale("en_GB");
144 162
145 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 163 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
146 164
147 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); 165 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time));
148 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); 166 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time));
149 EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07"), 167 EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07"),
150 TimeFormatShortDateAndTime(time)); 168 TimeFormatShortDateAndTime(time));
169 EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07 ") + GetShortTimeZone(),
170 TimeFormatShortDateAndTimeWithTimeZone(time));
151 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 15:42:07"), 171 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 15:42:07"),
152 TimeFormatFriendlyDateAndTime(time)); 172 TimeFormatFriendlyDateAndTime(time));
153 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), 173 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"),
154 TimeFormatFriendlyDate(time)); 174 TimeFormatFriendlyDate(time));
155 } 175 }
156 176
157 } // namespace 177 } // namespace
158 } // namespace base 178 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/time_formatting.cc ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698