1 // Copyright 2014 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 "chrome/browser/media/webrtc_browsertest_base.h"
7 #include "chrome/browser/media/webrtc_browsertest_common.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h"
17 static const char kMainWebrtcTestHtmlPage
[] =
18 "/webrtc/webrtc_jsep01_test.html";
20 // These tests runs on real webcams and ensure WebRTC can acquire webcams
21 // correctly. They will do nothing if there are no webcams on the system.
22 // The webcam on the system must support up to 1080p, or the test will fail.
23 class WebRtcWebcamBrowserTest
: public WebRtcTestBase
{
25 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
26 EXPECT_FALSE(command_line
->HasSwitch(
27 switches::kUseFakeDeviceForMediaStream
));
28 EXPECT_FALSE(command_line
->HasSwitch(
29 switches::kUseFakeUIForMediaStream
));
32 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
33 DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
37 std::string
GetUserMediaAndGetStreamSize(content::WebContents
* tab
,
38 const std::string
& constraints
) {
39 GetUserMediaWithSpecificConstraintsAndAccept(tab
, constraints
);
40 StartDetectingVideo(tab
, "local-view");
41 WaitForVideoToPlay(tab
);
42 std::string actual_stream_size
= GetStreamSize(tab
, "local-view");
43 CloseLastLocalStream(tab
);
44 return actual_stream_size
;
48 IN_PROC_BROWSER_TEST_F(WebRtcWebcamBrowserTest
,
49 TestAcquiringAndReacquiringWebcam
) {
50 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
51 GURL
url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage
));
52 ui_test_utils::NavigateToURL(browser(), url
);
53 content::WebContents
* tab
=
54 browser()->tab_strip_model()->GetActiveWebContents();
56 if (!HasWebcamAvailableOnSystem(tab
)) {
57 LOG(INFO
) << "No webcam found on bot: skipping...";
62 GetUserMediaAndGetStreamSize(tab
, kAudioVideoCallConstraintsVGA
));
64 GetUserMediaAndGetStreamSize(tab
, kAudioVideoCallConstraintsQVGA
));
66 GetUserMediaAndGetStreamSize(tab
, kAudioVideoCallConstraints360p
));
68 GetUserMediaAndGetStreamSize(tab
, kAudioVideoCallConstraints720p
));
69 EXPECT_EQ("1920x1080",
70 GetUserMediaAndGetStreamSize(tab
, kAudioVideoCallConstraints1080p
));