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 GetUserMediaWithSpecificConstraintsAndAccept(tab
, constraints
);
60 StartDetectingVideo(tab
, "local-view");
61 WaitForVideoToPlay(tab
);
62 std::string actual_stream_size
= GetStreamSize(tab
, "local-view");
63 CloseLastLocalStream(tab
);
64 return actual_stream_size
;
67 bool IsOnQtKit() const {
68 #if defined(OS_MACOSX)
69 return GetParam() && std::string(GetParam()) == switches::kForceQTKit
;
76 IN_PROC_BROWSER_TEST_P(WebRtcWebcamBrowserTest
,
77 TestAcquiringAndReacquiringWebcam
) {
78 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
79 GURL
url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage
));
80 ui_test_utils::NavigateToURL(browser(), url
);
81 content::WebContents
* tab
=
82 browser()->tab_strip_model()->GetActiveWebContents();
84 if (!HasWebcamAvailableOnSystem(tab
)) {
85 LOG(INFO
) << "No webcam found on bot: skipping...";
90 // "Temporarily" disabled on QtKit due to http://crbug.com/375185.
92 GetUserMediaAndGetStreamSize(tab
,
93 kVideoCallConstraintsQVGA
));
97 GetUserMediaAndGetStreamSize(tab
, kVideoCallConstraintsVGA
));
99 GetUserMediaAndGetStreamSize(tab
, kVideoCallConstraints360p
));
101 // QTKit supports up to 480p (used to support 720p until crbug.com/440762).
105 EXPECT_EQ("1280x720",
106 GetUserMediaAndGetStreamSize(tab
, kVideoCallConstraints720p
));
107 EXPECT_EQ("1920x1080",
108 GetUserMediaAndGetStreamSize(tab
, kVideoCallConstraints1080p
));
111 INSTANTIATE_TEST_CASE_P(WebRtcWebcamBrowserTests
,
112 WebRtcWebcamBrowserTest
,
113 testing::ValuesIn(kTestConfigFlags
));