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

Unified Diff: cc/test/test_now_source.cc

Issue 1531403002: Revert "Delete CC." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/test/test_now_source.h ('k') | cc/test/test_occlusion_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/test/test_now_source.cc
diff --git a/cc/test/test_now_source.cc b/cc/test/test_now_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e1a633f166283fb0592687894a047333e3daf772
--- /dev/null
+++ b/cc/test/test_now_source.cc
@@ -0,0 +1,130 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <limits>
+#include <string>
+
+#include "cc/test/test_now_source.h"
+
+namespace cc {
+
+// TestNowSource::Constructors
+scoped_refptr<TestNowSource> TestNowSource::Create() {
+ return make_scoped_refptr(new TestNowSource());
+}
+
+scoped_refptr<TestNowSource> TestNowSource::Create(base::TimeTicks initial) {
+ return make_scoped_refptr(new TestNowSource(initial));
+}
+
+scoped_refptr<TestNowSource> TestNowSource::Create(int64_t initial) {
+ return make_scoped_refptr(new TestNowSource(initial));
+}
+
+TestNowSource::TestNowSource()
+ : initial_(base::TimeTicks::FromInternalValue(10000)),
+ now_(),
+ num_now_calls_(0) {
+ Reset();
+}
+
+TestNowSource::TestNowSource(base::TimeTicks initial)
+ : initial_(initial), now_(), num_now_calls_(0) {
+ Reset();
+}
+
+TestNowSource::TestNowSource(int64_t initial)
+ : initial_(base::TimeTicks::FromInternalValue(initial)),
+ now_(),
+ num_now_calls_(0) {
+ Reset();
+}
+
+TestNowSource::~TestNowSource() {
+}
+
+// TestNowSource actual functionality
+void TestNowSource::Reset() {
+ TRACE_EVENT_INSTANT2("cc",
+ "TestNowSource::Reset",
+ TRACE_EVENT_SCOPE_THREAD,
+ "previous",
+ now_,
+ "initial",
+ initial_);
+ now_ = initial_;
+}
+
+base::TimeTicks TestNowSource::Now() const {
+ num_now_calls_++;
+ return now_;
+}
+
+void TestNowSource::SetNow(base::TimeTicks time) {
+ TRACE_EVENT_INSTANT2("cc",
+ "TestNowSource::SetNow",
+ TRACE_EVENT_SCOPE_THREAD,
+ "previous",
+ now_,
+ "new",
+ time);
+ DCHECK(time >= now_); // Time should always go forward.
+ now_ = time;
+}
+
+void TestNowSource::AdvanceNow(base::TimeDelta period) {
+ TRACE_EVENT_INSTANT2("cc",
+ "TestNowSource::AdvanceNow",
+ TRACE_EVENT_SCOPE_THREAD,
+ "previous",
+ now_,
+ "by",
+ period.ToInternalValue());
+ DCHECK(now_ != kAbsoluteMaxNow);
+ DCHECK(period >= base::TimeDelta()); // Time should always go forward.
+ now_ += period;
+}
+
+const base::TimeTicks TestNowSource::kAbsoluteMaxNow =
+ base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max());
+
+// TestNowSource::Convenience functions
+void TestNowSource::AdvanceNowMicroseconds(int64_t period_in_microseconds) {
+ AdvanceNow(base::TimeDelta::FromMicroseconds(period_in_microseconds));
+}
+void TestNowSource::SetNowMicroseconds(int64_t time_in_microseconds) {
+ SetNow(base::TimeTicks::FromInternalValue(time_in_microseconds));
+}
+
+// TestNowSource::Tracing functions
+void TestNowSource::AsValueInto(base::trace_event::TracedValue* state) const {
+ state->SetInteger("now_in_microseconds", now_.ToInternalValue());
+}
+
+scoped_refptr<base::trace_event::ConvertableToTraceFormat>
+TestNowSource::AsValue() const {
+ scoped_refptr<base::trace_event::TracedValue> state =
+ new base::trace_event::TracedValue();
+ AsValueInto(state.get());
+ return state;
+}
+
+// TestNowSource::Pretty printing functions
+std::string TestNowSource::ToString() const {
+ std::string output("TestNowSource(");
+ AsValue()->AppendAsTraceFormat(&output);
+ output += ")";
+ return output;
+}
+
+::std::ostream& operator<<(::std::ostream& os,
+ const scoped_refptr<TestNowSource>& src) {
+ os << src->ToString();
+ return os;
+}
+void PrintTo(const scoped_refptr<TestNowSource>& src, ::std::ostream* os) {
+ *os << src;
+}
+
+} // namespace cc
« no previous file with comments | « cc/test/test_now_source.h ('k') | cc/test/test_occlusion_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698