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

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

Issue 7237044: Make PP_TimeTicks actually be a tick counter rather than be the same as the (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <math.h>
6 #include <stdlib.h>
7
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "webkit/plugins/ppapi/time_conversion.h"
10
11 namespace webkit {
12 namespace ppapi {
13
14 // Slop we'll allow in two Time "internal values" to consider them equal.
15 // Double conversion can introduce rounding errors. The internal values are in
16 // microseconds, so an error here is very small.
17 static const int kTimeInternalValueSlop = 2;
18
19 // Same as above in double-precision seconds units.
20 static const double kTimeSecondsSlop =
21 static_cast<double>(kTimeInternalValueSlop) /
22 base::Time::kMicrosecondsPerSecond;
23
24 TEST(TimeConversion, Time) {
25 // Should be able to round-trip.
26 base::Time now = base::Time::Now();
27 base::Time converted = PPTimeToTime(TimeToPPTime(now));
28 EXPECT_GE(kTimeInternalValueSlop,
29 abs(static_cast<int>((converted - now).ToInternalValue())));
30
31 // Units should be in seconds.
32 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
33 EXPECT_EQ(1.0, TimeToPPTime(one_second_from_now) - TimeToPPTime(now));
34 }
35
36 TEST(TimeConversion, EventTime) {
37 // Should be able to round-trip.
38 base::Time now = base::Time::Now();
39 double event_now = now.ToDoubleT();
40 double converted = EventTimeToPPTimeTicks(PPTimeTicksToEventTime(event_now));
41 EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now));
42
43 // Units should be in seconds.
44 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
45 double event_one_second_from_now = one_second_from_now.ToDoubleT();
46 EXPECT_GE(kTimeSecondsSlop,
47 1.0 - EventTimeToPPTimeTicks(event_one_second_from_now) -
48 EventTimeToPPTimeTicks(event_now));
49 }
50
51 } // namespace ppapi
52 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698