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

Side by Side Diff: media/filters/pipeline_controller_unittest.cc

Issue 1830913005: Convert WMPI state management to level-triggered. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use EXPECT_TRUE/EXPECT_FALSE. Created 4 years, 8 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
« no previous file with comments | « media/filters/pipeline_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 class PipelineControllerTest : public ::testing::Test { 29 class PipelineControllerTest : public ::testing::Test {
30 public: 30 public:
31 PipelineControllerTest() 31 PipelineControllerTest()
32 : pipeline_controller_(&pipeline_, 32 : pipeline_controller_(&pipeline_,
33 base::Bind(&PipelineControllerTest::CreateRenderer, 33 base::Bind(&PipelineControllerTest::CreateRenderer,
34 base::Unretained(this)), 34 base::Unretained(this)),
35 base::Bind(&PipelineControllerTest::OnSeeked, 35 base::Bind(&PipelineControllerTest::OnSeeked,
36 base::Unretained(this)), 36 base::Unretained(this)),
37 base::Bind(&PipelineControllerTest::OnSuspended, 37 base::Bind(&PipelineControllerTest::OnSuspended,
38 base::Unretained(this)), 38 base::Unretained(this)),
39 base::Bind(&PipelineControllerTest::OnResumed,
40 base::Unretained(this)),
41 base::Bind(&PipelineControllerTest::OnError, 39 base::Bind(&PipelineControllerTest::OnError,
42 base::Unretained(this))) {} 40 base::Unretained(this))) {}
43 41
44 ~PipelineControllerTest() override {} 42 ~PipelineControllerTest() override {}
45 43
46 PipelineStatusCB StartPipeline(bool is_streaming, bool is_static) { 44 PipelineStatusCB StartPipeline(bool is_streaming, bool is_static) {
47 EXPECT_FALSE(pipeline_controller_.IsStable()); 45 EXPECT_FALSE(pipeline_controller_.IsStable());
48 PipelineStatusCB start_cb; 46 PipelineStatusCB start_cb;
49 EXPECT_CALL(pipeline_, Start(_, _, _, _, _, _, _, _, _, _)) 47 EXPECT_CALL(pipeline_, Start(_, _, _, _, _, _, _, _, _, _))
50 .WillOnce(SaveArg<4>(&start_cb)); 48 .WillOnce(SaveArg<4>(&start_cb));
(...skipping 26 matching lines...) Expand all
77 return seek_cb; 75 return seek_cb;
78 } 76 }
79 77
80 PipelineStatusCB SuspendPipeline() { 78 PipelineStatusCB SuspendPipeline() {
81 EXPECT_TRUE(pipeline_controller_.IsStable()); 79 EXPECT_TRUE(pipeline_controller_.IsStable());
82 PipelineStatusCB suspend_cb; 80 PipelineStatusCB suspend_cb;
83 EXPECT_CALL(pipeline_, Suspend(_)).WillOnce(SaveArg<0>(&suspend_cb)); 81 EXPECT_CALL(pipeline_, Suspend(_)).WillOnce(SaveArg<0>(&suspend_cb));
84 pipeline_controller_.Suspend(); 82 pipeline_controller_.Suspend();
85 Mock::VerifyAndClear(&pipeline_); 83 Mock::VerifyAndClear(&pipeline_);
86 EXPECT_FALSE(pipeline_controller_.IsStable()); 84 EXPECT_FALSE(pipeline_controller_.IsStable());
87 EXPECT_FALSE(pipeline_controller_.IsSuspended()); 85 EXPECT_FALSE(pipeline_controller_.IsPipelineSuspended());
88 return suspend_cb; 86 return suspend_cb;
89 } 87 }
90 88
91 PipelineStatusCB ResumePipeline() { 89 PipelineStatusCB ResumePipeline() {
92 EXPECT_TRUE(pipeline_controller_.IsSuspended()); 90 EXPECT_TRUE(pipeline_controller_.IsPipelineSuspended());
93 PipelineStatusCB resume_cb; 91 PipelineStatusCB resume_cb;
94 EXPECT_CALL(pipeline_, Resume(_, _, _)) 92 EXPECT_CALL(pipeline_, Resume(_, _, _))
95 .WillOnce( 93 .WillOnce(
96 DoAll(SaveArg<1>(&last_resume_time_), SaveArg<2>(&resume_cb))); 94 DoAll(SaveArg<1>(&last_resume_time_), SaveArg<2>(&resume_cb)));
97 EXPECT_CALL(pipeline_, GetMediaTime()) 95 EXPECT_CALL(pipeline_, GetMediaTime())
98 .WillRepeatedly(Return(base::TimeDelta())); 96 .WillRepeatedly(Return(base::TimeDelta()));
99 pipeline_controller_.Resume(); 97 pipeline_controller_.Resume();
100 Mock::VerifyAndClear(&pipeline_); 98 Mock::VerifyAndClear(&pipeline_);
101 EXPECT_FALSE(pipeline_controller_.IsStable()); 99 EXPECT_FALSE(pipeline_controller_.IsStable());
102 EXPECT_FALSE(pipeline_controller_.IsSuspended()); 100 EXPECT_FALSE(pipeline_controller_.IsPipelineSuspended());
103 return resume_cb; 101 return resume_cb;
104 } 102 }
105 103
106 void Complete(const PipelineStatusCB& cb) { 104 void Complete(const PipelineStatusCB& cb) {
107 cb.Run(PIPELINE_OK); 105 cb.Run(PIPELINE_OK);
108 message_loop_.RunUntilIdle(); 106 message_loop_.RunUntilIdle();
109 } 107 }
110 108
111 protected: 109 protected:
112 scoped_ptr<Renderer> CreateRenderer() { return scoped_ptr<Renderer>(); } 110 scoped_ptr<Renderer> CreateRenderer() { return scoped_ptr<Renderer>(); }
113 111
114 void OnSeeked(bool time_updated) { 112 void OnSeeked(bool time_updated) {
115 was_seeked_ = true; 113 was_seeked_ = true;
116 last_seeked_time_updated_ = time_updated; 114 last_seeked_time_updated_ = time_updated;
117 } 115 }
118 116
119 void OnSuspended() { was_suspended_ = true; } 117 void OnSuspended() { was_suspended_ = true; }
120 118
121 void OnResumed() { was_resumed_ = true; }
122
123 void OnError(PipelineStatus status) { NOTREACHED(); } 119 void OnError(PipelineStatus status) { NOTREACHED(); }
124 120
125 base::MessageLoop message_loop_; 121 base::MessageLoop message_loop_;
126 122
127 NiceMock<MockDemuxer> demuxer_; 123 NiceMock<MockDemuxer> demuxer_;
128 StrictMock<MockPipeline> pipeline_; 124 StrictMock<MockPipeline> pipeline_;
129 PipelineController pipeline_controller_; 125 PipelineController pipeline_controller_;
130 126
131 bool was_seeked_ = false; 127 bool was_seeked_ = false;
132 bool last_seeked_time_updated_ = false; 128 bool last_seeked_time_updated_ = false;
133 bool was_suspended_ = false; 129 bool was_suspended_ = false;
134 bool was_resumed_ = false;
135 base::TimeDelta last_resume_time_; 130 base::TimeDelta last_resume_time_;
136 131
137 DISALLOW_COPY_AND_ASSIGN(PipelineControllerTest); 132 DISALLOW_COPY_AND_ASSIGN(PipelineControllerTest);
138 }; 133 };
139 134
140 TEST_F(PipelineControllerTest, Startup) { 135 TEST_F(PipelineControllerTest, Startup) {
141 PipelineStatusCB start_cb = StartPipeline(); 136 PipelineStatusCB start_cb = StartPipeline();
142 EXPECT_FALSE(was_seeked_); 137 EXPECT_FALSE(was_seeked_);
143 138
144 Complete(start_cb); 139 Complete(start_cb);
145 EXPECT_TRUE(was_seeked_); 140 EXPECT_TRUE(was_seeked_);
146 EXPECT_FALSE(last_seeked_time_updated_); 141 EXPECT_FALSE(last_seeked_time_updated_);
147 EXPECT_FALSE(was_suspended_); 142 EXPECT_FALSE(was_suspended_);
148 EXPECT_FALSE(was_resumed_);
149 EXPECT_TRUE(pipeline_controller_.IsStable()); 143 EXPECT_TRUE(pipeline_controller_.IsStable());
150 } 144 }
151 145
152 TEST_F(PipelineControllerTest, SuspendResume) { 146 TEST_F(PipelineControllerTest, SuspendResume) {
153 Complete(StartPipeline()); 147 Complete(StartPipeline());
154 EXPECT_TRUE(was_seeked_); 148 EXPECT_TRUE(was_seeked_);
155 was_seeked_ = false; 149 was_seeked_ = false;
156 150
157 Complete(SuspendPipeline()); 151 Complete(SuspendPipeline());
158 EXPECT_TRUE(was_suspended_); 152 EXPECT_TRUE(was_suspended_);
159 EXPECT_FALSE(was_resumed_);
160 EXPECT_FALSE(pipeline_controller_.IsStable()); 153 EXPECT_FALSE(pipeline_controller_.IsStable());
161 154
162 Complete(ResumePipeline()); 155 Complete(ResumePipeline());
163 EXPECT_TRUE(was_resumed_);
164 EXPECT_TRUE(pipeline_controller_.IsStable()); 156 EXPECT_TRUE(pipeline_controller_.IsStable());
165 157
166 // |was_seeked_| should not be affected by Suspend()/Resume() at all. 158 // |was_seeked_| should not be affected by Suspend()/Resume() at all.
167 EXPECT_FALSE(was_seeked_); 159 EXPECT_FALSE(was_seeked_);
168 } 160 }
169 161
170 TEST_F(PipelineControllerTest, Seek) { 162 TEST_F(PipelineControllerTest, Seek) {
171 // Normal seeking should not result in a cancel. 163 // Normal seeking should not result in a cancel.
172 EXPECT_CALL(demuxer_, CancelPendingSeek(_)).Times(0); 164 EXPECT_CALL(demuxer_, CancelPendingSeek(_)).Times(0);
173 165
(...skipping 13 matching lines...) Expand all
187 179
188 TEST_F(PipelineControllerTest, SuspendResumeTime) { 180 TEST_F(PipelineControllerTest, SuspendResumeTime) {
189 Complete(StartPipeline()); 181 Complete(StartPipeline());
190 Complete(SuspendPipeline()); 182 Complete(SuspendPipeline());
191 183
192 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); 184 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
193 pipeline_controller_.Seek(seek_time, true); 185 pipeline_controller_.Seek(seek_time, true);
194 message_loop_.RunUntilIdle(); 186 message_loop_.RunUntilIdle();
195 187
196 Complete(ResumePipeline()); 188 Complete(ResumePipeline());
197 EXPECT_TRUE(was_resumed_);
198 EXPECT_EQ(seek_time, last_resume_time_); 189 EXPECT_EQ(seek_time, last_resume_time_);
199 } 190 }
200 191
201 TEST_F(PipelineControllerTest, SuspendResumeTime_WithStreamingData) { 192 TEST_F(PipelineControllerTest, SuspendResumeTime_WithStreamingData) {
202 Complete(StartPipeline_WithStreamingData()); 193 Complete(StartPipeline_WithStreamingData());
203 Complete(SuspendPipeline()); 194 Complete(SuspendPipeline());
204 195
205 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); 196 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
206 pipeline_controller_.Seek(seek_time, true); 197 pipeline_controller_.Seek(seek_time, true);
207 message_loop_.RunUntilIdle(); 198 message_loop_.RunUntilIdle();
208 199
209 Complete(ResumePipeline()); 200 Complete(ResumePipeline());
210 EXPECT_TRUE(was_resumed_);
211 EXPECT_EQ(base::TimeDelta(), last_resume_time_); 201 EXPECT_EQ(base::TimeDelta(), last_resume_time_);
212 } 202 }
213 203
214 TEST_F(PipelineControllerTest, SeekAborted) { 204 TEST_F(PipelineControllerTest, SeekAborted) {
215 Complete(StartPipeline()); 205 Complete(StartPipeline());
216 206
217 // Create a first pending seek. 207 // Create a first pending seek.
218 base::TimeDelta seek_time_1 = base::TimeDelta::FromSeconds(5); 208 base::TimeDelta seek_time_1 = base::TimeDelta::FromSeconds(5);
219 EXPECT_CALL(demuxer_, StartWaitingForSeek(seek_time_1)); 209 EXPECT_CALL(demuxer_, StartWaitingForSeek(seek_time_1));
220 PipelineStatusCB seek_cb_1 = SeekPipeline(seek_time_1); 210 PipelineStatusCB seek_cb_1 = SeekPipeline(seek_time_1);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // Request a seek to the same time again. 306 // Request a seek to the same time again.
317 pipeline_controller_.Seek(seek_time, true); 307 pipeline_controller_.Seek(seek_time, true);
318 message_loop_.RunUntilIdle(); 308 message_loop_.RunUntilIdle();
319 309
320 // Expect the second seek to trigger when the first seek completes. 310 // Expect the second seek to trigger when the first seek completes.
321 EXPECT_CALL(pipeline_, Seek(seek_time, _)); 311 EXPECT_CALL(pipeline_, Seek(seek_time, _));
322 Complete(seek_cb_1); 312 Complete(seek_cb_1);
323 } 313 }
324 314
325 } // namespace media 315 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/pipeline_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698