Commit 8ba44ef0 authored by phoglund's avatar phoglund Committed by Commit bot

Relanding WebRTC real webcam browsertest for Android.

Over the original patch that got reverted, this takes into account that
the android device can be in a different orientation. If the nexus
device happens to be in portrait mode in the lab, it will report a
480x640 resolution rather than 640x480, so this reland accounts for
that.

The main purpose of this test is to test the capture path on Android,
i.e. that we can acquire the device's built-in webcam. If we happen to
run on a device without a camera, we'll quietly succeed the test.

BUG=323921
R=tommi

Review URL: https://codereview.chromium.org/663793003

Cr-Commit-Position: refs/heads/master@{#300655}
parent 15d0c004
...@@ -152,12 +152,11 @@ class MAYBE_WebRtcInternalsBrowserTest: public ContentBrowserTest { ...@@ -152,12 +152,11 @@ class MAYBE_WebRtcInternalsBrowserTest: public ContentBrowserTest {
virtual ~MAYBE_WebRtcInternalsBrowserTest() {} virtual ~MAYBE_WebRtcInternalsBrowserTest() {}
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
// We need fake devices in this test since we want to run on naked VMs. We // Assume this is set by the content test launcher.
// assume these switches are set by default in content_browsertests.
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream));
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch( ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeUIForMediaStream)); switches::kUseFakeUIForMediaStream));
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream));
} }
protected: protected:
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "media/base/media_switches.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
namespace {
const base::CommandLine::StringType FAKE_DEVICE_FLAG =
#if defined(OS_WIN)
base::ASCIIToUTF16(switches::kUseFakeDeviceForMediaStream);
#else
switches::kUseFakeDeviceForMediaStream;
#endif
bool IsUseFakeDeviceForMediaStream(const base::CommandLine::StringType& arg) {
return arg.find(FAKE_DEVICE_FLAG) != std::string::npos;
}
void RemoveFakeDeviceFromCommandLine(base::CommandLine* command_line) {
CommandLine::StringVector argv = command_line->argv();
argv.erase(std::remove_if(argv.begin(), argv.end(),
IsUseFakeDeviceForMediaStream),
argv.end());
command_line->InitFromArgv(argv);
}
} // namespace
namespace content {
// This class doesn't inherit from WebRtcContentBrowserTestBase like the others
// since we want it to actually acquire the real webcam on the system (if there
// is one).
class WebRtcWebcamBrowserTest: public ContentBrowserTest {
public:
~WebRtcWebcamBrowserTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
ASSERT_TRUE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream));
// The content_browsertests run with this flag by default, and this test is
// the only current exception to that rule, so just remove the flag
// --use-fake-device-for-media-stream here. We could also have all tests
// involving media streams add this flag explicitly, but it will be really
// unintuitive for developers to write tests involving media stream and have
// them fail on what looks like random bots, so running with fake devices
// is really a reasonable default.
RemoveFakeDeviceFromCommandLine(command_line);
}
void SetUp() override {
EnablePixelOutput();
ContentBrowserTest::SetUp();
}
};
// The test is tagged as MANUAL since the webcam is a system-level resource; we
// only want it to run on bots where we can ensure sequential execution. The
// Android bots will run the test since they ignore MANUAL, but that's what we
// want here since the bot runs tests sequentially on the device.
IN_PROC_BROWSER_TEST_F(WebRtcWebcamBrowserTest,
MANUAL_CanAcquireVgaOnRealWebcam) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL url(embedded_test_server()->GetURL(
"/media/getusermedia-real-webcam.html"));
NavigateToURL(shell(), url);
std::string result;
ASSERT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(),
"hasVideoInputDeviceOnSystem()",
&result));
if (result != "has-video-input-device") {
VLOG(0) << "No video device; skipping test...";
return;
}
// GetUserMedia should acquire VGA by default.
ASSERT_TRUE(ExecuteScriptAndExtractString(
shell()->web_contents(),
"getUserMediaAndReturnVideoDimensions({video: true})",
&result));
if (result == "640x480" || result == "480x640") {
// Don't care if the device happens to be in landscape or portrait mode
// since we don't know how it is oriented in the lab :)
return;
}
FAIL() << "Expected resolution to be 640x480 or 480x640, got" << result;
}
} // namespace content
...@@ -1370,6 +1370,7 @@ ...@@ -1370,6 +1370,7 @@
'browser/media/webrtc_browsertest.cc', 'browser/media/webrtc_browsertest.cc',
'browser/media/webrtc_getusermedia_browsertest.cc', 'browser/media/webrtc_getusermedia_browsertest.cc',
'browser/media/webrtc_internals_browsertest.cc', 'browser/media/webrtc_internals_browsertest.cc',
'browser/media/webrtc_webcam_browsertest.cc',
'test/webrtc_content_browsertest_base.cc', 'test/webrtc_content_browsertest_base.cc',
'test/webrtc_content_browsertest_base.h', 'test/webrtc_content_browsertest_base.h',
], ],
......
<html>
<head>
<script type="text/javascript" src="webrtc_test_utilities.js"></script>
<script type="text/javascript">
$ = function(id) {
return document.getElementById(id);
};
function getUserMediaAndReturnVideoDimensions(constraints) {
navigator.webkitGetUserMedia(
constraints, gotStreamCallback, failedCallback);
}
function failedCallback(error) {
failTest('GetUserMedia call failed with code ' + error.code);
}
function gotStreamCallback(stream) {
var localView = $('local-view');
localView.src = URL.createObjectURL(stream);
detectVideoPlaying('local-view', function() {
sendValueToTest(localView.videoWidth + 'x' + localView.videoHeight);
});
}
</script>
</head>
<body>
<table border="0">
<tr>
<td><video id="local-view" autoplay="autoplay">
</video></td>
<td><canvas id="local-view-canvas" style="display:none"></canvas></td>
</tr>
</table>
</body>
</html>
...@@ -213,3 +213,19 @@ function assertNotEquals(expected, actual) { ...@@ -213,3 +213,19 @@ function assertNotEquals(expected, actual) {
} }
} }
// Returns has-video-input-device to the test if there's a webcam available on
// the system.
function hasVideoInputDeviceOnSystem() {
MediaStreamTrack.getSources(function(devices) {
var hasVideoInputDevice = false;
devices.forEach(function(device) {
if (device.kind == 'video')
hasVideoInputDevice = true;
});
if (hasVideoInputDevice)
sendValueToTest('has-video-input-device');
else
sendValueToTest('no-video-input-devices');
});
}
\ No newline at end of file
...@@ -24,12 +24,11 @@ ...@@ -24,12 +24,11 @@
namespace content { namespace content {
void WebRtcContentBrowserTest::SetUpCommandLine(CommandLine* command_line) { void WebRtcContentBrowserTest::SetUpCommandLine(CommandLine* command_line) {
// We need fake devices in this test since we want to run on naked VMs. We // Assume this is set by the content test launcher.
// assume these switches are set by default in content_browsertests.
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream));
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch( ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeUIForMediaStream)); switches::kUseFakeUIForMediaStream));
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream));
// Always include loopback interface in network list, in case the test device // Always include loopback interface in network list, in case the test device
// doesn't have other interfaces available. // doesn't have other interfaces available.
...@@ -38,6 +37,7 @@ void WebRtcContentBrowserTest::SetUpCommandLine(CommandLine* command_line) { ...@@ -38,6 +37,7 @@ void WebRtcContentBrowserTest::SetUpCommandLine(CommandLine* command_line) {
} }
void WebRtcContentBrowserTest::SetUp() { void WebRtcContentBrowserTest::SetUp() {
// We need pixel output when we dig pixels out of video tags for verification.
EnablePixelOutput(); EnablePixelOutput();
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::CrasAudioHandler::InitializeForTesting(); chromeos::CrasAudioHandler::InitializeForTesting();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment