blob: 58b3d3fdcfc557145f97ca3d0cdc8adfeaa8e8e9 [file] [log] [blame]
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001// 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"
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01006#include "base/strings/stringprintf.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01007#include "base/strings/utf_string_conversions.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00008#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/shell.h"
12#include "content/test/content_browser_test.h"
13#include "content/test/content_browser_test_utils.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010014#include "net/test/embedded_test_server/embedded_test_server.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000015
16#if defined(OS_WIN)
17#include "base/win/windows_version.h"
18#endif
19
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010020namespace {
21
22std::string GenerateGetUserMediaCall(int min_width,
23 int max_width,
24 int min_height,
25 int max_height,
26 int min_frame_rate,
27 int max_frame_rate) {
28 return base::StringPrintf(
29 "getUserMedia({video: {mandatory: {minWidth: %d, maxWidth: %d, "
30 "minHeight: %d, maxHeight: %d, minFrameRate: %d, maxFrameRate: %d}, "
31 "optional: []}});",
32 min_width,
33 max_width,
34 min_height,
35 max_height,
36 min_frame_rate,
37 max_frame_rate);
38}
39}
40
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000041namespace content {
42
43class WebrtcBrowserTest: public ContentBrowserTest {
44 public:
45 WebrtcBrowserTest() {}
46 virtual ~WebrtcBrowserTest() {}
47
48 virtual void SetUpOnMainThread() OVERRIDE {
49 // We need fake devices in this test since we want to run on naked VMs. We
Ben Murdocheb525c52013-07-10 11:40:50 +010050 // assume these switches are set by default in content_browsertests.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000051 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
52 switches::kUseFakeDeviceForMediaStream));
Ben Murdocheb525c52013-07-10 11:40:50 +010053 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
54 switches::kUseFakeUIForMediaStream));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000055
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010056 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000057 }
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010058
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000059 protected:
60 bool ExecuteJavascript(const std::string& javascript) {
61 return ExecuteScript(shell()->web_contents(), javascript);
62 }
63
64 void ExpectTitle(const std::string& expected_title) const {
65 string16 expected_title16(ASCIIToUTF16(expected_title));
66 TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
67 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
68 }
69};
70
71// These tests will all make a getUserMedia call with different constraints and
72// see that the success callback is called. If the error callback is called or
73// none of the callbacks are called the tests will simply time out and fail.
74IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, GetVideoStreamAndStop) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010075 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000076 NavigateToURL(shell(), url);
77
78 EXPECT_TRUE(ExecuteJavascript("getUserMedia({video: true});"));
79
80 ExpectTitle("OK");
81}
82
83IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, GetAudioAndVideoStreamAndStop) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010084 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000085 NavigateToURL(shell(), url);
86
87 EXPECT_TRUE(ExecuteJavascript("getUserMedia({video: true, audio: true});"));
88
89 ExpectTitle("OK");
90}
91
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010092IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, GetAudioAndVideoStreamAndClone) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010093 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010094 NavigateToURL(shell(), url);
95
96 EXPECT_TRUE(ExecuteJavascript("getUserMediaAndClone();"));
97
98 ExpectTitle("OK");
99}
100
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100101
102#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
103// Timing out on ARM linux bot: http://crbug.com/238490
104#define MAYBE_CanSetupVideoCall DISABLED_CanSetupVideoCall
105#else
106#define MAYBE_CanSetupVideoCall CanSetupVideoCall
107#endif
108
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000109// These tests will make a complete PeerConnection-based call and verify that
110// video is playing for the call.
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100111IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanSetupVideoCall) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100112 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000113 NavigateToURL(shell(), url);
114
115 EXPECT_TRUE(ExecuteJavascript("call({video: true});"));
116 ExpectTitle("OK");
117}
118
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100119#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
120// Timing out on ARM linux, see http://crbug.com/240376
121#define MAYBE_CanSetupAudioAndVideoCall DISABLED_CanSetupAudioAndVideoCall
122#else
123#define MAYBE_CanSetupAudioAndVideoCall CanSetupAudioAndVideoCall
124#endif
125
126IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CanSetupAudioAndVideoCall) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100127 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000128 NavigateToURL(shell(), url);
129
130 EXPECT_TRUE(ExecuteJavascript("call({video: true, audio: true});"));
131 ExpectTitle("OK");
132}
133
134IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MANUAL_CanSetupCallAndSendDtmf) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100135 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000136 NavigateToURL(shell(), url);
137
138 EXPECT_TRUE(
139 ExecuteJavascript("callAndSendDtmf('123,abc');"));
140}
141
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000142IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest,
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100143 CanMakeEmptyCallThenAddStreamsAndRenegotiate) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100144 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000145 NavigateToURL(shell(), url);
146
147 const char* kJavascript =
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100148 "callEmptyThenAddOneStreamAndRenegotiate({video: true, audio: true});";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000149 EXPECT_TRUE(ExecuteJavascript(kJavascript));
150 ExpectTitle("OK");
151}
152
153// This test will make a complete PeerConnection-based call but remove the
154// MSID and bundle attribute from the initial offer to verify that
155// video is playing for the call even if the initiating client don't support
156// MSID. http://tools.ietf.org/html/draft-alvestrand-rtcweb-msid-02
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100157#if defined(OS_WIN) && defined(USE_AURA)
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100158// Disabled for win7_aura, see http://crbug.com/235089.
159#define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
160 DISABLED_CanSetupAudioAndVideoCallWithoutMsidAndBundle
161#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
162// Timing out on ARM linux, see http://crbug.com/240373
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100163#define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
164 DISABLED_CanSetupAudioAndVideoCallWithoutMsidAndBundle
165#else
166#define MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle\
167 CanSetupAudioAndVideoCallWithoutMsidAndBundle
168#endif
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000169IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest,
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100170 MAYBE_CanSetupAudioAndVideoCallWithoutMsidAndBundle) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100171 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000172 NavigateToURL(shell(), url);
173
174 EXPECT_TRUE(ExecuteJavascript("callWithoutMsidAndBundle();"));
175 ExpectTitle("OK");
176}
177
178// This test will make a PeerConnection-based call and test an unreliable text
179// dataChannel.
180IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, CallWithDataOnly) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100181 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000182 NavigateToURL(shell(), url);
183
184 EXPECT_TRUE(ExecuteJavascript("callWithDataOnly();"));
185 ExpectTitle("OK");
186}
187
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100188#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
189// Timing out on ARM linux bot: http://crbug.com/238490
190#define MAYBE_CallWithDataAndMedia DISABLED_CallWithDataAndMedia
191#else
192#define MAYBE_CallWithDataAndMedia CallWithDataAndMedia
193#endif
194
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000195// This test will make a PeerConnection-based call and test an unreliable text
196// dataChannel and audio and video tracks.
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100197IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CallWithDataAndMedia) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100198 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000199 NavigateToURL(shell(), url);
200
201 EXPECT_TRUE(ExecuteJavascript("callWithDataAndMedia();"));
202 ExpectTitle("OK");
203}
204
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100205#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
206// Timing out on ARM linux bot: http://crbug.com/238490
207#define MAYBE_CallWithDataAndLaterAddMedia DISABLED_CallWithDataAndLaterAddMedia
208#else
209#define MAYBE_CallWithDataAndLaterAddMedia CallWithDataAndLaterAddMedia
210#endif
211
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000212// This test will make a PeerConnection-based call and test an unreliable text
213// dataChannel and later add an audio and video track.
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100214IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CallWithDataAndLaterAddMedia) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100215 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000216 NavigateToURL(shell(), url);
217
218 EXPECT_TRUE(ExecuteJavascript("callWithDataAndLaterAddMedia();"));
219 ExpectTitle("OK");
220}
221
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100222#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
223// Timing out on ARM linux bot: http://crbug.com/238490
224#define MAYBE_CallWithNewVideoMediaStream DISABLED_CallWithNewVideoMediaStream
225#else
226#define MAYBE_CallWithNewVideoMediaStream CallWithNewVideoMediaStream
227#endif
228
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100229// This test will make a PeerConnection-based call and send a new Video
230// MediaStream that has been created based on a MediaStream created with
231// getUserMedia.
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100232IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MAYBE_CallWithNewVideoMediaStream) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100233 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100234 NavigateToURL(shell(), url);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000235
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100236 EXPECT_TRUE(ExecuteJavascript("callWithNewVideoMediaStream();"));
237 ExpectTitle("OK");
238}
239
240// This test will make a PeerConnection-based call and send a new Video
241// MediaStream that has been created based on a MediaStream created with
242// getUserMedia. When video is flowing, the VideoTrack is removed and an
243// AudioTrack is added instead.
244// TODO(phoglund): This test is manual since not all buildbots has an audio
245// input.
246IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, MANUAL_CallAndModifyStream) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100247 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100248 NavigateToURL(shell(), url);
249
250 EXPECT_TRUE(
251 ExecuteJavascript("callWithNewVideoMediaStreamLaterSwitchToAudio();"));
252 ExpectTitle("OK");
253}
254
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100255// This test calls getUserMedia in sequence with different constraints.
256IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, TestGetUserMediaConstraints) {
257 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
258
259 std::vector<std::string> list_of_get_user_media_calls;
260 list_of_get_user_media_calls.push_back(
261 GenerateGetUserMediaCall(320, 320, 180, 180, 30, 30));
262 list_of_get_user_media_calls.push_back(
263 GenerateGetUserMediaCall(320, 320, 240, 240, 30, 30));
264 list_of_get_user_media_calls.push_back(
265 GenerateGetUserMediaCall(640, 640, 360, 360, 30, 30));
266 list_of_get_user_media_calls.push_back(
267 GenerateGetUserMediaCall(640, 640, 480, 480, 30, 30));
268 list_of_get_user_media_calls.push_back(
269 GenerateGetUserMediaCall(960, 960, 720, 720, 30, 30));
270 list_of_get_user_media_calls.push_back(
271 GenerateGetUserMediaCall(1280, 1280, 720, 720, 30, 30));
272 list_of_get_user_media_calls.push_back(
273 GenerateGetUserMediaCall(1920, 1920, 1080, 1080, 30, 30));
274
275 for (std::vector<std::string>::iterator const_iterator =
276 list_of_get_user_media_calls.begin();
277 const_iterator != list_of_get_user_media_calls.end();
278 ++const_iterator) {
279 DVLOG(1) << "Calling getUserMedia: " << *const_iterator;
280 NavigateToURL(shell(), url);
281 EXPECT_TRUE(ExecuteJavascript(*const_iterator));
282 ExpectTitle("OK");
283 }
284}
Ben Murdochbb1529c2013-08-08 10:24:53 +0100285
286IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, AddTwoMediaStreamsToOnePC) {
287 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
288 NavigateToURL(shell(), url);
289
290 EXPECT_TRUE(
291 ExecuteJavascript("addTwoMediaStreamsToOneConnection();"));
292 ExpectTitle("OK");
293}
294
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100295} // namespace content