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.
7 #include "base/message_loop/message_loop.h"
8 #include "content/child/child_process.h"
9 #include "content/renderer/media/media_stream.h"
10 #include "content/renderer/media/mock_media_stream_registry.h"
11 #include "content/renderer/media/video_track_to_pepper_adapter.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/web/WebHeap.h"
18 static const std::string kTestStreamUrl
= "stream_url";
19 static const std::string kTestVideoTrackId
= "video_track_id";
20 static const std::string kUnknownStreamUrl
= "unknown_stream_url";
22 class VideoTrackToPepperAdapterTest
: public ::testing::Test
,
23 public FrameReaderInterface
{
25 VideoTrackToPepperAdapterTest() : registry_(new MockMediaStreamRegistry()) {
26 handler_
.reset(new VideoTrackToPepperAdapter(registry_
.get()));
27 registry_
->Init(kTestStreamUrl
);
28 registry_
->AddVideoTrack(kTestVideoTrackId
);
29 EXPECT_FALSE(handler_
->GetFirstVideoTrack(kTestStreamUrl
).isNull());
32 MOCK_METHOD1(GotFrame
, void(const scoped_refptr
<media::VideoFrame
>&));
34 void TearDown() override
{
37 blink::WebHeap::collectAllGarbageForTesting();
40 void DeliverFrameForTesting(const scoped_refptr
<media::VideoFrame
>& frame
) {
41 handler_
->DeliverFrameForTesting(this, frame
);
45 scoped_ptr
<VideoTrackToPepperAdapter
> handler_
;
46 // A ChildProcess and a MessageLoop are both needed to fool the Tracks and
47 // Sources inside |registry_| into believing they are on the right threads.
48 const ChildProcess child_process_
;
49 const base::MessageLoop message_loop_
;
50 scoped_ptr
<MockMediaStreamRegistry
> registry_
;
53 // Open |handler_| and send a VideoFrame to be received at the other side.
54 TEST_F(VideoTrackToPepperAdapterTest
, OpenClose
) {
55 // Unknow url will return false.
56 EXPECT_FALSE(handler_
->Open(kUnknownStreamUrl
, this));
57 EXPECT_TRUE(handler_
->Open(kTestStreamUrl
, this));
59 const base::TimeDelta ts
= base::TimeDelta::FromMilliseconds(789012);
60 const scoped_refptr
<media::VideoFrame
> captured_frame
=
61 media::VideoFrame::CreateBlackFrame(gfx::Size(640, 360));
62 captured_frame
->set_timestamp(ts
);
64 EXPECT_CALL(*this, GotFrame(captured_frame
));
65 DeliverFrameForTesting(captured_frame
);
67 EXPECT_FALSE(handler_
->Close(NULL
));
68 EXPECT_TRUE(handler_
->Close(this));
71 TEST_F(VideoTrackToPepperAdapterTest
, OpenWithoutClose
) {
72 EXPECT_TRUE(handler_
->Open(kTestStreamUrl
, this));
75 } // namespace content