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. 4 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" 18 19 static const char kMainWebrtcTestHtmlPage[] = 20 "/webrtc/webrtc_jsep01_test.html"; 21 22 static const char* kTestConfigFlags[] = { 23 #if defined(OS_WIN) 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 31 #else 32 NULL 33 #endif 34 }; 35 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*> { 41 public: 42 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 43 EXPECT_FALSE(command_line->HasSwitch( 44 switches::kUseFakeDeviceForMediaStream)); 45 EXPECT_FALSE(command_line->HasSwitch( 46 switches::kUseFakeUIForMediaStream)); 47 if (GetParam()) 48 command_line->AppendSwitch(GetParam()); 49 } 50 51 protected: 52 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 53 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. 54 } 55 56 std::string GetUserMediaAndGetStreamSize(content::WebContents* tab, 57 const std::string& constraints) { 58 GetUserMediaWithSpecificConstraintsAndAccept(tab, constraints); 59 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; 65 } 66 67 bool IsOnQtKit() const { 68 #if defined(OS_MACOSX) 69 return GetParam() && std::string(GetParam()) == switches::kForceQTKit; 70 #else 71 return false; 72 #endif 73 } 74 }; 75 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(); 83 84 if (!HasWebcamAvailableOnSystem(tab)) { 85 LOG(INFO) << "No webcam found on bot: skipping..."; 86 return; 87 } 88 89 if (!IsOnQtKit()) { 90 // Temporarily disabled on QtKit due to http://crbug.com/375185. 91 EXPECT_EQ("320x240", 92 GetUserMediaAndGetStreamSize(tab, 93 kAudioVideoCallConstraintsQVGA)); 94 } 95 96 EXPECT_EQ("640x480", 97 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraintsVGA)); 98 EXPECT_EQ("640x360", 99 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraints360p)); 100 EXPECT_EQ("1280x720", 101 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraints720p)); 102 103 if (IsOnQtKit()) 104 return; // QTKit only supports up to 720p. 105 106 EXPECT_EQ("1920x1080", 107 GetUserMediaAndGetStreamSize(tab, kAudioVideoCallConstraints1080p)); 108 } 109 110 INSTANTIATE_TEST_CASE_P(WebRtcWebcamBrowserTests, 111 WebRtcWebcamBrowserTest, 112 testing::ValuesIn(kTestConfigFlags)); 113