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
36 #elif defined(OS_ANDROID) && defined(__aarch64__)
37 // Failures on ARM64 Android: http://crbug.com/408179.
38 #define MAYBE_WebRtcBrowserTest DISABLED_WebRtcBrowserTest
39 #elif defined(OS_ANDROID)
40 // TEMPORARY disable: http://crbug.com/430001.
41 // WebRTC stats-parsing tests broken due to renderer crash.
42 #define MAYBE_WebRtcBrowserTest DISABLED_WebRtcBrowserTest
44 #define MAYBE_WebRtcBrowserTest WebRtcBrowserTest
47 class MAYBE_WebRtcBrowserTest
: public WebRtcContentBrowserTest
{
49 MAYBE_WebRtcBrowserTest() {}
50 ~MAYBE_WebRtcBrowserTest() override
{}
52 // Convenience function since most peerconnection-call.html tests just load
53 // the page, kick off some javascript and wait for the title to change to OK.
54 void MakeTypicalPeerConnectionCall(const std::string
& javascript
) {
55 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
57 GURL
url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
58 NavigateToURL(shell(), url
);
60 DisableOpusIfOnAndroid();
61 ExecuteJavascriptAndWaitForOk(javascript
);
64 // Convenience method for making calls that detect if audio os playing (which
65 // has some special prerequisites, such that there needs to be an audio output
66 // device on the executing machine).
67 void MakeAudioDetectingPeerConnectionCall(const std::string
& javascript
) {
68 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
69 // Bots with no output devices will force the audio code into a state
70 // where it doesn't manage to set either the low or high latency path.
71 // This test will compute useless values in that case, so skip running on
72 // such bots (see crbug.com/326338).
73 LOG(INFO
) << "Missing output devices: skipping test...";
77 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch(
78 switches::kUseFakeDeviceForMediaStream
))
79 << "Must run with fake devices since the test will explicitly look "
80 << "for the fake device signal.";
82 MakeTypicalPeerConnectionCall(javascript
);
86 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
87 // Timing out on ARM linux bot: http://crbug.com/238490
88 #define MAYBE_CanSetupDefaultVideoCall DISABLED_CanSetupDefaultVideoCall
89 // Flaky on TSAN v2. http://crbug.com/408006
90 #elif defined(THREAD_SANITIZER)
91 #define MAYBE_CanSetupDefaultVideoCall DISABLED_CanSetupDefaultVideoCall
93 #define MAYBE_CanSetupDefaultVideoCall CanSetupDefaultVideoCall
96 // These tests will make a complete PeerConnection-based call and verify that
97 // video is playing for the call.
98 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
99 MAYBE_CanSetupDefaultVideoCall
) {
100 MakeTypicalPeerConnectionCall(
101 "callAndExpectResolution({video: true}, 640, 480);");
104 // Flaky on TSAN v2. http://crbug.com/408006
105 #if defined(THREAD_SANITIZER)
106 #define MAYBE_CanSetupVideoCallWith1To1AspectRatio \
107 DISABLED_CanSetupVideoCallWith1To1AspectRatio
109 #define MAYBE_CanSetupVideoCallWith1To1AspectRatio \
110 CanSetupVideoCallWith1To1AspectRatio
112 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
113 MAYBE_CanSetupVideoCallWith1To1AspectRatio
) {
114 const std::string javascript
=
115 "callAndExpectResolution({video: {mandatory: {minWidth: 320,"
116 " maxWidth: 320, minHeight: 320, maxHeight: 320}}}, 320, 320);";
117 MakeTypicalPeerConnectionCall(javascript
);
120 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARM64)
121 // Failing on ARM64 Android bot: http://crbug.com/408179
122 #define MAYBE_CanSetupVideoCallWith16To9AspectRatio \
123 DISABLED_CanSetupVideoCallWith16To9AspectRatio
124 // Flaky on TSAN v2. http://crbug.com/408006
125 #elif defined(THREAD_SANITIZER)
126 #define MAYBE_CanSetupVideoCallWith16To9AspectRatio \
127 DISABLED_CanSetupVideoCallWith16To9AspectRatio
129 #define MAYBE_CanSetupVideoCallWith16To9AspectRatio \
130 CanSetupVideoCallWith16To9AspectRatio
132 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
133 MAYBE_CanSetupVideoCallWith16To9AspectRatio
) {
134 const std::string javascript
=
135 "callAndExpectResolution({video: {mandatory: {minWidth: 640,"
136 " maxWidth: 640, minAspectRatio: 1.777}}}, 640, 360);";
137 MakeTypicalPeerConnectionCall(javascript
);
140 // Flaky on TSAN v2. http://crbug.com/408006
141 #if defined(THREAD_SANITIZER)
142 #define MAYBE_CanSetupVideoCallWith4To3AspectRatio \
143 DISABLED_CanSetupVideoCallWith4To3AspectRatio
145 #define MAYBE_CanSetupVideoCallWith4To3AspectRatio \
146 CanSetupVideoCallWith4To3AspectRatio
148 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
149 MAYBE_CanSetupVideoCallWith4To3AspectRatio
) {
150 const std::string javascript
=
151 "callAndExpectResolution({video: {mandatory: {minWidth: 960,"
152 "maxAspectRatio: 1.333}}}, 960, 720);";
153 MakeTypicalPeerConnectionCall(javascript
);
156 // Flaky on TSAN v2. http://crbug.com/408006
157 #if defined(THREAD_SANITIZER)
158 #define MAYBE_CanSetupVideoCallAndDisableLocalVideo \
159 DISABLED_CanSetupVideoCallAndDisableLocalVideo
161 #define MAYBE_CanSetupVideoCallAndDisableLocalVideo \
162 CanSetupVideoCallAndDisableLocalVideo
164 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
165 MAYBE_CanSetupVideoCallAndDisableLocalVideo
) {
166 const std::string javascript
=
167 "callAndDisableLocalVideo({video: true});";
168 MakeTypicalPeerConnectionCall(javascript
);
171 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
172 // Timing out on ARM linux, see http://crbug.com/240376
173 #define MAYBE_CanSetupAudioAndVideoCall DISABLED_CanSetupAudioAndVideoCall
175 #define MAYBE_CanSetupAudioAndVideoCall CanSetupAudioAndVideoCall
178 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
179 MAYBE_CanSetupAudioAndVideoCall
) {
180 MakeTypicalPeerConnectionCall("call({video: true, audio: true});");
183 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
184 MANUAL_CanSetupCallAndSendDtmf
) {
185 MakeTypicalPeerConnectionCall("callAndSendDtmf(\'123,abc\');");
188 // TODO(phoglund): this test fails because the peer connection state will be
189 // stable in the second negotiation round rather than have-local-offer.
190 // http://crbug.com/293125.
191 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
192 DISABLED_CanMakeEmptyCallThenAddStreamsAndRenegotiate
) {
193 const char* kJavascript
=
194 "callEmptyThenAddOneStreamAndRenegotiate({video: true, audio: true});";
195 MakeTypicalPeerConnectionCall(kJavascript
);
198 // Below 2 test will make a complete PeerConnection-based call between pc1 and
199 // pc2, and then use the remote stream to setup a call between pc3 and pc4, and
200 // then verify that video is received on pc3 and pc4.
201 // The stream sent from pc3 to pc4 is the stream received on pc1.
202 // The stream sent from pc4 to pc3 is cloned from stream the stream received
204 #if defined(THREAD_SANITIZER)
205 // Flaky on TSAN v2. http://crbug.com/373637
206 #define MAYBE_CanForwardRemoteStream DISABLED_CanForwardRemoteStream
207 #define MAYBE_CanForwardRemoteStream720p DISABLED_CanForwardRemoteStream720p
209 #define MAYBE_CanForwardRemoteStream CanForwardRemoteStream
210 #define MAYBE_CanForwardRemoteStream720p CanForwardRemoteStream720p
212 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CanForwardRemoteStream
) {
213 #if defined (OS_ANDROID)
214 // This test fails on Nexus 5 devices.
215 // TODO(henrika): see http://crbug.com/362437 and http://crbug.com/359389
217 base::CommandLine::ForCurrentProcess()->AppendSwitch(
218 switches::kDisableWebRtcHWDecoding
);
220 MakeTypicalPeerConnectionCall(
221 "callAndForwardRemoteStream({video: true, audio: false});");
224 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
225 MAYBE_CanForwardRemoteStream720p
) {
226 #if defined (OS_ANDROID)
227 // This test fails on Nexus 5 devices.
228 // TODO(henrika): see http://crbug.com/362437 and http://crbug.com/359389
230 base::CommandLine::ForCurrentProcess()->AppendSwitch(
231 switches::kDisableWebRtcHWDecoding
);
233 const std::string javascript
= GenerateGetUserMediaCall(
234 "callAndForwardRemoteStream", 1280, 1280, 720, 720, 10, 30);
235 MakeTypicalPeerConnectionCall(javascript
);
238 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
239 NoCrashWhenConnectChromiumSinkToRemoteTrack
) {
240 MakeTypicalPeerConnectionCall("ConnectChromiumSinkToRemoteAudioTrack();");
243 // This test will make a complete PeerConnection-based call but remove the
244 // MSID and bundle attribute from the initial offer to verify that
245 // video is playing for the call even if the initiating client don't support
246 // MSID. http://tools.ietf.org/html/draft-alvestrand-rtcweb-msid-02
247 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
248 // Timing out on ARM linux, see http://crbug.com/240373
249 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
250 DISABLED_CanSetupAudioAndVideoCallWithoutMsidAndBundle
252 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
253 CanSetupAudioAndVideoCallWithoutMsidAndBundle
255 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
256 MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle
) {
257 MakeTypicalPeerConnectionCall("callWithoutMsidAndBundle();");
260 // This test will modify the SDP offer to an unsupported codec, which should
261 // cause SetLocalDescription to fail.
262 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
263 NegotiateUnsupportedVideoCodec
) {
264 MakeTypicalPeerConnectionCall("negotiateUnsupportedVideoCodec();");
267 // This test will modify the SDP offer to use no encryption, which should
268 // cause SetLocalDescription to fail.
269 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, NegotiateNonCryptoCall
) {
270 MakeTypicalPeerConnectionCall("negotiateNonCryptoCall();");
273 // This test can negotiate an SDP offer that includes a b=AS:xx to control
274 // the bandwidth for audio and video
275 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, NegotiateOfferWithBLine
) {
276 MakeTypicalPeerConnectionCall("negotiateOfferWithBLine();");
279 // This test will make a complete PeerConnection-based call using legacy SDP
280 // settings: GIce, external SDES, and no BUNDLE.
281 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
282 // Timing out on ARM linux, see http://crbug.com/240373
283 #define MAYBE_CanSetupLegacyCall DISABLED_CanSetupLegacyCall
285 #define MAYBE_CanSetupLegacyCall CanSetupLegacyCall
288 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CanSetupLegacyCall
) {
289 MakeTypicalPeerConnectionCall("callWithLegacySdp();");
292 // This test will make a PeerConnection-based call and test an unreliable text
294 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
295 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallWithDataOnly
) {
296 MakeTypicalPeerConnectionCall("callWithDataOnly();");
299 #if defined(MEMORY_SANITIZER)
300 // Fails under MemorySanitizer: http://crbug.com/405951
301 #define MAYBE_CallWithSctpDataOnly DISABLED_CallWithSctpDataOnly
303 #define MAYBE_CallWithSctpDataOnly CallWithSctpDataOnly
305 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CallWithSctpDataOnly
) {
306 MakeTypicalPeerConnectionCall("callWithSctpDataOnly();");
309 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
310 // Timing out on ARM linux bot: http://crbug.com/238490
311 #define MAYBE_CallWithDataAndMedia DISABLED_CallWithDataAndMedia
313 #define MAYBE_CallWithDataAndMedia CallWithDataAndMedia
316 // This test will make a PeerConnection-based call and test an unreliable text
317 // dataChannel and audio and video tracks.
318 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
319 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CallWithDataAndMedia
) {
320 MakeTypicalPeerConnectionCall("callWithDataAndMedia();");
324 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS) && \
325 defined(ARCH_CPU_ARM_FAMILY)) || defined(MEMORY_SANITIZER)
326 // Timing out on ARM linux bot: http://crbug.com/238490
327 // Fails under MemorySanitizer: http://crbug.com/405951
328 #define MAYBE_CallWithSctpDataAndMedia DISABLED_CallWithSctpDataAndMedia
330 #define MAYBE_CallWithSctpDataAndMedia CallWithSctpDataAndMedia
333 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
334 MAYBE_CallWithSctpDataAndMedia
) {
335 MakeTypicalPeerConnectionCall("callWithSctpDataAndMedia();");
338 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
339 // Timing out on ARM linux bot: http://crbug.com/238490
340 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
342 // Temporarily disable the test on all platforms. http://crbug.com/293252
343 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
346 // This test will make a PeerConnection-based call and test an unreliable text
347 // dataChannel and later add an audio and video track.
348 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
349 MAYBE_CallWithDataAndLaterAddMedia
) {
350 MakeTypicalPeerConnectionCall("callWithDataAndLaterAddMedia();");
353 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
354 // Timing out on ARM linux bot: http://crbug.com/238490
355 #define MAYBE_CallWithNewVideoMediaStream DISABLED_CallWithNewVideoMediaStream
357 #define MAYBE_CallWithNewVideoMediaStream CallWithNewVideoMediaStream
360 // This test will make a PeerConnection-based call and send a new Video
361 // MediaStream that has been created based on a MediaStream created with
363 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
364 MAYBE_CallWithNewVideoMediaStream
) {
365 MakeTypicalPeerConnectionCall("callWithNewVideoMediaStream();");
368 // This test will make a PeerConnection-based call and send a new Video
369 // MediaStream that has been created based on a MediaStream created with
370 // getUserMedia. When video is flowing, the VideoTrack is removed and an
371 // AudioTrack is added instead.
372 // TODO(phoglund): This test is manual since not all buildbots has an audio
374 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MANUAL_CallAndModifyStream
) {
375 MakeTypicalPeerConnectionCall(
376 "callWithNewVideoMediaStreamLaterSwitchToAudio();");
379 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, AddTwoMediaStreamsToOnePC
) {
380 MakeTypicalPeerConnectionCall("addTwoMediaStreamsToOneConnection();");
383 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
384 EstablishAudioVideoCallAndEnsureAudioIsPlaying
) {
385 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
386 "callAndEnsureAudioIsPlaying(%s, {audio:true, video:true});",
387 kUseLenientAudioChecking
));
390 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
391 EstablishAudioOnlyCallAndEnsureAudioIsPlaying
) {
392 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
393 "callAndEnsureAudioIsPlaying(%s, {audio:true});",
394 kUseLenientAudioChecking
));
397 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
398 EstablishAudioVideoCallAndVerifyRemoteMutingWorks
) {
399 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
400 "callAndEnsureRemoteAudioTrackMutingWorks(%s);",
401 kUseLenientAudioChecking
));
404 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
405 EstablishAudioVideoCallAndVerifyLocalMutingWorks
) {
406 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
407 "callAndEnsureLocalAudioTrackMutingWorks(%s);",
408 kUseLenientAudioChecking
));
411 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
412 EnsureLocalVideoMuteDoesntMuteAudio
) {
413 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
414 "callAndEnsureLocalVideoMutingDoesntMuteAudio(%s);",
415 kUseLenientAudioChecking
));
418 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
419 EnsureRemoteVideoMuteDoesntMuteAudio
) {
420 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
421 "callAndEnsureRemoteVideoMutingDoesntMuteAudio(%s);",
422 kUseLenientAudioChecking
));
425 // Flaky on TSAN v2: http://crbug.com/373637
426 #if defined(THREAD_SANITIZER)
427 #define MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks\
428 DISABLED_EstablishAudioVideoCallAndVerifyUnmutingWorks
430 #define MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks\
431 EstablishAudioVideoCallAndVerifyUnmutingWorks
433 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
434 MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks
) {
435 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
436 "callAndEnsureAudioTrackUnmutingWorks(%s);", kUseLenientAudioChecking
));
439 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallAndVerifyVideoMutingWorks
) {
440 MakeTypicalPeerConnectionCall("callAndEnsureVideoTrackMutingWorks();");
443 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CreateOfferWithOfferOptions
) {
444 MakeTypicalPeerConnectionCall("testCreateOfferOptions();");
447 } // namespace content