OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/test/simple_test_tick_clock.h" |
| 8 #include "base/time/tick_clock.h" |
| 9 #include "media/cast/cast_config.h" |
6 #include "media/cast/cast_defines.h" | 10 #include "media/cast/cast_defines.h" |
| 11 #include "media/cast/cast_environment.h" |
| 12 #include "media/cast/cast_receiver.h" |
| 13 #include "media/cast/test/fake_task_runner.h" |
7 #include "media/cast/video_receiver/video_decoder.h" | 14 #include "media/cast/video_receiver/video_decoder.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
9 | 16 |
10 namespace media { | 17 namespace media { |
11 namespace cast { | 18 namespace cast { |
12 | 19 |
13 using testing::_; | 20 using testing::_; |
14 | 21 |
15 // Random frame size for testing. | 22 // Random frame size for testing. |
16 const int kFrameSize = 2345; | 23 const int kFrameSize = 2345; |
| 24 static const int64 kStartMillisecond = GG_INT64_C(1245); |
| 25 |
| 26 namespace { |
| 27 class DecodeTestFrameCallback : |
| 28 public base::RefCountedThreadSafe<DecodeTestFrameCallback> { |
| 29 public: |
| 30 DecodeTestFrameCallback() {} |
| 31 |
| 32 void DecodeComplete(scoped_ptr<I420VideoFrame> decoded_frame, |
| 33 const base::TimeTicks& render_time) {} |
| 34 protected: |
| 35 virtual ~DecodeTestFrameCallback() {} |
| 36 private: |
| 37 friend class base::RefCountedThreadSafe<DecodeTestFrameCallback>; |
| 38 }; |
| 39 } // namespace |
17 | 40 |
18 class VideoDecoderTest : public ::testing::Test { | 41 class VideoDecoderTest : public ::testing::Test { |
19 protected: | 42 protected: |
20 VideoDecoderTest() { | 43 VideoDecoderTest() |
| 44 : task_runner_(new test::FakeTaskRunner(&testing_clock_)), |
| 45 cast_environment_(new CastEnvironment(&testing_clock_, task_runner_, |
| 46 task_runner_, task_runner_, task_runner_, task_runner_)), |
| 47 test_callback_(new DecodeTestFrameCallback()) { |
21 // Configure to vp8. | 48 // Configure to vp8. |
22 config_.codec = kVp8; | 49 config_.codec = kVp8; |
23 config_.use_external_decoder = false; | 50 config_.use_external_decoder = false; |
24 decoder_.reset(new VideoDecoder(config_)); | 51 decoder_.reset(new VideoDecoder(config_, cast_environment_)); |
| 52 testing_clock_.Advance( |
| 53 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
25 } | 54 } |
26 | 55 |
27 virtual ~VideoDecoderTest() {} | 56 virtual ~VideoDecoderTest() {} |
28 | 57 |
29 scoped_ptr<VideoDecoder> decoder_; | 58 scoped_ptr<VideoDecoder> decoder_; |
30 VideoReceiverConfig config_; | 59 VideoReceiverConfig config_; |
| 60 base::SimpleTestTickClock testing_clock_; |
| 61 scoped_refptr<test::FakeTaskRunner> task_runner_; |
| 62 scoped_refptr<CastEnvironment> cast_environment_; |
| 63 scoped_refptr<DecodeTestFrameCallback> test_callback_; |
31 }; | 64 }; |
32 | 65 |
33 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind. | 66 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind. |
34 TEST_F(VideoDecoderTest, DISABLED_SizeZero) { | 67 TEST_F(VideoDecoderTest, DISABLED_SizeZero) { |
35 EncodedVideoFrame encoded_frame; | 68 EncodedVideoFrame encoded_frame; |
36 I420VideoFrame video_frame; | |
37 base::TimeTicks render_time; | 69 base::TimeTicks render_time; |
38 encoded_frame.codec = kVp8; | 70 encoded_frame.codec = kVp8; |
39 | |
40 EXPECT_DEATH( | 71 EXPECT_DEATH( |
41 decoder_->DecodeVideoFrame(&encoded_frame, render_time, &video_frame), | 72 decoder_->DecodeVideoFrame( |
42 "Empty video frame"); | 73 &encoded_frame, render_time, |
| 74 base::Bind(&DecodeTestFrameCallback::DecodeComplete, test_callback_)), |
| 75 "Empty frame"); |
43 } | 76 } |
44 | 77 |
45 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind. | 78 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind. |
46 TEST_F(VideoDecoderTest, DISABLED_InvalidCodec) { | 79 TEST_F(VideoDecoderTest, DISABLED_InvalidCodec) { |
47 EncodedVideoFrame encoded_frame; | 80 EncodedVideoFrame encoded_frame; |
48 I420VideoFrame video_frame; | |
49 base::TimeTicks render_time; | 81 base::TimeTicks render_time; |
50 encoded_frame.data.assign(kFrameSize, 0); | 82 encoded_frame.data.assign(kFrameSize, 0); |
51 encoded_frame.codec = kExternalVideo; | 83 encoded_frame.codec = kExternalVideo; |
52 EXPECT_DEATH( | 84 EXPECT_DEATH( |
53 decoder_->DecodeVideoFrame(&encoded_frame, render_time, &video_frame), | 85 decoder_->DecodeVideoFrame(&encoded_frame, render_time, base::Bind( |
54 "Invalid codec"); | 86 &DecodeTestFrameCallback::DecodeComplete, test_callback_)), |
| 87 "Invalid codec"); |
55 } | 88 } |
56 | 89 |
57 // TODO(pwestin): Test decoding a real frame. | 90 // TODO(pwestin): Test decoding a real frame. |
58 | 91 |
59 } // namespace cast | 92 } // namespace cast |
60 } // namespace media | 93 } // namespace media |
OLD | NEW |