Policy: check MustRemainInstalled in addition to UserMayModifySettings before offerin...
[chromium-blink-merge.git] / cc / test / test_now_source.cc
blob2ffb36ec04e469934df03cc929531865809fa4cb
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.
5 #include <limits>
6 #include <string>
8 #include "cc/test/test_now_source.h"
10 namespace cc {
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)), now_() {
27 Reset();
30 TestNowSource::TestNowSource(base::TimeTicks initial)
31 : initial_(initial), now_() {
32 Reset();
35 TestNowSource::TestNowSource(int64_t initial)
36 : initial_(base::TimeTicks::FromInternalValue(initial)), now_() {
37 Reset();
40 TestNowSource::~TestNowSource() {
43 // TestNowSource actual functionality
44 void TestNowSource::Reset() {
45 TRACE_EVENT_INSTANT2("cc",
46 "TestNowSource::Reset",
47 TRACE_EVENT_SCOPE_THREAD,
48 "previous",
49 now_,
50 "initial",
51 initial_);
52 now_ = initial_;
55 base::TimeTicks TestNowSource::Now() const {
56 return now_;
59 void TestNowSource::SetNow(base::TimeTicks time) {
60 TRACE_EVENT_INSTANT2("cc",
61 "TestNowSource::SetNow",
62 TRACE_EVENT_SCOPE_THREAD,
63 "previous",
64 now_,
65 "new",
66 time);
67 DCHECK(time >= now_); // Time should always go forward.
68 now_ = time;
71 void TestNowSource::AdvanceNow(base::TimeDelta period) {
72 TRACE_EVENT_INSTANT2("cc",
73 "TestNowSource::AdvanceNow",
74 TRACE_EVENT_SCOPE_THREAD,
75 "previous",
76 now_,
77 "by",
78 period.ToInternalValue());
79 DCHECK(now_ != kAbsoluteMaxNow);
80 DCHECK(period >= base::TimeDelta()); // Time should always go forward.
81 now_ += period;
84 const base::TimeTicks TestNowSource::kAbsoluteMaxNow =
85 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max());
87 // TestNowSource::Convenience functions
88 void TestNowSource::AdvanceNowMicroseconds(int64_t period_in_microseconds) {
89 AdvanceNow(base::TimeDelta::FromMicroseconds(period_in_microseconds));
91 void TestNowSource::SetNowMicroseconds(int64_t time_in_microseconds) {
92 SetNow(base::TimeTicks::FromInternalValue(time_in_microseconds));
95 // TestNowSource::Tracing functions
96 void TestNowSource::AsValueInto(base::debug::TracedValue* state) const {
97 state->SetInteger("now_in_microseconds", now_.ToInternalValue());
100 scoped_refptr<base::debug::ConvertableToTraceFormat> TestNowSource::AsValue()
101 const {
102 scoped_refptr<base::debug::TracedValue> state =
103 new base::debug::TracedValue();
104 AsValueInto(state.get());
105 return state;
108 // TestNowSource::Pretty printing functions
109 std::string TestNowSource::ToString() const {
110 std::string output("TestNowSource(");
111 AsValue()->AppendAsTraceFormat(&output);
112 output += ")";
113 return output;
116 ::std::ostream& operator<<(::std::ostream& os,
117 const scoped_refptr<TestNowSource>& src) {
118 os << src->ToString();
119 return os;
121 void PrintTo(const scoped_refptr<TestNowSource>& src, ::std::ostream* os) {
122 *os << src;
125 } // namespace cc