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

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

Issue 7344009: Move the time conversion code to the PPAPI shared_impl directory and use it in (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
« no previous file with comments | « webkit/plugins/ppapi/time_conversion.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) 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 <math.h> 5 #include <math.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "webkit/plugins/ppapi/time_conversion.h" 9 #include "ppapi/shared_impl/ppapi/time_conversion.h"
10
11 namespace webkit {
12 namespace ppapi {
13 10
14 // Slop we'll allow in two Time "internal values" to consider them equal. 11 // 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 12 // Double conversion can introduce rounding errors. The internal values are in
16 // microseconds, so an error here is very small. 13 // microseconds, so an error here is very small.
17 static const int kTimeInternalValueSlop = 2; 14 static const int kTimeInternalValueSlop = 2;
18 15
19 // Same as above in double-precision seconds units. 16 // Same as above in double-precision seconds units.
20 static const double kTimeSecondsSlop = 17 static const double kTimeSecondsSlop =
21 static_cast<double>(kTimeInternalValueSlop) / 18 static_cast<double>(kTimeInternalValueSlop) /
22 base::Time::kMicrosecondsPerSecond; 19 base::Time::kMicrosecondsPerSecond;
23 20
24 // Fails on linux. http://crbug.com/88971 21 // Fails on linux. http://crbug.com/88971
25 #if defined(OS_LINUX) 22 #if defined(OS_LINUX)
26 #define MAYBE_Time FAILS_Time 23 #define MAYBE_Time FAILS_Time
27 #else 24 #else
28 #define MAYBE_Time Time 25 #define MAYBE_Time Time
29 #endif 26 #endif
30 TEST(TimeConversion, MAYBE_Time) { 27 TEST(TimeConversion, MAYBE_Time) {
31 // Should be able to round-trip. 28 // Should be able to round-trip.
32 base::Time now = base::Time::Now(); 29 base::Time now = base::Time::Now();
33 base::Time converted = PPTimeToTime(TimeToPPTime(now)); 30 base::Time converted = ppapi::PPTimeToTime(TimeToPPTime(now));
34 EXPECT_GE(kTimeInternalValueSlop, 31 EXPECT_GE(kTimeInternalValueSlop,
35 abs(static_cast<int>((converted - now).ToInternalValue()))); 32 abs(static_cast<int>((converted - now).ToInternalValue())));
36 33
37 // Units should be in seconds. 34 // Units should be in seconds.
38 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1); 35 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
39 EXPECT_EQ(1.0, TimeToPPTime(one_second_from_now) - TimeToPPTime(now)); 36 EXPECT_EQ(1.0, ppapi::TimeToPPTime(one_second_from_now) -
37 ppapi::TimeToPPTime(now));
40 } 38 }
41 39
42 TEST(TimeConversion, EventTime) { 40 TEST(TimeConversion, EventTime) {
43 // Should be able to round-trip. 41 // Should be able to round-trip.
44 base::Time now = base::Time::Now(); 42 base::Time now = base::Time::Now();
45 double event_now = now.ToDoubleT(); 43 double event_now = now.ToDoubleT();
46 double converted = EventTimeToPPTimeTicks(PPTimeTicksToEventTime(event_now)); 44 double converted =
45 ppapi::EventTimeToPPTimeTicks(ppapi::PPTimeTicksToEventTime(event_now));
47 EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now)); 46 EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now));
48 47
49 // Units should be in seconds. 48 // Units should be in seconds.
50 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1); 49 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
51 double event_one_second_from_now = one_second_from_now.ToDoubleT(); 50 double event_one_second_from_now = one_second_from_now.ToDoubleT();
52 EXPECT_GE(kTimeSecondsSlop, 51 EXPECT_GE(kTimeSecondsSlop,
53 1.0 - EventTimeToPPTimeTicks(event_one_second_from_now) - 52 1.0 - ppapi::EventTimeToPPTimeTicks(event_one_second_from_now) -
54 EventTimeToPPTimeTicks(event_now)); 53 ppapi::EventTimeToPPTimeTicks(event_now));
55 } 54 }
56
57 } // namespace ppapi
58 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/time_conversion.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698