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