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/strings/stringprintf.h"
8 #include "base/threading/platform_thread.h"
9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/common/content_switches.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/content_browser_test_utils.h"
13 #include "content/public/test/test_utils.h"
14 #include "content/test/webrtc_content_browsertest_base.h"
15 #include "media/audio/audio_manager.h"
16 #include "media/base/media_switches.h"
17 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #if defined (OS_ANDROID) || defined(THREAD_SANITIZER)
22 // Just do the bare minimum of audio checking on Android and under TSAN since
23 // it's a bit sensitive to device performance.
24 const char kUseLenientAudioChecking
[] = "true";
26 const char kUseLenientAudioChecking
[] = "false";
33 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
34 // Renderer crashes under Android ASAN: https://crbug.com/408496.
35 #define MAYBE_WebRtcBrowserTest DISABLED_WebRtcBrowserTest
37 #define MAYBE_WebRtcBrowserTest WebRtcBrowserTest
40 class MAYBE_WebRtcBrowserTest
: public WebRtcContentBrowserTest
{
42 MAYBE_WebRtcBrowserTest() {}
43 ~MAYBE_WebRtcBrowserTest() override
{}
45 // Convenience function since most peerconnection-call.html tests just load
46 // the page, kick off some javascript and wait for the title to change to OK.
47 void MakeTypicalPeerConnectionCall(const std::string
& javascript
) {
49 // Test is flaky on Win XP. http://crbug.com/470013.
52 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
54 GURL
url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
55 NavigateToURL(shell(), url
);
57 DisableOpusIfOnAndroid();
58 ExecuteJavascriptAndWaitForOk(javascript
);
61 // Convenience method for making calls that detect if audio os playing (which
62 // has some special prerequisites, such that there needs to be an audio output
63 // device on the executing machine).
64 void MakeAudioDetectingPeerConnectionCall(const std::string
& javascript
) {
65 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
66 // Bots with no output devices will force the audio code into a state
67 // where it doesn't manage to set either the low or high latency path.
68 // This test will compute useless values in that case, so skip running on
69 // such bots (see crbug.com/326338).
70 LOG(INFO
) << "Missing output devices: skipping test...";
74 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch(
75 switches::kUseFakeDeviceForMediaStream
))
76 << "Must run with fake devices since the test will explicitly look "
77 << "for the fake device signal.";
79 MakeTypicalPeerConnectionCall(javascript
);
83 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
84 // Timing out on ARM linux bot: http://crbug.com/238490
85 #define MAYBE_CanSetupDefaultVideoCall DISABLED_CanSetupDefaultVideoCall
86 // Flaky on TSAN v2. http://crbug.com/408006
87 #elif defined(THREAD_SANITIZER)
88 #define MAYBE_CanSetupDefaultVideoCall DISABLED_CanSetupDefaultVideoCall
90 #define MAYBE_CanSetupDefaultVideoCall CanSetupDefaultVideoCall
93 // These tests will make a complete PeerConnection-based call and verify that
94 // video is playing for the call.
95 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
96 MAYBE_CanSetupDefaultVideoCall
) {
97 MakeTypicalPeerConnectionCall(
98 "callAndExpectResolution({video: true}, 640, 480);");
101 // Flaky on TSAN v2. http://crbug.com/408006
102 #if defined(THREAD_SANITIZER)
103 #define MAYBE_CanSetupVideoCallWith1To1AspectRatio \
104 DISABLED_CanSetupVideoCallWith1To1AspectRatio
106 #define MAYBE_CanSetupVideoCallWith1To1AspectRatio \
107 CanSetupVideoCallWith1To1AspectRatio
109 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
110 MAYBE_CanSetupVideoCallWith1To1AspectRatio
) {
111 const std::string javascript
=
112 "callAndExpectResolution({video: {mandatory: {minWidth: 320,"
113 " maxWidth: 320, minHeight: 320, maxHeight: 320}}}, 320, 320);";
114 MakeTypicalPeerConnectionCall(javascript
);
117 // Flaky on TSAN v2. http://crbug.com/408006
118 #if defined(THREAD_SANITIZER)
119 #define MAYBE_CanSetupVideoCallWith16To9AspectRatio \
120 DISABLED_CanSetupVideoCallWith16To9AspectRatio
122 #define MAYBE_CanSetupVideoCallWith16To9AspectRatio \
123 CanSetupVideoCallWith16To9AspectRatio
125 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
126 MAYBE_CanSetupVideoCallWith16To9AspectRatio
) {
127 const std::string javascript
=
128 "callAndExpectResolution({video: {mandatory: {minWidth: 640,"
129 " maxWidth: 640, minAspectRatio: 1.777}}}, 640, 360);";
130 MakeTypicalPeerConnectionCall(javascript
);
133 // Flaky on TSAN v2. http://crbug.com/408006
134 #if defined(THREAD_SANITIZER)
135 #define MAYBE_CanSetupVideoCallWith4To3AspectRatio \
136 DISABLED_CanSetupVideoCallWith4To3AspectRatio
138 #define MAYBE_CanSetupVideoCallWith4To3AspectRatio \
139 CanSetupVideoCallWith4To3AspectRatio
141 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
142 MAYBE_CanSetupVideoCallWith4To3AspectRatio
) {
143 const std::string javascript
=
144 "callAndExpectResolution({video: {mandatory: { minWidth: 960,"
145 "maxWidth: 960, minAspectRatio: 1.333, maxAspectRatio: 1.333}}}, 960,"
147 MakeTypicalPeerConnectionCall(javascript
);
150 // Flaky on TSAN v2. http://crbug.com/408006
151 #if defined(THREAD_SANITIZER)
152 #define MAYBE_CanSetupVideoCallAndDisableLocalVideo \
153 DISABLED_CanSetupVideoCallAndDisableLocalVideo
155 #define MAYBE_CanSetupVideoCallAndDisableLocalVideo \
156 CanSetupVideoCallAndDisableLocalVideo
158 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
159 MAYBE_CanSetupVideoCallAndDisableLocalVideo
) {
160 const std::string javascript
=
161 "callAndDisableLocalVideo({video: true});";
162 MakeTypicalPeerConnectionCall(javascript
);
165 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
166 // Timing out on ARM linux, see http://crbug.com/240376
167 #define MAYBE_CanSetupAudioAndVideoCall DISABLED_CanSetupAudioAndVideoCall
169 #define MAYBE_CanSetupAudioAndVideoCall CanSetupAudioAndVideoCall
172 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
173 MAYBE_CanSetupAudioAndVideoCall
) {
174 MakeTypicalPeerConnectionCall("call({video: true, audio: true});");
177 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
178 MANUAL_CanSetupCallAndSendDtmf
) {
179 MakeTypicalPeerConnectionCall("callAndSendDtmf(\'123,abc\');");
182 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
183 CanMakeEmptyCallThenAddStreamsAndRenegotiate
) {
184 const char* kJavascript
=
185 "callEmptyThenAddOneStreamAndRenegotiate({video: true, audio: true});";
186 MakeTypicalPeerConnectionCall(kJavascript
);
189 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
190 CanMakeAudioCallAndThenRenegotiateToVideo
) {
191 const char* kJavascript
=
192 "callAndRenegotiateToVideo({audio: true}, {audio: true, video:true});";
193 MakeTypicalPeerConnectionCall(kJavascript
);
196 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
197 CanMakeVideoCallAndThenRenegotiateToAudio
) {
198 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
199 "callAndRenegotiateToAudio("
200 " %s, {audio: true, video:true}, {audio: true});",
201 kUseLenientAudioChecking
));
204 // This test makes a call between pc1 and pc2 where a video only stream is sent
205 // from pc1 to pc2. The stream sent from pc1 to pc2 is cloned from the stream
206 // received on pc2 to test that cloning of remote video tracks works as
207 // intended and is sent back to pc1.
208 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CanForwardRemoteStream
) {
209 #if defined (OS_ANDROID)
210 // This test fails on Nexus 5 devices.
211 // TODO(henrika): see http://crbug.com/362437 and http://crbug.com/359389
213 base::CommandLine::ForCurrentProcess()->AppendSwitch(
214 switches::kDisableWebRtcHWDecoding
);
216 MakeTypicalPeerConnectionCall(
217 "callAndForwardRemoteStream({video: true, audio: false});");
220 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
221 NoCrashWhenConnectChromiumSinkToRemoteTrack
) {
222 MakeTypicalPeerConnectionCall("ConnectChromiumSinkToRemoteAudioTrack();");
225 // This test will make a complete PeerConnection-based call but remove the
226 // MSID and bundle attribute from the initial offer to verify that
227 // video is playing for the call even if the initiating client don't support
228 // MSID. http://tools.ietf.org/html/draft-alvestrand-rtcweb-msid-02
229 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
230 // Timing out on ARM linux, see http://crbug.com/240373
231 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
232 DISABLED_CanSetupAudioAndVideoCallWithoutMsidAndBundle
234 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
235 CanSetupAudioAndVideoCallWithoutMsidAndBundle
237 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
238 MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle
) {
239 MakeTypicalPeerConnectionCall("callWithoutMsidAndBundle();");
242 // This test will modify the SDP offer to an unsupported codec, which should
243 // cause SetLocalDescription to fail.
244 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
245 NegotiateUnsupportedVideoCodec
) {
246 MakeTypicalPeerConnectionCall("negotiateUnsupportedVideoCodec();");
249 // This test will modify the SDP offer to use no encryption, which should
250 // cause SetLocalDescription to fail.
251 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, NegotiateNonCryptoCall
) {
252 MakeTypicalPeerConnectionCall("negotiateNonCryptoCall();");
255 // This test can negotiate an SDP offer that includes a b=AS:xx to control
256 // the bandwidth for audio and video
257 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, NegotiateOfferWithBLine
) {
258 MakeTypicalPeerConnectionCall("negotiateOfferWithBLine();");
261 // This test will make a complete PeerConnection-based call using legacy SDP
262 // settings: GIce, external SDES, and no BUNDLE.
263 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
264 // Timing out on ARM linux, see http://crbug.com/240373
265 #define MAYBE_CanSetupLegacyCall DISABLED_CanSetupLegacyCall
267 #define MAYBE_CanSetupLegacyCall CanSetupLegacyCall
270 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CanSetupLegacyCall
) {
271 MakeTypicalPeerConnectionCall("callWithLegacySdp();");
274 // This test will make a PeerConnection-based call and test an unreliable text
276 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
277 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallWithDataOnly
) {
278 MakeTypicalPeerConnectionCall("callWithDataOnly();");
281 #if defined(MEMORY_SANITIZER)
282 // Fails under MemorySanitizer: http://crbug.com/405951
283 #define MAYBE_CallWithSctpDataOnly DISABLED_CallWithSctpDataOnly
285 #define MAYBE_CallWithSctpDataOnly CallWithSctpDataOnly
287 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CallWithSctpDataOnly
) {
288 MakeTypicalPeerConnectionCall("callWithSctpDataOnly();");
291 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
292 // Timing out on ARM linux bot: http://crbug.com/238490
293 #define MAYBE_CallWithDataAndMedia DISABLED_CallWithDataAndMedia
295 #define MAYBE_CallWithDataAndMedia CallWithDataAndMedia
298 // This test will make a PeerConnection-based call and test an unreliable text
299 // dataChannel and audio and video tracks.
300 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
301 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CallWithDataAndMedia
) {
302 MakeTypicalPeerConnectionCall("callWithDataAndMedia();");
306 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS) && \
307 defined(ARCH_CPU_ARM_FAMILY)) || defined(MEMORY_SANITIZER)
308 // Timing out on ARM linux bot: http://crbug.com/238490
309 // Fails under MemorySanitizer: http://crbug.com/405951
310 #define MAYBE_CallWithSctpDataAndMedia DISABLED_CallWithSctpDataAndMedia
312 #define MAYBE_CallWithSctpDataAndMedia CallWithSctpDataAndMedia
315 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
316 MAYBE_CallWithSctpDataAndMedia
) {
317 MakeTypicalPeerConnectionCall("callWithSctpDataAndMedia();");
320 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
321 // Timing out on ARM linux bot: http://crbug.com/238490
322 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
324 // Temporarily disable the test on all platforms. http://crbug.com/293252
325 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
328 // This test will make a PeerConnection-based call and test an unreliable text
329 // dataChannel and later add an audio and video track.
330 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
331 MAYBE_CallWithDataAndLaterAddMedia
) {
332 MakeTypicalPeerConnectionCall("callWithDataAndLaterAddMedia();");
335 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
336 // Timing out on ARM linux bot: http://crbug.com/238490
337 #define MAYBE_CallWithNewVideoMediaStream DISABLED_CallWithNewVideoMediaStream
339 #define MAYBE_CallWithNewVideoMediaStream CallWithNewVideoMediaStream
342 // This test will make a PeerConnection-based call and send a new Video
343 // MediaStream that has been created based on a MediaStream created with
345 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
346 MAYBE_CallWithNewVideoMediaStream
) {
347 MakeTypicalPeerConnectionCall("callWithNewVideoMediaStream();");
350 // This test will make a PeerConnection-based call and send a new Video
351 // MediaStream that has been created based on a MediaStream created with
352 // getUserMedia. When video is flowing, the VideoTrack is removed and an
353 // AudioTrack is added instead.
354 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallAndModifyStream
) {
355 MakeTypicalPeerConnectionCall(
356 "callWithNewVideoMediaStreamLaterSwitchToAudio();");
359 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, AddTwoMediaStreamsToOnePC
) {
360 MakeTypicalPeerConnectionCall("addTwoMediaStreamsToOneConnection();");
363 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
364 EstablishAudioVideoCallAndEnsureAudioIsPlaying
) {
365 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
366 "callAndEnsureAudioIsPlaying(%s, {audio:true, video:true});",
367 kUseLenientAudioChecking
));
370 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
371 EstablishAudioOnlyCallAndEnsureAudioIsPlaying
) {
372 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
373 "callAndEnsureAudioIsPlaying(%s, {audio:true});",
374 kUseLenientAudioChecking
));
377 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
378 EstablishAudioVideoCallAndVerifyRemoteMutingWorks
) {
379 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
380 "callAndEnsureRemoteAudioTrackMutingWorks(%s);",
381 kUseLenientAudioChecking
));
384 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
385 EstablishAudioVideoCallAndVerifyLocalMutingWorks
) {
386 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
387 "callAndEnsureLocalAudioTrackMutingWorks(%s);",
388 kUseLenientAudioChecking
));
391 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
392 EnsureLocalVideoMuteDoesntMuteAudio
) {
393 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
394 "callAndEnsureLocalVideoMutingDoesntMuteAudio(%s);",
395 kUseLenientAudioChecking
));
398 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
399 EnsureRemoteVideoMuteDoesntMuteAudio
) {
400 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
401 "callAndEnsureRemoteVideoMutingDoesntMuteAudio(%s);",
402 kUseLenientAudioChecking
));
405 // Flaky on TSAN v2: http://crbug.com/373637
406 #if defined(THREAD_SANITIZER)
407 #define MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks\
408 DISABLED_EstablishAudioVideoCallAndVerifyUnmutingWorks
410 #define MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks\
411 EstablishAudioVideoCallAndVerifyUnmutingWorks
413 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
414 MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks
) {
415 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
416 "callAndEnsureAudioTrackUnmutingWorks(%s);", kUseLenientAudioChecking
));
419 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallAndVerifyVideoMutingWorks
) {
420 MakeTypicalPeerConnectionCall("callAndEnsureVideoTrackMutingWorks();");
423 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CreateOfferWithOfferOptions
) {
424 MakeTypicalPeerConnectionCall("testCreateOfferOptions();");
427 } // namespace content