| OLD | NEW | 
|    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2012 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 <string> |    5 #include <string> | 
|    6  |    6  | 
|    7 #include "base/bind.h" |    7 #include "base/bind.h" | 
|    8 #include "base/message_loop.h" |    8 #include "base/message_loop.h" | 
|    9 #include "base/stl_util.h" |    9 #include "base/stl_util.h" | 
|   10 #include "base/threading/simple_thread.h" |   10 #include "base/threading/simple_thread.h" | 
|   11 #include "media/base/clock.h" |   11 #include "media/base/clock.h" | 
|   12 #include "media/base/filter_host.h" |   12 #include "media/base/filter_host.h" | 
|   13 #include "media/base/filters.h" |   13 #include "media/base/filters.h" | 
|   14 #include "media/base/media_log.h" |   14 #include "media/base/media_log.h" | 
|   15 #include "media/base/pipeline.h" |   15 #include "media/base/pipeline.h" | 
|   16 #include "media/base/mock_callback.h" |   16 #include "media/base/mock_callback.h" | 
|   17 #include "media/base/mock_filters.h" |   17 #include "media/base/mock_filters.h" | 
|   18 #include "testing/gtest/include/gtest/gtest.h" |   18 #include "testing/gtest/include/gtest/gtest.h" | 
|   19 #include "ui/gfx/size.h" |   19 #include "ui/gfx/size.h" | 
|   20  |   20  | 
|   21 using ::testing::_; |   21 using ::testing::_; | 
|   22 using ::testing::DeleteArg; |   22 using ::testing::DeleteArg; | 
 |   23 using ::testing::DoAll; | 
