Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / media / webrtc_browsertest.cc
blob8bda0168fedc2af6149ec8383b542a1a7801fb4f
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/strings/stringprintf.h"
7 #include "base/values.h"
8 #include "content/browser/media/webrtc_internals.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/shell/browser/shell.h"
15 #include "content/test/webrtc_content_browsertest_base.h"
16 #include "media/audio/audio_manager.h"
17 #include "net/test/embedded_test_server/embedded_test_server.h"
19 #if defined(OS_WIN)
20 #include "base/win/windows_version.h"
21 #endif
23 namespace content {
25 class WebRtcBrowserTest : public WebRtcContentBrowserTest,
26 public testing::WithParamInterface<bool> {
27 public:
28 WebRtcBrowserTest() {}
29 virtual ~WebRtcBrowserTest() {}
31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
32 WebRtcContentBrowserTest::SetUpCommandLine(command_line);
34 bool enable_audio_track_processing = GetParam();
35 if (enable_audio_track_processing)
36 command_line->AppendSwitch(switches::kEnableAudioTrackProcessing);
39 // Convenience function since most peerconnection-call.html tests just load
40 // the page, kick off some javascript and wait for the title to change to OK.
41 void MakeTypicalPeerConnectionCall(const std::string& javascript) {
42 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
44 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
45 NavigateToURL(shell(), url);
47 DisableOpusIfOnAndroid();
48 ExecuteJavascriptAndWaitForOk(javascript);
51 void DisableOpusIfOnAndroid() {
52 #if defined (OS_ANDROID)
53 // Always force iSAC 16K on Android for now (Opus is broken).
54 EXPECT_EQ("isac-forced",
55 ExecuteJavascriptAndReturnResult("forceIsac16KInSdp();"));
56 #endif
60 static const bool kRunTestsWithFlag[] = { false, true };
61 INSTANTIATE_TEST_CASE_P(WebRtcBrowserTests,
62 WebRtcBrowserTest,
63 testing::ValuesIn(kRunTestsWithFlag));
65 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
66 // Timing out on ARM linux bot: http://crbug.com/238490
67 #define MAYBE_CanSetupDefaultVideoCall DISABLED_CanSetupDefaultVideoCall
68 #else
69 #define MAYBE_CanSetupDefaultVideoCall CanSetupDefaultVideoCall
70 #endif
72 // These tests will make a complete PeerConnection-based call and verify that
73 // video is playing for the call.
74 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CanSetupDefaultVideoCall) {
75 MakeTypicalPeerConnectionCall(
76 "callAndExpectResolution({video: true}, 640, 480);");
79 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, CanSetupVideoCallWith1To1AspecRatio) {
80 const std::string javascript =
81 "callAndExpectResolution({video: {mandatory: {minWidth: 320,"
82 " maxWidth: 320, minHeight: 320, maxHeight: 320}}}, 320, 320);";
83 MakeTypicalPeerConnectionCall(javascript);
86 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
87 // Timing out on ARM linux, see http://crbug.com/240376
88 #define MAYBE_CanSetupAudioAndVideoCall DISABLED_CanSetupAudioAndVideoCall
89 #else
90 #define MAYBE_CanSetupAudioAndVideoCall CanSetupAudioAndVideoCall
91 #endif
93 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CanSetupAudioAndVideoCall) {
94 MakeTypicalPeerConnectionCall("call({video: true, audio: true});");
97 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MANUAL_CanSetupCallAndSendDtmf) {
98 MakeTypicalPeerConnectionCall("callAndSendDtmf(\'123,abc\');");
101 // TODO(phoglund): this test fails because the peer connection state will be
102 // stable in the second negotiation round rather than have-local-offer.
103 // http://crbug.com/293125.
104 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
105 DISABLED_CanMakeEmptyCallThenAddStreamsAndRenegotiate) {
106 const char* kJavascript =
107 "callEmptyThenAddOneStreamAndRenegotiate({video: true, audio: true});";
108 MakeTypicalPeerConnectionCall(kJavascript);
111 // Below 2 test will make a complete PeerConnection-based call between pc1 and
112 // pc2, and then use the remote stream to setup a call between pc3 and pc4, and
113 // then verify that video is received on pc3 and pc4.
114 // Flaky on win xp. http://crbug.com/304775
115 #if defined(OS_WIN)
116 #define MAYBE_CanForwardRemoteStream DISABLED_CanForwardRemoteStream
117 #define MAYBE_CanForwardRemoteStream720p DISABLED_CanForwardRemoteStream720p
118 #else
119 #define MAYBE_CanForwardRemoteStream CanForwardRemoteStream
120 #define MAYBE_CanForwardRemoteStream720p CanForwardRemoteStream720p
121 #endif
122 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CanForwardRemoteStream) {
123 MakeTypicalPeerConnectionCall(
124 "callAndForwardRemoteStream({video: true, audio: false});");
127 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CanForwardRemoteStream720p) {
128 const std::string javascript = GenerateGetUserMediaCall(
129 "callAndForwardRemoteStream", 1280, 1280, 720, 720, 30, 30);
130 MakeTypicalPeerConnectionCall(javascript);
133 // This test will make a complete PeerConnection-based call but remove the
134 // MSID and bundle attribute from the initial offer to verify that
135 // video is playing for the call even if the initiating client don't support
136 // MSID. http://tools.ietf.org/html/draft-alvestrand-rtcweb-msid-02
137 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
138 // Timing out on ARM linux, see http://crbug.com/240373
139 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
140 DISABLED_CanSetupAudioAndVideoCallWithoutMsidAndBundle
141 #else
142 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
143 CanSetupAudioAndVideoCallWithoutMsidAndBundle
144 #endif
145 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
146 MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle) {
147 MakeTypicalPeerConnectionCall("callWithoutMsidAndBundle();");
150 // This test will modify the SDP offer to an unsupported codec, which should
151 // cause SetLocalDescription to fail.
152 #if defined(USE_OZONE)
153 // Disabled for Ozone, see http://crbug.com/315392#c15
154 #define MAYBE_NegotiateUnsupportedVideoCodec\
155 DISABLED_NegotiateUnsupportedVideoCodec
156 #else
157 #define MAYBE_NegotiateUnsupportedVideoCodec NegotiateUnsupportedVideoCodec
158 #endif
160 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
161 MAYBE_NegotiateUnsupportedVideoCodec) {
162 MakeTypicalPeerConnectionCall("negotiateUnsupportedVideoCodec();");
165 // This test will modify the SDP offer to use no encryption, which should
166 // cause SetLocalDescription to fail.
167 #if defined(USE_OZONE)
168 // Disabled for Ozone, see http://crbug.com/315392#c15
169 #define MAYBE_NegotiateNonCryptoCall DISABLED_NegotiateNonCryptoCall
170 #else
171 #define MAYBE_NegotiateNonCryptoCall NegotiateNonCryptoCall
172 #endif
174 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_NegotiateNonCryptoCall) {
175 MakeTypicalPeerConnectionCall("negotiateNonCryptoCall();");
178 // This test can negotiate an SDP offer that includes a b=AS:xx to control
179 // the bandwidth for audio and video
180 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, NegotiateOfferWithBLine) {
181 MakeTypicalPeerConnectionCall("negotiateOfferWithBLine();");
184 // This test will make a complete PeerConnection-based call using legacy SDP
185 // settings: GIce, external SDES, and no BUNDLE.
186 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
187 // Timing out on ARM linux, see http://crbug.com/240373
188 #define MAYBE_CanSetupLegacyCall DISABLED_CanSetupLegacyCall
189 #else
190 #define MAYBE_CanSetupLegacyCall CanSetupLegacyCall
191 #endif
193 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CanSetupLegacyCall) {
194 MakeTypicalPeerConnectionCall("callWithLegacySdp();");
197 // This test will make a PeerConnection-based call and test an unreliable text
198 // dataChannel.
199 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
200 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, CallWithDataOnly) {
201 MakeTypicalPeerConnectionCall("callWithDataOnly();");
204 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, CallWithSctpDataOnly) {
205 MakeTypicalPeerConnectionCall("callWithSctpDataOnly();");
208 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
209 // Timing out on ARM linux bot: http://crbug.com/238490
210 #define MAYBE_CallWithDataAndMedia DISABLED_CallWithDataAndMedia
211 #else
212 #define MAYBE_CallWithDataAndMedia CallWithDataAndMedia
213 #endif
215 // This test will make a PeerConnection-based call and test an unreliable text
216 // dataChannel and audio and video tracks.
217 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
218 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CallWithDataAndMedia) {
219 MakeTypicalPeerConnectionCall("callWithDataAndMedia();");
223 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
224 // Timing out on ARM linux bot: http://crbug.com/238490
225 #define MAYBE_CallWithSctpDataAndMedia DISABLED_CallWithSctpDataAndMedia
226 #else
227 #define MAYBE_CallWithSctpDataAndMedia CallWithSctpDataAndMedia
228 #endif
230 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
231 MAYBE_CallWithSctpDataAndMedia) {
232 MakeTypicalPeerConnectionCall("callWithSctpDataAndMedia();");
235 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
236 // Timing out on ARM linux bot: http://crbug.com/238490
237 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
238 #else
239 // Temporarily disable the test on all platforms. http://crbug.com/293252
240 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
241 #endif
243 // This test will make a PeerConnection-based call and test an unreliable text
244 // dataChannel and later add an audio and video track.
245 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CallWithDataAndLaterAddMedia) {
246 MakeTypicalPeerConnectionCall("callWithDataAndLaterAddMedia();");
249 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
250 // Timing out on ARM linux bot: http://crbug.com/238490
251 #define MAYBE_CallWithNewVideoMediaStream DISABLED_CallWithNewVideoMediaStream
252 #else
253 #define MAYBE_CallWithNewVideoMediaStream CallWithNewVideoMediaStream
254 #endif
256 // This test will make a PeerConnection-based call and send a new Video
257 // MediaStream that has been created based on a MediaStream created with
258 // getUserMedia.
259 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CallWithNewVideoMediaStream) {
260 MakeTypicalPeerConnectionCall("callWithNewVideoMediaStream();");
263 // This test will make a PeerConnection-based call and send a new Video
264 // MediaStream that has been created based on a MediaStream created with
265 // getUserMedia. When video is flowing, the VideoTrack is removed and an
266 // AudioTrack is added instead.
267 // TODO(phoglund): This test is manual since not all buildbots has an audio
268 // input.
269 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MANUAL_CallAndModifyStream) {
270 MakeTypicalPeerConnectionCall(
271 "callWithNewVideoMediaStreamLaterSwitchToAudio();");
274 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, AddTwoMediaStreamsToOnePC) {
275 MakeTypicalPeerConnectionCall("addTwoMediaStreamsToOneConnection();");
278 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
279 EstablishAudioVideoCallAndMeasureOutputLevel) {
280 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
281 // Bots with no output devices will force the audio code into a different
282 // path where it doesn't manage to set either the low or high latency path.
283 // This test will compute useless values in that case, so skip running on
284 // such bots (see crbug.com/326338).
285 LOG(INFO) << "Missing output devices: skipping test...";
286 return;
289 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
290 switches::kUseFakeDeviceForMediaStream))
291 << "Must run with fake devices since the test will explicitly look "
292 << "for the fake device signal.";
294 MakeTypicalPeerConnectionCall("callAndEnsureAudioIsPlaying();");
297 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
298 EstablishAudioVideoCallAndVerifyMutingWorks) {
299 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
300 // Bots with no output devices will force the audio code into a different
301 // path where it doesn't manage to set either the low or high latency path.
302 // This test will compute useless values in that case, so skip running on
303 // such bots (see crbug.com/326338).
304 LOG(INFO) << "Missing output devices: skipping test...";
305 return;
308 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
309 switches::kUseFakeDeviceForMediaStream))
310 << "Must run with fake devices since the test will explicitly look "
311 << "for the fake device signal.";
313 MakeTypicalPeerConnectionCall("callAndEnsureAudioTrackMutingWorks();");
316 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
317 EstablishAudioVideoCallAndVerifyUnmutingWorks) {
318 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
319 // See comment on EstablishAudioVideoCallAndVerifyMutingWorks.
320 LOG(INFO) << "Missing output devices: skipping test...";
321 return;
324 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
325 switches::kUseFakeDeviceForMediaStream))
326 << "Must run with fake devices since the test will explicitly look "
327 << "for the fake device signal.";
329 MakeTypicalPeerConnectionCall("callAndEnsureAudioTrackUnmutingWorks();");
332 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, CallAndVerifyVideoMutingWorks) {
333 MakeTypicalPeerConnectionCall("callAndEnsureVideoTrackMutingWorks();");
336 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
337 // Timing out on ARM linux bot: http://crbug.com/238490
338 #define MAYBE_CallWithAecDump DISABLED_CallWithAecDump
339 #else
340 #define MAYBE_CallWithAecDump CallWithAecDump
341 #endif
343 // This tests will make a complete PeerConnection-based call, verify that
344 // video is playing for the call, and verify that a non-empty AEC dump file
345 // exists. The AEC dump is enabled through webrtc-internals, in contrast to
346 // using a command line flag (tested in webrtc_aecdump_browsertest.cc). The HTML
347 // and Javascript is bypassed since it would trigger a file picker dialog.
348 // Instead, the dialog callback FileSelected() is invoked directly. In fact,
349 // there's never a webrtc-internals page opened at all since that's not needed.
350 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MAYBE_CallWithAecDump) {
351 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
353 // We must navigate somewhere first so that the render process is created.
354 NavigateToURL(shell(), GURL(""));
356 base::FilePath dump_file;
357 ASSERT_TRUE(CreateTemporaryFile(&dump_file));
359 // This fakes the behavior of another open tab with webrtc-internals, and
360 // enabling AEC dump in that tab.
361 WebRTCInternals::GetInstance()->FileSelected(dump_file, -1, NULL);
363 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
364 NavigateToURL(shell(), url);
365 DisableOpusIfOnAndroid();
366 ExecuteJavascriptAndWaitForOk("call({video: true, audio: true});");
368 EXPECT_TRUE(base::PathExists(dump_file));
369 int64 file_size = 0;
370 EXPECT_TRUE(base::GetFileSize(dump_file, &file_size));
371 EXPECT_GT(file_size, 0);
373 base::DeleteFile(dump_file, false);
376 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
377 // Timing out on ARM linux bot: http://crbug.com/238490
378 #define MAYBE_CallWithAecDumpEnabledThenDisabled DISABLED_CallWithAecDumpEnabledThenDisabled
379 #else
380 #define MAYBE_CallWithAecDumpEnabledThenDisabled CallWithAecDumpEnabledThenDisabled
381 #endif
383 // As above, but enable and disable dump before starting a call. The file should
384 // be created, but should be empty.
385 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
386 MAYBE_CallWithAecDumpEnabledThenDisabled) {
387 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
389 // We must navigate somewhere first so that the render process is created.
390 NavigateToURL(shell(), GURL(""));
392 base::FilePath dump_file;
393 ASSERT_TRUE(CreateTemporaryFile(&dump_file));
395 // This fakes the behavior of another open tab with webrtc-internals, and
396 // enabling AEC dump in that tab, then disabling it.
397 WebRTCInternals::GetInstance()->FileSelected(dump_file, -1, NULL);
398 WebRTCInternals::GetInstance()->DisableAecDump();
400 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
401 NavigateToURL(shell(), url);
402 DisableOpusIfOnAndroid();
403 ExecuteJavascriptAndWaitForOk("call({video: true, audio: true});");
405 EXPECT_TRUE(base::PathExists(dump_file));
406 int64 file_size = 0;
407 EXPECT_TRUE(base::GetFileSize(dump_file, &file_size));
408 EXPECT_EQ(0, file_size);
410 base::DeleteFile(dump_file, false);
413 } // namespace content