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/strings/utf_string_conversions.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/shell/browser/shell.h"
12 #include "content/test/content_browser_test.h"
13 #include "content/test/content_browser_test_utils.h"
14 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "base/win/windows_version.h"
22 static const char kGetUserMedia[] = "getUserMedia";
23 static const char kGetUserMediaWithAnalysis[] = "getUserMediaWithAnalysis";
25 std::string GenerateGetUserMediaCall(const char* function_name,
32 return base::StringPrintf(
33 "%s({video: {mandatory: {minWidth: %d, maxWidth: %d, "
34 "minHeight: %d, maxHeight: %d, minFrameRate: %d, maxFrameRate: %d}, "
48 class WebrtcBrowserTest: public ContentBrowserTest {
50 WebrtcBrowserTest() {}
51 virtual ~WebrtcBrowserTest() {}
53 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
54 // We need fake devices in this test since we want to run on naked VMs. We
55 // assume these switches are set by default in content_browsertests.
56 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
57 switches::kUseFakeDeviceForMediaStream));
58 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
59 switches::kUseFakeUIForMediaStream));
61 // The video playback will not work without a GPU, so force its use here.
62 // This may not be available on all VMs though.
63 command_line->AppendSwitch(switches::kUseGpuInTests);
67 bool ExecuteJavascript(const std::string& javascript) {
68 return ExecuteScript(shell()->web_contents(), javascript);
71 void ExpectTitle(const std::string& expected_title) const {
72 string16 expected_title16(ASCIIToUTF16(expected_title));
73 TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
74 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
78 // These tests will all make a getUserMedia call with different constraints and
79 // see that the success callback is called. If the error callback is called or
80 // none of the callbacks are called the tests will simply time out and fail.
81 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, GetVideoStreamAndStop) {
82 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
84 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
85 NavigateToURL(shell(), url);
87 EXPECT_TRUE(ExecuteJavascript("getUserMedia({video: true});"));
92 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, GetAudioAndVideoStreamAndStop) {
93 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
95 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
96 NavigateToURL(shell(), url);
98 EXPECT_TRUE(ExecuteJavascript("getUserMedia({video: true, audio: true});"));
103 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, GetAudioAndVideoStreamAndClone) {
104 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
106 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
107 NavigateToURL(shell(), url);
109 EXPECT_TRUE(ExecuteJavascript("getUserMediaAndClone();"));
115 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
116 // Timing out on ARM linux bot: http://crbug.com/238490
117 #define MAYBE_CanSetupVideoCall DISABLED_CanSetupVideoCall
119 #define MAYBE_CanSetupVideoCall CanSetupVideoCall
122 // These tests will make a complete PeerConnection-based call and verify that
123 // video is playing for the call.
124 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanSetupVideoCall) {
125 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
127 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
128 NavigateToURL(shell(), url);
130 EXPECT_TRUE(ExecuteJavascript("call({video: true});"));
134 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
135 // Timing out on ARM linux, see http://crbug.com/240376
136 #define MAYBE_CanSetupAudioAndVideoCall DISABLED_CanSetupAudioAndVideoCall
138 #define MAYBE_CanSetupAudioAndVideoCall CanSetupAudioAndVideoCall
141 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanSetupAudioAndVideoCall) {
142 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
144 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
145 NavigateToURL(shell(), url);
147 EXPECT_TRUE(ExecuteJavascript("call({video: true, audio: true});"));
151 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MANUAL_CanSetupCallAndSendDtmf) {
152 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
154 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
155 NavigateToURL(shell(), url);
158 ExecuteJavascript("callAndSendDtmf('123,abc');"));
161 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest,
162 DISABLED_CanMakeEmptyCallThenAddStreamsAndRenegotiate) {
163 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
165 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
166 NavigateToURL(shell(), url);
168 const char* kJavascript =
169 "callEmptyThenAddOneStreamAndRenegotiate({video: true, audio: true});";
170 EXPECT_TRUE(ExecuteJavascript(kJavascript));
174 // Below 2 test will make a complete PeerConnection-based call between pc1 and
175 // pc2, and then use the remote stream to setup a call between pc3 and pc4, and
176 // then verify that video is received on pc3 and pc4.
177 // Flaky on win xp. http://crbug.com/304775
179 #define MAYBE_CanForwardRemoteStream DISABLED_CanForwardRemoteStream
180 #define MAYBE_CanForwardRemoteStream720p DISABLED_CanForwardRemoteStream720p
182 #define MAYBE_CanForwardRemoteStream CanForwardRemoteStream
183 #define MAYBE_CanForwardRemoteStream720p CanForwardRemoteStream720p
185 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanForwardRemoteStream) {
186 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
188 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
189 NavigateToURL(shell(), url);
191 EXPECT_TRUE(ExecuteJavascript(
192 "callAndForwardRemoteStream({video: true, audio: true});"));
196 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanForwardRemoteStream720p) {
197 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
199 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
200 NavigateToURL(shell(), url);
202 const std::string cmd = GenerateGetUserMediaCall("callAndForwardRemoteStream",
205 EXPECT_TRUE(ExecuteJavascript(cmd));
209 // This test will make a complete PeerConnection-based call but remove the
210 // MSID and bundle attribute from the initial offer to verify that
211 // video is playing for the call even if the initiating client don't support
212 // MSID. http://tools.ietf.org/html/draft-alvestrand-rtcweb-msid-02
213 #if defined(OS_WIN) && defined(USE_AURA)
214 // Disabled for win7_aura, see http://crbug.com/235089.
215 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
216 DISABLED_CanSetupAudioAndVideoCallWithoutMsidAndBundle
217 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
218 // Timing out on ARM linux, see http://crbug.com/240373
219 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
220 DISABLED_CanSetupAudioAndVideoCallWithoutMsidAndBundle
222 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
223 CanSetupAudioAndVideoCallWithoutMsidAndBundle
225 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest,
226 MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle) {
227 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
229 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
230 NavigateToURL(shell(), url);
232 EXPECT_TRUE(ExecuteJavascript("callWithoutMsidAndBundle();"));
236 // This test will make a complete PeerConnection-based call using legacy SDP
237 // settings: GIce, external SDES, and no BUNDLE.
238 #if defined(OS_WIN) && defined(USE_AURA)
239 // Disabled for win7_aura, see http://crbug.com/235089.
240 #define MAYBE_CanSetupLegacyCall DISABLED_CanSetupLegacyCall
241 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
242 // Timing out on ARM linux, see http://crbug.com/240373
243 #define MAYBE_CanSetupLegacyCall DISABLED_CanSetupLegacyCall
245 #define MAYBE_CanSetupLegacyCall CanSetupLegacyCall
248 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanSetupLegacyCall) {
249 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
251 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
252 NavigateToURL(shell(), url);
254 EXPECT_TRUE(ExecuteJavascript("callWithLegacySdp();"));
258 // This test will make a PeerConnection-based call and test an unreliable text
260 // TODO(mallinath) - Remove this test after rtp based data channel is disabled.
261 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, CallWithDataOnly) {
262 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
264 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
265 NavigateToURL(shell(), url);
267 EXPECT_TRUE(ExecuteJavascript("callWithDataOnly();"));
271 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, CallWithSctpDataOnly) {
272 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
274 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
275 NavigateToURL(shell(), url);
277 EXPECT_TRUE(ExecuteJavascript("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(WebrtcBrowserTest, MAYBE_CallWithDataAndMedia) {
292 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
294 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
295 NavigateToURL(shell(), url);
297 EXPECT_TRUE(ExecuteJavascript("callWithDataAndMedia();"));
302 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
303 // Timing out on ARM linux bot: http://crbug.com/238490
304 #define MAYBE_CallWithSctpDataAndMedia DISABLED_CallWithSctpDataAndMedia
306 #define MAYBE_CallWithSctpDataAndMedia CallWithSctpDataAndMedia
309 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest,
310 MAYBE_CallWithSctpDataAndMedia) {
311 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
313 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
314 NavigateToURL(shell(), url);
316 EXPECT_TRUE(ExecuteJavascript("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(WebrtcBrowserTest, MAYBE_CallWithDataAndLaterAddMedia) {
331 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
333 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
334 NavigateToURL(shell(), url);
336 EXPECT_TRUE(ExecuteJavascript("callWithDataAndLaterAddMedia();"));
340 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
341 // Timing out on ARM linux bot: http://crbug.com/238490
342 #define MAYBE_CallWithNewVideoMediaStream DISABLED_CallWithNewVideoMediaStream
344 #define MAYBE_CallWithNewVideoMediaStream CallWithNewVideoMediaStream
347 // This test will make a PeerConnection-based call and send a new Video
348 // MediaStream that has been created based on a MediaStream created with
350 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CallWithNewVideoMediaStream) {
351 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
353 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
354 NavigateToURL(shell(), url);
356 EXPECT_TRUE(ExecuteJavascript("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
362 // getUserMedia. When video is flowing, the VideoTrack is removed and an
363 // AudioTrack is added instead.
364 // TODO(phoglund): This test is manual since not all buildbots has an audio
366 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MANUAL_CallAndModifyStream) {
367 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
369 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
370 NavigateToURL(shell(), url);
373 ExecuteJavascript("callWithNewVideoMediaStreamLaterSwitchToAudio();"));
377 // This test calls getUserMedia in sequence with different constraints.
378 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, TestGetUserMediaConstraints) {
379 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
381 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
383 std::vector<std::string> list_of_get_user_media_calls;
384 list_of_get_user_media_calls.push_back(
385 GenerateGetUserMediaCall(kGetUserMedia, 320, 320, 180, 180, 30, 30));
386 list_of_get_user_media_calls.push_back(
387 GenerateGetUserMediaCall(kGetUserMedia, 320, 320, 240, 240, 30, 30));
388 list_of_get_user_media_calls.push_back(
389 GenerateGetUserMediaCall(kGetUserMedia, 640, 640, 360, 360, 30, 30));
390 list_of_get_user_media_calls.push_back(
391 GenerateGetUserMediaCall(kGetUserMedia, 640, 640, 480, 480, 30, 30));
392 list_of_get_user_media_calls.push_back(
393 GenerateGetUserMediaCall(kGetUserMedia, 960, 960, 720, 720, 30, 30));
394 list_of_get_user_media_calls.push_back(
395 GenerateGetUserMediaCall(kGetUserMedia, 1280, 1280, 720, 720, 30, 30));
396 list_of_get_user_media_calls.push_back(
397 GenerateGetUserMediaCall(kGetUserMedia, 1920, 1920, 1080, 1080, 30, 30));
399 for (std::vector<std::string>::iterator const_iterator =
400 list_of_get_user_media_calls.begin();
401 const_iterator != list_of_get_user_media_calls.end();
403 DVLOG(1) << "Calling getUserMedia: " << *const_iterator;
404 NavigateToURL(shell(), url);
405 EXPECT_TRUE(ExecuteJavascript(*const_iterator));
410 // This test calls getUserMedia and checks for aspect ratio behavior.
411 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, TestGetUserMediaAspectRatio) {
412 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
414 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
416 std::string constraints_4_3 = GenerateGetUserMediaCall(
417 kGetUserMediaWithAnalysis, 640, 640, 480, 480, 30, 30);
418 std::string constraints_16_9 = GenerateGetUserMediaCall(
419 kGetUserMediaWithAnalysis, 640, 640, 360, 360, 30, 30);
421 // TODO(mcasas): add more aspect ratios, in particular 16:10 crbug.com/275594.
423 NavigateToURL(shell(), url);
424 EXPECT_TRUE(ExecuteJavascript(constraints_4_3));
425 ExpectTitle("4:3 letterbox");
427 NavigateToURL(shell(), url);
428 EXPECT_TRUE(ExecuteJavascript(constraints_16_9));
429 ExpectTitle("16:9 letterbox");
432 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, AddTwoMediaStreamsToOnePC) {
433 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
435 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
436 NavigateToURL(shell(), url);
439 ExecuteJavascript("addTwoMediaStreamsToOneConnection();"));
443 } // namespace content