OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/utf_string_conversions.h" |
| 8 #include "content/renderer/media/media_stream_extra_data.h" |
| 9 #include "content/renderer/media/media_stream_registry_interface.h" |
| 10 #include "content/renderer/media/mock_media_stream_dependency_factory.h" |
| 11 #include "content/renderer/media/mock_media_stream_registry.h" |
| 12 #include "content/renderer/media/video_source_handler.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack
.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 17 #include "third_party/libjingle/source/talk/media/base/videorenderer.h" |
| 18 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" |
| 19 |
| 20 using cricket::VideoFrame; |
| 21 |
| 22 namespace content { |
| 23 |
| 24 static const std::string kTestStreamUrl = "stream_url"; |
| 25 static const std::string kTestVideoTrackId = "video_track_id"; |
| 26 static const std::string kUnknownStreamUrl = "unknown_stream_url"; |
| 27 |
| 28 class FakeFrameReader : public FrameReaderInterface { |
| 29 public: |
| 30 virtual bool GotFrame(VideoFrame* frame) OVERRIDE { |
| 31 last_frame_.reset(frame); |
| 32 return true; |
| 33 } |
| 34 |
| 35 const VideoFrame* last_frame() { |
| 36 return last_frame_.get(); |
| 37 } |
| 38 |
| 39 private: |
| 40 scoped_ptr<VideoFrame> last_frame_; |
| 41 }; |
| 42 |
| 43 class VideoSourceHandlerTest : public ::testing::Test { |
| 44 public: |
| 45 VideoSourceHandlerTest() : registry_(&dependency_factory_) { |
| 46 handler_.reset(new VideoSourceHandler(®istry_)); |
| 47 dependency_factory_.EnsurePeerConnectionFactory(); |
| 48 registry_.Init(kTestStreamUrl); |
| 49 registry_.AddVideoTrack(kTestVideoTrackId); |
| 50 } |
| 51 |
| 52 protected: |
| 53 scoped_ptr<VideoSourceHandler> handler_; |
| 54 MockMediaStreamDependencyFactory dependency_factory_; |
| 55 MockMediaStreamRegistry registry_; |
| 56 }; |
| 57 |
| 58 TEST_F(VideoSourceHandlerTest, OpenClose) { |
| 59 FakeFrameReader reader; |
| 60 // Unknow url will return false. |
| 61 EXPECT_FALSE(handler_->Open(kUnknownStreamUrl, &reader)); |
| 62 EXPECT_TRUE(handler_->Open(kTestStreamUrl, &reader)); |
| 63 cricket::WebRtcVideoFrame test_frame; |
| 64 int width = 640; |
| 65 int height = 360; |
| 66 int64 et = 123456; |
| 67 int64 ts = 789012; |
| 68 test_frame.InitToBlack(width, height, 1, 1, et, ts); |
| 69 cricket::VideoRenderer* receiver = handler_->GetReceiver(&reader); |
| 70 ASSERT(receiver != NULL); |
| 71 receiver->RenderFrame(&test_frame); |
| 72 |
| 73 const VideoFrame* frame = reader.last_frame(); |
| 74 ASSERT_TRUE(frame != NULL); |
| 75 |
| 76 // Compare |frame| to |test_frame|. |
| 77 EXPECT_EQ(test_frame.GetWidth(), frame->GetWidth()); |
| 78 EXPECT_EQ(test_frame.GetHeight(), frame->GetHeight()); |
| 79 EXPECT_EQ(test_frame.GetElapsedTime(), frame->GetElapsedTime()); |
| 80 EXPECT_EQ(test_frame.GetTimeStamp(), frame->GetTimeStamp()); |
| 81 EXPECT_EQ(test_frame.GetYPlane(), frame->GetYPlane()); |
| 82 EXPECT_EQ(test_frame.GetUPlane(), frame->GetUPlane()); |
| 83 EXPECT_EQ(test_frame.GetVPlane(), frame->GetVPlane()); |
| 84 |
| 85 EXPECT_TRUE(handler_->Close(kTestStreamUrl, &reader)); |
| 86 EXPECT_TRUE(handler_->GetReceiver(&reader) == NULL); |
| 87 } |
| 88 |
| 89 } // namespace content |
OLD | NEW |