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

Unified Diff: cc/scheduler/begin_frame_source_unittest.cc

Issue 1022483003: cc: Adding a BeginFrameObserverMultiplexer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Trying to get windows to work. Created 5 years, 9 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
« cc/scheduler/begin_frame_source.cc ('K') | « cc/scheduler/begin_frame_source.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/scheduler/begin_frame_source_unittest.cc
diff --git a/cc/scheduler/begin_frame_source_unittest.cc b/cc/scheduler/begin_frame_source_unittest.cc
index 22126bead4504af443d585740c491a68710833a9..9ee777c9969591e44abe85e1c9d18eea46253d19 100644
--- a/cc/scheduler/begin_frame_source_unittest.cc
+++ b/cc/scheduler/begin_frame_source_unittest.cc
@@ -221,6 +221,176 @@ TEST(BeginFrameObserverMixInTest, OnBeginFrameImplementation) {
EXPECT_EQ(1, obs.dropped_begin_frame_args());
}
+// BeginFrameObserverMultiplexer testing ---------------------------------
+
+class MockHasObserversCallback {
+ public:
+ MOCK_METHOD1(Callback, void(bool));
+
+ BeginFrameObserverMultiplexer::HasObserversCallback Get() {
+ return base::Bind(&MockHasObserversCallback::Callback,
+ base::Unretained(this));
+ }
+};
+
+TEST(BeginFrameObserverMultiplexerTest, ObserverManipulation) {
+ scoped_ptr<BeginFrameObserverMultiplexer> obs =
+ BeginFrameObserverMultiplexer::Create();
+
+ ::testing::StrictMock<MockMinimalBeginFrameObserverMixIn> obs_child1;
+ ::testing::StrictMock<MockMinimalBeginFrameObserverMixIn> obs_child2;
+
+ // Initial conditions
+ EXPECT_EQ(BeginFrameArgs(), obs->LastUsedBeginFrameArgs());
+
+ // Calling without any observers, should be fine
+ BeginFrameArgs args1 =
+ CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 100, 200, 300);
+ obs->OnBeginFrame(args1);
+ EXPECT_EQ(args1, obs->LastUsedBeginFrameArgs());
+
+ // Adding an observer triggers a MISSED frame for that observer if they have
+ // never receive the BeginFrameArgs before.
+ EXPECT_CALL(obs_child1,
+ OnBeginFrameMixInDelegate(CreateBeginFrameArgsForTesting(
+ BEGINFRAME_FROM_HERE, 100, 200, 300, BeginFrameArgs::MISSED)))
+ .WillOnce(::testing::Return(true));
+ obs->AddObserver(&obs_child1);
+
+#ifndef NDEBUG
+ EXPECT_DEATH({ obs->AddObserver(&obs_child1); }, "");
+
+ EXPECT_DEATH({ obs->RemoveObserver(&obs_child2); }, "");
+#endif
+
+ EXPECT_CALL(obs_child2,
+ OnBeginFrameMixInDelegate(CreateBeginFrameArgsForTesting(
+ BEGINFRAME_FROM_HERE, 100, 200, 300, BeginFrameArgs::MISSED)))
+ .WillOnce(::testing::Return(false));
+ obs->AddObserver(&obs_child2);
+
+ // Re-adding the observer shouldn't cause OnBeginFrame to get called again if
+ // it was used.
+ obs->RemoveObserver(&obs_child1);
+ obs->AddObserver(&obs_child1);
+
+ // This observer dropped the last missed frames so should get it again.
+ EXPECT_CALL(obs_child2,
+ OnBeginFrameMixInDelegate(CreateBeginFrameArgsForTesting(
+ BEGINFRAME_FROM_HERE, 100, 200, 300, BeginFrameArgs::MISSED)))
+ .WillOnce(::testing::Return(false));
+ obs->RemoveObserver(&obs_child2);
+ obs->AddObserver(&obs_child2);
+}
+
+TEST(BeginFrameObserverMultiplexerTest, HasObserverCallback) {
+ {
+ ::testing::StrictMock<MockHasObserversCallback> cb;
+ EXPECT_CALL(cb, Callback(false));
+
+ scoped_ptr<BeginFrameObserverMultiplexer> obs =
+ BeginFrameObserverMultiplexer::Create();
+ obs->SetHasObserverCallback(cb.Get());
+ }
+
+ {
+ ::testing::StrictMock<MockHasObserversCallback> cb;
+ EXPECT_CALL(cb, Callback(true));
+ EXPECT_CALL(cb, Callback(false)); // Destructor
+
+ scoped_ptr<BeginFrameObserverMultiplexer> obs =
+ BeginFrameObserverMultiplexer::Create();
+ MockMinimalBeginFrameObserverMixIn obs_child;
+ obs->AddObserver(&obs_child);
+ obs->SetHasObserverCallback(cb.Get());
+ }
+
+ {
+ ::testing::InSequence ordered;
+
+ ::testing::StrictMock<MockHasObserversCallback> cb;
+ EXPECT_CALL(cb, Callback(false));
+ EXPECT_CALL(cb, Callback(true));
+ EXPECT_CALL(cb, Callback(false));
+
+ scoped_ptr<BeginFrameObserverMultiplexer> obs =
+ BeginFrameObserverMultiplexer::Create();
+ MockMinimalBeginFrameObserverMixIn obs_child;
+ obs->SetHasObserverCallback(cb.Get());
+ obs->AddObserver(&obs_child);
+ obs->RemoveObserver(&obs_child);
+ }
+
+ {
+ ::testing::InSequence ordered;
+
+ ::testing::StrictMock<MockHasObserversCallback> cb;
+ EXPECT_CALL(cb, Callback(false));
+ EXPECT_CALL(cb, Callback(true));
+ EXPECT_CALL(cb, Callback(false));
+
+ scoped_ptr<BeginFrameObserverMultiplexer> obs =
+ BeginFrameObserverMultiplexer::Create();
+ MockMinimalBeginFrameObserverMixIn obs_child1;
+ MockMinimalBeginFrameObserverMixIn obs_child2;
+ obs->SetHasObserverCallback(cb.Get());
+ obs->AddObserver(&obs_child1);
+ obs->AddObserver(&obs_child2);
+ obs->RemoveObserver(&obs_child1);
+ obs->RemoveObserver(&obs_child2);
+ }
+
+ {
+ ::testing::InSequence ordered;
+ ::testing::StrictMock<MockHasObserversCallback> cb1;
+ EXPECT_CALL(cb1, Callback(false));
+ EXPECT_CALL(cb1, Callback(true));
+ EXPECT_CALL(cb1, Callback(false));
+
+ ::testing::StrictMock<MockHasObserversCallback> cb2;
+ EXPECT_CALL(cb2, Callback(true));
+ EXPECT_CALL(cb2, Callback(false));
+
+ ::testing::StrictMock<MockHasObserversCallback> cb3;
+ EXPECT_CALL(cb3, Callback(false));
+
+ scoped_ptr<BeginFrameObserverMultiplexer> obs =
+ BeginFrameObserverMultiplexer::Create();
+ MockMinimalBeginFrameObserverMixIn obs_child;
+ obs->SetHasObserverCallback(cb1.Get());
+ obs->AddObserver(&obs_child);
+ obs->SetHasObserverCallback(cb2.Get());
+ obs->RemoveObserver(&obs_child);
+ obs->SetHasObserverCallback(cb3.Get());
+ }
+}
+
+TEST(BeginFrameObserverMultiplexerTest, OnBeginFrame) {
+ scoped_ptr<BeginFrameObserverMultiplexer> obs =
+ BeginFrameObserverMultiplexer::Create();
+
+ MockBeginFrameObserver obs_child1;
+ EXPECT_BEGIN_FRAME_USED(obs_child1, 100, 200, 300);
+ EXPECT_BEGIN_FRAME_USED(obs_child1, 400, 600, 300);
+ MockBeginFrameObserver obs_child2;
+ EXPECT_CALL(obs_child2,
+ OnBeginFrame(CreateBeginFrameArgsForTesting(
+ BEGINFRAME_FROM_HERE, 100, 200, 300, BeginFrameArgs::MISSED)))
+ .InSequence(obs_child2.sequence);
+ EXPECT_BEGIN_FRAME_USED(obs_child2, 400, 600, 300);
+ EXPECT_BEGIN_FRAME_USED(obs_child2, 700, 800, 300);
+
+ obs->AddObserver(&obs_child1);
+ obs->OnBeginFrame(
+ CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 100, 200, 300));
+ obs->AddObserver(&obs_child2);
+ obs->OnBeginFrame(
+ CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 400, 600, 300));
+ obs->RemoveObserver(&obs_child1);
+ obs->OnBeginFrame(
+ CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 700, 800, 300));
+}
+
// BeginFrameSource testing ----------------------------------------------
TEST(BeginFrameSourceMixInTest, ObserverManipulation) {
MockBeginFrameObserver obs;
« cc/scheduler/begin_frame_source.cc ('K') | « cc/scheduler/begin_frame_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698