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

Side by Side Diff: ppapi/shared_impl/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.cc ('k') | webkit/plugins/ppapi/time_conversion_unittest.cc » ('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) 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 <math.h> 5 #include <math.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #include "ppapi/shared_impl/time_conversion.h" 8 #include "ppapi/shared_impl/time_conversion.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now)); 43 EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now));
44 44
45 // Units should be in seconds. 45 // Units should be in seconds.
46 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1); 46 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
47 double event_one_second_from_now = one_second_from_now.ToDoubleT(); 47 double event_one_second_from_now = one_second_from_now.ToDoubleT();
48 EXPECT_GE(kTimeSecondsSlop, 48 EXPECT_GE(kTimeSecondsSlop,
49 1.0 - ppapi::EventTimeToPPTimeTicks(event_one_second_from_now) - 49 1.0 - ppapi::EventTimeToPPTimeTicks(event_one_second_from_now) -
50 ppapi::EventTimeToPPTimeTicks(event_now)); 50 ppapi::EventTimeToPPTimeTicks(event_now));
51 } 51 }
52 52
53 TEST(TimeConversion, EpochTime) {
54 // Should be able to round-trip.
55 base::Time epoch = base::Time::UnixEpoch();
56 base::Time converted = ppapi::PPTimeToTime(TimeToPPTime(epoch));
57 EXPECT_GE(kTimeInternalValueSlop,
58 abs(static_cast<int>((converted - epoch).ToInternalValue())));
59
60 // Units should be in seconds.
61 base::Time one_second_from_epoch = epoch + base::TimeDelta::FromSeconds(1);
62 double converted_one_second_from_epoch =
63 ppapi::TimeToPPTime(one_second_from_epoch) - ppapi::TimeToPPTime(epoch);
64 EXPECT_GE(kTimeSecondsSlop, fabs(converted_one_second_from_epoch - 1));
Scott Hess - ex-Googler 2012/12/13 18:35:24 I think you should have a straight up test that PP
raymes 2012/12/14 17:28:22 Done.
65 }
66
53 } // namespace ppapi 67 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/time_conversion.cc ('k') | webkit/plugins/ppapi/time_conversion_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698