OLD | NEW |
---|---|
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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 // BeginFrameSource testing ---------------------------------------------- | 224 // BeginFrameSource testing ---------------------------------------------- |
225 TEST(BeginFrameSourceBaseTest, ObserverManipulation) { | 225 TEST(BeginFrameSourceBaseTest, ObserverManipulation) { |
226 MockBeginFrameObserver obs; | 226 MockBeginFrameObserver obs; |
227 MockBeginFrameObserver otherObs; | 227 MockBeginFrameObserver otherObs; |
228 FakeBeginFrameSource source; | 228 FakeBeginFrameSource source; |
229 | 229 |
230 source.AddObserver(&obs); | 230 source.AddObserver(&obs); |
231 EXPECT_EQ(&obs, source.GetObserver()); | 231 EXPECT_EQ(&obs, source.GetObserver()); |
232 | 232 |
233 #ifndef NDEBUG | 233 #ifndef NDEBUG |
234 // Adding an observer when an observer already exists should DCHECK fail. | |
235 EXPECT_DEATH({ source.AddObserver(&otherObs); }, ""); | |
236 | |
237 // Removing wrong observer should DCHECK fail. | 234 // Removing wrong observer should DCHECK fail. |
238 EXPECT_DEATH({ source.RemoveObserver(&otherObs); }, ""); | 235 EXPECT_DEATH({ source.RemoveObserver(&otherObs); }, ""); |
239 | 236 |
240 // Removing an observer when there is no observer should DCHECK fail. | 237 // Removing an observer when there is no observer should DCHECK fail. |
241 EXPECT_DEATH({ | 238 EXPECT_DEATH({ |
242 source.RemoveObserver(&obs); | 239 source.RemoveObserver(&obs); |
243 source.RemoveObserver(&obs); | 240 source.RemoveObserver(&obs); |
244 }, | 241 }, |
245 ""); | 242 ""); |
246 #endif | 243 #endif |
(...skipping 17 matching lines...) Expand all Loading... | |
264 SEND_BEGIN_FRAME_DROP(source, 400, 600, 300); | 261 SEND_BEGIN_FRAME_DROP(source, 400, 600, 300); |
265 SEND_BEGIN_FRAME_DROP(source, 450, 650, 300); | 262 SEND_BEGIN_FRAME_DROP(source, 450, 650, 300); |
266 SEND_BEGIN_FRAME_USED(source, 700, 900, 300); | 263 SEND_BEGIN_FRAME_USED(source, 700, 900, 300); |
267 } | 264 } |
268 | 265 |
269 TEST(BeginFrameSourceBaseTest, NoObserver) { | 266 TEST(BeginFrameSourceBaseTest, NoObserver) { |
270 FakeBeginFrameSource source; | 267 FakeBeginFrameSource source; |
271 SEND_BEGIN_FRAME_DROP(source, 100, 200, 300); | 268 SEND_BEGIN_FRAME_DROP(source, 100, 200, 300); |
272 } | 269 } |
273 | 270 |
271 TEST(BeginFrameSourceBaseTest, ObserverMulti) { | |
brianderson
2015/09/12 00:23:50
Looks like the same test as ObserverMultiSimple?
| |
272 MockBeginFrameObserver obs; | |
273 MockBeginFrameObserver otherObs; | |
274 FakeBeginFrameSource source; | |
275 | |
276 EXPECT_BEGIN_FRAME_USED(obs, 100, 200, 300); | |
277 EXPECT_BEGIN_FRAME_USED(obs, 400, 600, 300); | |
278 EXPECT_BEGIN_FRAME_USED(obs, 450, 650, 300); | |
279 EXPECT_BEGIN_FRAME_USED(obs, 700, 900, 300); | |
280 | |
281 EXPECT_BEGIN_FRAME_USED(otherObs, 400, 600, 300); | |
282 EXPECT_BEGIN_FRAME_USED(otherObs, 450, 650, 300); | |
283 | |
284 source.AddObserver(&obs); | |
285 SEND_BEGIN_FRAME_USED(source, 100, 200, 300); | |
286 source.AddObserver(&otherObs); | |
287 SEND_BEGIN_FRAME_USED(source, 400, 600, 300); | |
288 SEND_BEGIN_FRAME_USED(source, 450, 650, 300); | |
289 source.RemoveObserver(&otherObs); | |
290 SEND_BEGIN_FRAME_USED(source, 700, 900, 300); | |
291 } | |
292 | |
293 TEST(BeginFrameSourceBaseTest, ObserverMultiSimple) { | |
294 MockBeginFrameObserver obs; | |
295 MockBeginFrameObserver otherObs; | |
296 FakeBeginFrameSource source; | |
297 | |
298 EXPECT_BEGIN_FRAME_USED(obs, 100, 200, 300); | |
299 EXPECT_BEGIN_FRAME_USED(obs, 400, 600, 300); | |
300 EXPECT_BEGIN_FRAME_USED(obs, 450, 650, 300); | |
301 EXPECT_BEGIN_FRAME_USED(obs, 700, 900, 300); | |
302 | |
303 EXPECT_BEGIN_FRAME_USED(otherObs, 400, 600, 300); | |
304 EXPECT_BEGIN_FRAME_USED(otherObs, 450, 650, 300); | |
305 | |
306 source.AddObserver(&obs); | |
307 SEND_BEGIN_FRAME_USED(source, 100, 200, 300); | |
308 source.AddObserver(&otherObs); | |
309 SEND_BEGIN_FRAME_USED(source, 400, 600, 300); | |
310 SEND_BEGIN_FRAME_USED(source, 450, 650, 300); | |
311 source.RemoveObserver(&otherObs); | |
312 SEND_BEGIN_FRAME_USED(source, 700, 900, 300); | |
313 | |
314 scoped_refptr<base::trace_event::TracedValue> state1 = | |
315 new base::trace_event::TracedValue(); | |
316 source.AsValueInto(state1.get()); | |
317 | |
318 source.AddObserver(&otherObs); | |
319 scoped_refptr<base::trace_event::TracedValue> state2 = | |
320 new base::trace_event::TracedValue(); | |
321 source.AsValueInto(state2.get()); | |
322 } | |
323 | |
324 class RemovingBeginFrameObserver : public BeginFrameObserverBase { | |
325 public: | |
326 explicit RemovingBeginFrameObserver(BeginFrameSource* bfs) : source_(bfs) {} | |
327 | |
328 protected: | |
329 // BeginFrameObserverBase | |
330 bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) override { | |
331 source_->RemoveObserver(this); | |
332 return true; | |
333 } | |
334 | |
335 BeginFrameSource* source_; | |
336 }; | |
337 | |
338 TEST(BeginFrameSourceBaseTest, ObserverMultiRemoveOnBeginFrame) { | |
brianderson
2015/09/12 00:23:50
If you are going to add a WillLoseBeginFrameSource
| |
339 MockBeginFrameObserver obs; | |
340 FakeBeginFrameSource source; | |
341 RemovingBeginFrameObserver otherObs(&source); | |
342 | |
343 EXPECT_BEGIN_FRAME_USED(obs, 100, 200, 300); | |
344 EXPECT_BEGIN_FRAME_USED(obs, 400, 600, 300); | |
345 EXPECT_BEGIN_FRAME_USED(obs, 700, 900, 300); | |
346 | |
347 source.AddObserver(&obs); | |
348 SEND_BEGIN_FRAME_USED(source, 100, 200, 300); | |
349 source.AddObserver(&otherObs); | |
350 SEND_BEGIN_FRAME_USED(source, 400, 600, 300); | |
351 SEND_BEGIN_FRAME_USED(source, 700, 900, 300); | |
352 EXPECT_EQ( | |
353 otherObs.LastUsedBeginFrameArgs(), | |
354 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 400, 600, 300)); | |
355 } | |
356 | |
274 TEST(BeginFrameSourceBaseTest, NeedsBeginFrames) { | 357 TEST(BeginFrameSourceBaseTest, NeedsBeginFrames) { |
275 FakeBeginFrameSource source; | 358 FakeBeginFrameSource source; |
276 EXPECT_FALSE(source.NeedsBeginFrames()); | 359 EXPECT_FALSE(source.NeedsBeginFrames()); |
277 source.SetNeedsBeginFrames(true); | 360 source.SetNeedsBeginFrames(true); |
278 EXPECT_TRUE(source.NeedsBeginFrames()); | 361 EXPECT_TRUE(source.NeedsBeginFrames()); |
279 source.SetNeedsBeginFrames(false); | 362 source.SetNeedsBeginFrames(false); |
280 EXPECT_FALSE(source.NeedsBeginFrames()); | 363 EXPECT_FALSE(source.NeedsBeginFrames()); |
281 } | 364 } |
282 | 365 |
283 class LoopingBeginFrameObserver : public BeginFrameObserverBase { | 366 class LoopingBeginFrameObserver : public BeginFrameObserverBase { |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 mux_->SetActiveSource(source2_); | 853 mux_->SetActiveSource(source2_); |
771 SEND_BEGIN_FRAME_DROP(*source2_, 750, 1050, 300); | 854 SEND_BEGIN_FRAME_DROP(*source2_, 750, 1050, 300); |
772 SEND_BEGIN_FRAME_USED(*source2_, 1050, 1250, 300); | 855 SEND_BEGIN_FRAME_USED(*source2_, 1050, 1250, 300); |
773 | 856 |
774 mux_->SetActiveSource(source1_); | 857 mux_->SetActiveSource(source1_); |
775 SEND_BEGIN_FRAME_DROP(*source2_, 1100, 1400, 300); | 858 SEND_BEGIN_FRAME_DROP(*source2_, 1100, 1400, 300); |
776 } | 859 } |
777 | 860 |
778 } // namespace | 861 } // namespace |
779 } // namespace cc | 862 } // namespace cc |
OLD | NEW |