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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.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/filter_host.h" | 11 #include "media/base/filter_host.h" |
12 #include "media/base/filters.h" | 12 #include "media/base/filters.h" |
13 #include "media/base/media_log.h" | 13 #include "media/base/media_log.h" |
14 #include "media/base/pipeline_impl.h" | 14 #include "media/base/pipeline_impl.h" |
15 #include "media/base/mock_callback.h" | 15 #include "media/base/mock_callback.h" |
16 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
19 | 19 |
20 using ::testing::_; | 20 using ::testing::_; |
21 using ::testing::DeleteArg; | 21 using ::testing::DeleteArg; |
22 using ::testing::InSequence; | 22 using ::testing::InSequence; |
23 using ::testing::Invoke; | 23 using ::testing::Invoke; |
| 24 using ::testing::InvokeArgument; |
24 using ::testing::Mock; | 25 using ::testing::Mock; |
25 using ::testing::NotNull; | 26 using ::testing::NotNull; |
26 using ::testing::Return; | 27 using ::testing::Return; |
27 using ::testing::ReturnRef; | 28 using ::testing::ReturnRef; |
28 using ::testing::StrictMock; | 29 using ::testing::StrictMock; |
| 30 using ::testing::WithArg; |
29 | 31 |
30 namespace media { | 32 namespace media { |
31 | 33 |
32 // Total bytes of the data source. | 34 // Total bytes of the data source. |
33 static const int kTotalBytes = 1024; | 35 static const int kTotalBytes = 1024; |
34 | 36 |
35 // Buffered bytes of the data source. | 37 // Buffered bytes of the data source. |
36 static const int kBufferedBytes = 1024; | 38 static const int kBufferedBytes = 1024; |
37 | 39 |
38 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 40 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
39 // also lets us test for missing callbacks. | 41 // also lets us test for missing callbacks. |
40 class CallbackHelper { | 42 class CallbackHelper { |
41 public: | 43 public: |
42 CallbackHelper() {} | 44 CallbackHelper() {} |
43 virtual ~CallbackHelper() {} | 45 virtual ~CallbackHelper() {} |
44 | 46 |
45 MOCK_METHOD1(OnStart, void(PipelineStatus)); | 47 MOCK_METHOD1(OnStart, void(PipelineStatus)); |
46 MOCK_METHOD1(OnSeek, void(PipelineStatus)); | 48 MOCK_METHOD1(OnSeek, void(PipelineStatus)); |
47 MOCK_METHOD1(OnStop, void(PipelineStatus)); | 49 MOCK_METHOD1(OnStop, void(PipelineStatus)); |
48 MOCK_METHOD1(OnEnded, void(PipelineStatus)); | 50 MOCK_METHOD1(OnEnded, void(PipelineStatus)); |
49 MOCK_METHOD1(OnError, void(PipelineStatus)); | 51 MOCK_METHOD1(OnError, void(PipelineStatus)); |
50 | 52 |
51 private: | 53 private: |
52 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); | 54 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); |
53 }; | 55 }; |
54 | 56 |
| 57 // Run |cb| w/ OK status. |
| 58 static void RunPipelineStatusOKCB(const PipelineStatusCB& cb) { |
| 59 cb.Run(PIPELINE_OK); |
| 60 } |
| 61 |
55 // TODO(scherkus): even though some filters are initialized on separate | 62 // TODO(scherkus): even though some filters are initialized on separate |
56 // threads these test aren't flaky... why? It's because filters' Initialize() | 63 // threads these test aren't flaky... why? It's because filters' Initialize() |
57 // is executed on |message_loop_| and the mock filters instantly call | 64 // is executed on |message_loop_| and the mock filters instantly call |
58 // InitializationComplete(), which keeps the pipeline humming along. If | 65 // InitializationComplete(), which keeps the pipeline humming along. If |
59 // either filters don't call InitializationComplete() immediately or filter | 66 // either filters don't call InitializationComplete() immediately or filter |
60 // initialization is moved to a separate thread this test will become flaky. | 67 // initialization is moved to a separate thread this test will become flaky. |
61 class PipelineImplTest : public ::testing::Test { | 68 class PipelineImplTest : public ::testing::Test { |
62 public: | 69 public: |
63 PipelineImplTest() | 70 PipelineImplTest() |
64 : pipeline_(new PipelineImpl(&message_loop_, new MediaLog())) { | 71 : pipeline_(new PipelineImpl(&message_loop_, new MediaLog())) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 new StrictMock<MockDemuxerStream>(); | 126 new StrictMock<MockDemuxerStream>(); |
120 EXPECT_CALL(*stream, type()) | 127 EXPECT_CALL(*stream, type()) |
121 .WillRepeatedly(Return(type)); | 128 .WillRepeatedly(Return(type)); |
122 return stream; | 129 return stream; |
123 } | 130 } |
124 | 131 |
125 // Sets up expectations to allow the video decoder to initialize. | 132 // Sets up expectations to allow the video decoder to initialize. |
126 void InitializeVideoDecoder(MockDemuxerStream* stream) { | 133 void InitializeVideoDecoder(MockDemuxerStream* stream) { |
127 EXPECT_CALL(*mocks_->video_decoder(), | 134 EXPECT_CALL(*mocks_->video_decoder(), |
128 Initialize(stream, _, _)) | 135 Initialize(stream, _, _)) |
129 .WillOnce(Invoke(&RunFilterCallback3)); | 136 .WillOnce(WithArg<1>(Invoke(&RunPipelineStatusOKCB))); |
130 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); | 137 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); |
131 EXPECT_CALL(*mocks_->video_decoder(), | 138 EXPECT_CALL(*mocks_->video_decoder(), |
132 Seek(mocks_->demuxer()->GetStartTime(), _)) | 139 Seek(mocks_->demuxer()->GetStartTime(), _)) |
133 .WillOnce(Invoke(&RunFilterStatusCB)); | 140 .WillOnce(Invoke(&RunFilterStatusCB)); |
134 EXPECT_CALL(*mocks_->video_decoder(), Stop(_)) | 141 EXPECT_CALL(*mocks_->video_decoder(), Stop(_)) |
135 .WillOnce(Invoke(&RunStopFilterCallback)); | 142 .WillOnce(Invoke(&RunStopFilterCallback)); |
136 } | 143 } |
137 | 144 |
138 // Sets up expectations to allow the audio decoder to initialize. | 145 // Sets up expectations to allow the audio decoder to initialize. |
139 void InitializeAudioDecoder(MockDemuxerStream* stream) { | 146 void InitializeAudioDecoder(MockDemuxerStream* stream) { |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 TestPipelineStatusNotification(0); | 919 TestPipelineStatusNotification(0); |
913 } | 920 } |
914 | 921 |
915 // Test that different-thread, some-delay callback (the expected common case) | 922 // Test that different-thread, some-delay callback (the expected common case) |
916 // works correctly. | 923 // works correctly. |
917 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 924 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
918 TestPipelineStatusNotification(20); | 925 TestPipelineStatusNotification(20); |
919 } | 926 } |
920 | 927 |
921 } // namespace media | 928 } // namespace media |
OLD | NEW |