summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphoglund@chromium.org <phoglund@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-04 13:58:16 +0000
committerphoglund@chromium.org <phoglund@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-04 13:58:16 +0000
commit570554c7be19526366fcfd3d70e4567cee1098da (patch)
tree5ca5bb8c5f015d021fa5e4053c6778a8742078a4
parentff85797d6caefda6a04514fa749a2a8c8757e920 (diff)
downloadchromium_src-570554c7be19526366fcfd3d70e4567cee1098da.zip
chromium_src-570554c7be19526366fcfd3d70e4567cee1098da.tar.gz
chromium_src-570554c7be19526366fcfd3d70e4567cee1098da.tar.bz2
Adding physical webcam tests for WebRTC.
These tests are meant to run on special webcam-equipped bots and test WebRTC's capturer paths. BUG=332781 Review URL: https://codereview.chromium.org/216423004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261745 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/media/chrome_webrtc_webcam_browsertest.cc80
-rw-r--r--chrome/browser/media/webrtc_browsertest_base.cc36
-rw-r--r--chrome/browser/media/webrtc_browsertest_base.h14
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/data/webrtc/getusermedia.js71
-rw-r--r--chrome/test/data/webrtc/sources.js29
-rw-r--r--chrome/test/data/webrtc/video_detector.js15
-rw-r--r--chrome/test/data/webrtc/webrtc_jsep01_test.html1
8 files changed, 186 insertions, 61 deletions
diff --git a/chrome/browser/media/chrome_webrtc_webcam_browsertest.cc b/chrome/browser/media/chrome_webrtc_webcam_browsertest.cc
new file mode 100644
index 0000000..d8f6449
--- /dev/null
+++ b/chrome/browser/media/chrome_webrtc_webcam_browsertest.cc
@@ -0,0 +1,80 @@
+// 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 "chrome/browser/media/webrtc_browsertest_base.h"
+#include "chrome/browser/media/webrtc_browsertest_common.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/test/browser_test_utils.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+
+static const char kMainWebrtcTestHtmlPage[] =
+ "/webrtc/webrtc_jsep01_test.html";
+
+// These tests runs on real webcams and ensure WebRTC can acquire webcams
+// correctly. They will do nothing if there are no webcams on the system.
+// The webcam on the system must support up to 1080p, or the test will fail.
+class WebRtcWebcamBrowserTest : public WebRtcTestBase {
+ public:
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ EXPECT_FALSE(command_line->HasSwitch(
+ switches::kUseFakeDeviceForMediaStream));
+ EXPECT_FALSE(command_line->HasSwitch(
+ switches::kUseFakeUIForMediaStream));
+ }
+
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
+ DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(WebRtcWebcamBrowserTest,
+ TestAcquiringAndReacquiringWebcam) {
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+ GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage));
+ ui_test_utils::NavigateToURL(browser(), url);
+ content::WebContents* tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+
+ if (!HasWebcamAvailableOnSystem(tab)) {
+ LOG(INFO) << "No webcam found on bot: skipping...";
+ return;
+ }
+
+ GetUserMediaWithSpecificConstraintsAndAccept(tab,
+ kAudioVideoCallConstraintsVGA);
+ StartDetectingVideo(tab, "local-view");
+ WaitForVideoToPlay(tab);
+ EXPECT_EQ("640x480", GetStreamSize(tab, "local-view"));
+ CloseLastLocalStream(tab);
+ GetUserMediaWithSpecificConstraintsAndAccept(tab,
+ kAudioVideoCallConstraintsQVGA);
+ StartDetectingVideo(tab, "local-view");
+ WaitForVideoToPlay(tab);
+ EXPECT_EQ("320x240", GetStreamSize(tab, "local-view"));
+ CloseLastLocalStream(tab);
+ GetUserMediaWithSpecificConstraintsAndAccept(tab,
+ kAudioVideoCallConstraints360p);
+ StartDetectingVideo(tab, "local-view");
+ WaitForVideoToPlay(tab);
+ EXPECT_EQ("640x360", GetStreamSize(tab, "local-view"));
+ CloseLastLocalStream(tab);
+ GetUserMediaWithSpecificConstraintsAndAccept(tab,
+ kAudioVideoCallConstraints720p);
+ StartDetectingVideo(tab, "local-view");
+ WaitForVideoToPlay(tab);
+ EXPECT_EQ("1280x720", GetStreamSize(tab, "local-view"));
+ CloseLastLocalStream(tab);
+ GetUserMediaWithSpecificConstraintsAndAccept(tab,
+ kAudioVideoCallConstraints1080p);
+ StartDetectingVideo(tab, "local-view");
+ WaitForVideoToPlay(tab);
+ EXPECT_EQ("1920x1080", GetStreamSize(tab, "local-view"));
+ CloseLastLocalStream(tab);
+}
diff --git a/chrome/browser/media/webrtc_browsertest_base.cc b/chrome/browser/media/webrtc_browsertest_base.cc
index 294c18f..6c1f823 100644
--- a/chrome/browser/media/webrtc_browsertest_base.cc
+++ b/chrome/browser/media/webrtc_browsertest_base.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/media/webrtc_browsertest_base.h"
#include "base/lazy_instance.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/infobars/infobar.h"
@@ -22,9 +23,21 @@
const char WebRtcTestBase::kAudioVideoCallConstraints[] =
"'{audio: true, video: true}'";
+const char WebRtcTestBase::kAudioVideoCallConstraintsQVGA[] =
+ "'{audio: true, video: {mandatory: {minWidth: 320, maxWidth: 320, "
+ " minHeight: 240, maxHeight: 240}}}'";
const char WebRtcTestBase::kAudioVideoCallConstraints360p[] =
"'{audio: true, video: {mandatory: {minWidth: 640, maxWidth: 640, "
" minHeight: 360, maxHeight: 360}}}'";
+const char WebRtcTestBase::kAudioVideoCallConstraintsVGA[] =
+ "'{audio: true, video: {mandatory: {minWidth: 640, maxWidth: 640, "
+ " minHeight: 480, maxHeight: 480}}}'";
+const char WebRtcTestBase::kAudioVideoCallConstraints720p[] =
+ "'{audio: true, video: {mandatory: {minWidth: 1280, maxWidth: 1280, "
+ " minHeight: 720, maxHeight: 720}}}'";
+const char WebRtcTestBase::kAudioVideoCallConstraints1080p[] =
+ "'{audio: true, video: {mandatory: {minWidth: 1920, maxWidth: 1920, "
+ " minHeight: 1080, maxHeight: 1080}}}'";
const char WebRtcTestBase::kAudioOnlyCallConstraints[] = "'{audio: true}'";
const char WebRtcTestBase::kVideoOnlyCallConstraints[] = "'{video: true}'";
const char WebRtcTestBase::kFailedWithPermissionDeniedError[] =
@@ -216,6 +229,12 @@ void WebRtcTestBase::CloseInfoBarInTab(
infobar_removed.Wait();
}
+void WebRtcTestBase::CloseLastLocalStream(
+ content::WebContents* tab_contents) const {
+ EXPECT_EQ("ok-stopped",
+ ExecuteJavascript("stopLocalStream();", tab_contents));
+}
+
// Convenience method which executes the provided javascript in the context
// of the provided web contents and returns what it evaluated to.
std::string WebRtcTestBase::ExecuteJavascript(
@@ -282,3 +301,20 @@ void WebRtcTestBase::WaitForVideoToPlay(
EXPECT_TRUE(test::PollingWaitUntil("isVideoPlaying()", "video-playing",
tab_contents));
}
+
+std::string WebRtcTestBase::GetStreamSize(
+ content::WebContents* tab_contents,
+ const std::string& video_element) const {
+ std::string javascript =
+ base::StringPrintf("getStreamSize('%s')", video_element.c_str());
+ std::string result = ExecuteJavascript(javascript, tab_contents);
+ EXPECT_TRUE(StartsWithASCII(result, "ok-", true));
+ return result.substr(3);
+}
+
+bool WebRtcTestBase::HasWebcamAvailableOnSystem(
+ content::WebContents* tab_contents) const {
+ std::string result =
+ ExecuteJavascript("HasVideoSourceOnSystem();", tab_contents);
+ return result == "has-video-source";
+}
diff --git a/chrome/browser/media/webrtc_browsertest_base.h b/chrome/browser/media/webrtc_browsertest_base.h
index 079868ce..93567e3 100644
--- a/chrome/browser/media/webrtc_browsertest_base.h
+++ b/chrome/browser/media/webrtc_browsertest_base.h
@@ -24,7 +24,11 @@ class WebRtcTestBase : public InProcessBrowserTest {
static const char kAudioVideoCallConstraints[];
static const char kAudioOnlyCallConstraints[];
static const char kVideoOnlyCallConstraints[];
+ static const char kAudioVideoCallConstraintsQVGA[];
static const char kAudioVideoCallConstraints360p[];
+ static const char kAudioVideoCallConstraintsVGA[];
+ static const char kAudioVideoCallConstraints720p[];
+ static const char kAudioVideoCallConstraints1080p[];
static const char kFailedWithPermissionDeniedError[];
static const char kFailedWithPermissionDismissedError[];
@@ -64,6 +68,9 @@ class WebRtcTestBase : public InProcessBrowserTest {
// means and accepts the user media request.
content::WebContents* OpenPageAndAcceptUserMedia(const GURL& url) const;
+ // Closes the last local stream acquired by the GetUserMedia* methods.
+ void CloseLastLocalStream(content::WebContents* tab_contents) const;
+
void ConnectToPeerConnectionServer(const std::string& peer_name,
content::WebContents* tab_contents) const;
std::string ExecuteJavascript(const std::string& javascript,
@@ -88,6 +95,13 @@ class WebRtcTestBase : public InProcessBrowserTest {
const std::string& video_element) const;
void WaitForVideoToPlay(content::WebContents* tab_contents) const;
+ // Returns the stream size as a string on the format <width>x<height>.
+ std::string GetStreamSize(content::WebContents* tab_contents,
+ const std::string& video_element) const;
+
+ // Methods to check what devices we have on the system.
+ bool HasWebcamAvailableOnSystem(content::WebContents* tab_contents) const;
+
private:
void CloseInfoBarInTab(content::WebContents* tab_contents,
InfoBar* infobar) const;
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 7e9c093..564f295 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1279,6 +1279,7 @@
'browser/media/chrome_webrtc_audio_quality_browsertest.cc',
'browser/media/chrome_webrtc_typing_detection_browsertest.cc',
'browser/media/chrome_webrtc_video_quality_browsertest.cc',
+ 'browser/media/chrome_webrtc_webcam_browsertest.cc',
'browser/media/encrypted_media_istypesupported_browsertest.cc',
'browser/media/test_license_server.cc',
'browser/media/test_license_server.h',
diff --git a/chrome/test/data/webrtc/getusermedia.js b/chrome/test/data/webrtc/getusermedia.js
index 3cb78bf..49be28a 100644
--- a/chrome/test/data/webrtc/getusermedia.js
+++ b/chrome/test/data/webrtc/getusermedia.js
@@ -83,14 +83,21 @@ function obtainGetUserMediaResult() {
}
/**
- * Stops the local stream.
+ * Stops all tracks of the last acquired local stream.
*/
function stopLocalStream() {
if (gLocalStream == null)
throw failTest('Tried to stop local stream, ' +
'but media access is not granted.');
- gLocalStream.stop();
+ gLocalStream.getVideoTracks().forEach(function(track) {
+ track.stop();
+ });
+ gLocalStream.getAudioTracks().forEach(function(track) {
+ track.stop();
+ });
+ gLocalStream = null;
+ gRequestWebcamAndMicrophoneResult = 'not-called-yet';
returnToTest('ok-stopped');
}
@@ -168,65 +175,7 @@ function getUserMediaOkCallback_(stream) {
gLocalStream = stream;
gRequestWebcamAndMicrophoneResult = 'ok-got-stream';
- if (stream.getVideoTracks().length > 0) {
- // Show the video tag if we did request video in the getUserMedia call.
- var videoTag = $('local-view');
- attachMediaStream(videoTag, stream);
-
- // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires.
- // videoTag.onloadedmetadata = displayVideoSize_(videoTag);.
- // Use setTimeout as a workaround for now.
- setTimeout(function() {displayVideoSize_(videoTag);}, 500);
- }
-}
-
-/**
- * @private
- * @param {string} videoTagId The ID of the video tag to update.
- * @param {string} width The width of the video to update the video tag, if
- * width or height is 0, size will be taken from videoTag.videoWidth.
- * @param {string} height The height of the video to update the video tag, if
- * width or height is 0 size will be taken from the videoTag.videoHeight.
- */
-function updateVideoTagSize_(videoTagId, width, height) {
- var videoTag = $(videoTagId);
- if (width > 0 || height > 0) {
- videoTag.width = width;
- videoTag.height = height;
- }
- else {
- if (videoTag.videoWidth > 0 || videoTag.videoHeight > 0) {
- videoTag.width = videoTag.videoWidth;
- videoTag.height = videoTag.videoHeight;
- }
- else {
- debug('"' + videoTagId + '" video stream size is 0, skipping resize');
- }
- }
- debug('Set video tag "' + videoTagId + '" size to ' + videoTag.width + 'x' +
- videoTag.height);
- displayVideoSize_(videoTag);
-}
-
-/**
- * @private
- * @param {string} videoTag The ID of the video tag + stream used to
- * write the size to a HTML tag based on id if the div's exists.
- */
-function displayVideoSize_(videoTag) {
- if ($(videoTag.id + '-stream-size') && $(videoTag.id + '-size')) {
- if (videoTag.videoWidth > 0 || videoTag.videoHeight > 0) {
- $(videoTag.id + '-stream-size').innerHTML = '(stream size: ' +
- videoTag.videoWidth + 'x' +
- videoTag.videoHeight + ')';
- $(videoTag.id + '-size').innerHTML = videoTag.width + 'x' +
- videoTag.height;
- }
- }
- else {
- debug('Skipping updating -stream-size and -size tags due to div\'s are ' +
- 'missing');
- }
+ attachMediaStream($('local-view'), stream);
}
/**
diff --git a/chrome/test/data/webrtc/sources.js b/chrome/test/data/webrtc/sources.js
new file mode 100644
index 0000000..e382547
--- /dev/null
+++ b/chrome/test/data/webrtc/sources.js
@@ -0,0 +1,29 @@
+/**
+ * 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.
+ */
+
+/**
+ * Queries for video sources on the current system using the getSources API.
+ *
+ * This does not guarantee that a getUserMedia with video will succeed, as the
+ * camera could be busy for instance.
+ *
+ * Returns has-video-source to the test if there is a webcam available,
+ * no-video-sources otherwise.
+ */
+function HasVideoSourceOnSystem() {
+ MediaStreamTrack.getSources(function(sources) {
+ var hasVideoSource = false;
+ sources.forEach(function(source) {
+ if (source.kind == 'video')
+ hasVideoSource = true;
+ });
+
+ if (hasVideoSource)
+ returnToTest('has-video-source');
+ else
+ returnToTest('no-video-sources');
+ });
+} \ No newline at end of file
diff --git a/chrome/test/data/webrtc/video_detector.js b/chrome/test/data/webrtc/video_detector.js
index 37f6b9b..3c10813 100644
--- a/chrome/test/data/webrtc/video_detector.js
+++ b/chrome/test/data/webrtc/video_detector.js
@@ -71,6 +71,21 @@ function isVideoPlaying() {
returnToTest('video-not-playing');
}
+/**
+ * Queries for the stream size (not necessarily the size at which the video tag
+ * is rendered).
+ *
+ * @param videoElementId The video element to check.
+ * @return {string} ok-<width>x<height>, e.g. ok-640x480 for VGA.
+ */
+function getStreamSize(videoElementId) {
+ var video = document.getElementById(videoElementId);
+ if (!video)
+ throw failTest('Could not find video element with id ' + videoElementId);
+
+ returnToTest('ok-' + video.videoWidth + 'x' + video.videoHeight);
+}
+
// Internals.
/** @private */
diff --git a/chrome/test/data/webrtc/webrtc_jsep01_test.html b/chrome/test/data/webrtc/webrtc_jsep01_test.html
index 2f66f6e..e07291e 100644
--- a/chrome/test/data/webrtc/webrtc_jsep01_test.html
+++ b/chrome/test/data/webrtc/webrtc_jsep01_test.html
@@ -8,6 +8,7 @@
<script type="text/javascript" src="getusermedia.js"></script>
<script type="text/javascript" src="jsep01_call.js"></script>
<script type="text/javascript" src="video_detector.js"></script>
+ <script type="text/javascript" src="sources.js"></script>
</head>
<body>
<table border="0">