OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/bind.h" |
5 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
6 #include "media/base/composite_filter.h" | 7 #include "media/base/composite_filter.h" |
7 #include "media/base/mock_callback.h" | 8 #include "media/base/mock_callback.h" |
8 #include "media/base/mock_filter_host.h" | 9 #include "media/base/mock_filter_host.h" |
9 #include "media/base/mock_filters.h" | 10 #include "media/base/mock_filters.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 using ::testing::_; | 13 using ::testing::_; |
13 using ::testing::InSequence; | 14 using ::testing::InSequence; |
14 using ::testing::Return; | 15 using ::testing::Return; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 base::TimeDelta seek_time); | 47 base::TimeDelta seek_time); |
47 | 48 |
48 // Helper method that calls a filter method based on the value of | 49 // Helper method that calls a filter method based on the value of |
49 // |method_to_call|. | 50 // |method_to_call|. |
50 // | 51 // |
51 // |method_to_call| - Indicates which method to call. | 52 // |method_to_call| - Indicates which method to call. |
52 // |filter| - The Filter to make the method call on. | 53 // |filter| - The Filter to make the method call on. |
53 // |seek_time| - The time to pass to the Seek() call if |method_to_call| | 54 // |seek_time| - The time to pass to the Seek() call if |method_to_call| |
54 // equals SEEK. | 55 // equals SEEK. |
55 // |callback| - The callback object to pass to the method. | 56 // |callback| - The callback object to pass to the method. |
| 57 // |expected_status| - Some filter methods use a FilterStatusCB instead of |
| 58 // a FilterCallback. For these methods this function |
| 59 // creates a FilterStatusCB that makes sure the status |
| 60 // passed to the callback matches |expected_status| and |
| 61 // then calls |callback|. |
56 void DoFilterCall(MethodToCall method_to_call, Filter* filter, | 62 void DoFilterCall(MethodToCall method_to_call, Filter* filter, |
57 base::TimeDelta seek_time, | 63 base::TimeDelta seek_time, |
58 FilterCallback* callback); | 64 FilterCallback* callback, |
| 65 PipelineStatus expected_status); |
59 | 66 |
60 // Creates an expectation sequence based on the value of method_to_call. | 67 // Creates an expectation sequence based on the value of method_to_call. |
61 // | 68 // |
62 // |method_to_call| - Indicates which method we want a success sequence for. | 69 // |method_to_call| - Indicates which method we want a success sequence for. |
63 // |seek_time| - The time to pass in the Seek() call if |method_to_call| | 70 // |seek_time| - The time to pass in the Seek() call if |method_to_call| |
64 // equals SEEK. | 71 // equals SEEK. |
65 void ExpectSuccess(MethodToCall method_to_call, | 72 void ExpectSuccess(MethodToCall method_to_call, |
66 base::TimeDelta seek_time = base::TimeDelta()); | 73 base::TimeDelta seek_time = base::TimeDelta()); |
67 | 74 |
68 // Issue a Play(), Pause(), Flush(), Stop(), or Seek() on the composite and | 75 // Issue a Play(), Pause(), Flush(), Stop(), or Seek() on the composite and |
69 // verify all the expected calls on the filters. | 76 // verify all the expected calls on the filters. |
70 void DoPlay(); | 77 void DoPlay(); |
71 void DoPause(); | 78 void DoPause(); |
72 void DoFlush(); | 79 void DoFlush(); |
73 void DoStop(); | 80 void DoStop(); |
74 void DoSeek(base::TimeDelta time); | 81 void DoSeek(base::TimeDelta time); |
75 | 82 |
76 // Issue a Play(), Pause(), Flush(), or Seek() and expect the calls to fail | 83 // Issue a Play(), Pause(), Flush(), or Seek() and expect the calls to fail |
77 // with a PIPELINE_ERROR_INVALID_STATE error. | 84 // with a PIPELINE_ERROR_INVALID_STATE error. |
78 // | 85 // |
79 // |method_to_call| - Indicates whick method to call. | 86 // |method_to_call| - Indicates whick method to call. |
80 // |seek_time| - The time to pass to the Seek() call if |method_to_call| | 87 // |seek_time| - The time to pass to the Seek() call if |method_to_call| |
81 // equals SEEK. | 88 // equals SEEK. |
82 void ExpectInvalidStateFail(MethodToCall method_to_call, | 89 void ExpectInvalidStateFail(MethodToCall method_to_call, |
83 base::TimeDelta seek_time = base::TimeDelta()); | 90 base::TimeDelta seek_time = base::TimeDelta()); |
84 | 91 |
85 // Run the callback stored in |filter_1_callback_|. | 92 // Returns whether |filter_1_callback_| or |filter_1_status_cb_| is set. |
| 93 bool HasFilter1Callback() const; |
| 94 |
| 95 // Run the callback stored in |filter_1_callback_| or |filter_2_status_cb_|. |
86 void RunFilter1Callback(); | 96 void RunFilter1Callback(); |
87 | 97 |
88 // Run the callback stored in |filter_2_callback_|. | 98 // Returns whether |filter_2_callback_| or |filter_2_status_cb_| is set. |
| 99 bool HasFilter2Callback() const; |
| 100 |
| 101 // Run the callback stored in |filter_2_callback_| or |filter_2_status_cb_|. |
89 void RunFilter2Callback(); | 102 void RunFilter2Callback(); |
90 | 103 |
91 protected: | 104 protected: |
92 MessageLoop message_loop_; | 105 MessageLoop message_loop_; |
93 | 106 |
94 // The composite object being tested. | 107 // The composite object being tested. |
95 scoped_refptr<CompositeFilter> composite_; | 108 scoped_refptr<CompositeFilter> composite_; |
96 | 109 |
97 // First filter added to the composite. | 110 // First filter added to the composite. |
98 scoped_refptr<StrictMock<MockFilter> > filter_1_; | 111 scoped_refptr<StrictMock<MockFilter> > filter_1_; |
99 | 112 |
100 // Callback passed to |filter_1_| during last Play(), Pause(), Flush(), | 113 // Callback passed to |filter_1_| during last Play(), Pause(), Flush(), |
101 // Stop(), or Seek() call. | 114 // or Stop() call. |
102 FilterCallback* filter_1_callback_; | 115 FilterCallback* filter_1_callback_; |
103 | 116 |
| 117 // Status to pass to |filter_1_status_cb_|. |
| 118 PipelineStatus filter_1_status_; |
| 119 |
| 120 // Callback passed to |filter_1_| during last Seek() call. |
| 121 FilterStatusCB filter_1_status_cb_; |
| 122 |
104 // Second filter added to the composite. | 123 // Second filter added to the composite. |
105 scoped_refptr<StrictMock<MockFilter> > filter_2_; | 124 scoped_refptr<StrictMock<MockFilter> > filter_2_; |
106 | 125 |
107 // Callback passed to |filter_2_| during last Play(), Pause(), Flush(), | 126 // Callback passed to |filter_2_| during last Play(), Pause(), Flush(), |
108 // Stop(), or Seek() call. | 127 // Stop(), or Seek() call. |
109 FilterCallback* filter_2_callback_; | 128 FilterCallback* filter_2_callback_; |
110 | 129 |
| 130 // Status to pass to |filter_2_status_cb_|. |
| 131 PipelineStatus filter_2_status_; |
| 132 |
| 133 // Callback passed to |filter_2_| during last Seek() call. |
| 134 FilterStatusCB filter_2_status_cb_; |
| 135 |
111 // FilterHost implementation passed to |composite_| via set_host(). | 136 // FilterHost implementation passed to |composite_| via set_host(). |
112 scoped_ptr<StrictMock<MockFilterHost> > mock_filter_host_; | 137 scoped_ptr<StrictMock<MockFilterHost> > mock_filter_host_; |
113 | 138 |
114 DISALLOW_COPY_AND_ASSIGN(CompositeFilterTest); | 139 DISALLOW_COPY_AND_ASSIGN(CompositeFilterTest); |
115 }; | 140 }; |
116 | 141 |
117 CompositeFilterTest::CompositeFilterTest() : | 142 CompositeFilterTest::CompositeFilterTest() : |
118 composite_(new CompositeFilter(&message_loop_)), | 143 composite_(new CompositeFilter(&message_loop_)), |
119 filter_1_callback_(NULL), | 144 filter_1_callback_(NULL), |
| 145 filter_1_status_(PIPELINE_OK), |
120 filter_2_callback_(NULL), | 146 filter_2_callback_(NULL), |
| 147 filter_2_status_(PIPELINE_OK), |
121 mock_filter_host_(new StrictMock<MockFilterHost>()) { | 148 mock_filter_host_(new StrictMock<MockFilterHost>()) { |
122 } | 149 } |
123 | 150 |
124 CompositeFilterTest::~CompositeFilterTest() {} | 151 CompositeFilterTest::~CompositeFilterTest() {} |
125 | 152 |
126 void CompositeFilterTest::SetupAndAdd2Filters() { | 153 void CompositeFilterTest::SetupAndAdd2Filters() { |
127 mock_filter_host_.reset(new StrictMock<MockFilterHost>()); | 154 mock_filter_host_.reset(new StrictMock<MockFilterHost>()); |
128 composite_ = new CompositeFilter(&message_loop_); | 155 composite_ = new CompositeFilter(&message_loop_); |
129 composite_->set_host(mock_filter_host_.get()); | 156 composite_->set_host(mock_filter_host_.get()); |
130 | 157 |
131 // Setup |filter_1_| and arrange for methods to set | 158 // Setup |filter_1_| and arrange for methods to set |
132 // |filter_1_callback_| when they are called. | 159 // |filter_1_callback_| when they are called. |
133 filter_1_ = new StrictMock<MockFilter>(); | 160 filter_1_ = new StrictMock<MockFilter>(); |
134 filter_1_callback_ = NULL; | 161 filter_1_callback_ = NULL; |
| 162 filter_1_status_ = PIPELINE_OK; |
| 163 filter_1_status_cb_.Reset(); |
135 ON_CALL(*filter_1_, Play(_)) | 164 ON_CALL(*filter_1_, Play(_)) |
136 .WillByDefault(SaveArg<0>(&filter_1_callback_)); | 165 .WillByDefault(SaveArg<0>(&filter_1_callback_)); |
137 ON_CALL(*filter_1_, Pause(_)) | 166 ON_CALL(*filter_1_, Pause(_)) |
138 .WillByDefault(SaveArg<0>(&filter_1_callback_)); | 167 .WillByDefault(SaveArg<0>(&filter_1_callback_)); |
139 ON_CALL(*filter_1_, Flush(_)) | 168 ON_CALL(*filter_1_, Flush(_)) |
140 .WillByDefault(SaveArg<0>(&filter_1_callback_)); | 169 .WillByDefault(SaveArg<0>(&filter_1_callback_)); |
141 ON_CALL(*filter_1_, Stop(_)) | 170 ON_CALL(*filter_1_, Stop(_)) |
142 .WillByDefault(SaveArg<0>(&filter_1_callback_)); | 171 .WillByDefault(SaveArg<0>(&filter_1_callback_)); |
143 ON_CALL(*filter_1_, Seek(_,_)) | 172 ON_CALL(*filter_1_, Seek(_,_)) |
144 .WillByDefault(SaveArg<1>(&filter_1_callback_)); | 173 .WillByDefault(SaveArg<1>(&filter_1_status_cb_)); |
145 | 174 |
146 // Setup |filter_2_| and arrange for methods to set | 175 // Setup |filter_2_| and arrange for methods to set |
147 // |filter_2_callback_| when they are called. | 176 // |filter_2_callback_| when they are called. |
148 filter_2_ = new StrictMock<MockFilter>(); | 177 filter_2_ = new StrictMock<MockFilter>(); |
149 filter_2_callback_ = NULL; | 178 filter_2_callback_ = NULL; |
| 179 filter_2_status_ = PIPELINE_OK; |
| 180 filter_2_status_cb_.Reset(); |
150 ON_CALL(*filter_2_, Play(_)) | 181 ON_CALL(*filter_2_, Play(_)) |
151 .WillByDefault(SaveArg<0>(&filter_2_callback_)); | 182 .WillByDefault(SaveArg<0>(&filter_2_callback_)); |
152 ON_CALL(*filter_2_, Pause(_)) | 183 ON_CALL(*filter_2_, Pause(_)) |
153 .WillByDefault(SaveArg<0>(&filter_2_callback_)); | 184 .WillByDefault(SaveArg<0>(&filter_2_callback_)); |
154 ON_CALL(*filter_2_, Flush(_)) | 185 ON_CALL(*filter_2_, Flush(_)) |
155 .WillByDefault(SaveArg<0>(&filter_2_callback_)); | 186 .WillByDefault(SaveArg<0>(&filter_2_callback_)); |
156 ON_CALL(*filter_2_, Stop(_)) | 187 ON_CALL(*filter_2_, Stop(_)) |
157 .WillByDefault(SaveArg<0>(&filter_2_callback_)); | 188 .WillByDefault(SaveArg<0>(&filter_2_callback_)); |
158 ON_CALL(*filter_2_, Seek(_,_)) | 189 ON_CALL(*filter_2_, Seek(_,_)) |
159 .WillByDefault(SaveArg<1>(&filter_2_callback_)); | 190 .WillByDefault(SaveArg<1>(&filter_2_status_cb_)); |
160 | 191 |
161 composite_->AddFilter(filter_1_); | 192 composite_->AddFilter(filter_1_); |
162 composite_->AddFilter(filter_2_); | 193 composite_->AddFilter(filter_2_); |
163 } | 194 } |
164 | 195 |
165 void CompositeFilterTest::ExpectFilterCall(MethodToCall method_to_call, | 196 void CompositeFilterTest::ExpectFilterCall(MethodToCall method_to_call, |
166 MockFilter* filter, | 197 MockFilter* filter, |
167 base::TimeDelta seek_time) { | 198 base::TimeDelta seek_time) { |
168 switch(method_to_call) { | 199 switch(method_to_call) { |
169 case PLAY: | 200 case PLAY: |
170 EXPECT_CALL(*filter, Play(_)); | 201 EXPECT_CALL(*filter, Play(_)); |
171 break; | 202 break; |
172 case PAUSE: | 203 case PAUSE: |
173 EXPECT_CALL(*filter, Pause(_)); | 204 EXPECT_CALL(*filter, Pause(_)); |
174 break; | 205 break; |
175 case FLUSH: | 206 case FLUSH: |
176 EXPECT_CALL(*filter, Flush(_)); | 207 EXPECT_CALL(*filter, Flush(_)); |
177 break; | 208 break; |
178 case STOP: | 209 case STOP: |
179 EXPECT_CALL(*filter, Stop(_)); | 210 EXPECT_CALL(*filter, Stop(_)); |
180 break; | 211 break; |
181 case SEEK: | 212 case SEEK: |
182 EXPECT_CALL(*filter, Seek(seek_time, _)); | 213 EXPECT_CALL(*filter, Seek(seek_time, _)); |
183 break; | 214 break; |
184 }; | 215 }; |
185 } | 216 } |
186 | 217 |
| 218 void OnStatusCB(PipelineStatus expected_status, FilterCallback* callback, |
| 219 PipelineStatus status) { |
| 220 EXPECT_EQ(status, expected_status); |
| 221 |
| 222 callback->Run(); |
| 223 delete callback; |
| 224 } |
| 225 |
187 void CompositeFilterTest::DoFilterCall(MethodToCall method_to_call, | 226 void CompositeFilterTest::DoFilterCall(MethodToCall method_to_call, |
188 Filter* filter, | 227 Filter* filter, |
189 base::TimeDelta seek_time, | 228 base::TimeDelta seek_time, |
190 FilterCallback* callback) { | 229 FilterCallback* callback, |
| 230 PipelineStatus expected_status) { |
| 231 filter_1_status_ = expected_status; |
| 232 filter_2_status_ = expected_status; |
| 233 |
191 switch(method_to_call) { | 234 switch(method_to_call) { |
192 case PLAY: | 235 case PLAY: |
193 filter->Play(callback); | 236 filter->Play(callback); |
194 break; | 237 break; |
195 case PAUSE: | 238 case PAUSE: |
196 filter->Pause(callback); | 239 filter->Pause(callback); |
197 break; | 240 break; |
198 case FLUSH: | 241 case FLUSH: |
199 filter->Flush(callback); | 242 filter->Flush(callback); |
200 break; | 243 break; |
201 case STOP: | 244 case STOP: |
202 filter->Stop(callback); | 245 filter->Stop(callback); |
203 break; | 246 break; |
204 case SEEK: | 247 case SEEK: |
205 filter->Seek(seek_time, callback); | 248 filter->Seek(seek_time, base::Bind(&OnStatusCB, expected_status, |
| 249 callback)); |
206 break; | 250 break; |
207 }; | 251 }; |
208 } | 252 } |
209 | 253 |
210 void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call, | 254 void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call, |
211 base::TimeDelta seek_time) { | 255 base::TimeDelta seek_time) { |
212 InSequence seq; | 256 InSequence seq; |
213 | 257 |
214 bool is_parallel_call = (method_to_call == FLUSH); | 258 bool is_parallel_call = (method_to_call == FLUSH); |
215 | 259 |
216 ExpectFilterCall(method_to_call, filter_1_.get(), seek_time); | 260 ExpectFilterCall(method_to_call, filter_1_.get(), seek_time); |
217 | 261 |
218 if (is_parallel_call) { | 262 if (is_parallel_call) { |
219 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time); | 263 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time); |
220 } | 264 } |
221 | 265 |
222 // Make method call on the composite. | 266 // Make method call on the composite. |
223 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); | 267 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); |
224 DoFilterCall(method_to_call, composite_.get(), seek_time, callback); | 268 DoFilterCall(method_to_call, composite_.get(), seek_time, callback, |
| 269 PIPELINE_OK); |
225 | 270 |
226 if (is_parallel_call) { | 271 if (is_parallel_call) { |
227 // Make sure both filters have their callbacks set. | 272 // Make sure both filters have their callbacks set. |
228 EXPECT_TRUE(filter_1_callback_ != NULL); | 273 EXPECT_TRUE(HasFilter1Callback()); |
229 EXPECT_TRUE(filter_2_callback_ != NULL); | 274 EXPECT_TRUE(HasFilter2Callback()); |
230 | 275 |
231 RunFilter1Callback(); | 276 RunFilter1Callback(); |
232 } else { | 277 } else { |
233 // Make sure that only |filter_1_| has its callback set. | 278 // Make sure that only |filter_1_| has its callback set. |
234 EXPECT_TRUE(filter_1_callback_ != NULL); | 279 EXPECT_TRUE(HasFilter1Callback()); |
235 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | 280 EXPECT_FALSE(HasFilter2Callback()); |
236 | 281 |
237 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time); | 282 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time); |
238 | 283 |
239 RunFilter1Callback(); | 284 RunFilter1Callback(); |
240 | 285 |
241 // Verify that |filter_2_| was called by checking the callback pointer. | 286 // Verify that |filter_2_| was called by checking the callback pointer. |
242 EXPECT_TRUE(filter_2_callback_ != NULL); | 287 EXPECT_TRUE(HasFilter2Callback()); |
243 } | 288 } |
244 | 289 |
245 callback->ExpectRunAndDelete(); | 290 callback->ExpectRunAndDelete(); |
246 | 291 |
247 RunFilter2Callback(); | 292 RunFilter2Callback(); |
248 } | 293 } |
249 | 294 |
250 void CompositeFilterTest::DoPlay() { | 295 void CompositeFilterTest::DoPlay() { |
251 ExpectSuccess(PLAY); | 296 ExpectSuccess(PLAY); |
252 } | 297 } |
(...skipping 11 matching lines...) Expand all Loading... |
264 } | 309 } |
265 | 310 |
266 void CompositeFilterTest::DoSeek(base::TimeDelta time) { | 311 void CompositeFilterTest::DoSeek(base::TimeDelta time) { |
267 ExpectSuccess(SEEK, time); | 312 ExpectSuccess(SEEK, time); |
268 } | 313 } |
269 | 314 |
270 void CompositeFilterTest::ExpectInvalidStateFail(MethodToCall method_to_call, | 315 void CompositeFilterTest::ExpectInvalidStateFail(MethodToCall method_to_call, |
271 base::TimeDelta seek_time) { | 316 base::TimeDelta seek_time) { |
272 InSequence seq; | 317 InSequence seq; |
273 | 318 |
274 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_INVALID_STATE)) | 319 if (method_to_call != SEEK) { |
275 .WillOnce(Return()); | 320 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_INVALID_STATE)) |
| 321 .WillOnce(Return()); |
| 322 } |
276 | 323 |
277 DoFilterCall(method_to_call, composite_, seek_time, NewExpectedCallback()); | 324 DoFilterCall(method_to_call, composite_, seek_time, NewExpectedCallback(), |
| 325 PIPELINE_ERROR_INVALID_STATE); |
278 | 326 |
279 // Make sure that neither of the filters were called by | 327 // Make sure that neither of the filters were called by |
280 // verifying that the callback pointers weren't set. | 328 // verifying that the callback pointers weren't set. |
281 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); | 329 EXPECT_FALSE(HasFilter1Callback()); |
282 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | 330 EXPECT_FALSE(HasFilter2Callback()); |
| 331 } |
| 332 |
| 333 bool CompositeFilterTest::HasFilter1Callback() const { |
| 334 CHECK(!(filter_1_callback_ && !filter_1_status_cb_.is_null())); |
| 335 return filter_1_callback_ != NULL || !filter_1_status_cb_.is_null(); |
283 } | 336 } |
284 | 337 |
285 void CompositeFilterTest::RunFilter1Callback() { | 338 void CompositeFilterTest::RunFilter1Callback() { |
| 339 EXPECT_TRUE(HasFilter1Callback()); |
| 340 |
| 341 if (!filter_1_status_cb_.is_null()) { |
| 342 ResetAndRunCB(&filter_1_status_cb_, filter_1_status_); |
| 343 filter_1_status_ = PIPELINE_OK; |
| 344 return; |
| 345 } |
| 346 |
286 EXPECT_TRUE(filter_1_callback_ != NULL); | 347 EXPECT_TRUE(filter_1_callback_ != NULL); |
287 FilterCallback* callback = filter_1_callback_; | 348 FilterCallback* callback = filter_1_callback_; |
288 filter_1_callback_ = NULL; | 349 filter_1_callback_ = NULL; |
289 callback->Run(); | 350 callback->Run(); |
290 delete callback; | 351 delete callback; |
291 } | 352 } |
292 | 353 |
| 354 bool CompositeFilterTest::HasFilter2Callback() const { |
| 355 CHECK(!(filter_2_callback_ && !filter_2_status_cb_.is_null())); |
| 356 return filter_2_callback_ != NULL || !filter_2_status_cb_.is_null(); |
| 357 } |
| 358 |
293 void CompositeFilterTest::RunFilter2Callback() { | 359 void CompositeFilterTest::RunFilter2Callback() { |
| 360 EXPECT_TRUE(HasFilter2Callback()); |
| 361 |
| 362 if (!filter_2_status_cb_.is_null()) { |
| 363 ResetAndRunCB(&filter_2_status_cb_, filter_2_status_); |
| 364 filter_2_status_ = PIPELINE_OK; |
| 365 return; |
| 366 } |
| 367 |
294 EXPECT_TRUE(filter_2_callback_ != NULL); | 368 EXPECT_TRUE(filter_2_callback_ != NULL); |
295 FilterCallback* callback = filter_2_callback_; | 369 FilterCallback* callback = filter_2_callback_; |
296 filter_2_callback_ = NULL; | 370 filter_2_callback_ = NULL; |
297 callback->Run(); | 371 callback->Run(); |
298 delete callback; | 372 delete callback; |
299 } | 373 } |
300 | 374 |
301 // Test AddFilter() failure cases. | 375 // Test AddFilter() failure cases. |
302 TEST_F(CompositeFilterTest, TestAddFilterFailCases) { | 376 TEST_F(CompositeFilterTest, TestAddFilterFailCases) { |
303 // Test adding a null pointer. | 377 // Test adding a null pointer. |
(...skipping 28 matching lines...) Expand all Loading... |
332 DoPlay(); | 406 DoPlay(); |
333 | 407 |
334 // At this point we are now in the kPlaying state. | 408 // At this point we are now in the kPlaying state. |
335 | 409 |
336 // Try calling Play() again to make sure that we simply get a callback. | 410 // Try calling Play() again to make sure that we simply get a callback. |
337 // We are already in the Play() state so there is no point calling the | 411 // We are already in the Play() state so there is no point calling the |
338 // filters. | 412 // filters. |
339 composite_->Play(NewExpectedCallback()); | 413 composite_->Play(NewExpectedCallback()); |
340 | 414 |
341 // Verify that neither of the filter callbacks were set. | 415 // Verify that neither of the filter callbacks were set. |
342 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); | 416 EXPECT_FALSE(HasFilter1Callback()); |
343 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | 417 EXPECT_FALSE(HasFilter2Callback()); |
344 | 418 |
345 // Stop playback. | 419 // Stop playback. |
346 DoStop(); | 420 DoStop(); |
347 | 421 |
348 // At this point we should be in the kStopped state. | 422 // At this point we should be in the kStopped state. |
349 | 423 |
350 // Try calling Stop() again to make sure neither filter is called. | 424 // Try calling Stop() again to make sure neither filter is called. |
351 composite_->Stop(NewExpectedCallback()); | 425 composite_->Stop(NewExpectedCallback()); |
352 | 426 |
353 // Verify that neither of the filter callbacks were set. | 427 // Verify that neither of the filter callbacks were set. |
354 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); | 428 EXPECT_FALSE(HasFilter1Callback()); |
355 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | 429 EXPECT_FALSE(HasFilter2Callback()); |
356 | 430 |
357 // Try calling Play() again to make sure we get an error. | 431 // Try calling Play() again to make sure we get an error. |
358 ExpectInvalidStateFail(PLAY); | 432 ExpectInvalidStateFail(PLAY); |
359 } | 433 } |
360 | 434 |
361 // Test errors in the middle of a serial call sequence like Play(). | 435 // Test errors in the middle of a serial call sequence like Play(). |
362 TEST_F(CompositeFilterTest, TestPlayErrors) { | 436 TEST_F(CompositeFilterTest, TestPlayErrors) { |
363 InSequence sequence; | 437 InSequence sequence; |
364 | 438 |
365 SetupAndAdd2Filters(); | 439 SetupAndAdd2Filters(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 // Issue a successful Pause(). | 485 // Issue a successful Pause(). |
412 DoPause(); | 486 DoPause(); |
413 | 487 |
414 // At this point we are paused. | 488 // At this point we are paused. |
415 | 489 |
416 // Try calling Pause() again to make sure that the filters aren't called | 490 // Try calling Pause() again to make sure that the filters aren't called |
417 // because we are already in the paused state. | 491 // because we are already in the paused state. |
418 composite_->Pause(NewExpectedCallback()); | 492 composite_->Pause(NewExpectedCallback()); |
419 | 493 |
420 // Verify that neither of the filter callbacks were set. | 494 // Verify that neither of the filter callbacks were set. |
421 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); | 495 EXPECT_FALSE(HasFilter1Callback()); |
422 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | 496 EXPECT_FALSE(HasFilter2Callback()); |
423 | 497 |
424 // Verify that we can transition pack to the play state. | 498 // Verify that we can transition pack to the play state. |
425 DoPlay(); | 499 DoPlay(); |
426 | 500 |
427 // Go back to the pause state. | 501 // Go back to the pause state. |
428 DoPause(); | 502 DoPause(); |
429 | 503 |
430 // Transition to the stop state. | 504 // Transition to the stop state. |
431 DoStop(); | 505 DoStop(); |
432 | 506 |
(...skipping 20 matching lines...) Expand all Loading... |
453 // interface. | 527 // interface. |
454 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); | 528 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); |
455 | 529 |
456 // Expect error to be reported and "pause done" callback to be called. | 530 // Expect error to be reported and "pause done" callback to be called. |
457 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); | 531 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); |
458 callback->ExpectRunAndDelete(); | 532 callback->ExpectRunAndDelete(); |
459 | 533 |
460 RunFilter1Callback(); | 534 RunFilter1Callback(); |
461 | 535 |
462 // Make sure |filter_2_callback_| was not set. | 536 // Make sure |filter_2_callback_| was not set. |
463 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | 537 EXPECT_FALSE(HasFilter2Callback()); |
464 | 538 |
465 // Verify that Play/Pause/Flush/Seek fail now that an error occured. | 539 // Verify that Play/Pause/Flush/Seek fail now that an error occured. |
466 ExpectInvalidStateFail(PLAY); | 540 ExpectInvalidStateFail(PLAY); |
467 ExpectInvalidStateFail(PAUSE); | 541 ExpectInvalidStateFail(PAUSE); |
468 ExpectInvalidStateFail(FLUSH); | 542 ExpectInvalidStateFail(FLUSH); |
469 ExpectInvalidStateFail(SEEK); | 543 ExpectInvalidStateFail(SEEK); |
470 | 544 |
471 // Make sure you can still Stop(). | 545 // Make sure you can still Stop(). |
472 DoStop(); | 546 DoStop(); |
473 } | 547 } |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 composite_->Play(NewExpectedCallback()); | 781 composite_->Play(NewExpectedCallback()); |
708 | 782 |
709 // Issue a Pause() and expect no errors. | 783 // Issue a Pause() and expect no errors. |
710 composite_->Pause(NewExpectedCallback()); | 784 composite_->Pause(NewExpectedCallback()); |
711 | 785 |
712 // Issue a Flush() and expect no errors. | 786 // Issue a Flush() and expect no errors. |
713 composite_->Flush(NewExpectedCallback()); | 787 composite_->Flush(NewExpectedCallback()); |
714 | 788 |
715 // Issue a Seek() and expect no errors. | 789 // Issue a Seek() and expect no errors. |
716 composite_->Seek(base::TimeDelta::FromSeconds(5), | 790 composite_->Seek(base::TimeDelta::FromSeconds(5), |
717 NewExpectedCallback()); | 791 NewExpectedStatusCB(PIPELINE_OK)); |
718 | 792 |
719 // Issue a Play() and expect no errors. | 793 // Issue a Play() and expect no errors. |
720 composite_->Play(NewExpectedCallback()); | 794 composite_->Play(NewExpectedCallback()); |
721 | 795 |
722 // Issue a Stop() and expect no errors. | 796 // Issue a Stop() and expect no errors. |
723 composite_->Stop(NewExpectedCallback()); | 797 composite_->Stop(NewExpectedCallback()); |
724 } | 798 } |
725 | 799 |
726 } // namespace media | 800 } // namespace media |
OLD | NEW |