| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 closure.Run(); | 29 closure.Run(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 static const std::string kTestStreamUrl = "stream_url"; | 32 static const std::string kTestStreamUrl = "stream_url"; |
| 33 static const std::string kUnknownStreamUrl = "unknown_stream_url"; | 33 static const std::string kUnknownStreamUrl = "unknown_stream_url"; |
| 34 | 34 |
| 35 class VideoDestinationHandlerTest : public PpapiUnittest { | 35 class VideoDestinationHandlerTest : public PpapiUnittest { |
| 36 public: | 36 public: |
| 37 VideoDestinationHandlerTest() | 37 VideoDestinationHandlerTest() |
| 38 : child_process_(new ChildProcess()), | 38 : child_process_(new ChildProcess()), |
| 39 registry_(MockMediaStreamRegistry()) { | 39 registry_(new MockMediaStreamRegistry()) { |
| 40 registry_.Init(kTestStreamUrl); | 40 registry_->Init(kTestStreamUrl); |
| 41 } |
| 42 |
| 43 virtual void TearDown() { |
| 44 registry_.reset(); |
| 45 PpapiUnittest::TearDown(); |
| 41 } | 46 } |
| 42 | 47 |
| 43 base::MessageLoop* io_message_loop() const { | 48 base::MessageLoop* io_message_loop() const { |
| 44 return child_process_->io_message_loop(); | 49 return child_process_->io_message_loop(); |
| 45 } | 50 } |
| 46 | 51 |
| 47 protected: | 52 protected: |
| 48 scoped_ptr<ChildProcess> child_process_; | 53 scoped_ptr<ChildProcess> child_process_; |
| 49 MockMediaStreamRegistry registry_; | 54 scoped_ptr<MockMediaStreamRegistry> registry_; |
| 50 }; | 55 }; |
| 51 | 56 |
| 52 TEST_F(VideoDestinationHandlerTest, Open) { | 57 TEST_F(VideoDestinationHandlerTest, Open) { |
| 53 FrameWriterInterface* frame_writer = NULL; | 58 FrameWriterInterface* frame_writer = NULL; |
| 54 // Unknow url will return false. | 59 // Unknow url will return false. |
| 55 EXPECT_FALSE(VideoDestinationHandler::Open(®istry_, | 60 EXPECT_FALSE(VideoDestinationHandler::Open(registry_.get(), |
| 56 kUnknownStreamUrl, &frame_writer)); | 61 kUnknownStreamUrl, &frame_writer)); |
| 57 EXPECT_TRUE(VideoDestinationHandler::Open(®istry_, | 62 EXPECT_TRUE(VideoDestinationHandler::Open(registry_.get(), |
| 58 kTestStreamUrl, &frame_writer)); | 63 kTestStreamUrl, &frame_writer)); |
| 59 // The |frame_writer| is a proxy and is owned by whoever call Open. | 64 // The |frame_writer| is a proxy and is owned by whoever call Open. |
| 60 delete frame_writer; | 65 delete frame_writer; |
| 61 } | 66 } |
| 62 | 67 |
| 63 TEST_F(VideoDestinationHandlerTest, PutFrame) { | 68 TEST_F(VideoDestinationHandlerTest, PutFrame) { |
| 64 FrameWriterInterface* frame_writer = NULL; | 69 FrameWriterInterface* frame_writer = NULL; |
| 65 EXPECT_TRUE(VideoDestinationHandler::Open(®istry_, | 70 EXPECT_TRUE(VideoDestinationHandler::Open(registry_.get(), |
| 66 kTestStreamUrl, &frame_writer)); | 71 kTestStreamUrl, &frame_writer)); |
| 67 ASSERT_TRUE(frame_writer); | 72 ASSERT_TRUE(frame_writer); |
| 68 | 73 |
| 69 // Verify the video track has been added. | 74 // Verify the video track has been added. |
| 70 const blink::WebMediaStream test_stream = registry_.test_stream(); | 75 const blink::WebMediaStream test_stream = registry_->test_stream(); |
| 71 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 76 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 72 test_stream.videoTracks(video_tracks); | 77 test_stream.videoTracks(video_tracks); |
| 73 ASSERT_EQ(1u, video_tracks.size()); | 78 ASSERT_EQ(1u, video_tracks.size()); |
| 74 | 79 |
| 75 // Verify the native video track has been added. | 80 // Verify the native video track has been added. |
| 76 MediaStreamVideoTrack* native_track = | 81 MediaStreamVideoTrack* native_track = |
| 77 MediaStreamVideoTrack::GetVideoTrack(video_tracks[0]); | 82 MediaStreamVideoTrack::GetVideoTrack(video_tracks[0]); |
| 78 ASSERT_TRUE(native_track != NULL); | 83 ASSERT_TRUE(native_track != NULL); |
| 79 | 84 |
| 80 MockMediaStreamVideoSink sink; | 85 MockMediaStreamVideoSink sink; |
| 81 native_track->AddSink(&sink); | 86 native_track->AddSink(&sink, sink.GetDeliverFrameCB()); |
| 82 | 87 scoped_refptr<PPB_ImageData_Impl> image( |
| 83 scoped_refptr<PPB_ImageData_Impl> image( | |
| 84 new PPB_ImageData_Impl(instance()->pp_instance(), | 88 new PPB_ImageData_Impl(instance()->pp_instance(), |
| 85 PPB_ImageData_Impl::ForTest())); | 89 PPB_ImageData_Impl::ForTest())); |
| 86 image->Init(PP_IMAGEDATAFORMAT_BGRA_PREMUL, 640, 360, true); | 90 image->Init(PP_IMAGEDATAFORMAT_BGRA_PREMUL, 640, 360, true); |
| 87 { | 91 { |
| 88 base::RunLoop run_loop; | 92 base::RunLoop run_loop; |
| 89 base::Closure quit_closure = run_loop.QuitClosure(); | 93 base::Closure quit_closure = run_loop.QuitClosure(); |
| 90 | 94 |
| 91 EXPECT_CALL(sink, OnVideoFrame()).WillOnce( | 95 EXPECT_CALL(sink, OnVideoFrame()).WillOnce( |
| 92 RunClosure(quit_closure)); | 96 RunClosure(quit_closure)); |
| 93 frame_writer->PutFrame(image, 10); | 97 frame_writer->PutFrame(image, 10); |
| 94 run_loop.Run(); | 98 run_loop.Run(); |
| 95 } | 99 } |
| 96 // TODO(perkj): Verify that the track output I420 when | 100 // TODO(perkj): Verify that the track output I420 when |
| 97 // https://codereview.chromium.org/213423006/ is landed. | 101 // https://codereview.chromium.org/213423006/ is landed. |
| 98 EXPECT_EQ(1, sink.number_of_frames()); | 102 EXPECT_EQ(1, sink.number_of_frames()); |
| 99 native_track->RemoveSink(&sink); | 103 native_track->RemoveSink(&sink); |
| 100 | 104 |
| 101 // The |frame_writer| is a proxy and is owned by whoever call Open. | 105 // The |frame_writer| is a proxy and is owned by whoever call Open. |
| 102 delete frame_writer; | 106 delete frame_writer; |
| 103 } | 107 } |
| 104 | 108 |
| 105 } // namespace content | 109 } // namespace content |
| OLD | NEW |