diff options
author | phoglund@chromium.org <phoglund@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 13:58:16 +0000 |
---|---|---|
committer | phoglund@chromium.org <phoglund@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 13:58:16 +0000 |
commit | 570554c7be19526366fcfd3d70e4567cee1098da (patch) | |
tree | 5ca5bb8c5f015d021fa5e4053c6778a8742078a4 /chrome/browser/media | |
parent | ff85797d6caefda6a04514fa749a2a8c8757e920 (diff) | |
download | chromium_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
Diffstat (limited to 'chrome/browser/media')
-rw-r--r-- | chrome/browser/media/chrome_webrtc_webcam_browsertest.cc | 80 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_browsertest_base.cc | 36 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_browsertest_base.h | 14 |
3 files changed, 130 insertions, 0 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; |