| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // When used LastUsedBeginFrameArgs **should** be updated. | 55 // When used LastUsedBeginFrameArgs **should** be updated. |
| 56 #define SEND_BEGIN_FRAME_USED(source, frame_time, deadline, interval) \ | 56 #define SEND_BEGIN_FRAME_USED(source, frame_time, deadline, interval) \ |
| 57 SEND_BEGIN_FRAME(new_args, source, frame_time, deadline, interval); | 57 SEND_BEGIN_FRAME(new_args, source, frame_time, deadline, interval); |
| 58 | 58 |
| 59 namespace cc { | 59 namespace cc { |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 class MockBeginFrameObserver : public BeginFrameObserver { | 62 class MockBeginFrameObserver : public BeginFrameObserver { |
| 63 public: | 63 public: |
| 64 MOCK_METHOD1(OnBeginFrame, void(const BeginFrameArgs&)); | 64 MOCK_METHOD1(OnBeginFrame, void(const BeginFrameArgs&)); |
| 65 MOCK_CONST_METHOD0(LastUsedBeginFrameArgs, const BeginFrameArgs()); | 65 MOCK_METHOD0(LastUsedBeginFrameArgs, const BeginFrameArgs()); |
| 66 | 66 |
| 67 virtual void AsValueInto(base::trace_event::TracedValue* dict) const { | 67 virtual void AsValueInto(base::trace_event::TracedValue* dict) { |
| 68 dict->SetString("type", "MockBeginFrameObserver"); | 68 dict->SetString("type", "MockBeginFrameObserver"); |
| 69 dict->BeginDictionary("last_begin_frame_args"); | 69 dict->BeginDictionary("last_begin_frame_args"); |
| 70 LastUsedBeginFrameArgs().AsValueInto(dict); | 70 LastUsedBeginFrameArgs().AsValueInto(dict); |
| 71 dict->EndDictionary(); | 71 dict->EndDictionary(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // A value different from the normal default returned by a BeginFrameObserver | 74 // A value different from the normal default returned by a BeginFrameObserver |
| 75 // so it is easiable traced back here. | 75 // so it is easiable traced back here. |
| 76 static const BeginFrameArgs kDefaultBeginFrameArgs; | 76 static const BeginFrameArgs kDefaultBeginFrameArgs; |
| 77 | 77 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // BeginFrameSource testing ---------------------------------------------- | 224 // BeginFrameSource testing ---------------------------------------------- |
| 225 TEST(BeginFrameSourceMixInTest, ObserverManipulation) { | 225 TEST(BeginFrameSourceMixInTest, 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 30 matching lines...) Expand all Loading... |
| 277 source.SetNeedsBeginFrames(true); | 274 source.SetNeedsBeginFrames(true); |
| 278 EXPECT_TRUE(source.NeedsBeginFrames()); | 275 EXPECT_TRUE(source.NeedsBeginFrames()); |
| 279 source.SetNeedsBeginFrames(false); | 276 source.SetNeedsBeginFrames(false); |
| 280 EXPECT_FALSE(source.NeedsBeginFrames()); | 277 EXPECT_FALSE(source.NeedsBeginFrames()); |
| 281 } | 278 } |
| 282 | 279 |
| 283 class LoopingBeginFrameObserver : public BeginFrameObserverMixIn { | 280 class LoopingBeginFrameObserver : public BeginFrameObserverMixIn { |
| 284 public: | 281 public: |
| 285 BeginFrameSource* source_; | 282 BeginFrameSource* source_; |
| 286 | 283 |
| 287 void AsValueInto(base::trace_event::TracedValue* dict) const override { | 284 void AsValueInto(base::trace_event::TracedValue* dict) override { |
| 288 dict->SetString("type", "LoopingBeginFrameObserver"); | 285 dict->SetString("type", "LoopingBeginFrameObserver"); |
| 289 dict->BeginDictionary("source"); | 286 dict->BeginDictionary("source"); |
| 290 source_->AsValueInto(dict); | 287 source_->AsValueInto(dict); |
| 291 dict->EndDictionary(); | 288 dict->EndDictionary(); |
| 292 } | 289 } |
| 293 | 290 |
| 294 protected: | 291 protected: |
| 295 // BeginFrameObserverMixIn | 292 // BeginFrameObserverMixIn |
| 296 bool OnBeginFrameMixInDelegate(const BeginFrameArgs& args) override { | 293 bool OnBeginFrameMixInDelegate(const BeginFrameArgs& args) override { |
| 297 return true; | 294 return true; |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 mux_->SetActiveSource(source2_); | 763 mux_->SetActiveSource(source2_); |
| 767 SEND_BEGIN_FRAME_DROP(*source2_, 750, 1050, 300); | 764 SEND_BEGIN_FRAME_DROP(*source2_, 750, 1050, 300); |
| 768 SEND_BEGIN_FRAME_USED(*source2_, 1050, 1250, 300); | 765 SEND_BEGIN_FRAME_USED(*source2_, 1050, 1250, 300); |
| 769 | 766 |
| 770 mux_->SetActiveSource(source1_); | 767 mux_->SetActiveSource(source1_); |
| 771 SEND_BEGIN_FRAME_DROP(*source2_, 1100, 1400, 300); | 768 SEND_BEGIN_FRAME_DROP(*source2_, 1100, 1400, 300); |
| 772 } | 769 } |
| 773 | 770 |
| 774 } // namespace | 771 } // namespace |
| 775 } // namespace cc | 772 } // namespace cc |
| OLD | NEW |