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/utf_string_conversions.h"
7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/common/content_switches.h"
9 #include "content/public/test/browser_test_utils.h"
10 #include "content/shell/shell.h"
11 #include "content/test/content_browser_test.h"
12 #include "content/test/content_browser_test_utils.h"
13 #include "net/test/test_server.h"
17 class WebrtcBrowserTest
: public ContentBrowserTest
{
19 WebrtcBrowserTest() {}
20 virtual ~WebrtcBrowserTest() {}
22 virtual void SetUp() OVERRIDE
{
23 // We need fake devices in this test since we want to run on naked VMs. We
24 // assume this switch is set by default in content_browsertests.
25 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
26 switches::kUseFakeDeviceForMediaStream
));
28 ASSERT_TRUE(test_server()->Start());
29 ContentBrowserTest::SetUp();
32 bool ExecuteJavascript(const std::string
& javascript
) {
33 RenderViewHost
* render_view_host
=
34 shell()->web_contents()->GetRenderViewHost();
36 return ExecuteJavaScript(render_view_host
, L
"", ASCIIToWide(javascript
));
39 void ExpectTitle(const std::string
& expected_title
) const {
40 string16
expected_title16(ASCIIToUTF16(expected_title
));
41 TitleWatcher
title_watcher(shell()->web_contents(), expected_title16
);
42 EXPECT_EQ(expected_title16
, title_watcher
.WaitAndGetTitle());
46 // These tests will all make a getUserMedia call with different constraints and
47 // see that the success callback is called. If the error callback is called or
48 // none of the callbacks are called the tests will simply time out and fail.
49 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest
, GetVideoStreamAndStop
) {
50 GURL
url(test_server()->GetURL("files/media/getusermedia_and_stop.html"));
51 NavigateToURL(shell(), url
);
53 EXPECT_TRUE(ExecuteJavascript("getUserMedia({video: true});"));
58 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest
, GetAudioAndVideoStreamAndStop
) {
59 GURL
url(test_server()->GetURL("files/media/getusermedia_and_stop.html"));
60 NavigateToURL(shell(), url
);
62 EXPECT_TRUE(ExecuteJavascript("getUserMedia({video: true, audio: true});"));
67 // These tests will make a complete PeerConnection-based call and verify that
68 // video is playing for the call.
69 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest
, CanSetupVideoCall
) {
70 GURL
url(test_server()->GetURL("files/media/peerconnection-call.html"));
71 NavigateToURL(shell(), url
);
73 EXPECT_TRUE(ExecuteJavascript("call({video: true});"));
77 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest
, CanSetupAudioAndVideoCall
) {
78 GURL
url(test_server()->GetURL("files/media/peerconnection-call.html"));
79 NavigateToURL(shell(), url
);
81 EXPECT_TRUE(ExecuteJavascript("call({video: true, audio: true});"));
85 } // namespace content