Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: content/renderer/media/video_destination_handler_unittest.cc

Issue 14312015: Effects Pepper Plugin and MediaStream Glue. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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/mock_media_stream_dependency_factory.h"
10 #include "content/renderer/media/mock_media_stream_registry.h"
11 #include "content/renderer/media/video_destination_handler.h"
12 #include "ppapi/c/ppb_image_data.h"
13 #include "ppapi/c/ppb_instance.h"
14 #include "ppapi/c/pp_size.h"
15 #include "ppapi/shared_impl/test_globals.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack .h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
20 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
21
22 using cricket::CapturedFrame;
23 using cricket::CaptureState;
24 using cricket::VideoCapturer;
25 using cricket::VideoFormat;
26 using cricket::VideoFormatPod;
27 using ppapi::TestGlobals;
28 using webkit::ppapi::PPB_ImageData_Impl;
29
30 namespace content {
31
32 static const std::string kTestStreamUrl = "stream_url";
33 static const std::string kUnknownStreamUrl = "unknown_stream_url";
34 static const VideoFormatPod kTestFormat = {
35 640, 360, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY
36 };
37
38 class PpFrameWriterTest
39 : public ::testing::Test,
40 public sigslot::has_slots<> {
41 public:
42 PpFrameWriterTest()
43 : last_capture_state_(cricket::CS_FAILED),
44 captured_frame_count_(0),
45 captured_frame_(NULL) {
46 writer_.SignalStateChange.connect(this, &PpFrameWriterTest::OnStateChange);
47 writer_.SignalFrameCaptured.connect(
48 this, &PpFrameWriterTest::OnFrameCaptured);
49 }
50
51 void OnStateChange(VideoCapturer* capturer, CaptureState state) {
52 last_capture_state_ = state;
53 }
54
55 void OnFrameCaptured(VideoCapturer* capturer, const CapturedFrame* frame) {
56 ++captured_frame_count_;
57 captured_frame_ = const_cast<CapturedFrame*>(frame);
58 }
59
60 protected:
61 PpFrameWriter writer_;
62 CaptureState last_capture_state_;
63 int captured_frame_count_;
64 CapturedFrame* captured_frame_;
65 TestGlobals globals_;
66 };
67
68 class VideoDestinationHandlerTest : public ::testing::Test {
69 public:
70 VideoDestinationHandlerTest() : registry_(&factory_) {
71 factory_.EnsurePeerConnectionFactory();
72 registry_.Init(kTestStreamUrl);
73 }
74
75 protected:
76 MockMediaStreamDependencyFactory factory_;
77 MockMediaStreamRegistry registry_;
78 };
79
80 TEST_F(PpFrameWriterTest, StartStop) {
81 EXPECT_FALSE(writer_.IsRunning());
82 EXPECT_EQ(cricket::CS_STARTING, writer_.Start(VideoFormat(kTestFormat)));
83 EXPECT_TRUE(writer_.IsRunning());
84 EXPECT_EQ(cricket::CS_FAILED, writer_.Start(VideoFormat(kTestFormat)));
85 writer_.Stop();
86 EXPECT_EQ(cricket::CS_STOPPED, last_capture_state_);
87 }
88
89 TEST_F(PpFrameWriterTest, GetPreferredFourccs) {
90 std::vector<uint32> fourccs;
91 EXPECT_TRUE(writer_.GetPreferredFourccs(&fourccs));
92 EXPECT_EQ(1u, fourccs.size());
93 EXPECT_EQ(cricket::FOURCC_BGRA, fourccs[0]);
94 }
95
96 TEST_F(PpFrameWriterTest, GetBestCaptureFormat) {
97 VideoFormat desired(kTestFormat);
98 VideoFormat best_format;
99 EXPECT_FALSE(writer_.GetBestCaptureFormat(desired, NULL));
100 EXPECT_TRUE(writer_.GetBestCaptureFormat(desired, &best_format));
101 EXPECT_EQ(cricket::FOURCC_BGRA, best_format.fourcc);
102
103 desired.fourcc = best_format.fourcc;
104 EXPECT_EQ(desired, best_format);
105 }
106
107 TEST_F(PpFrameWriterTest, PutFrame) {
108 // TODO(ronghuawu): Figure out how to mock PPB_ImageData_Impl and enable
109 // this test.
110 // PP_Instance instance = 0x1234561;
111 // globals_.GetResourceTracker()->DidCreateInstance(instance);
112 // PP_Size size = {640, 480};
113 // PP_Bool init_to_zero = PP_TRUE;
114 // PP_ImageDataFormat format = PP_IMAGEDATAFORMAT_BGRA_PREMUL;
115 // scoped_refptr<PPB_ImageData_Impl>
116 // data(new PPB_ImageData_Impl(instance, PPB_ImageData_Impl::NACL));
117 // EXPECT_TRUE(data->Init(format, size.width, size.height, init_to_zero));
118 // int64 ts_ns = 345678;
119 //
120 // EXPECT_EQ(cricket::CS_STARTING, writer_.Start(VideoFormat(kTestFormat)));
121 // EXPECT_EQ(0, captured_frame_count_);
122 // writer_.PutFrame(data.get(), ts_ns);
123 // EXPECT_EQ(1, captured_frame_count_);
124 }
125
126 TEST_F(VideoDestinationHandlerTest, Open) {
127 FrameWriterInterface* frame_writer = NULL;
128 // Unknow url will return false.
129 EXPECT_FALSE(VideoDestinationHandler::Open(&factory_, &registry_,
130 kUnknownStreamUrl, &frame_writer));
131 EXPECT_TRUE(VideoDestinationHandler::Open(&factory_, &registry_,
132 kTestStreamUrl, &frame_writer));
133 EXPECT_TRUE(frame_writer);
134
135 // Verify the video track has been added.
136 const WebKit::WebMediaStream test_stream = registry_.test_stream();
137 WebKit::WebVector<WebKit::WebMediaStreamTrack> video_tracks;
138 test_stream.videoSources(video_tracks);
139 EXPECT_EQ(1u, video_tracks.size());
140
141 // Verify the native video track has been added.
142 MediaStreamExtraData* extra_data =
143 static_cast<MediaStreamExtraData*>(test_stream.extraData());
144 DCHECK(extra_data);
145 webrtc::MediaStreamInterface* native_stream = extra_data->stream();
146 DCHECK(native_stream);
147 webrtc::VideoTrackVector native_video_tracks =
148 native_stream->GetVideoTracks();
149 EXPECT_EQ(1u, native_video_tracks.size());
150
151 delete frame_writer;
152 }
153
154 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698