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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/video_destination_handler_unittest.cc
===================================================================
--- content/renderer/media/video_destination_handler_unittest.cc (revision 0)
+++ content/renderer/media/video_destination_handler_unittest.cc (revision 0)
@@ -0,0 +1,145 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/utf_string_conversions.h"
+#include "content/renderer/media/media_stream_extra_data.h"
+#include "content/renderer/media/mock_media_stream_dependency_factory.h"
+#include "content/renderer/media/mock_media_stream_registry.h"
+#include "content/renderer/media/video_destination_handler.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
+
+using cricket::CapturedFrame;
+using cricket::CaptureState;
+using cricket::VideoCapturer;
+using cricket::VideoFormat;
+using cricket::VideoFormatPod;
+
+namespace content {
+
+static const std::string kTestStreamUrl = "stream_url";
+static const std::string kUnknownStreamUrl = "unknown_stream_url";
+static const VideoFormatPod kTestFormat = {
+ 640, 360, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY
+};
+
+class PpFrameWriterTest
+ : public ::testing::Test,
+ public sigslot::has_slots<> {
+ public:
+ PpFrameWriterTest()
+ : last_capture_state_(cricket::CS_FAILED),
+ captured_frame_count_(0),
+ captured_frame_(NULL) {
+ writer_.SignalStateChange.connect(this, &PpFrameWriterTest::OnStateChange);
+ writer_.SignalFrameCaptured.connect(
+ this, &PpFrameWriterTest::OnFrameCaptured);
+ }
+
+ void OnStateChange(VideoCapturer* capturer, CaptureState state) {
+ last_capture_state_ = state;
+ }
+
+ void OnFrameCaptured(VideoCapturer* capturer, const CapturedFrame* frame) {
+ ++captured_frame_count_;
+ captured_frame_ = const_cast<CapturedFrame*>(frame);
+ }
+
+ protected:
+ PpFrameWriter writer_;
+ CaptureState last_capture_state_;
+ int captured_frame_count_;
+ CapturedFrame* captured_frame_;
+};
+
+class VideoDestinationHandlerTest : public ::testing::Test {
+ public:
+ VideoDestinationHandlerTest() : registry_(&dependency_factory_) {
+ handler_.reset(new VideoDestinationHandler(&dependency_factory_,
+ &registry_));
+ dependency_factory_.EnsurePeerConnectionFactory();
+ registry_.Init(kTestStreamUrl);
+ }
+
+ protected:
+ scoped_ptr<VideoDestinationHandler> handler_;
+ MockMediaStreamDependencyFactory dependency_factory_;
+ MockMediaStreamRegistry registry_;
+};
+
+TEST_F(PpFrameWriterTest, StartStop) {
+ EXPECT_FALSE(writer_.IsRunning());
+ EXPECT_EQ(cricket::CS_STARTING, writer_.Start(VideoFormat(kTestFormat)));
+ EXPECT_TRUE(writer_.IsRunning());
+ EXPECT_EQ(cricket::CS_FAILED, writer_.Start(VideoFormat(kTestFormat)));
+ writer_.Stop();
+ EXPECT_EQ(cricket::CS_STOPPED, last_capture_state_);
+}
+
+TEST_F(PpFrameWriterTest, GetPreferredFourccs) {
+ std::vector<uint32> fourccs;
+ EXPECT_TRUE(writer_.GetPreferredFourccs(&fourccs));
+ EXPECT_EQ(1u, fourccs.size());
+ EXPECT_EQ(cricket::FOURCC_BGRA, fourccs[0]);
+}
+
+TEST_F(PpFrameWriterTest, GetBestCaptureFormat) {
+ VideoFormat desired(kTestFormat);
+ VideoFormat best_format;
+ EXPECT_FALSE(writer_.GetBestCaptureFormat(desired, NULL));
+ EXPECT_TRUE(writer_.GetBestCaptureFormat(desired, &best_format));
+ EXPECT_EQ(cricket::FOURCC_BGRA, best_format.fourcc);
+
+ desired.fourcc = best_format.fourcc;
+ EXPECT_EQ(desired, best_format);
+}
+
+TEST_F(PpFrameWriterTest, PutFrame) {
+ // Init a test frame.
+ CapturedFrame test_frame1;
+ CapturedFrame test_frame2;
+ writer_.PutFrame(&test_frame1);
+ EXPECT_EQ(cricket::CS_STARTING, writer_.Start(VideoFormat(kTestFormat)));
+ EXPECT_EQ(0, captured_frame_count_);
+ writer_.PutFrame(&test_frame1);
+ EXPECT_EQ(1, captured_frame_count_);
+ EXPECT_EQ(&test_frame1, captured_frame_);
+ writer_.PutFrame(&test_frame2);
+ EXPECT_EQ(2, captured_frame_count_);
+ EXPECT_EQ(&test_frame2, captured_frame_);
+}
+
+TEST_F(VideoDestinationHandlerTest, Open) {
+ FrameWriterInterface* frame_writer = NULL;
+ // Unknow url will return false.
+ EXPECT_FALSE(handler_->Open(kUnknownStreamUrl, &frame_writer));
+ EXPECT_TRUE(handler_->Open(kTestStreamUrl, &frame_writer));
+ EXPECT_TRUE(frame_writer);
+
+ // Verify the video track has been added.
+ const WebKit::WebMediaStream test_stream = registry_.test_stream();
+ WebKit::WebVector<WebKit::WebMediaStreamTrack> video_tracks;
+ test_stream.videoSources(video_tracks);
+ EXPECT_EQ(1u, video_tracks.size());
+
+ // Verify the |frame_writer| has been set to the capturer of the video track.
+ MediaStreamExtraData* extra_data =
+ static_cast<MediaStreamExtraData*>(test_stream.extraData());
+ DCHECK(extra_data);
+ webrtc::MediaStreamInterface* native_stream = extra_data->stream();
+ DCHECK(native_stream);
+ webrtc::VideoTrackVector native_video_tracks =
+ native_stream->GetVideoTracks();
+ EXPECT_EQ(1u, native_video_tracks.size());
+ cricket::VideoCapturer* capturer =
+ native_video_tracks[0]->GetSource()->GetVideoCapturer();
+ EXPECT_EQ(static_cast<PpFrameWriter*>(capturer),
+ static_cast<PpFrameWriter*>(frame_writer));
+}
+
+} // namespace content
Property changes on: content/renderer/media/video_destination_handler_unittest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698