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 "media/base/media_switches.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "testing/gtest/include/gtest/gtest-param-test.h"
19 static const char kMainWebrtcTestHtmlPage
[] =
20 "/webrtc/webrtc_jsep01_test.html";
22 static const char* kTestConfigFlags
[] = {
24 switches::kForceDirectShowVideoCapture
,
25 // Media Foundation is only available in Windows versions >= 7, below that the
26 // following flag has no effect; the test would run twice using DirectShow.
27 switches::kForceMediaFoundationVideoCapture
28 #elif defined(OS_MACOSX)
29 switches::kForceQTKit
,
30 switches::kEnableAVFoundation
36 // These tests runs on real webcams and ensure WebRTC can acquire webcams
37 // correctly. They will do nothing if there are no webcams on the system.
38 // The webcam on the system must support up to 1080p, or the test will fail.
39 class WebRtcWebcamBrowserTest
: public WebRtcTestBase
,
40 public testing::WithParamInterface
<const char*> {
42 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
43 EXPECT_FALSE(command_line
->HasSwitch(
44 switches::kUseFakeDeviceForMediaStream
));
45 EXPECT_FALSE(command_line
->HasSwitch(
46 switches::kUseFakeUIForMediaStream
));
48 command_line
->AppendSwitch(GetParam());
52 void SetUpInProcessBrowserTestFixture() override
{
53 DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
56 std::string
GetUserMediaAndGetStreamSize(content::WebContents
* tab
,
57 const std::string
& constraints
) {
58 std::string actual_stream_size
;
59 if (GetUserMediaWithSpecificConstraintsAndAcceptIfPrompted(tab
,
61 StartDetectingVideo(tab
, "local-view");
62 if (WaitForVideoToPlay(tab
))
63 actual_stream_size
= GetStreamSize(tab
, "local-view");
64 CloseLastLocalStream(tab
);
66 return actual_stream_size
;
69 bool IsOnQtKit() const {
70 #if defined(OS_MACOSX)
71 return GetParam() && std::string(GetParam()) == switches::kForceQTKit
;
78 IN_PROC_BROWSER_TEST_P(WebRtcWebcamBrowserTest
,
79 TestAcquiringAndReacquiringWebcam
) {
80 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
81 GURL
url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage
));
82 ui_test_utils::NavigateToURL(browser(), url
);
83 content::WebContents
* tab
=
84 browser()->tab_strip_model()->GetActiveWebContents();
86 if (!HasWebcamAvailableOnSystem(tab
)) {
87 LOG(INFO
) << "No webcam found on bot: skipping...";
92 // "Temporarily" disabled on QtKit due to http://crbug.com/375185.
94 GetUserMediaAndGetStreamSize(tab
,
95 kVideoCallConstraintsQVGA
));
99 GetUserMediaAndGetStreamSize(tab
, kVideoCallConstraintsVGA
));
101 GetUserMediaAndGetStreamSize(tab
, kVideoCallConstraints360p
));
103 // QTKit supports up to 480p (used to support 720p until crbug.com/440762).
107 EXPECT_EQ("1280x720",
108 GetUserMediaAndGetStreamSize(tab
, kVideoCallConstraints720p
));
109 EXPECT_EQ("1920x1080",
110 GetUserMediaAndGetStreamSize(tab
, kVideoCallConstraints1080p
));
113 INSTANTIATE_TEST_CASE_P(WebRtcWebcamBrowserTests
,
114 WebRtcWebcamBrowserTest
,
115 testing::ValuesIn(kTestConfigFlags
));