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

Side by Side Diff: webkit/plugins/ppapi/time_conversion_unittest.cc

Issue 11567013: Fix PPAPI time conversion code to handle epoch times. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/time_conversion_unittest.cc ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <math.h>
6 #include <stdlib.h>
7
8 #include "ppapi/shared_impl/time_conversion.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace ppapi {
12
13 // Slop we'll allow in two Time "internal values" to consider them equal.
14 // Double conversion can introduce rounding errors. The internal values are in
15 // microseconds, so an error here is very small.
16 static const int kTimeInternalValueSlop = 2;
17
18 // Same as above in double-precision seconds units.
19 static const double kTimeSecondsSlop =
20 static_cast<double>(kTimeInternalValueSlop) /
21 base::Time::kMicrosecondsPerSecond;
22
23 TEST(TimeConversion, Time) {
24 // Should be able to round-trip.
25 base::Time now = base::Time::Now();
26 base::Time converted = ppapi::PPTimeToTime(TimeToPPTime(now));
27 EXPECT_GE(kTimeInternalValueSlop,
28 abs(static_cast<int>((converted - now).ToInternalValue())));
29
30 // Units should be in seconds.
31 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
32 double converted_one_second_from_now =
33 ppapi::TimeToPPTime(one_second_from_now) - ppapi::TimeToPPTime(now);
34 EXPECT_GE(kTimeSecondsSlop, fabs(converted_one_second_from_now - 1));
35 }
36
37 TEST(TimeConversion, EventTime) {
38 // Should be able to round-trip.
39 base::Time now = base::Time::Now();
40 double event_now = now.ToDoubleT();
41 double converted =
42 ppapi::EventTimeToPPTimeTicks(ppapi::PPTimeTicksToEventTime(event_now));
43 EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now));
44
45 // Units should be in seconds.
46 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
47 double event_one_second_from_now = one_second_from_now.ToDoubleT();
48 EXPECT_GE(kTimeSecondsSlop,
49 1.0 - ppapi::EventTimeToPPTimeTicks(event_one_second_from_now) -
50 ppapi::EventTimeToPPTimeTicks(event_now));
51 }
52
53 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/time_conversion_unittest.cc ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698