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

Unified Diff: cc/scheduler/frame_source_unittest.cc

Issue 267783004: Refactoring the way begin frame sources inside scheduler work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Scheduler tests now pass and the code is cleaner. Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/scheduler/frame_source.cc ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/scheduler/frame_source_unittest.cc
diff --git a/cc/scheduler/frame_source_unittest.cc b/cc/scheduler/frame_source_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d9a47b9f8c3d2f5dca8b651ffeef7fa24d918f6a
--- /dev/null
+++ b/cc/scheduler/frame_source_unittest.cc
@@ -0,0 +1,176 @@
+// Copyright 2011 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 <deque>
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+#include "base/test/test_simple_task_runner.h"
+#include "cc/scheduler/frame_source.h"
+#include "cc/test/begin_frame_args_test.h"
+#include "cc/test/scheduler_test_common.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cc {
+namespace {
+
+class FakeBeginFrameSink : public BeginFrameSink {
+ public:
+ void Expect(BeginFrameArgs args) { expected_.push_back(args); }
+
+ virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE {
+ ASSERT_GT(expected_.size(), 0U) << "Unexpected BeginFrame("
+ << ::testing::PrintToString(args)
+ << ") call!";
+ EXPECT_EQ(expected_[0], args);
+ expected_.pop_front();
+ }
+
+ virtual void Reset() {
+ EXPECT_EQ(expected_.size(), 0U) << "Missing " << expected_.size()
+ << " BeginFrame calls!";
+ expected_.clear();
+ }
+
+ virtual ~FakeBeginFrameSink() { Reset(); }
+
+ private:
+ std::deque<BeginFrameArgs> expected_;
+};
+
+class FakeBeginFrameSource : public BaseBeginFrameSource {
+ public:
+ FakeBeginFrameSource() : BaseBeginFrameSource(0) {}
+
+ void SendTestBeginFrame(const BeginFrameArgs& args) {
+ frame_sink_->BeginFrame(args);
+ }
+
+ protected:
+ virtual std::string TypeString() const OVERRIDE {
+ return "FakeBeginFrameSource";
+ }
+
+ FRIEND_TEST_ALL_PREFIXES(BeginFrameSourceTest, ProxyFrameSource);
+ FRIEND_TEST_ALL_PREFIXES(BeginFrameSourceTest, DualFrameSource);
+};
+
+TEST(BeginFrameSourceTest, ProxyFrameSource) {
+ FakeBeginFrameSink sink;
+ FakeBeginFrameSource source;
+
+ // BeginFrame
+ sink.Expect(CreateBeginFrameArgsForTesting(100, 200, 300));
+ sink.Expect(CreateBeginFrameArgsForTesting(400, 600, 300));
+ ProxyBeginFrameSource proxy(&sink, &source);
+ proxy.BeginFrame(CreateBeginFrameArgsForTesting(100, 200, 300));
+ proxy.BeginFrame(CreateBeginFrameArgsForTesting(400, 600, 300));
+
+ // SetGenerateFrames
+ source.generate_frames_ = false;
+ proxy.SetGenerateFrames(true);
+ EXPECT_EQ(source.generate_frames_, true);
+ proxy.SetGenerateFrames(false);
+ EXPECT_EQ(source.generate_frames_, false);
+
+ // PendingFrames
+
+ // SetTimeBaseAndInterval
+ source.timebase_ = base::TimeTicks();
+ source.interval_ = base::TimeDelta();
+ proxy.SetTimeBaseAndInterval(base::TimeTicks::FromInternalValue(123),
+ base::TimeDelta::FromInternalValue(456));
+ EXPECT_EQ(source.timebase_.ToInternalValue(), 123);
+ EXPECT_EQ(source.interval_.ToInternalValue(), 456);
+}
+
+TEST(BeginFrameSourceTest, ThrottledFrameSource) {
+ FakeBeginFrameSink sink;
+ FakeBeginFrameSource source;
+
+ ThrottledBeginFrameSource throttle(
+ &sink, &source, base::TimeDelta::FromInternalValue(600));
+
+ sink.Expect(CreateBeginFrameArgsForTesting(100, 200, 300));
+ sink.Expect(CreateBeginFrameArgsForTesting(700, 900, 300));
+ source.SendTestBeginFrame(CreateBeginFrameArgsForTesting(100, 200, 300));
+ source.SendTestBeginFrame(CreateBeginFrameArgsForTesting(400, 600, 300));
+ source.SendTestBeginFrame(CreateBeginFrameArgsForTesting(700, 900, 300));
+}
+
+TEST(BeginFrameSourceTest, BackToBackFrameSource) {
+ FakeBeginFrameSink sink;
+ // BackToBackBeginFrameSource source;
+}
+
+TEST(BeginFrameSourceTest, SyntheticFrameSource) {
+ FakeBeginFrameSink sink;
+ // SyntheticFrameSource
+}
+
+TEST(BeginFrameSourceTest, DualFrameSource) {
+ FakeBeginFrameSink sink;
+
+ FakeBeginFrameSource* fake_primary = new FakeBeginFrameSource();
+ fake_primary->generate_frames_ = false;
+ FakeBeginFrameSource* fake_secondary = new FakeBeginFrameSource();
+ fake_secondary->generate_frames_ = false;
+
+ DualBeginFrameSource source(&sink,
+ scoped_ptr<BeginFrameSource>(fake_primary),
+ scoped_ptr<BeginFrameSource>(fake_secondary));
+ source.SwitchSource(source.SourceForeground());
+
+ // Check SetGenerateFrames works
+ source.SetGenerateFrames(true);
+ EXPECT_EQ(fake_primary->generate_frames_, true);
+ EXPECT_EQ(fake_secondary->generate_frames_, false);
+ source.SetGenerateFrames(false);
+ EXPECT_EQ(fake_primary->generate_frames_, false);
+ EXPECT_EQ(fake_secondary->generate_frames_, false);
+
+ // Checking that switching the source makes SetGenerateFrames on the
+ // subsources correctly.
+ source.SetGenerateFrames(true);
+ source.SwitchSource(source.SourceBackground());
+ EXPECT_EQ(fake_primary->generate_frames_, false);
+ EXPECT_EQ(fake_secondary->generate_frames_, true);
+ source.SwitchSource(source.SourceForeground());
+ EXPECT_EQ(fake_primary->generate_frames_, true);
+ EXPECT_EQ(fake_secondary->generate_frames_, false);
+
+ sink.Reset();
+
+ // Check that BeginFrame calls end up at the sink
+ {
+ SCOPED_TRACE("First test");
+ sink.Expect(CreateBeginFrameArgsForTesting(100, 200, 300));
+ sink.Expect(CreateBeginFrameArgsForTesting(400, 600, 300));
+ fake_primary->SendTestBeginFrame(
+ CreateBeginFrameArgsForTesting(100, 200, 300));
+ fake_secondary->SendTestBeginFrame(
+ CreateBeginFrameArgsForTesting(400, 600, 300));
+ sink.Reset();
+ }
+
+ // Check that BeginFrames can't go backwards
+ {
+ SCOPED_TRACE("Backwards test");
+ sink.Expect(CreateBeginFrameArgsForTesting(400, 600, 300));
+ sink.Expect(CreateBeginFrameArgsForTesting(700, 900, 300));
+ sink.Expect(CreateBeginFrameArgsForTesting(1000, 1200, 300));
+ fake_primary->SendTestBeginFrame(
+ CreateBeginFrameArgsForTesting(400, 600, 300));
+ fake_primary->SendTestBeginFrame(
+ CreateBeginFrameArgsForTesting(700, 900, 300));
+ fake_secondary->SendTestBeginFrame(
+ CreateBeginFrameArgsForTesting(699, 899, 300));
+ fake_primary->SendTestBeginFrame(
+ CreateBeginFrameArgsForTesting(1000, 1200, 300));
+ sink.Reset();
+ }
+}
+
+} // namespace
+} // namespace cc
« no previous file with comments | « cc/scheduler/frame_source.cc ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698