OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" |
5 #include "media/base/composite_filter.h" | 6 #include "media/base/composite_filter.h" |
6 #include "media/base/mock_filter_host.h" | 7 #include "media/base/mock_filter_host.h" |
7 #include "media/base/mock_filters.h" | 8 #include "media/base/mock_filters.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 | 10 |
10 using ::testing::_; | 11 using ::testing::_; |
11 using ::testing::InSequence; | 12 using ::testing::InSequence; |
12 using ::testing::Return; | 13 using ::testing::Return; |
13 using ::testing::SaveArg; | 14 using ::testing::SaveArg; |
14 using ::testing::StrictMock; | 15 using ::testing::StrictMock; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 297 } |
297 | 298 |
298 void CompositeFilterTest::RunFilter2Callback() { | 299 void CompositeFilterTest::RunFilter2Callback() { |
299 EXPECT_TRUE(filter_2_callback_ != NULL); | 300 EXPECT_TRUE(filter_2_callback_ != NULL); |
300 FilterCallback* callback = filter_2_callback_; | 301 FilterCallback* callback = filter_2_callback_; |
301 filter_2_callback_ = NULL; | 302 filter_2_callback_ = NULL; |
302 callback->Run(); | 303 callback->Run(); |
303 delete callback; | 304 delete callback; |
304 } | 305 } |
305 | 306 |
306 static base::Thread* NullThreadFactory(const char* thread_name) { | |
307 return NULL; | |
308 } | |
309 | |
310 // Test AddFilter() failure cases. | 307 // Test AddFilter() failure cases. |
311 TEST_F(CompositeFilterTest, TestAddFilterFailCases) { | 308 TEST_F(CompositeFilterTest, TestAddFilterFailCases) { |
312 // Test adding a null pointer. | 309 // Test adding a null pointer. |
313 EXPECT_FALSE(composite_->AddFilter(NULL)); | 310 EXPECT_FALSE(composite_->AddFilter(NULL)); |
314 | 311 |
315 scoped_refptr<StrictMock<MockFilter> > filter = | 312 scoped_refptr<StrictMock<MockFilter> > filter = new StrictMock<MockFilter>(); |
316 new StrictMock<MockFilter>(true); | |
317 EXPECT_EQ(NULL, filter->host()); | 313 EXPECT_EQ(NULL, filter->host()); |
318 EXPECT_EQ(NULL, filter->message_loop()); | |
319 | 314 |
320 // Test failing because set_host() hasn't been called yet. | 315 // Test failing because set_host() hasn't been called yet. |
321 EXPECT_FALSE(composite_->AddFilter(filter)); | 316 EXPECT_FALSE(composite_->AddFilter(filter)); |
322 | |
323 // Test thread creation failure. | |
324 composite_ = new CompositeFilter(&message_loop_, &NullThreadFactory); | |
325 composite_->set_host(mock_filter_host_.get()); | |
326 EXPECT_FALSE(composite_->AddFilter(filter)); | |
327 EXPECT_EQ(NULL, filter->host()); | |
328 EXPECT_EQ(NULL, filter->message_loop()); | |
329 } | 317 } |
330 | 318 |
331 // Test successful AddFilter() cases. | 319 // Test successful AddFilter() cases. |
332 TEST_F(CompositeFilterTest, TestAddFilter) { | 320 TEST_F(CompositeFilterTest, TestAddFilter) { |
333 composite_->set_host(mock_filter_host_.get()); | 321 composite_->set_host(mock_filter_host_.get()); |
334 | 322 |
335 // Add a filter that doesn't require a message loop. | 323 // Add a filter. |
336 scoped_refptr<StrictMock<MockFilter> > filter = new StrictMock<MockFilter>(); | 324 scoped_refptr<StrictMock<MockFilter> > filter = new StrictMock<MockFilter>(); |
337 EXPECT_EQ(NULL, filter->host()); | 325 EXPECT_EQ(NULL, filter->host()); |
338 EXPECT_EQ(NULL, filter->message_loop()); | |
339 | 326 |
340 EXPECT_TRUE(composite_->AddFilter(filter)); | 327 EXPECT_TRUE(composite_->AddFilter(filter)); |
341 | 328 |
342 EXPECT_TRUE(filter->host() != NULL); | 329 EXPECT_TRUE(filter->host() != NULL); |
343 EXPECT_EQ(NULL, filter->message_loop()); | |
344 | |
345 // Add a filter that requires a message loop. | |
346 scoped_refptr<StrictMock<MockFilter> > filter_2 = | |
347 new StrictMock<MockFilter>(true); | |
348 | |
349 EXPECT_EQ(NULL, filter_2->host()); | |
350 EXPECT_EQ(NULL, filter_2->message_loop()); | |
351 | |
352 EXPECT_TRUE(composite_->AddFilter(filter_2)); | |
353 | |
354 EXPECT_TRUE(filter_2->host() != NULL); | |
355 EXPECT_TRUE(filter_2->message_loop() != NULL); | |
356 } | 330 } |
357 | 331 |
358 TEST_F(CompositeFilterTest, TestPlay) { | 332 TEST_F(CompositeFilterTest, TestPlay) { |
359 InSequence sequence; | 333 InSequence sequence; |
360 | 334 |
361 SetupAndAdd2Filters(); | 335 SetupAndAdd2Filters(); |
362 | 336 |
363 // Verify successful call to Play(). | 337 // Verify successful call to Play(). |
364 DoPlay(); | 338 DoPlay(); |
365 | 339 |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 // Issue a Play() and expect no errors. | 764 // Issue a Play() and expect no errors. |
791 EXPECT_CALL(*mock_callback, OnFilterCallback()); | 765 EXPECT_CALL(*mock_callback, OnFilterCallback()); |
792 composite_->Play(mock_callback->NewCallback()); | 766 composite_->Play(mock_callback->NewCallback()); |
793 | 767 |
794 // Issue a Stop() and expect no errors. | 768 // Issue a Stop() and expect no errors. |
795 EXPECT_CALL(*mock_callback, OnFilterCallback()); | 769 EXPECT_CALL(*mock_callback, OnFilterCallback()); |
796 composite_->Stop(mock_callback->NewCallback()); | 770 composite_->Stop(mock_callback->NewCallback()); |
797 } | 771 } |
798 | 772 |
799 } // namespace media | 773 } // namespace media |
OLD | NEW |