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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <deque> 5 #include <deque>
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 EXPECT_EQ(1, obs.dropped_begin_frame_args()); 214 EXPECT_EQ(1, obs.dropped_begin_frame_args());
215 215
216 BeginFrameArgs args3 = 216 BeginFrameArgs args3 =
217 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 150, 300, 400); 217 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 150, 300, 400);
218 EXPECT_CALL(obs, OnBeginFrameMixInDelegate(args3)).WillOnce(Return(true)); 218 EXPECT_CALL(obs, OnBeginFrameMixInDelegate(args3)).WillOnce(Return(true));
219 obs.OnBeginFrame(args3); 219 obs.OnBeginFrame(args3);
220 EXPECT_EQ(args3, obs.LastUsedBeginFrameArgs()); 220 EXPECT_EQ(args3, obs.LastUsedBeginFrameArgs());
221 EXPECT_EQ(1, obs.dropped_begin_frame_args()); 221 EXPECT_EQ(1, obs.dropped_begin_frame_args());
222 } 222 }
223 223
224 // BeginFrameObserverMultiplexer testing ---------------------------------
225
226 class MockHasObserversCallback {
227 public:
228 MOCK_METHOD1(Callback, void(bool));
229
230 BeginFrameObserverMultiplexer::HasObserversCallback Get() {
231 return base::Bind(&MockHasObserversCallback::Callback,
232 base::Unretained(this));
233 }
234 };
235
236 TEST(BeginFrameObserverMultiplexerTest, ObserverManipulation) {
237 scoped_ptr<BeginFrameObserverMultiplexer> obs =
238 BeginFrameObserverMultiplexer::Create();
239
240 ::testing::StrictMock<MockMinimalBeginFrameObserverMixIn> obs_child1;
241 ::testing::StrictMock<MockMinimalBeginFrameObserverMixIn> obs_child2;
242
243 // Initial conditions
244 EXPECT_EQ(BeginFrameArgs(), obs->LastUsedBeginFrameArgs());
245
246 // Calling without any observers, should be fine
247 BeginFrameArgs args1 =
248 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 100, 200, 300);
249 obs->OnBeginFrame(args1);
250 EXPECT_EQ(args1, obs->LastUsedBeginFrameArgs());
251
252 // Adding an observer triggers a MISSED frame for that observer if they have
253 // never receive the BeginFrameArgs before.
254 EXPECT_CALL(obs_child1,
255 OnBeginFrameMixInDelegate(CreateBeginFrameArgsForTesting(
256 BEGINFRAME_FROM_HERE, 100, 200, 300, BeginFrameArgs::MISSED)))
257 .WillOnce(::testing::Return(true));
258 obs->AddObserver(&obs_child1);
259
260 #ifndef NDEBUG
261 EXPECT_DEATH({ obs->AddObserver(&obs_child1); }, "");
262
263 EXPECT_DEATH({ obs->RemoveObserver(&obs_child2); }, "");
264 #endif
265
266 EXPECT_CALL(obs_child2,
267 OnBeginFrameMixInDelegate(CreateBeginFrameArgsForTesting(
268 BEGINFRAME_FROM_HERE, 100, 200, 300, BeginFrameArgs::MISSED)))
269 .WillOnce(::testing::Return(false));
270 obs->AddObserver(&obs_child2);
271
272 // Re-adding the observer shouldn't cause OnBeginFrame to get called again if
273 // it was used.
274 obs->RemoveObserver(&obs_child1);
275 obs->AddObserver(&obs_child1);
276
277 // This observer dropped the last missed frames so should get it again.
278 EXPECT_CALL(obs_child2,
279 OnBeginFrameMixInDelegate(CreateBeginFrameArgsForTesting(
280 BEGINFRAME_FROM_HERE, 100, 200, 300, BeginFrameArgs::MISSED)))
281 .WillOnce(::testing::Return(false));
282 obs->RemoveObserver(&obs_child2);
283 obs->AddObserver(&obs_child2);
284 }
285
286 TEST(BeginFrameObserverMultiplexerTest, HasObserverCallback) {
287 {
288 ::testing::StrictMock<MockHasObserversCallback> cb;
289 EXPECT_CALL(cb, Callback(false));
290
291 scoped_ptr<BeginFrameObserverMultiplexer> obs =
292 BeginFrameObserverMultiplexer::Create();
293 obs->SetHasObserverCallback(cb.Get());
294 }
295
296 {
297 ::testing::StrictMock<MockHasObserversCallback> cb;
298 EXPECT_CALL(cb, Callback(true));
299 EXPECT_CALL(cb, Callback(false)); // Destructor
300
301 scoped_ptr<BeginFrameObserverMultiplexer> obs =
302 BeginFrameObserverMultiplexer::Create();
303 MockMinimalBeginFrameObserverMixIn obs_child;
304 obs->AddObserver(&obs_child);
305 obs->SetHasObserverCallback(cb.Get());
306 }
307
308 {
309 ::testing::InSequence ordered;
310
311 ::testing::StrictMock<MockHasObserversCallback> cb;
312 EXPECT_CALL(cb, Callback(false));
313 EXPECT_CALL(cb, Callback(true));
314 EXPECT_CALL(cb, Callback(false));
315
316 scoped_ptr<BeginFrameObserverMultiplexer> obs =
317 BeginFrameObserverMultiplexer::Create();
318 MockMinimalBeginFrameObserverMixIn obs_child;
319 obs->SetHasObserverCallback(cb.Get());
320 obs->AddObserver(&obs_child);
321 obs->RemoveObserver(&obs_child);
322 }
323
324 {
325 ::testing::InSequence ordered;
326
327 ::testing::StrictMock<MockHasObserversCallback> cb;
328 EXPECT_CALL(cb, Callback(false));
329 EXPECT_CALL(cb, Callback(true));
330 EXPECT_CALL(cb, Callback(false));
331
332 scoped_ptr<BeginFrameObserverMultiplexer> obs =
333 BeginFrameObserverMultiplexer::Create();
334 MockMinimalBeginFrameObserverMixIn obs_child1;
335 MockMinimalBeginFrameObserverMixIn obs_child2;
336 obs->SetHasObserverCallback(cb.Get());
337 obs->AddObserver(&obs_child1);
338 obs->AddObserver(&obs_child2);
339 obs->RemoveObserver(&obs_child1);
340 obs->RemoveObserver(&obs_child2);
341 }
342
343 {
344 ::testing::InSequence ordered;
345 ::testing::StrictMock<MockHasObserversCallback> cb1;
346 EXPECT_CALL(cb1, Callback(false));
347 EXPECT_CALL(cb1, Callback(true));
348 EXPECT_CALL(cb1, Callback(false));
349
350 ::testing::StrictMock<MockHasObserversCallback> cb2;
351 EXPECT_CALL(cb2, Callback(true));
352 EXPECT_CALL(cb2, Callback(false));
353
354 ::testing::StrictMock<MockHasObserversCallback> cb3;
355 EXPECT_CALL(cb3, Callback(false));
356
357 scoped_ptr<BeginFrameObserverMultiplexer> obs =
358 BeginFrameObserverMultiplexer::Create();
359 MockMinimalBeginFrameObserverMixIn obs_child;
360 obs->SetHasObserverCallback(cb1.Get());
361 obs->AddObserver(&obs_child);
362 obs->SetHasObserverCallback(cb2.Get());
363 obs->RemoveObserver(&obs_child);
364 obs->SetHasObserverCallback(cb3.Get());
365 }
366 }
367
368 TEST(BeginFrameObserverMultiplexerTest, OnBeginFrame) {
369 scoped_ptr<BeginFrameObserverMultiplexer> obs =
370 BeginFrameObserverMultiplexer::Create();
371
372 MockBeginFrameObserver obs_child1;
373 EXPECT_BEGIN_FRAME_USED(obs_child1, 100, 200, 300);
374 EXPECT_BEGIN_FRAME_USED(obs_child1, 400, 600, 300);
375 MockBeginFrameObserver obs_child2;
376 EXPECT_CALL(obs_child2,
377 OnBeginFrame(CreateBeginFrameArgsForTesting(
378 BEGINFRAME_FROM_HERE, 100, 200, 300, BeginFrameArgs::MISSED)))
379 .InSequence(obs_child2.sequence);
380 EXPECT_BEGIN_FRAME_USED(obs_child2, 400, 600, 300);
381 EXPECT_BEGIN_FRAME_USED(obs_child2, 700, 800, 300);
382
383 obs->AddObserver(&obs_child1);
384 obs->OnBeginFrame(
385 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 100, 200, 300));
386 obs->AddObserver(&obs_child2);
387 obs->OnBeginFrame(
388 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 400, 600, 300));
389 obs->RemoveObserver(&obs_child1);
390 obs->OnBeginFrame(
391 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 700, 800, 300));
392 }
393
224 // BeginFrameSource testing ---------------------------------------------- 394 // BeginFrameSource testing ----------------------------------------------
225 TEST(BeginFrameSourceMixInTest, ObserverManipulation) { 395 TEST(BeginFrameSourceMixInTest, ObserverManipulation) {
226 MockBeginFrameObserver obs; 396 MockBeginFrameObserver obs;
227 MockBeginFrameObserver otherObs; 397 MockBeginFrameObserver otherObs;
228 FakeBeginFrameSource source; 398 FakeBeginFrameSource source;
229 399
230 source.AddObserver(&obs); 400 source.AddObserver(&obs);
231 EXPECT_EQ(&obs, source.GetObserver()); 401 EXPECT_EQ(&obs, source.GetObserver());
232 402
233 #ifndef NDEBUG 403 #ifndef NDEBUG
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 mux_->SetActiveSource(source2_); 936 mux_->SetActiveSource(source2_);
767 SEND_BEGIN_FRAME_DROP(*source2_, 750, 1050, 300); 937 SEND_BEGIN_FRAME_DROP(*source2_, 750, 1050, 300);
768 SEND_BEGIN_FRAME_USED(*source2_, 1050, 1250, 300); 938 SEND_BEGIN_FRAME_USED(*source2_, 1050, 1250, 300);
769 939
770 mux_->SetActiveSource(source1_); 940 mux_->SetActiveSource(source1_);
771 SEND_BEGIN_FRAME_DROP(*source2_, 1100, 1400, 300); 941 SEND_BEGIN_FRAME_DROP(*source2_, 1100, 1400, 300);
772 } 942 }
773 943
774 } // namespace 944 } // namespace
775 } // namespace cc 945 } // namespace cc
OLDNEW
« 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