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
) {
48 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
50 GURL
url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
51 NavigateToURL(shell(), url
);
53 DisableOpusIfOnAndroid();
54 ExecuteJavascriptAndWaitForOk(javascript
);
57 // Convenience method for making calls that detect if audio os playing (which
58 // has some special prerequisites, such that there needs to be an audio output
59 // device on the executing machine).
60 void MakeAudioDetectingPeerConnectionCall(const std::string
& javascript
) {
61 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
62 // Bots with no output devices will force the audio code into a state
63 // where it doesn't manage to set either the low or high latency path.
64 // This test will compute useless values in that case, so skip running on
65 // such bots (see crbug.com/326338).
66 LOG(INFO
) << "Missing output devices: skipping test...";
70 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch(
71 switches::kUseFakeDeviceForMediaStream
))
72 << "Must run with fake devices since the test will explicitly look "
73 << "for the fake device signal.";
75 MakeTypicalPeerConnectionCall(javascript
);
79 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
80 // Timing out on ARM linux bot: http://crbug.com/238490
81 #define MAYBE_CanSetupDefaultVideoCall DISABLED_CanSetupDefaultVideoCall
82 // Flaky on TSAN v2. http://crbug.com/408006
83 #elif defined(THREAD_SANITIZER)
84 #define MAYBE_CanSetupDefaultVideoCall DISABLED_CanSetupDefaultVideoCall
86 #define MAYBE_CanSetupDefaultVideoCall CanSetupDefaultVideoCall
89 // These tests will make a complete PeerConnection-based call and verify that
90 // video is playing for the call.
91 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
92 MAYBE_CanSetupDefaultVideoCall
) {
93 MakeTypicalPeerConnectionCall(
94 "callAndExpectResolution({video: true}, 640, 480);");
97 // Flaky on TSAN v2. http://crbug.com/408006
98 #if defined(THREAD_SANITIZER)
99 #define MAYBE_CanSetupVideoCallWith1To1AspectRatio \
100 DISABLED_CanSetupVideoCallWith1To1AspectRatio
102 #define MAYBE_CanSetupVideoCallWith1To1AspectRatio \
103 CanSetupVideoCallWith1To1AspectRatio
105 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
106 MAYBE_CanSetupVideoCallWith1To1AspectRatio
) {
107 const std::string javascript
=
108 "callAndExpectResolution({video: {mandatory: {minWidth: 320,"
109 " maxWidth: 320, minHeight: 320, maxHeight: 320}}}, 320, 320);";
110 MakeTypicalPeerConnectionCall(javascript
);
113 // Flaky on TSAN v2. http://crbug.com/408006
114 #if defined(THREAD_SANITIZER)
115 #define MAYBE_CanSetupVideoCallWith16To9AspectRatio \
116 DISABLED_CanSetupVideoCallWith16To9AspectRatio
118 #define MAYBE_CanSetupVideoCallWith16To9AspectRatio \
119 CanSetupVideoCallWith16To9AspectRatio
121 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
122 MAYBE_CanSetupVideoCallWith16To9AspectRatio
) {
123 const std::string javascript
=
124 "callAndExpectResolution({video: {mandatory: {minWidth: 640,"
125 " maxWidth: 640, minAspectRatio: 1.777}}}, 640, 360);";
126 MakeTypicalPeerConnectionCall(javascript
);
129 // Flaky on TSAN v2. http://crbug.com/408006
130 #if defined(THREAD_SANITIZER)
131 #define MAYBE_CanSetupVideoCallWith4To3AspectRatio \
132 DISABLED_CanSetupVideoCallWith4To3AspectRatio
134 #define MAYBE_CanSetupVideoCallWith4To3AspectRatio \
135 CanSetupVideoCallWith4To3AspectRatio
137 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
138 MAYBE_CanSetupVideoCallWith4To3AspectRatio
) {
139 const std::string javascript
=
140 "callAndExpectResolution({video: {mandatory: { minWidth: 960,"
141 "maxWidth: 960, minAspectRatio: 1.333, maxAspectRatio: 1.333}}}, 960,"
143 MakeTypicalPeerConnectionCall(javascript
);
146 // Flaky on TSAN v2. http://crbug.com/408006
147 // Flaky everywhere: http://crbug.com/477498
148 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
149 DISABLED_CanSetupVideoCallAndDisableLocalVideo
) {
150 const std::string javascript
=
151 "callAndDisableLocalVideo({video: true});";
152 MakeTypicalPeerConnectionCall(javascript
);
155 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
156 // Timing out on ARM linux, see http://crbug.com/240376
157 #define MAYBE_CanSetupAudioAndVideoCall DISABLED_CanSetupAudioAndVideoCall
159 #define MAYBE_CanSetupAudioAndVideoCall CanSetupAudioAndVideoCall
162 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
163 MAYBE_CanSetupAudioAndVideoCall
) {
164 MakeTypicalPeerConnectionCall("call({video: true, audio: true});");
167 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
168 MANUAL_CanSetupCallAndSendDtmf
) {
169 MakeTypicalPeerConnectionCall("callAndSendDtmf(\'123,abc\');");
172 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
173 CanMakeEmptyCallThenAddStreamsAndRenegotiate
) {
174 const char* kJavascript
=
175 "callEmptyThenAddOneStreamAndRenegotiate({video: true, audio: true});";
176 MakeTypicalPeerConnectionCall(kJavascript
);
179 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
180 CanMakeAudioCallAndThenRenegotiateToVideo
) {
181 const char* kJavascript
=
182 "callAndRenegotiateToVideo({audio: true}, {audio: true, video:true});";
183 MakeTypicalPeerConnectionCall(kJavascript
);
186 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
187 CanMakeVideoCallAndThenRenegotiateToAudio
) {
188 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
189 "callAndRenegotiateToAudio("
190 " %s, {audio: true, video:true}, {audio: true});",
191 kUseLenientAudioChecking
));
194 // This test makes a call between pc1 and pc2 where a video only stream is sent
195 // from pc1 to pc2. The stream sent from pc1 to pc2 is cloned from the stream
196 // received on pc2 to test that cloning of remote video tracks works as
197 // intended and is sent back to pc1.
198 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CanForwardRemoteStream
) {
199 #if defined (OS_ANDROID)
200 // This test fails on Nexus 5 devices.
201 // TODO(henrika): see http://crbug.com/362437 and http://crbug.com/359389
203 base::CommandLine::ForCurrentProcess()->AppendSwitch(
204 switches::kDisableWebRtcHWDecoding
);
206 MakeTypicalPeerConnectionCall(
207 "callAndForwardRemoteStream({video: true, audio: false});");
210 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
211 NoCrashWhenConnectChromiumSinkToRemoteTrack
) {
212 MakeTypicalPeerConnectionCall("ConnectChromiumSinkToRemoteAudioTrack();");
215 // This test will make a complete PeerConnection-based call but remove the
216 // MSID and bundle attribute from the initial offer to verify that
217 // video is playing for the call even if the initiating client don't support
218 // MSID. http://tools.ietf.org/html/draft-alvestrand-rtcweb-msid-02
219 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
220 // Timing out on ARM linux, see http://crbug.com/240373
221 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
222 DISABLED_CanSetupAudioAndVideoCallWithoutMsidAndBundle
224 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
225 CanSetupAudioAndVideoCallWithoutMsidAndBundle
227 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
228 MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle
) {
229 MakeTypicalPeerConnectionCall("callWithoutMsidAndBundle();");
232 // This test will modify the SDP offer to an unsupported codec, which should
233 // cause SetLocalDescription to fail.
234 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
235 NegotiateUnsupportedVideoCodec
) {
236 MakeTypicalPeerConnectionCall("negotiateUnsupportedVideoCodec();");
239 // This test will modify the SDP offer to use no encryption, which should
240 // cause SetLocalDescription to fail.
241 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, NegotiateNonCryptoCall
) {
242 MakeTypicalPeerConnectionCall("negotiateNonCryptoCall();");
245 // This test can negotiate an SDP offer that includes a b=AS:xx to control
246 // the bandwidth for audio and video
247 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, NegotiateOfferWithBLine
) {
248 MakeTypicalPeerConnectionCall("negotiateOfferWithBLine();");
251 // This test will make a complete PeerConnection-based call using legacy SDP
252 // settings: GIce, external SDES, and no BUNDLE.
253 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
254 // Timing out on ARM linux, see http://crbug.com/240373
255 #define MAYBE_CanSetupLegacyCall DISABLED_CanSetupLegacyCall
257 #define MAYBE_CanSetupLegacyCall CanSetupLegacyCall
260 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CanSetupLegacyCall
) {
261 MakeTypicalPeerConnectionCall("callWithLegacySdp();");
264 // This test will make a PeerConnection-based call and test an unreliable text
266 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
267 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallWithDataOnly
) {
268 MakeTypicalPeerConnectionCall("callWithDataOnly();");
271 #if defined(MEMORY_SANITIZER)
272 // Fails under MemorySanitizer: http://crbug.com/405951
273 #define MAYBE_CallWithSctpDataOnly DISABLED_CallWithSctpDataOnly
275 #define MAYBE_CallWithSctpDataOnly CallWithSctpDataOnly
277 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CallWithSctpDataOnly
) {
278 MakeTypicalPeerConnectionCall("callWithSctpDataOnly();");
281 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
282 // Timing out on ARM linux bot: http://crbug.com/238490
283 #define MAYBE_CallWithDataAndMedia DISABLED_CallWithDataAndMedia
285 #define MAYBE_CallWithDataAndMedia CallWithDataAndMedia
288 // This test will make a PeerConnection-based call and test an unreliable text
289 // dataChannel and audio and video tracks.
290 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
291 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, MAYBE_CallWithDataAndMedia
) {
292 MakeTypicalPeerConnectionCall("callWithDataAndMedia();");
296 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS) && \
297 defined(ARCH_CPU_ARM_FAMILY)) || defined(MEMORY_SANITIZER)
298 // Timing out on ARM linux bot: http://crbug.com/238490
299 // Fails under MemorySanitizer: http://crbug.com/405951
300 #define MAYBE_CallWithSctpDataAndMedia DISABLED_CallWithSctpDataAndMedia
302 #define MAYBE_CallWithSctpDataAndMedia CallWithSctpDataAndMedia
305 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
306 MAYBE_CallWithSctpDataAndMedia
) {
307 MakeTypicalPeerConnectionCall("callWithSctpDataAndMedia();");
310 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
311 // Timing out on ARM linux bot: http://crbug.com/238490
312 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
314 // Temporarily disable the test on all platforms. http://crbug.com/293252
315 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
318 // This test will make a PeerConnection-based call and test an unreliable text
319 // dataChannel and later add an audio and video track.
320 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
321 MAYBE_CallWithDataAndLaterAddMedia
) {
322 MakeTypicalPeerConnectionCall("callWithDataAndLaterAddMedia();");
325 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
326 // Timing out on ARM linux bot: http://crbug.com/238490
327 #define MAYBE_CallWithNewVideoMediaStream DISABLED_CallWithNewVideoMediaStream
329 #define MAYBE_CallWithNewVideoMediaStream CallWithNewVideoMediaStream
332 // This test will make a PeerConnection-based call and send a new Video
333 // MediaStream that has been created based on a MediaStream created with
335 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
336 MAYBE_CallWithNewVideoMediaStream
) {
337 MakeTypicalPeerConnectionCall("callWithNewVideoMediaStream();");
340 // This test will make a PeerConnection-based call and send a new Video
341 // MediaStream that has been created based on a MediaStream created with
342 // getUserMedia. When video is flowing, the VideoTrack is removed and an
343 // AudioTrack is added instead.
344 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallAndModifyStream
) {
345 MakeTypicalPeerConnectionCall(
346 "callWithNewVideoMediaStreamLaterSwitchToAudio();");
349 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, AddTwoMediaStreamsToOnePC
) {
350 MakeTypicalPeerConnectionCall("addTwoMediaStreamsToOneConnection();");
353 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
354 EstablishAudioVideoCallAndEnsureAudioIsPlaying
) {
355 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
356 "callAndEnsureAudioIsPlaying(%s, {audio:true, video:true});",
357 kUseLenientAudioChecking
));
360 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
361 EstablishAudioOnlyCallAndEnsureAudioIsPlaying
) {
362 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
363 "callAndEnsureAudioIsPlaying(%s, {audio:true});",
364 kUseLenientAudioChecking
));
367 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
368 EstablishAudioVideoCallAndVerifyRemoteMutingWorks
) {
369 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
370 "callAndEnsureRemoteAudioTrackMutingWorks(%s);",
371 kUseLenientAudioChecking
));
374 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
375 EstablishAudioVideoCallAndVerifyLocalMutingWorks
) {
376 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
377 "callAndEnsureLocalAudioTrackMutingWorks(%s);",
378 kUseLenientAudioChecking
));
381 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
382 EnsureLocalVideoMuteDoesntMuteAudio
) {
383 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
384 "callAndEnsureLocalVideoMutingDoesntMuteAudio(%s);",
385 kUseLenientAudioChecking
));
388 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
389 EnsureRemoteVideoMuteDoesntMuteAudio
) {
390 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
391 "callAndEnsureRemoteVideoMutingDoesntMuteAudio(%s);",
392 kUseLenientAudioChecking
));
395 // Flaky on TSAN v2: http://crbug.com/373637
396 #if defined(THREAD_SANITIZER)
397 #define MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks\
398 DISABLED_EstablishAudioVideoCallAndVerifyUnmutingWorks
400 #define MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks\
401 EstablishAudioVideoCallAndVerifyUnmutingWorks
403 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
,
404 MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks
) {
405 MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
406 "callAndEnsureAudioTrackUnmutingWorks(%s);", kUseLenientAudioChecking
));
409 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CallAndVerifyVideoMutingWorks
) {
410 MakeTypicalPeerConnectionCall("callAndEnsureVideoTrackMutingWorks();");
413 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest
, CreateOfferWithOfferOptions
) {
414 MakeTypicalPeerConnectionCall("testCreateOfferOptions();");
417 } // namespace content