- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / media / webrtc_browsertest.cc
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.
4
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"
15
16 #if defined(OS_WIN)
17 #include "base/win/windows_version.h"
18 #endif
19
20 namespace {
21
22 static const char kGetUserMedia[] = "getUserMedia";
23 static const char kGetUserMediaWithAnalysis[] = "getUserMediaWithAnalysis";
24
25 std::string GenerateGetUserMediaCall(const char* function_name,
26                                      int min_width,
27                                      int max_width,
28                                      int min_height,
29                                      int max_height,
30                                      int min_frame_rate,
31                                      int max_frame_rate) {
32   return base::StringPrintf(
33       "%s({video: {mandatory: {minWidth: %d, maxWidth: %d, "
34       "minHeight: %d, maxHeight: %d, minFrameRate: %d, maxFrameRate: %d}, "
35       "optional: []}});",
36       function_name,
37       min_width,
38       max_width,
39       min_height,
40       max_height,
41       min_frame_rate,
42       max_frame_rate);
43 }
44 }
45
46 namespace content {
47
48 class WebrtcBrowserTest: public ContentBrowserTest {
49  public:
50   WebrtcBrowserTest() {}
51   virtual ~WebrtcBrowserTest() {}
52
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));
60
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);
64   }
65
66  protected:
67   bool ExecuteJavascript(const std::string& javascript) {
68     return ExecuteScript(shell()->web_contents(), javascript);
69   }
70
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());
75   }
76 };
77
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());
83
84   GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
85   NavigateToURL(shell(), url);
86
87   EXPECT_TRUE(ExecuteJavascript("getUserMedia({video: true});"));
88
89   ExpectTitle("OK");
90 }
91
92 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, GetAudioAndVideoStreamAndStop) {
93   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
94
95   GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
96   NavigateToURL(shell(), url);
97
98   EXPECT_TRUE(ExecuteJavascript("getUserMedia({video: true, audio: true});"));
99
100   ExpectTitle("OK");
101 }
102
103 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, GetAudioAndVideoStreamAndClone) {
104   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
105
106   GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
107   NavigateToURL(shell(), url);
108
109   EXPECT_TRUE(ExecuteJavascript("getUserMediaAndClone();"));
110
111   ExpectTitle("OK");
112 }
113
114
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
118 #else
119 #define MAYBE_CanSetupVideoCall CanSetupVideoCall
120 #endif
121
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());
126
127   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
128   NavigateToURL(shell(), url);
129
130   EXPECT_TRUE(ExecuteJavascript("call({video: true});"));
131   ExpectTitle("OK");
132 }
133
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
137 #else
138 #define MAYBE_CanSetupAudioAndVideoCall CanSetupAudioAndVideoCall
139 #endif
140
141 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanSetupAudioAndVideoCall) {
142   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
143
144   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
145   NavigateToURL(shell(), url);
146
147   EXPECT_TRUE(ExecuteJavascript("call({video: true, audio: true});"));
148   ExpectTitle("OK");
149 }
150
151 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MANUAL_CanSetupCallAndSendDtmf) {
152   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
153
154   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
155   NavigateToURL(shell(), url);
156
157   EXPECT_TRUE(
158       ExecuteJavascript("callAndSendDtmf('123,abc');"));
159 }
160
161 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest,
162                        DISABLED_CanMakeEmptyCallThenAddStreamsAndRenegotiate) {
163   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
164
165   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
166   NavigateToURL(shell(), url);
167
168   const char* kJavascript =
169       "callEmptyThenAddOneStreamAndRenegotiate({video: true, audio: true});";
170   EXPECT_TRUE(ExecuteJavascript(kJavascript));
171   ExpectTitle("OK");
172 }
173
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
178 #if defined(OS_WIN)
179 #define MAYBE_CanForwardRemoteStream DISABLED_CanForwardRemoteStream
180 #define MAYBE_CanForwardRemoteStream720p DISABLED_CanForwardRemoteStream720p
181 #else
182 #define MAYBE_CanForwardRemoteStream CanForwardRemoteStream
183 #define MAYBE_CanForwardRemoteStream720p CanForwardRemoteStream720p
184 #endif
185 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanForwardRemoteStream) {
186   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
187
188   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
189   NavigateToURL(shell(), url);
190
191   EXPECT_TRUE(ExecuteJavascript(
192                   "callAndForwardRemoteStream({video: true, audio: true});"));
193   ExpectTitle("OK");
194 }
195
196 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanForwardRemoteStream720p) {
197   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
198
199   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
200   NavigateToURL(shell(), url);
201
202   const std::string cmd = GenerateGetUserMediaCall("callAndForwardRemoteStream",
203                                                    1280, 1280,
204                                                    720, 720, 30, 30);
205   EXPECT_TRUE(ExecuteJavascript(cmd));
206   ExpectTitle("OK");
207 }
208
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
221 #else
222 #define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
223         CanSetupAudioAndVideoCallWithoutMsidAndBundle
224 #endif
225 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest,
226                        MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle) {
227   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
228
229   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
230   NavigateToURL(shell(), url);
231
232   EXPECT_TRUE(ExecuteJavascript("callWithoutMsidAndBundle();"));
233   ExpectTitle("OK");
234 }
235
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
244 #else
245 #define MAYBE_CanSetupLegacyCall CanSetupLegacyCall
246 #endif
247
248 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanSetupLegacyCall) {
249   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
250
251   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
252   NavigateToURL(shell(), url);
253
254   EXPECT_TRUE(ExecuteJavascript("callWithLegacySdp();"));
255   ExpectTitle("OK");
256 }
257
258 // This test will make a PeerConnection-based call and test an unreliable text
259 // dataChannel.
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());
263
264   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
265   NavigateToURL(shell(), url);
266
267   EXPECT_TRUE(ExecuteJavascript("callWithDataOnly();"));
268   ExpectTitle("OK");
269 }
270
271 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, CallWithSctpDataOnly) {
272   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
273
274   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
275   NavigateToURL(shell(), url);
276
277   EXPECT_TRUE(ExecuteJavascript("callWithSctpDataOnly();"));
278   ExpectTitle("OK");
279 }
280
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
284 #else
285 #define MAYBE_CallWithDataAndMedia CallWithDataAndMedia
286 #endif
287
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());
293
294   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
295   NavigateToURL(shell(), url);
296
297   EXPECT_TRUE(ExecuteJavascript("callWithDataAndMedia();"));
298   ExpectTitle("OK");
299 }
300
301
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
305 #else
306 #define MAYBE_CallWithSctpDataAndMedia CallWithSctpDataAndMedia
307 #endif
308
309 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest,
310                        MAYBE_CallWithSctpDataAndMedia) {
311   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
312
313   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
314   NavigateToURL(shell(), url);
315
316   EXPECT_TRUE(ExecuteJavascript("callWithSctpDataAndMedia();"));
317   ExpectTitle("OK");
318 }
319
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
323 #else
324 // Temporarily disable the test on all platforms. http://crbug.com/293252
325 #define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
326 #endif
327
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());
332
333   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
334   NavigateToURL(shell(), url);
335
336   EXPECT_TRUE(ExecuteJavascript("callWithDataAndLaterAddMedia();"));
337   ExpectTitle("OK");
338 }
339
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
343 #else
344 #define MAYBE_CallWithNewVideoMediaStream CallWithNewVideoMediaStream
345 #endif
346
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
349 // getUserMedia.
350 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CallWithNewVideoMediaStream) {
351   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
352
353   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
354   NavigateToURL(shell(), url);
355
356   EXPECT_TRUE(ExecuteJavascript("callWithNewVideoMediaStream();"));
357   ExpectTitle("OK");
358 }
359
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
365 // input.
366 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MANUAL_CallAndModifyStream) {
367   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
368
369   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
370   NavigateToURL(shell(), url);
371
372   EXPECT_TRUE(
373       ExecuteJavascript("callWithNewVideoMediaStreamLaterSwitchToAudio();"));
374   ExpectTitle("OK");
375 }
376
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());
380
381   GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
382
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));
398
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();
402        ++const_iterator) {
403     DVLOG(1) << "Calling getUserMedia: " << *const_iterator;
404     NavigateToURL(shell(), url);
405     EXPECT_TRUE(ExecuteJavascript(*const_iterator));
406     ExpectTitle("OK");
407   }
408 }
409
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());
413
414   GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
415
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);
420
421   // TODO(mcasas): add more aspect ratios, in particular 16:10 crbug.com/275594.
422
423   NavigateToURL(shell(), url);
424   EXPECT_TRUE(ExecuteJavascript(constraints_4_3));
425   ExpectTitle("4:3 letterbox");
426
427   NavigateToURL(shell(), url);
428   EXPECT_TRUE(ExecuteJavascript(constraints_16_9));
429   ExpectTitle("16:9 letterbox");
430 }
431
432 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, AddTwoMediaStreamsToOnePC) {
433   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
434
435   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
436   NavigateToURL(shell(), url);
437
438   EXPECT_TRUE(
439       ExecuteJavascript("addTwoMediaStreamsToOneConnection();"));
440   ExpectTitle("OK");
441 }
442
443 }  // namespace content