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.
8 #include "cc/test/test_now_source.h"
12 // TestNowSource::Constructors
13 scoped_refptr
<TestNowSource
> TestNowSource::Create() {
14 return make_scoped_refptr(new TestNowSource());
17 scoped_refptr
<TestNowSource
> TestNowSource::Create(base::TimeTicks initial
) {
18 return make_scoped_refptr(new TestNowSource(initial
));
21 scoped_refptr
<TestNowSource
> TestNowSource::Create(int64_t initial
) {
22 return make_scoped_refptr(new TestNowSource(initial
));
25 TestNowSource::TestNowSource()
26 : initial_(base::TimeTicks::FromInternalValue(10000)),
32 TestNowSource::TestNowSource(base::TimeTicks initial
)
33 : initial_(initial
), now_(), num_now_calls_(0) {
37 TestNowSource::TestNowSource(int64_t initial
)
38 : initial_(base::TimeTicks::FromInternalValue(initial
)),
44 TestNowSource::~TestNowSource() {
47 // TestNowSource actual functionality
48 void TestNowSource::Reset() {
49 TRACE_EVENT_INSTANT2("cc",
50 "TestNowSource::Reset",
51 TRACE_EVENT_SCOPE_THREAD
,
59 base::TimeTicks
TestNowSource::Now() const {
64 void TestNowSource::SetNow(base::TimeTicks time
) {
65 TRACE_EVENT_INSTANT2("cc",
66 "TestNowSource::SetNow",
67 TRACE_EVENT_SCOPE_THREAD
,
72 DCHECK(time
>= now_
); // Time should always go forward.
76 void TestNowSource::AdvanceNow(base::TimeDelta period
) {
77 TRACE_EVENT_INSTANT2("cc",
78 "TestNowSource::AdvanceNow",
79 TRACE_EVENT_SCOPE_THREAD
,
83 period
.ToInternalValue());
84 DCHECK(now_
!= kAbsoluteMaxNow
);
85 DCHECK(period
>= base::TimeDelta()); // Time should always go forward.
89 const base::TimeTicks
TestNowSource::kAbsoluteMaxNow
=
90 base::TimeTicks::FromInternalValue(std::numeric_limits
<int64_t>::max());
92 // TestNowSource::Convenience functions
93 void TestNowSource::AdvanceNowMicroseconds(int64_t period_in_microseconds
) {
94 AdvanceNow(base::TimeDelta::FromMicroseconds(period_in_microseconds
));
96 void TestNowSource::SetNowMicroseconds(int64_t time_in_microseconds
) {
97 SetNow(base::TimeTicks::FromInternalValue(time_in_microseconds
));
100 // TestNowSource::Tracing functions
101 void TestNowSource::AsValueInto(base::trace_event::TracedValue
* state
) const {
102 state
->SetInteger("now_in_microseconds", now_
.ToInternalValue());
105 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
106 TestNowSource::AsValue() const {
107 scoped_refptr
<base::trace_event::TracedValue
> state
=
108 new base::trace_event::TracedValue();
109 AsValueInto(state
.get());
113 // TestNowSource::Pretty printing functions
114 std::string
TestNowSource::ToString() const {
115 std::string
output("TestNowSource(");
116 AsValue()->AppendAsTraceFormat(&output
);
121 ::std::ostream
& operator<<(::std::ostream
& os
,
122 const scoped_refptr
<TestNowSource
>& src
) {
123 os
<< src
->ToString();
126 void PrintTo(const scoped_refptr
<TestNowSource
>& src
, ::std::ostream
* os
) {