|   23 using ::testing::InSequence; |   24 using ::testing::InSequence; | 
|   24 using ::testing::Invoke; |   25 using ::testing::Invoke; | 
|   25 using ::testing::InvokeArgument; |  | 
|   26 using ::testing::Mock; |   26 using ::testing::Mock; | 
|   27 using ::testing::NotNull; |   27 using ::testing::NotNull; | 
|   28 using ::testing::Return; |   28 using ::testing::Return; | 
|   29 using ::testing::ReturnRef; |   29 using ::testing::ReturnRef; | 
|   30 using ::testing::StrictMock; |   30 using ::testing::StrictMock; | 
|   31 using ::testing::WithArg; |   31 using ::testing::WithArg; | 
|   32  |   32  | 
|   33 namespace media { |   33 namespace media { | 
|   34  |   34  | 
|   35 // Total bytes of the data source. |   35 // Total bytes of the data source. | 
|   36 static const int kTotalBytes = 1024; |   36 static const int kTotalBytes = 1024; | 
|   37  |   37  | 
|   38 // Buffered bytes of the data source. |   38 // Buffered bytes of the data source. | 
|   39 static const int kBufferedBytes = 1024; |   39 static const int kBufferedBytes = 1024; | 
|   40  |   40  | 
 |   41 ACTION_P(InitializeDemuxerWithError, error) { | 
 |   42   arg1.Run(error); | 
 |   43 } | 
 |   44  | 
 |   45 ACTION_P(SetDemuxerProperties, duration) { | 
 |   46   arg0->SetTotalBytes(kTotalBytes); | 
 |   47   arg0->SetBufferedBytes(kBufferedBytes); | 
 |   48   arg0->SetDuration(duration); | 
 |   49 } | 
 |   50  | 
|   41 // Used for setting expectations on pipeline callbacks.  Using a StrictMock |   51 // Used for setting expectations on pipeline callbacks.  Using a StrictMock | 
|   42 // also lets us test for missing callbacks. |   52 // also lets us test for missing callbacks. | 
|   43 class CallbackHelper { |   53 class CallbackHelper { | 
|   44  public: |   54  public: | 
|   45   CallbackHelper() {} |   55   CallbackHelper() {} | 
|   46   virtual ~CallbackHelper() {} |   56   virtual ~CallbackHelper() {} | 
|   47  |   57  | 
|   48   MOCK_METHOD1(OnStart, void(PipelineStatus)); |   58   MOCK_METHOD1(OnStart, void(PipelineStatus)); | 
|   49   MOCK_METHOD1(OnSeek, void(PipelineStatus)); |   59   MOCK_METHOD1(OnSeek, void(PipelineStatus)); | 
|   50   MOCK_METHOD0(OnStop, void()); |   60   MOCK_METHOD0(OnStop, void()); | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   90  |  100  | 
|   91     pipeline_ = NULL; |  101     pipeline_ = NULL; | 
|   92     mocks_.reset(); |  102     mocks_.reset(); | 
|   93   } |  103   } | 
|   94  |  104  | 
|   95  protected: |  105  protected: | 
|   96   // Sets up expectations to allow the demuxer to initialize. |  106   // Sets up expectations to allow the demuxer to initialize. | 
|   97   typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |  107   typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 
|   98   void InitializeDemuxer(MockDemuxerStreamVector* streams, |  108   void InitializeDemuxer(MockDemuxerStreamVector* streams, | 
|   99                          const base::TimeDelta& duration) { |  109                          const base::TimeDelta& duration) { | 
|  100     EXPECT_CALL(*mocks_->demuxer(), Initialize(_)) |  110     EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 
|  101         .WillOnce(Invoke(&RunPipelineStatusCB)); |  111         .WillOnce(DoAll(SetDemuxerProperties(duration), | 
|  102     mocks_->demuxer()->SetTotalAndBufferedBytesAndDuration( |  112                         Invoke(&RunPipelineStatusCB2))); | 
|  103         kTotalBytes, kBufferedBytes, duration); |  | 
|  104     EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |  113     EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 
|  105     EXPECT_CALL(*mocks_->demuxer(), Seek(mocks_->demuxer()->GetStartTime(), _)) |  114     EXPECT_CALL(*mocks_->demuxer(), Seek(mocks_->demuxer()->GetStartTime(), _)) | 
|  106         .WillOnce(Invoke(&RunPipelineStatusCB2)); |  115         .WillOnce(Invoke(&RunPipelineStatusCB2)); | 
|  107     EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |  116     EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 
|  108         .WillOnce(Invoke(&RunStopFilterCallback)); |  117         .WillOnce(Invoke(&RunStopFilterCallback)); | 
|  109  |  118  | 
|  110     // Configure the demuxer to return the streams. |  119     // Configure the demuxer to return the streams. | 
|  111     for (size_t i = 0; i < streams->size(); ++i) { |  120     for (size_t i = 0; i < streams->size(); ++i) { | 
|  112       scoped_refptr<DemuxerStream> stream((*streams)[i]); |  121       scoped_refptr<DemuxerStream> stream((*streams)[i]); | 
|  113       EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) |  122       EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) | 
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  274  |  283  | 
|  275   // Should always get set to zero. |  284   // Should always get set to zero. | 
|  276   gfx::Size size(1, 1); |  285   gfx::Size size(1, 1); | 
|  277   pipeline_->GetNaturalVideoSize(&size); |  286   pipeline_->GetNaturalVideoSize(&size); | 
|  278   EXPECT_EQ(0, size.width()); |  287   EXPECT_EQ(0, size.width()); | 
|  279   EXPECT_EQ(0, size.height()); |  288   EXPECT_EQ(0, size.height()); | 
|  280 } |  289 } | 
|  281  |  290  | 
|  282 TEST_F(PipelineTest, NeverInitializes) { |  291 TEST_F(PipelineTest, NeverInitializes) { | 
|  283   // Don't execute the callback passed into Initialize(). |  292   // Don't execute the callback passed into Initialize(). | 
|  284   EXPECT_CALL(*mocks_->demuxer(), Initialize(_)); |  293   EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)); | 
|  285   EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |  294   EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 
|  286       .WillOnce(Invoke(&RunStopFilterCallback)); |  295       .WillOnce(Invoke(&RunStopFilterCallback)); | 
|  287  |  296  | 
|  288   // This test hangs during initialization by never calling |  297   // This test hangs during initialization by never calling | 
|  289   // InitializationComplete().  StrictMock<> will ensure that the callback is |  298   // InitializationComplete().  StrictMock<> will ensure that the callback is | 
|  290   // never executed. |  299   // never executed. | 
|  291   pipeline_->Start( |  300   pipeline_->Start( | 
|  292         mocks_->Create().Pass(), |  301         mocks_->Create().Pass(), | 
|  293         base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |  302         base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 
|  294         base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |  303         base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|  315       collection.Pass(), |  324       collection.Pass(), | 
|  316       base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |  325       base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 
|  317       base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |  326       base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 
|  318       NetworkEventCB(), |  327       NetworkEventCB(), | 
|  319       base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); |  328       base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); | 
|  320   message_loop_.RunAllPending(); |  329   message_loop_.RunAllPending(); | 
|  321   EXPECT_FALSE(pipeline_->IsInitialized()); |  330   EXPECT_FALSE(pipeline_->IsInitialized()); | 
|  322 } |  331 } | 
|  323  |  332  | 
|  324 TEST_F(PipelineTest, URLNotFound) { |  333 TEST_F(PipelineTest, URLNotFound) { | 
|  325   EXPECT_CALL(*mocks_->demuxer(), Initialize(_)) |  334   EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 
|  326       .WillOnce(RunPipelineStatusCBWithError( |  335       .WillOnce(InitializeDemuxerWithError(PIPELINE_ERROR_URL_NOT_FOUND)); | 
|  327           PIPELINE_ERROR_URL_NOT_FOUND)); |  | 
|  328   EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |  336   EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 
|  329       .WillOnce(Invoke(&RunStopFilterCallback)); |  337       .WillOnce(Invoke(&RunStopFilterCallback)); | 
|  330  |  338  | 
|  331   InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); |  339   InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); | 
|  332   EXPECT_FALSE(pipeline_->IsInitialized()); |  340   EXPECT_FALSE(pipeline_->IsInitialized()); | 
|  333 } |  341 } | 
|  334  |  342  | 
|  335 TEST_F(PipelineTest, NoStreams) { |  343 TEST_F(PipelineTest, NoStreams) { | 
|  336   EXPECT_CALL(*mocks_->demuxer(), Initialize(_)) |  344   EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 
|  337       .WillOnce(Invoke(&RunPipelineStatusCB)); |  345       .WillOnce(Invoke(&RunPipelineStatusCB2)); | 
|  338   EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |  346   EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 
|  339       .WillOnce(Invoke(&RunStopFilterCallback)); |  347       .WillOnce(Invoke(&RunStopFilterCallback)); | 
|  340  |  348  | 
|  341   InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); |  349   InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); | 
|  342   EXPECT_FALSE(pipeline_->IsInitialized()); |  350   EXPECT_FALSE(pipeline_->IsInitialized()); | 
|  343 } |  351 } | 
|  344  |  352  | 
|  345 TEST_F(PipelineTest, AudioStream) { |  353 TEST_F(PipelineTest, AudioStream) { | 
|  346   CreateAudioStream(); |  354   CreateAudioStream(); | 
|  347   MockDemuxerStreamVector streams; |  355   MockDemuxerStreamVector streams; | 
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  861   TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); |  869   TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); | 
|  862 } |  870 } | 
|  863  |  871  | 
|  864 // Test that different-thread, some-delay callback (the expected common case) |  872 // Test that different-thread, some-delay callback (the expected common case) | 
|  865 // works correctly. |  873 // works correctly. | 
|  866 TEST(PipelineStatusNotificationTest, DelayedCallback) { |  874 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 
|  867   TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |  875   TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 
|  868 } |  876 } | 
|  869  |  877  | 
|  870 }  // namespace media |  878 }  // namespace media | 
| OLD | NEW |