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

Side by Side Diff: cc/test/test_now_source.cc

Issue 387493002: Fixing and enhancing OrderedSimpleTaskRunner to allow 100% deterministic tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing Windows compile (no idea why this worked on non-windows!) Created 6 years, 3 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
OLDNEW
(Empty)
1 // Copyright 2014 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 <string>
6
7 #include "cc/test/test_now_source.h"
8
9 namespace cc {
10
11 // TestNowSource::Constructors
12 scoped_refptr<TestNowSource> TestNowSource::Create() {
13 return make_scoped_refptr(new TestNowSource());
14 }
15
16 scoped_refptr<TestNowSource> TestNowSource::Create(base::TimeTicks initial) {
17 return make_scoped_refptr(new TestNowSource(initial));
18 }
19
20 scoped_refptr<TestNowSource> TestNowSource::Create(int64_t initial) {
21 return make_scoped_refptr(new TestNowSource(initial));
22 }
23
24 TestNowSource::TestNowSource()
25 : initial_(base::TimeTicks::FromInternalValue(10000)), now_() {
26 Reset();
27 }
28
29 TestNowSource::TestNowSource(base::TimeTicks initial)
30 : initial_(initial), now_() {
31 Reset();
32 }
33
34 TestNowSource::TestNowSource(int64_t initial)
35 : initial_(base::TimeTicks::FromInternalValue(initial)), now_() {
36 Reset();
37 }
38
39 TestNowSource::~TestNowSource() {
40 }
41
42 // TestNowSource actual functionality
43 void TestNowSource::Reset() {
44 TRACE_EVENT_INSTANT2("cc",
45 "TestNowSource::Reset",
46 TRACE_EVENT_SCOPE_THREAD,
47 "previous",
48 now_,
49 "initial",
50 initial_);
51 now_ = initial_;
52 }
53
54 base::TimeTicks TestNowSource::Now() const {
55 return now_;
56 }
57
58 void TestNowSource::SetNow(base::TimeTicks time) {
59 TRACE_EVENT_INSTANT2("cc",
60 "TestNowSource::SetNow",
61 TRACE_EVENT_SCOPE_THREAD,
62 "previous",
63 now_,
64 "new",
65 time);
66 DCHECK(time >= now_); // Time should always go forward.
67 now_ = time;
68 }
69
70 void TestNowSource::AdvanceNow(base::TimeDelta period) {
71 TRACE_EVENT_INSTANT2("cc",
72 "TestNowSource::AdvanceNow",
73 TRACE_EVENT_SCOPE_THREAD,
74 "previous",
75 now_,
76 "by",
77 period.ToInternalValue());
78 DCHECK(period >= base::TimeDelta()); // Time should always go forward.
79 now_ += period;
80 }
81
82 // TestNowSource::Convenience functions
83 void TestNowSource::AdvanceNowMicroseconds(int64_t period_in_microseconds) {
84 AdvanceNow(base::TimeDelta::FromMicroseconds(period_in_microseconds));
85 }
86 void TestNowSource::SetNowMicroseconds(int64_t time_in_microseconds) {
87 SetNow(base::TimeTicks::FromInternalValue(time_in_microseconds));
88 }
89
90 // TestNowSource::Tracing functions
91 void TestNowSource::AsValueInto(base::debug::TracedValue* state) const {
92 state->SetInteger("now_in_microseconds", now_.ToInternalValue());
93 }
94
95 scoped_refptr<base::debug::ConvertableToTraceFormat> TestNowSource::AsValue()
96 const {
97 scoped_refptr<base::debug::TracedValue> state =
98 new base::debug::TracedValue();
99 AsValueInto(state);
100 return state;
101 }
102
103 // TestNowSource::Pretty printing functions
104 std::string TestNowSource::ToString() const {
105 std::string output("TestNowSource(");
106 AsValue()->AppendAsTraceFormat(&output);
107 output += ")";
108 return output;
109 }
110
111 ::std::ostream& operator<<(::std::ostream& os,
112 const scoped_refptr<TestNowSource>& src) {
113 os << src->ToString();
114 return os;
115 }
116 void PrintTo(const scoped_refptr<TestNowSource>& src, ::std::ostream* os) {
117 *os << src;
118 }
119
120 } // namespace cc
OLDNEW
« cc/test/ordered_simple_task_runner.cc ('K') | « cc/test/test_now_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698