1 // Copyright (c) 2012 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.
5 #include "base/command_line.h"
6 #include "base/files/file_util.h"
7 #include "base/threading/platform_thread.h"
8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/browser_test_utils.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/public/test/test_utils.h"
13 #include "content/test/webrtc_content_browsertest_base.h"
14 #include "media/audio/audio_manager.h"
15 #include "media/base/media_switches.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h"
20 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
21 // Renderer crashes under Android ASAN: https://crbug.com/408496.
22 #define MAYBE_WebRtcBrowserTest DISABLED_WebRtcBrowserTest
24 #define MAYBE_WebRtcBrowserTest WebRtcBrowserTest
27 class MAYBE_WebRtcBrowserTest
: public WebRtcContentBrowserTest
{
29 MAYBE_WebRtcBrowserTest() {}
30 ~MAYBE_WebRtcBrowserTest() override
{}
32 // Convenience function since most peerconnection-call.html tests just load
33 // the page, kick off some javascript and wait for the title to change to OK.
34 void MakeTypicalPeerConnectionCall(const std::string
& javascript
) {
35 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
37 GURL
url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
38 NavigateToURL(shell(), url
);
40 ExecuteJavascriptAndWaitForOk(javascript
);
43 // Convenience method for making calls that detect if audio os playing (which
44 // has some special prerequisites, such that there needs to be an audio output
45 // device on the executing machine).
46 void MakeAudioDetectingPeerConnectionCall(const std::string
& javascript
) {
47 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
48 // Bots with no output devices will force the audio code into a state
49 // where it doesn't manage to set either the low or high latency path.
50 // This test will compute useless values in that case, so skip running on
51 // such bots (see crbug.com/326338).
52 LOG(INFO
) << "Missing output devices: skipping test...";
56 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch(
57 switches::kUseFakeDeviceForMediaStream
))
58 << "Must run with fake devices since the test will explicitly look "
59 << "for the fake device signal.";
61 MakeTypicalPeerConnectionCall(javascript
);
65 // These tests will make a complete PeerConnection-based call and verify that
66 // video is playing for the call.
67 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
68 CanSetupDefaultVideoCall
) {
69 MakeTypicalPeerConnectionCall(
70 "callAndExpectResolution({video: true}, 640, 480);");
73 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
74 CanSetupVideoCallWith1To1AspectRatio
) {
75 const std::string javascript
=
76 "callAndExpectResolution({video: {mandatory: {minWidth: 320,"
77 " maxWidth: 320, minHeight: 320, maxHeight: 320}}}, 320, 320);";
78 MakeTypicalPeerConnectionCall(javascript
);
81 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
82 CanSetupVideoCallWith16To9AspectRatio
) {
83 const std::string javascript
=
84 "callAndExpectResolution({video: {mandatory: {minWidth: 640,"
85 " maxWidth: 640, minAspectRatio: 1.777}}}, 640, 360);";
86 MakeTypicalPeerConnectionCall(javascript
);
90 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
91 CanSetupVideoCallWith4To3AspectRatio
) {
92 const std::string javascript
=
93 "callAndExpectResolution({video: {mandatory: { minWidth: 960,"
94 "maxWidth: 960, minAspectRatio: 1.333, maxAspectRatio: 1.333}}}, 960,"
96 MakeTypicalPeerConnectionCall(javascript
);
99 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
100 CanSetupVideoCallAndDisableLocalVideo
) {
101 const std::string javascript
=
102 "callAndDisableLocalVideo({video: true});";
103 MakeTypicalPeerConnectionCall(javascript
);
106 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
107 CanSetupAudioAndVideoCall
) {
108 MakeTypicalPeerConnectionCall("call({video: true, audio: true});");
111 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CanSetupCallAndSendDtmf
) {
112 MakeTypicalPeerConnectionCall("callAndSendDtmf(\'123,abc\');");
115 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
116 CanMakeEmptyCallThenAddStreamsAndRenegotiate
) {
117 const char* kJavascript
=
118 "callEmptyThenAddOneStreamAndRenegotiate({video: true, audio: true});";
119 MakeTypicalPeerConnectionCall(kJavascript
);
122 // Causes asserts in libjingle: http://crbug.com/484826.
123 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
124 DISABLED_CanMakeAudioCallAndThenRenegotiateToVideo
) {
125 const char* kJavascript
=
126 "callAndRenegotiateToVideo({audio: true}, {audio: true, video:true});";
127 MakeTypicalPeerConnectionCall(kJavascript
);
130 // Causes asserts in libjingle: http://crbug.com/484826.
131 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
132 DISABLED_CanMakeVideoCallAndThenRenegotiateToAudio
) {
133 MakeAudioDetectingPeerConnectionCall(
134 "callAndRenegotiateToAudio({audio: true, video:true}, {audio: true});");
137 // This test makes a call between pc1 and pc2 where a video only stream is sent
138 // from pc1 to pc2. The stream sent from pc1 to pc2 is cloned from the stream
139 // received on pc2 to test that cloning of remote video tracks works as
140 // intended and is sent back to pc1.
141 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CanForwardRemoteStream
) {
142 #if defined (OS_ANDROID)
143 // This test fails on Nexus 5 devices.
144 // TODO(henrika): see http://crbug.com/362437 and http://crbug.com/359389
146 base::CommandLine::ForCurrentProcess()->AppendSwitch(
147 switches::kDisableWebRtcHWDecoding
);
149 MakeTypicalPeerConnectionCall(
150 "callAndForwardRemoteStream({video: true, audio: false});");
153 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
154 NoCrashWhenConnectChromiumSinkToRemoteTrack
) {
155 MakeTypicalPeerConnectionCall("ConnectChromiumSinkToRemoteAudioTrack();");
158 // This test will make a complete PeerConnection-based call but remove the
159 // MSID and bundle attribute from the initial offer to verify that
160 // video is playing for the call even if the initiating client don't support
161 // MSID. http://tools.ietf.org/html/draft-alvestrand-rtcweb-msid-02
162 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
163 CanSetupAudioAndVideoCallWithoutMsidAndBundle
) {
164 MakeTypicalPeerConnectionCall("callWithoutMsidAndBundle();");
167 // This test will modify the SDP offer to an unsupported codec, which should
168 // cause SetLocalDescription to fail.
169 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
170 NegotiateUnsupportedVideoCodec
) {
171 MakeTypicalPeerConnectionCall("negotiateUnsupportedVideoCodec();");
174 // This test will modify the SDP offer to use no encryption, which should
175 // cause SetLocalDescription to fail.
176 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, NegotiateNonCryptoCall
) {
177 MakeTypicalPeerConnectionCall("negotiateNonCryptoCall();");
180 // This test can negotiate an SDP offer that includes a b=AS:xx to control
181 // the bandwidth for audio and video
182 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, NegotiateOfferWithBLine
) {
183 MakeTypicalPeerConnectionCall("negotiateOfferWithBLine();");
186 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CanSetupLegacyCall
) {
187 MakeTypicalPeerConnectionCall("callWithLegacySdp();");
190 // This test will make a PeerConnection-based call and test an unreliable text
192 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
193 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallWithDataOnly
) {
194 MakeTypicalPeerConnectionCall("callWithDataOnly();");
197 #if defined(MEMORY_SANITIZER)
198 // Fails under MemorySanitizer: http://crbug.com/405951
199 #define MAYBE_CallWithSctpDataOnly DISABLED_CallWithSctpDataOnly
201 #define MAYBE_CallWithSctpDataOnly CallWithSctpDataOnly
203 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CallWithSctpDataOnly
) {
204 MakeTypicalPeerConnectionCall("callWithSctpDataOnly();");
207 // This test will make a PeerConnection-based call and test an unreliable text
208 // dataChannel and audio and video tracks.
209 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
210 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallWithDataAndMedia
) {
211 MakeTypicalPeerConnectionCall("callWithDataAndMedia();");
215 #if defined(MEMORY_SANITIZER)
216 // Fails under MemorySanitizer: http://crbug.com/405951
217 #define MAYBE_CallWithSctpDataAndMedia DISABLED_CallWithSctpDataAndMedia
219 #define MAYBE_CallWithSctpDataAndMedia CallWithSctpDataAndMedia
221 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
222 MAYBE_CallWithSctpDataAndMedia
) {
223 MakeTypicalPeerConnectionCall("callWithSctpDataAndMedia();");
226 // This test will make a PeerConnection-based call and test an unreliable text
227 // dataChannel and later add an audio and video track.
228 // Doesn't work, therefore disabled: https://crbug.com/293252.
229 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
230 DISABLED_CallWithDataAndLaterAddMedia
) {
231 MakeTypicalPeerConnectionCall("callWithDataAndLaterAddMedia();");
234 // This test will make a PeerConnection-based call and send a new Video
235 // MediaStream that has been created based on a MediaStream created with
237 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
238 CallWithNewVideoMediaStream
) {
239 MakeTypicalPeerConnectionCall("callWithNewVideoMediaStream();");
242 // This test will make a PeerConnection-based call and send a new Video
243 // MediaStream that has been created based on a MediaStream created with
244 // getUserMedia. When video is flowing, the VideoTrack is removed and an
245 // AudioTrack is added instead.
246 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallAndModifyStream
) {
247 MakeTypicalPeerConnectionCall(
248 "callWithNewVideoMediaStreamLaterSwitchToAudio();");
251 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, AddTwoMediaStreamsToOnePC
) {
252 MakeTypicalPeerConnectionCall("addTwoMediaStreamsToOneConnection();");
255 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
256 EstablishAudioVideoCallAndEnsureAudioIsPlaying
) {
257 MakeAudioDetectingPeerConnectionCall(
258 "callAndEnsureAudioIsPlaying({audio:true, video:true});");
261 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
262 EstablishAudioOnlyCallAndEnsureAudioIsPlaying
) {
263 MakeAudioDetectingPeerConnectionCall(
264 "callAndEnsureAudioIsPlaying({audio:true});");
267 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
268 EstablishIsac16KCallAndEnsureAudioIsPlaying
) {
269 MakeAudioDetectingPeerConnectionCall(
270 "callWithIsac16KAndEnsureAudioIsPlaying({audio:true});");
273 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
274 EstablishAudioVideoCallAndVerifyRemoteMutingWorks
) {
275 MakeAudioDetectingPeerConnectionCall(
276 "callAndEnsureRemoteAudioTrackMutingWorks();");
279 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
280 EstablishAudioVideoCallAndVerifyLocalMutingWorks
) {
281 MakeAudioDetectingPeerConnectionCall(
282 "callAndEnsureLocalAudioTrackMutingWorks();");
285 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
286 EnsureLocalVideoMuteDoesntMuteAudio
) {
287 MakeAudioDetectingPeerConnectionCall(
288 "callAndEnsureLocalVideoMutingDoesntMuteAudio();");
291 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
292 EnsureRemoteVideoMuteDoesntMuteAudio
) {
293 MakeAudioDetectingPeerConnectionCall(
294 "callAndEnsureRemoteVideoMutingDoesntMuteAudio();");
297 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
298 EstablishAudioVideoCallAndVerifyUnmutingWorks
) {
299 MakeAudioDetectingPeerConnectionCall(
300 "callAndEnsureAudioTrackUnmutingWorks();");
303 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallAndVerifyVideoMutingWorks
) {
304 MakeTypicalPeerConnectionCall("callAndEnsureVideoTrackMutingWorks();");
307 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CreateOfferWithOfferOptions
) {
308 MakeTypicalPeerConnectionCall("testCreateOfferOptions();");
311 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallInsideIframe
) {
312 MakeTypicalPeerConnectionCall("callInsideIframe({video: true, audio:true});");
315 } // namespace content