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 "base/strings/utf_string_conversions.h"
7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/common/content_switches.h"
9 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/public/test/test_utils.h"
13 #include "content/shell/browser/shell.h"
14 #include "media/base/media_switches.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h"
19 const base::CommandLine::StringType FAKE_DEVICE_FLAG
=
21 base::ASCIIToUTF16(switches::kUseFakeDeviceForMediaStream
);
23 switches::kUseFakeDeviceForMediaStream
;
26 bool IsUseFakeDeviceForMediaStream(const base::CommandLine::StringType
& arg
) {
27 return arg
.find(FAKE_DEVICE_FLAG
) != std::string::npos
;
30 void RemoveFakeDeviceFromCommandLine(base::CommandLine
* command_line
) {
31 CommandLine::StringVector argv
= command_line
->argv();
32 argv
.erase(std::remove_if(argv
.begin(), argv
.end(),
33 IsUseFakeDeviceForMediaStream
),
35 command_line
->InitFromArgv(argv
);
42 // This class doesn't inherit from WebRtcContentBrowserTestBase like the others
43 // since we want it to actually acquire the real webcam on the system (if there
45 class WebRtcWebcamBrowserTest
: public ContentBrowserTest
{
47 ~WebRtcWebcamBrowserTest() override
{}
49 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
50 ASSERT_TRUE(command_line
->HasSwitch(switches::kUseFakeUIForMediaStream
));
52 // The content_browsertests run with this flag by default, and this test is
53 // the only current exception to that rule, so just remove the flag
54 // --use-fake-device-for-media-stream here. We could also have all tests
55 // involving media streams add this flag explicitly, but it will be really
56 // unintuitive for developers to write tests involving media stream and have
57 // them fail on what looks like random bots, so running with fake devices
58 // is really a reasonable default.
59 RemoveFakeDeviceFromCommandLine(command_line
);
62 void SetUp() override
{
64 ContentBrowserTest::SetUp();
68 // The test is tagged as MANUAL since the webcam is a system-level resource; we
69 // only want it to run on bots where we can ensure sequential execution. The
70 // Android bots will run the test since they ignore MANUAL, but that's what we
71 // want here since the bot runs tests sequentially on the device.
72 IN_PROC_BROWSER_TEST_F(WebRtcWebcamBrowserTest
,
73 MANUAL_CanAcquireVgaOnRealWebcam
) {
74 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
75 GURL
url(embedded_test_server()->GetURL(
76 "/media/getusermedia-real-webcam.html"));
77 NavigateToURL(shell(), url
);
80 ASSERT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(),
81 "hasVideoInputDeviceOnSystem()",
83 if (result
!= "has-video-input-device") {
84 VLOG(0) << "No video device; skipping test...";
88 // GetUserMedia should acquire VGA by default.
89 ASSERT_TRUE(ExecuteScriptAndExtractString(
90 shell()->web_contents(),
91 "getUserMediaAndReturnVideoDimensions({video: true})",
94 if (result
== "640x480" || result
== "480x640") {
95 // Don't care if the device happens to be in landscape or portrait mode
96 // since we don't know how it is oriented in the lab :)
99 FAIL() << "Expected resolution to be 640x480 or 480x640, got" << result
;
102 } // namespace content