blob: 8703374586f4ce81a5cad51bd92e1046fbcf8085 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Copyright (c) 2012 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 "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "content/renderer/media/media_stream_impl.h"
#include "content/renderer/media/mock_media_stream_dependency_factory.h"
#include "content/renderer/media/mock_media_stream_dispatcher.h"
#include "content/renderer/media/mock_web_peer_connection_00_handler_client.h"
#include "content/renderer/media/mock_web_peer_connection_handler_client.h"
#include "content/renderer/media/peer_connection_handler.h"
#include "content/renderer/media/peer_connection_handler_jsep.h"
#include "content/renderer/media/video_capture_impl_manager.h"
#include "content/renderer/p2p/socket_dispatcher.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
class MediaStreamImplTest : public ::testing::Test {
public:
void SetUp() {
// Create our test object.
ms_dispatcher_.reset(new MockMediaStreamDispatcher());
p2p_socket_dispatcher_.reset(new content::P2PSocketDispatcher(NULL));
scoped_refptr<VideoCaptureImplManager> vc_manager(
new VideoCaptureImplManager());
MockMediaStreamDependencyFactory* dependency_factory =
new MockMediaStreamDependencyFactory();
ms_impl_.reset(new MediaStreamImpl(NULL,
ms_dispatcher_.get(),
p2p_socket_dispatcher_.get(),
vc_manager.get(),
dependency_factory));
}
void TearDown() {
// Make sure the message created by
// P2PSocketDispatcher::AsyncMessageSender::Send is handled before
// tear down to avoid a memory leak.
loop_.RunAllPending();
}
protected:
MessageLoop loop_;
scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher_;
scoped_ptr<content::P2PSocketDispatcher> p2p_socket_dispatcher_;
scoped_ptr<MediaStreamImpl> ms_impl_;
};
TEST_F(MediaStreamImplTest, Basic) {
// TODO(grunell): Add tests for WebKit::WebUserMediaClient and
// MediaStreamDispatcherEventHandler implementations.
WebKit::MockWebPeerConnectionHandlerClient client;
WebKit::WebPeerConnectionHandler* pc_handler =
ms_impl_->CreatePeerConnectionHandler(&client);
EXPECT_EQ(1u, ms_impl_->peer_connection_handlers_.size());
// Delete PC handler explicitly after closing to mimic WebKit behavior.
ms_impl_->ClosePeerConnection(
static_cast<PeerConnectionHandler*>(pc_handler));
EXPECT_TRUE(ms_impl_->peer_connection_handlers_.empty());
delete pc_handler;
WebKit::MockWebPeerConnection00HandlerClient client_jsep;
WebKit::WebPeerConnection00Handler* pc_handler_jsep =
ms_impl_->CreatePeerConnectionHandlerJsep(&client_jsep);
EXPECT_EQ(1u, ms_impl_->peer_connection_handlers_.size());
// Delete PC handler explicitly after closing to mimic WebKit behavior.
ms_impl_->ClosePeerConnection(
static_cast<PeerConnectionHandlerJsep*>(pc_handler_jsep));
EXPECT_TRUE(ms_impl_->peer_connection_handlers_.empty());
delete pc_handler_jsep;
}
TEST_F(MediaStreamImplTest, MultiplePeerConnections) {
// TODO(grunell): Add tests for WebKit::WebUserMediaClient and
// MediaStreamDispatcherEventHandler implementations.
WebKit::MockWebPeerConnectionHandlerClient client;
WebKit::WebPeerConnectionHandler* pc_handler =
ms_impl_->CreatePeerConnectionHandler(&client);
EXPECT_EQ(1u, ms_impl_->peer_connection_handlers_.size());
WebKit::MockWebPeerConnection00HandlerClient client_jsep;
WebKit::WebPeerConnection00Handler* pc_handler_jsep =
ms_impl_->CreatePeerConnectionHandlerJsep(&client_jsep);
EXPECT_EQ(2u, ms_impl_->peer_connection_handlers_.size());
// Delete PC handler explicitly after closing to mimic WebKit behavior.
ms_impl_->ClosePeerConnection(
static_cast<PeerConnectionHandler*>(pc_handler));
EXPECT_EQ(1u, ms_impl_->peer_connection_handlers_.size());
delete pc_handler;
// Delete PC handler explicitly after closing to mimic WebKit behavior.
ms_impl_->ClosePeerConnection(
static_cast<PeerConnectionHandlerJsep*>(pc_handler_jsep));
EXPECT_TRUE(ms_impl_->peer_connection_handlers_.empty());
delete pc_handler_jsep;
}
|