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

Side by Side Diff: base/time/time_unittest.cc

Issue 2655233003: Revert of base::Time should correctly handle -epoch time values from Javascript (Closed)
Patch Set: Created 3 years, 11 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/time/time.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <time.h> 8 #include <time.h>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 // Test conversions to/from javascript time. 154 // Test conversions to/from javascript time.
155 TEST_F(TimeTest, JsTime) { 155 TEST_F(TimeTest, JsTime) {
156 Time epoch = Time::FromJsTime(0.0); 156 Time epoch = Time::FromJsTime(0.0);
157 EXPECT_EQ(epoch, Time::UnixEpoch()); 157 EXPECT_EQ(epoch, Time::UnixEpoch());
158 Time t = Time::FromJsTime(700000.3); 158 Time t = Time::FromJsTime(700000.3);
159 EXPECT_EQ(700.0003, t.ToDoubleT()); 159 EXPECT_EQ(700.0003, t.ToDoubleT());
160 t = Time::FromDoubleT(800.73); 160 t = Time::FromDoubleT(800.73);
161 EXPECT_EQ(800730.0, t.ToJsTime()); 161 EXPECT_EQ(800730.0, t.ToJsTime());
162
163 // Correctly convert |- epoch offset| which is valid time in javascript.
164 Time minusEpoch = Time::FromJsTime(-11644473600000.0);
165 EXPECT_EQ(-11644473600000, minusEpoch.ToJsTime());
166
167 // Check conversion of boundary javascript time values.
168 // See http://www.ecma-international.org/ecma-262/6.0/#sec-timeclip
169 EXPECT_EQ(-8.46e15, Time::FromJsTime(-8.46e15).ToJsTime());
170 EXPECT_EQ(8.46e15, Time::FromJsTime(8.46e15).ToJsTime());
171 } 162 }
172 163
173 #if defined(OS_POSIX) 164 #if defined(OS_POSIX)
174 TEST_F(TimeTest, FromTimeVal) { 165 TEST_F(TimeTest, FromTimeVal) {
175 Time now = Time::Now(); 166 Time now = Time::Now();
176 Time also_now = Time::FromTimeVal(now.ToTimeVal()); 167 Time also_now = Time::FromTimeVal(now.ToTimeVal());
177 EXPECT_EQ(now, also_now); 168 EXPECT_EQ(now, also_now);
178 } 169 }
179 #endif // OS_POSIX 170 #endif // OS_POSIX
180 171
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 1190
1200 TEST(TimeTicksLogging, DoesNotMakeStreamBad) { 1191 TEST(TimeTicksLogging, DoesNotMakeStreamBad) {
1201 std::ostringstream oss; 1192 std::ostringstream oss;
1202 oss << TimeTicks(); 1193 oss << TimeTicks();
1203 EXPECT_TRUE(oss.good()); 1194 EXPECT_TRUE(oss.good());
1204 } 1195 }
1205 1196
1206 } // namespace 1197 } // namespace
1207 1198
1208 } // namespace base 1199 } // namespace base
OLDNEW
« no previous file with comments | « base/time/time.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698