Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
|
DaleCurtis
2016/02/25 01:58:30
No (c) these days.
sandersd (OOO until July 31)
2016/02/25 20:33:46
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "base/bind_helpers.h" | |
| 7 #include "base/logging.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/time/time.h" | |
| 12 #include "media/base/mock_filters.h" | |
| 13 #include "media/base/pipeline.h" | |
| 14 #include "media/filters/pipeline_controller.h" | |
| 15 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 using ::testing::_; | |
|
DaleCurtis
2016/02/25 01:58:30
We generally elide the first ::
sandersd (OOO until July 31)
2016/02/25 20:33:46
That seems to be just you.
(And separately I have
DaleCurtis
2016/02/26 02:59:34
3652 hits
https://code.google.com/p/chromium/codes
sandersd (OOO until July 31)
2016/02/26 22:10:48
https://code.google.com/p/chromium/codesearch#sear
| |
| 19 using ::testing::DoAll; | |
| 20 using ::testing::Mock; | |
| 21 using ::testing::Return; | |
| 22 using ::testing::SaveArg; | |
| 23 using ::testing::StrictMock; | |
| 24 | |
| 25 namespace media { | |
| 26 | |
| 27 class PipelineControllerTest : public ::testing::Test { | |
| 28 public: | |
| 29 PipelineControllerTest() | |
| 30 : pipeline_controller_(&pipeline_, | |
| 31 base::Bind(&PipelineControllerTest::CreateRenderer, | |
| 32 base::Unretained(this)), | |
| 33 base::Bind(&PipelineControllerTest::OnSeeked, | |
| 34 base::Unretained(this)), | |
| 35 base::Bind(&PipelineControllerTest::OnSuspended, | |
| 36 base::Unretained(this)), | |
| 37 base::Bind(&PipelineControllerTest::OnError, | |
| 38 base::Unretained(this))) {} | |
| 39 | |
| 40 ~PipelineControllerTest() override {} | |
| 41 | |
| 42 PipelineStatusCB StartPipeline() { | |
| 43 EXPECT_FALSE(pipeline_controller_.IsStable()); | |
| 44 PipelineStatusCB start_cb; | |
| 45 EXPECT_CALL(pipeline_, Start(_, _, _, _, _, _, _, _, _, _)) | |
| 46 .WillOnce(SaveArg<4>(&start_cb)); | |
| 47 pipeline_controller_.Start( | |
| 48 nullptr, nullptr, false, base::Closure(), PipelineMetadataCB(), | |
| 49 BufferingStateCB(), base::Closure(), AddTextTrackCB(), base::Closure()); | |
| 50 Mock::VerifyAndClear(&pipeline_); | |
| 51 EXPECT_FALSE(pipeline_controller_.IsStable()); | |
| 52 return start_cb; | |
| 53 } | |
| 54 | |
| 55 PipelineStatusCB SeekPipeline(base::TimeDelta time) { | |
| 56 EXPECT_TRUE(pipeline_controller_.IsStable()); | |
| 57 PipelineStatusCB seek_cb; | |
| 58 EXPECT_CALL(pipeline_, Seek(time, _)).WillOnce(SaveArg<1>(&seek_cb)); | |
| 59 pipeline_controller_.Seek(time, true); | |
| 60 Mock::VerifyAndClear(&pipeline_); | |
| 61 EXPECT_FALSE(pipeline_controller_.IsStable()); | |
| 62 return seek_cb; | |
| 63 } | |
| 64 | |
| 65 PipelineStatusCB SuspendPipeline() { | |
| 66 EXPECT_TRUE(pipeline_controller_.IsStable()); | |
| 67 PipelineStatusCB suspend_cb; | |
| 68 EXPECT_CALL(pipeline_, Suspend(_)).WillOnce(SaveArg<0>(&suspend_cb)); | |
| 69 pipeline_controller_.Suspend(); | |
| 70 Mock::VerifyAndClear(&pipeline_); | |
| 71 EXPECT_FALSE(pipeline_controller_.IsStable()); | |
| 72 EXPECT_FALSE(pipeline_controller_.IsSuspended()); | |
| 73 return suspend_cb; | |
| 74 } | |
| 75 | |
| 76 PipelineStatusCB ResumePipeline() { | |
| 77 EXPECT_TRUE(pipeline_controller_.IsSuspended()); | |
| 78 PipelineStatusCB resume_cb; | |
| 79 EXPECT_CALL(pipeline_, Resume(_, _, _)) | |
| 80 .WillOnce( | |
| 81 DoAll(SaveArg<1>(&last_resume_time_), SaveArg<2>(&resume_cb))); | |
| 82 EXPECT_CALL(pipeline_, GetMediaTime()) | |
| 83 .WillRepeatedly(Return(base::TimeDelta())); | |
| 84 pipeline_controller_.Resume(); | |
| 85 Mock::VerifyAndClear(&pipeline_); | |
| 86 EXPECT_FALSE(pipeline_controller_.IsStable()); | |
| 87 EXPECT_FALSE(pipeline_controller_.IsSuspended()); | |
| 88 return resume_cb; | |
| 89 } | |
| 90 | |
| 91 protected: | |
| 92 scoped_ptr<Renderer> CreateRenderer() { return scoped_ptr<Renderer>(); } | |
| 93 | |
| 94 void OnSeeked(bool time_updated) {} | |
|
DaleCurtis
2016/02/25 01:58:30
Seems you might want to verify these two?
sandersd (OOO until July 31)
2016/02/25 20:33:46
Done.
| |
| 95 | |
| 96 void OnSuspended() {} | |
| 97 | |
| 98 void OnError(PipelineStatus status) { NOTREACHED(); } | |
| 99 | |
| 100 StrictMock<MockPipeline> pipeline_; | |
| 101 PipelineController pipeline_controller_; | |
| 102 base::TimeDelta last_resume_time_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(PipelineControllerTest); | |
| 105 }; | |
| 106 | |
| 107 TEST_F(PipelineControllerTest, SuspendResume) { | |
| 108 StartPipeline().Run(PIPELINE_OK); | |
| 109 SuspendPipeline().Run(PIPELINE_OK); | |
| 110 EXPECT_FALSE(pipeline_controller_.IsStable()); | |
| 111 ResumePipeline().Run(PIPELINE_OK); | |
| 112 EXPECT_TRUE(pipeline_controller_.IsStable()); | |
| 113 } | |
| 114 | |
| 115 TEST_F(PipelineControllerTest, PendingSuspend) { | |
| 116 StartPipeline().Run(PIPELINE_OK); | |
| 117 | |
| 118 // Start a seek, but do not complete it yet. | |
| 119 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | |
| 120 PipelineStatusCB seek_cb = SeekPipeline(seek_time); | |
| 121 | |
| 122 // Request a suspend. It will be a mock failure it happens immediately. | |
| 123 pipeline_controller_.Suspend(); | |
| 124 | |
| 125 // Expect the suspend to trigger when the seek is completed. | |
| 126 EXPECT_CALL(pipeline_, Suspend(_)); | |
| 127 seek_cb.Run(PIPELINE_OK); | |
| 128 } | |
| 129 | |
| 130 TEST_F(PipelineControllerTest, SeekMergesWithResume) { | |
| 131 StartPipeline().Run(PIPELINE_OK); | |
| 132 SuspendPipeline().Run(PIPELINE_OK); | |
| 133 | |
| 134 // Request a seek. It will be a mock failure it happens. | |
| 135 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | |
| 136 pipeline_controller_.Seek(seek_time, true); | |
| 137 | |
| 138 // Resume and verify the resume time. | |
| 139 ResumePipeline().Run(PIPELINE_OK); | |
| 140 EXPECT_EQ(seek_time, last_resume_time_); | |
| 141 } | |
| 142 | |
| 143 TEST_F(PipelineControllerTest, SeekMergesWithSeek) { | |
| 144 StartPipeline().Run(PIPELINE_OK); | |
| 145 | |
| 146 // Start a seek, but do not complete it yet. | |
| 147 base::TimeDelta seek_time_1 = base::TimeDelta::FromSeconds(5); | |
| 148 PipelineStatusCB seek_cb_1 = SeekPipeline(seek_time_1); | |
| 149 | |
| 150 // Request another seek. It will be a mock failure it happens. | |
| 151 base::TimeDelta seek_time_2 = base::TimeDelta::FromSeconds(10); | |
| 152 pipeline_controller_.Seek(seek_time_2, true); | |
| 153 | |
| 154 // Request a third seek. (It should replace the second.) | |
| 155 base::TimeDelta seek_time_3 = base::TimeDelta::FromSeconds(15); | |
| 156 pipeline_controller_.Seek(seek_time_3, true); | |
| 157 | |
| 158 // Expect that the third seek triggers when the first seek completes. | |
| 159 EXPECT_CALL(pipeline_, Seek(seek_time_3, _)); | |
| 160 seek_cb_1.Run(PIPELINE_OK); | |
| 161 } | |
| 162 | |
| 163 } // namespace media | |
| OLD | NEW |