#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"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/media/media_stream_infobar_delegate.h"
#include "chrome/browser/media/webrtc_browsertest_common.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "components/infobars/core/infobar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
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[] =
void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept(
content::WebContents* tab_contents,
const std::string& constraints) const {
- InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints);
+ infobars::InfoBar* infobar =
+ GetUserMediaAndWaitForInfoBar(tab_contents, constraints);
infobar->delegate()->AsConfirmInfoBarDelegate()->Accept();
CloseInfoBarInTab(tab_contents, infobar);
// Wait for WebRTC to call the success callback.
const char kOkGotStream[] = "ok-got-stream";
- EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream,
- tab_contents));
+ EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream,
+ tab_contents));
}
void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) {
void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny(
content::WebContents* tab_contents,
const std::string& constraints) const {
- InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints);
+ infobars::InfoBar* infobar =
+ GetUserMediaAndWaitForInfoBar(tab_contents, constraints);
infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel();
CloseInfoBarInTab(tab_contents, infobar);
// Wait for WebRTC to call the fail callback.
- EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()",
- kFailedWithPermissionDeniedError, tab_contents));
+ EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
+ kFailedWithPermissionDeniedError,
+ tab_contents));
}
void WebRtcTestBase::GetUserMediaAndDismiss(
content::WebContents* tab_contents) const {
- InfoBar* infobar =
+ infobars::InfoBar* infobar =
GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints);
infobar->delegate()->InfoBarDismissed();
CloseInfoBarInTab(tab_contents, infobar);
// A dismiss should be treated like a deny.
- EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()",
- kFailedWithPermissionDismissedError,
- tab_contents));
+ EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
+ kFailedWithPermissionDismissedError,
+ tab_contents));
}
void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents,
EXPECT_EQ("ok-requested", result);
}
-InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar(
+infobars::InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar(
content::WebContents* tab_contents,
const std::string& constraints) const {
content::WindowedNotificationObserver infobar_added(
// Wait for the bar to pop up, then return it.
infobar_added.Wait();
- content::Details<InfoBar::AddedDetails> details(infobar_added.details());
+ content::Details<infobars::InfoBar::AddedDetails> details(
+ infobar_added.details());
EXPECT_TRUE(details->delegate()->AsMediaStreamInfoBarDelegate());
return details.ptr();
}
content::WebContents* tab_contents =
browser()->tab_strip_model()->GetActiveWebContents();
- content::Details<InfoBar::AddedDetails> details(infobar_added.details());
- InfoBar* infobar = details.ptr();
+ content::Details<infobars::InfoBar::AddedDetails> details(
+ infobar_added.details());
+ infobars::InfoBar* infobar = details.ptr();
EXPECT_TRUE(infobar);
infobar->delegate()->AsMediaStreamInfoBarDelegate()->Accept();
return tab_contents;
}
-void WebRtcTestBase::CloseInfoBarInTab(
- content::WebContents* tab_contents,
- InfoBar* infobar) const {
+void WebRtcTestBase::CloseInfoBarInTab(content::WebContents* tab_contents,
+ infobars::InfoBar* infobar) const {
content::WindowedNotificationObserver infobar_removed(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
content::NotificationService::AllSources());
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(
return result;
}
-// The peer connection server lets our two tabs find each other and talk to
-// each other (e.g. it is the application-specific "signaling solution").
-void WebRtcTestBase::ConnectToPeerConnectionServer(
- const std::string& peer_name,
- content::WebContents* tab_contents) const {
- std::string javascript = base::StringPrintf(
- "connect('http://localhost:%s', '%s');",
- PeerConnectionServerRunner::kDefaultPort, peer_name.c_str());
- EXPECT_EQ("ok-connected", ExecuteJavascript(javascript, tab_contents));
+void WebRtcTestBase::SetupPeerconnectionWithLocalStream(
+ content::WebContents* tab) const {
+ EXPECT_EQ("ok-peerconnection-created",
+ ExecuteJavascript("preparePeerConnection()", tab));
+ EXPECT_EQ("ok-added", ExecuteJavascript("addLocalStream()", tab));
+}
+
+std::string WebRtcTestBase::CreateLocalOffer(
+ content::WebContents* from_tab) const {
+ std::string response = ExecuteJavascript("createLocalOffer({})", from_tab);
+ EXPECT_EQ("ok-", response.substr(0, 3)) << "Failed to create local offer: "
+ << response;
+
+ std::string local_offer = response.substr(3);
+ return local_offer;
+}
+
+std::string WebRtcTestBase::CreateAnswer(std::string local_offer,
+ content::WebContents* to_tab) const {
+ std::string javascript =
+ base::StringPrintf("receiveOfferFromPeer('%s', {})", local_offer.c_str());
+ std::string response = ExecuteJavascript(javascript, to_tab);
+ EXPECT_EQ("ok-", response.substr(0, 3))
+ << "Receiving peer failed to receive offer and create answer: "
+ << response;
+
+ std::string answer = response.substr(3);
+ return answer;
+}
+
+void WebRtcTestBase::ReceiveAnswer(std::string answer,
+ content::WebContents* from_tab) const {
+ ASSERT_EQ(
+ "ok-accepted-answer",
+ ExecuteJavascript(
+ base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()),
+ from_tab));
}
-void WebRtcTestBase::EstablishCall(content::WebContents* from_tab,
+void WebRtcTestBase::GatherAndSendIceCandidates(
+ content::WebContents* from_tab,
+ content::WebContents* to_tab) const {
+ std::string ice_candidates =
+ ExecuteJavascript("getAllIceCandidates()", from_tab);
+
+ EXPECT_EQ("ok-received-candidates", ExecuteJavascript(
+ base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()),
+ to_tab));
+}
+
+void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab,
content::WebContents* to_tab) const {
- ConnectToPeerConnectionServer("peer 1", from_tab);
- ConnectToPeerConnectionServer("peer 2", to_tab);
+ std::string local_offer = CreateLocalOffer(from_tab);
+ std::string answer = CreateAnswer(local_offer, to_tab);
+ ReceiveAnswer(answer, from_tab);
- EXPECT_EQ("ok-peerconnection-created",
- ExecuteJavascript("preparePeerConnection()", from_tab));
- EXPECT_EQ("ok-added", ExecuteJavascript("addLocalStream()", from_tab));
- EXPECT_EQ("ok-negotiating", ExecuteJavascript("negotiateCall()", from_tab));
-
- // Ensure the call gets up on both sides.
- EXPECT_TRUE(PollingWaitUntil("getPeerConnectionReadyState()",
- "active", from_tab));
- EXPECT_TRUE(PollingWaitUntil("getPeerConnectionReadyState()",
- "active", to_tab));
+ // Send all ICE candidates (wait for gathering to finish if necessary).
+ GatherAndSendIceCandidates(to_tab, from_tab);
+ GatherAndSendIceCandidates(from_tab, to_tab);
}
void WebRtcTestBase::HangUp(content::WebContents* from_tab) const {
EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab));
}
-void WebRtcTestBase::WaitUntilHangupVerified(
- content::WebContents* tab_contents) const {
- EXPECT_TRUE(PollingWaitUntil("getPeerConnectionReadyState()",
- "no-peer-connection", tab_contents));
-}
-
void WebRtcTestBase::DetectErrorsInJavaScript() {
detect_errors_in_javascript_ = true;
}
void WebRtcTestBase::WaitForVideoToPlay(
content::WebContents* tab_contents) const {
- EXPECT_TRUE(PollingWaitUntil("isVideoPlaying()", "video-playing",
- tab_contents));
+ 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";
}