Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / media / chrome_webrtc_webcam_browsertest.cc
blob8385860fca05ae111f49889e96b1e553806064f8
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[] = {
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
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 // This test is excellent for testing the various capture paths of WebRTC
40 // on all desktop platforms.
41 class WebRtcWebcamBrowserTest : public WebRtcTestBase,
42 public testing::WithParamInterface<const char*> {
43 public:
44 void SetUpCommandLine(base::CommandLine* command_line) override {
45 EXPECT_FALSE(command_line->HasSwitch(
46 switches::kUseFakeDeviceForMediaStream));
47 EXPECT_FALSE(command_line->HasSwitch(
48 switches::kUseFakeUIForMediaStream));
49 if (GetParam())
50 command_line->AppendSwitch(GetParam());
53 protected:
54 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 std::string actual_stream_size;
61 if (GetUserMediaWithSpecificConstraintsAndAcceptIfPrompted(tab,
62 constraints)) {
63 StartDetectingVideo(tab, "local-view");
64 if (WaitForVideoToPlay(tab))
65 actual_stream_size = GetStreamSize(tab, "local-view");
66 CloseLastLocalStream(tab);
68 return actual_stream_size;
71 bool IsOnQtKit() const {
72 #if defined(OS_MACOSX)
73 return GetParam() && std::string(GetParam()) == switches::kForceQTKit;
74 #else
75 return false;
76 #endif
80 // This test is manual because the test results can vary heavily depending on
81 // which webcam or drivers you have on the system.
82 IN_PROC_BROWSER_TEST_P(WebRtcWebcamBrowserTest,
83 MANUAL_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...";
92 return;
95 if (!IsOnQtKit()) {
96 // "Temporarily" disabled on QtKit due to http://crbug.com/375185.
97 EXPECT_EQ("320x240",
98 GetUserMediaAndGetStreamSize(tab,
99 kVideoCallConstraintsQVGA));
102 EXPECT_EQ("640x480",
103 GetUserMediaAndGetStreamSize(tab, kVideoCallConstraintsVGA));
104 EXPECT_EQ("640x360",
105 GetUserMediaAndGetStreamSize(tab, kVideoCallConstraints360p));
107 // QTKit supports up to 480p (used to support 720p until crbug.com/440762).
108 if (IsOnQtKit())
109 return;
111 EXPECT_EQ("1280x720",
112 GetUserMediaAndGetStreamSize(tab, kVideoCallConstraints720p));
113 EXPECT_EQ("1920x1080",
114 GetUserMediaAndGetStreamSize(tab, kVideoCallConstraints1080p));
117 INSTANTIATE_TEST_CASE_P(WebRtcWebcamBrowserTests,
118 WebRtcWebcamBrowserTest,
119 testing::ValuesIn(kTestConfigFlags));