| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "media/filters/pipeline_controller.h" | 5 #include "media/filters/pipeline_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 class PipelineControllerTest : public ::testing::Test, public Pipeline::Client { | 32 class PipelineControllerTest : public ::testing::Test, public Pipeline::Client { |
| 33 public: | 33 public: |
| 34 PipelineControllerTest() | 34 PipelineControllerTest() |
| 35 : pipeline_controller_(&pipeline_, | 35 : pipeline_controller_(&pipeline_, |
| 36 base::Bind(&PipelineControllerTest::CreateRenderer, | 36 base::Bind(&PipelineControllerTest::CreateRenderer, |
| 37 base::Unretained(this)), | 37 base::Unretained(this)), |
| 38 base::Bind(&PipelineControllerTest::OnSeeked, | 38 base::Bind(&PipelineControllerTest::OnSeeked, |
| 39 base::Unretained(this)), | 39 base::Unretained(this)), |
| 40 base::Bind(&PipelineControllerTest::OnSuspended, | 40 base::Bind(&PipelineControllerTest::OnSuspended, |
| 41 base::Unretained(this)), | 41 base::Unretained(this)), |
| 42 base::Bind(&PipelineControllerTest::OnBeforeResume, |
| 43 base::Unretained(this)), |
| 44 base::Bind(&PipelineControllerTest::OnResumed, |
| 45 base::Unretained(this)), |
| 42 base::Bind(&PipelineControllerTest::OnError, | 46 base::Bind(&PipelineControllerTest::OnError, |
| 43 base::Unretained(this))) {} | 47 base::Unretained(this))) {} |
| 44 | 48 |
| 45 ~PipelineControllerTest() override {} | 49 ~PipelineControllerTest() override {} |
| 46 | 50 |
| 47 PipelineStatusCB StartPipeline(bool is_streaming, bool is_static) { | 51 PipelineStatusCB StartPipeline(bool is_streaming, bool is_static) { |
| 48 EXPECT_FALSE(pipeline_controller_.IsStable()); | 52 EXPECT_FALSE(pipeline_controller_.IsStable()); |
| 49 PipelineStatusCB start_cb; | 53 PipelineStatusCB start_cb; |
| 50 EXPECT_CALL(pipeline_, Start(_, _, _, _)).WillOnce(SaveArg<3>(&start_cb)); | 54 EXPECT_CALL(pipeline_, Start(_, _, _, _)).WillOnce(SaveArg<3>(&start_cb)); |
| 51 pipeline_controller_.Start(&demuxer_, this, is_streaming, is_static); | 55 pipeline_controller_.Start(&demuxer_, this, is_streaming, is_static); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 std::unique_ptr<Renderer> CreateRenderer() { | 115 std::unique_ptr<Renderer> CreateRenderer() { |
| 112 return std::unique_ptr<Renderer>(); | 116 return std::unique_ptr<Renderer>(); |
| 113 } | 117 } |
| 114 | 118 |
| 115 void OnSeeked(bool time_updated) { | 119 void OnSeeked(bool time_updated) { |
| 116 was_seeked_ = true; | 120 was_seeked_ = true; |
| 117 last_seeked_time_updated_ = time_updated; | 121 last_seeked_time_updated_ = time_updated; |
| 118 } | 122 } |
| 119 | 123 |
| 120 void OnSuspended() { was_suspended_ = true; } | 124 void OnSuspended() { was_suspended_ = true; } |
| 125 void OnBeforeResume() { was_resuming_ = true; } |
| 126 void OnResumed() { was_resumed_ = true; } |
| 121 | 127 |
| 122 // Pipeline::Client overrides | 128 // Pipeline::Client overrides |
| 123 void OnError(PipelineStatus status) override { NOTREACHED(); } | 129 void OnError(PipelineStatus status) override { NOTREACHED(); } |
| 124 void OnEnded() override {} | 130 void OnEnded() override {} |
| 125 void OnMetadata(PipelineMetadata metadata) override {} | 131 void OnMetadata(PipelineMetadata metadata) override {} |
| 126 void OnBufferingStateChange(BufferingState state) override {} | 132 void OnBufferingStateChange(BufferingState state) override {} |
| 127 void OnDurationChange() override {} | 133 void OnDurationChange() override {} |
| 128 void OnAddTextTrack(const TextTrackConfig& config, | 134 void OnAddTextTrack(const TextTrackConfig& config, |
| 129 const AddTextTrackDoneCB& done_cb) override {} | 135 const AddTextTrackDoneCB& done_cb) override {} |
| 130 void OnWaitingForDecryptionKey() override {} | 136 void OnWaitingForDecryptionKey() override {} |
| 131 void OnVideoNaturalSizeChange(const gfx::Size& size) override {} | 137 void OnVideoNaturalSizeChange(const gfx::Size& size) override {} |
| 132 void OnVideoOpacityChange(bool opaque) override {} | 138 void OnVideoOpacityChange(bool opaque) override {} |
| 133 | 139 |
| 134 base::MessageLoop message_loop_; | 140 base::MessageLoop message_loop_; |
| 135 | 141 |
| 136 NiceMock<MockDemuxer> demuxer_; | 142 NiceMock<MockDemuxer> demuxer_; |
| 137 StrictMock<MockPipeline> pipeline_; | 143 StrictMock<MockPipeline> pipeline_; |
| 138 PipelineController pipeline_controller_; | 144 PipelineController pipeline_controller_; |
| 139 | 145 |
| 140 bool was_seeked_ = false; | 146 bool was_seeked_ = false; |
| 141 bool last_seeked_time_updated_ = false; | 147 bool last_seeked_time_updated_ = false; |
| 142 bool was_suspended_ = false; | 148 bool was_suspended_ = false; |
| 149 bool was_resuming_ = false; |
| 150 bool was_resumed_ = false; |
| 143 base::TimeDelta last_resume_time_; | 151 base::TimeDelta last_resume_time_; |
| 144 | 152 |
| 145 DISALLOW_COPY_AND_ASSIGN(PipelineControllerTest); | 153 DISALLOW_COPY_AND_ASSIGN(PipelineControllerTest); |
| 146 }; | 154 }; |
| 147 | 155 |
| 148 TEST_F(PipelineControllerTest, Startup) { | 156 TEST_F(PipelineControllerTest, Startup) { |
| 149 PipelineStatusCB start_cb = StartPipeline(); | 157 PipelineStatusCB start_cb = StartPipeline(); |
| 150 EXPECT_FALSE(was_seeked_); | 158 EXPECT_FALSE(was_seeked_); |
| 151 | 159 |
| 152 Complete(start_cb); | 160 Complete(start_cb); |
| 153 EXPECT_TRUE(was_seeked_); | 161 EXPECT_TRUE(was_seeked_); |
| 154 EXPECT_FALSE(last_seeked_time_updated_); | 162 EXPECT_FALSE(last_seeked_time_updated_); |
| 155 EXPECT_FALSE(was_suspended_); | 163 EXPECT_FALSE(was_suspended_); |
| 156 EXPECT_TRUE(pipeline_controller_.IsStable()); | 164 EXPECT_TRUE(pipeline_controller_.IsStable()); |
| 157 } | 165 } |
| 158 | 166 |
| 159 TEST_F(PipelineControllerTest, SuspendResume) { | 167 TEST_F(PipelineControllerTest, SuspendResume) { |
| 160 Complete(StartPipeline()); | 168 Complete(StartPipeline()); |
| 161 EXPECT_TRUE(was_seeked_); | 169 EXPECT_TRUE(was_seeked_); |
| 162 was_seeked_ = false; | 170 was_seeked_ = false; |
| 163 | 171 |
| 164 Complete(SuspendPipeline()); | 172 Complete(SuspendPipeline()); |
| 165 EXPECT_TRUE(was_suspended_); | 173 EXPECT_TRUE(was_suspended_); |
| 166 EXPECT_FALSE(pipeline_controller_.IsStable()); | 174 EXPECT_FALSE(pipeline_controller_.IsStable()); |
| 167 | 175 |
| 168 Complete(ResumePipeline()); | 176 PipelineStatusCB resume_cb = ResumePipeline(); |
| 177 EXPECT_TRUE(was_resuming_); |
| 178 EXPECT_FALSE(was_resumed_); |
| 179 |
| 180 Complete(resume_cb); |
| 181 EXPECT_TRUE(was_resumed_); |
| 169 EXPECT_TRUE(pipeline_controller_.IsStable()); | 182 EXPECT_TRUE(pipeline_controller_.IsStable()); |
| 170 | 183 |
| 171 // |was_seeked_| should not be affected by Suspend()/Resume() at all. | 184 // |was_seeked_| should not be affected by Suspend()/Resume() at all. |
| 172 EXPECT_FALSE(was_seeked_); | 185 EXPECT_FALSE(was_seeked_); |
| 173 } | 186 } |
| 174 | 187 |
| 175 TEST_F(PipelineControllerTest, Seek) { | 188 TEST_F(PipelineControllerTest, Seek) { |
| 176 // Normal seeking should not result in a cancel. | 189 // Normal seeking should not result in a cancel. |
| 177 EXPECT_CALL(demuxer_, CancelPendingSeek(_)).Times(0); | 190 EXPECT_CALL(demuxer_, CancelPendingSeek(_)).Times(0); |
| 178 | 191 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // Request a seek to the same time again. | 332 // Request a seek to the same time again. |
| 320 pipeline_controller_.Seek(seek_time, true); | 333 pipeline_controller_.Seek(seek_time, true); |
| 321 base::RunLoop().RunUntilIdle(); | 334 base::RunLoop().RunUntilIdle(); |
| 322 | 335 |
| 323 // Expect the second seek to trigger when the first seek completes. | 336 // Expect the second seek to trigger when the first seek completes. |
| 324 EXPECT_CALL(pipeline_, Seek(seek_time, _)); | 337 EXPECT_CALL(pipeline_, Seek(seek_time, _)); |
| 325 Complete(seek_cb_1); | 338 Complete(seek_cb_1); |
| 326 } | 339 } |
| 327 | 340 |
| 328 } // namespace media | 341 } // namespace media |
| OLD | NEW |