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 WebRtcWebcamBrowserTest() : get_user_media_call_count_(0) {}
44 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
45 EXPECT_FALSE(command_line->HasSwitch(
46 switches::kUseFakeDeviceForMediaStream));
47 EXPECT_FALSE(command_line->HasSwitch(
48 switches::kUseFakeUIForMediaStream));
50 command_line->AppendSwitch(GetParam());
54 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
55 DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
58 std::string GetUserMediaAndGetStreamSize(content::WebContents* tab,
59 const std::string& constraints) {
60 // We will get a permission prompt for the first getUserMedia call.
61 // Subsequent calls won't trigger a prompt.
62 if (get_user_media_call_count_ == 0) {
63 GetUserMediaWithSpecificConstraintsAndAccept(tab, constraints);
65 GetUserMedia(tab, constraints);
66 EXPECT_TRUE(test::PollingWaitUntil(
67 "obtainGetUserMediaResult()", "ok-got-stream", tab));
70 ++get_user_media_call_count_;
72 StartDetectingVideo(tab, "local-view");
73 WaitForVideoToPlay(tab);
74 std::string actual_stream_size = GetStreamSize(tab, "local-view");
75 CloseLastLocalStream(tab);
76 return actual_stream_size;
79 int get_user_media_call_count_;
82 IN_PROC_BROWSER_TEST_P(WebRtcWebcamBrowserTest,
83 TestAcquiringAndReacquiringWebcam) {
84 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
85 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage));
86 ui_test_utils::NavigateToURL(browser(), url);
87 content::WebContents* tab =
88 browser()->tab_strip_model()->GetActiveWebContents();
90 if (!HasWebcamAvailableOnSystem(tab)) {
91 LOG(INFO) << "No webcam found on bot: skipping...";
96 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraintsVGA));
98 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraintsQVGA));
100 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraints360p));
101 EXPECT_EQ("1280x720",
102 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraints720p));
103 EXPECT_EQ("1920x1080",
104 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraints1080p));
107 INSTANTIATE_TEST_CASE_P(WebRtcWebcamBrowserTests,
108 WebRtcWebcamBrowserTest,
109 testing::ValuesIn(kTestConfigFlags));