OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/media/webrtc_browsertest_base.h" | 5 #include "chrome/browser/media/webrtc_browsertest_base.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/infobars/infobar.h" | 10 #include "chrome/browser/infobars/infobar.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( | 85 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( |
86 content::WebContents* tab_contents, | 86 content::WebContents* tab_contents, |
87 const std::string& constraints) const { | 87 const std::string& constraints) const { |
88 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 88 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
89 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); | 89 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
90 CloseInfoBarInTab(tab_contents, infobar); | 90 CloseInfoBarInTab(tab_contents, infobar); |
91 | 91 |
92 // Wait for WebRTC to call the success callback. | 92 // Wait for WebRTC to call the success callback. |
93 const char kOkGotStream[] = "ok-got-stream"; | 93 const char kOkGotStream[] = "ok-got-stream"; |
94 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, | 94 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, |
95 tab_contents)); | 95 tab_contents)); |
96 } | 96 } |
97 | 97 |
98 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { | 98 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { |
99 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 99 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
100 kAudioVideoCallConstraints); | 100 kAudioVideoCallConstraints); |
101 } | 101 } |
102 | 102 |
103 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( | 103 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( |
104 content::WebContents* tab_contents, | 104 content::WebContents* tab_contents, |
105 const std::string& constraints) const { | 105 const std::string& constraints) const { |
106 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 106 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
107 infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel(); | 107 infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
108 CloseInfoBarInTab(tab_contents, infobar); | 108 CloseInfoBarInTab(tab_contents, infobar); |
109 | 109 |
110 // Wait for WebRTC to call the fail callback. | 110 // Wait for WebRTC to call the fail callback. |
111 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", | 111 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", |
112 kFailedWithPermissionDeniedError, | 112 kFailedWithPermissionDeniedError, tab_contents)); |
113 tab_contents)); | |
114 } | 113 } |
115 | 114 |
116 void WebRtcTestBase::GetUserMediaAndDismiss( | 115 void WebRtcTestBase::GetUserMediaAndDismiss( |
117 content::WebContents* tab_contents) const { | 116 content::WebContents* tab_contents) const { |
118 InfoBar* infobar = | 117 InfoBar* infobar = |
119 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); | 118 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); |
120 infobar->delegate()->InfoBarDismissed(); | 119 infobar->delegate()->InfoBarDismissed(); |
121 CloseInfoBarInTab(tab_contents, infobar); | 120 CloseInfoBarInTab(tab_contents, infobar); |
122 | 121 |
123 // A dismiss should be treated like a deny. | 122 // A dismiss should be treated like a deny. |
124 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", | 123 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", |
125 kFailedWithPermissionDismissedError, | 124 kFailedWithPermissionDismissedError, |
126 tab_contents)); | 125 tab_contents)); |
127 } | 126 } |
128 | 127 |
129 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, | 128 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, |
130 const std::string& constraints) const { | 129 const std::string& constraints) const { |
131 // Request user media: this will launch the media stream info bar. | 130 // Request user media: this will launch the media stream info bar. |
132 std::string result; | 131 std::string result; |
133 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 132 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
134 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); | 133 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); |
135 EXPECT_EQ("ok-requested", result); | 134 EXPECT_EQ("ok-requested", result); |
136 } | 135 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 return result; | 225 return result; |
227 } | 226 } |
228 | 227 |
229 // The peer connection server lets our two tabs find each other and talk to | 228 // The peer connection server lets our two tabs find each other and talk to |
230 // each other (e.g. it is the application-specific "signaling solution"). | 229 // each other (e.g. it is the application-specific "signaling solution"). |
231 void WebRtcTestBase::ConnectToPeerConnectionServer( | 230 void WebRtcTestBase::ConnectToPeerConnectionServer( |
232 const std::string& peer_name, | 231 const std::string& peer_name, |
233 content::WebContents* tab_contents) const { | 232 content::WebContents* tab_contents) const { |
234 std::string javascript = base::StringPrintf( | 233 std::string javascript = base::StringPrintf( |
235 "connect('http://localhost:%s', '%s');", | 234 "connect('http://localhost:%s', '%s');", |
236 test::PeerConnectionServerRunner::kDefaultPort, peer_name.c_str()); | 235 PeerConnectionServerRunner::kDefaultPort, peer_name.c_str()); |
237 EXPECT_EQ("ok-connected", ExecuteJavascript(javascript, tab_contents)); | 236 EXPECT_EQ("ok-connected", ExecuteJavascript(javascript, tab_contents)); |
238 } | 237 } |
239 | 238 |
240 void WebRtcTestBase::EstablishCall(content::WebContents* from_tab, | 239 void WebRtcTestBase::EstablishCall(content::WebContents* from_tab, |
241 content::WebContents* to_tab) const { | 240 content::WebContents* to_tab) const { |
242 ConnectToPeerConnectionServer("peer 1", from_tab); | 241 ConnectToPeerConnectionServer("peer 1", from_tab); |
243 ConnectToPeerConnectionServer("peer 2", to_tab); | 242 ConnectToPeerConnectionServer("peer 2", to_tab); |
244 | 243 |
245 EXPECT_EQ("ok-peerconnection-created", | 244 EXPECT_EQ("ok-peerconnection-created", |
246 ExecuteJavascript("preparePeerConnection()", from_tab)); | 245 ExecuteJavascript("preparePeerConnection()", from_tab)); |
247 EXPECT_EQ("ok-added", ExecuteJavascript("addLocalStream()", from_tab)); | 246 EXPECT_EQ("ok-added", ExecuteJavascript("addLocalStream()", from_tab)); |
248 EXPECT_EQ("ok-negotiating", ExecuteJavascript("negotiateCall()", from_tab)); | 247 EXPECT_EQ("ok-negotiating", ExecuteJavascript("negotiateCall()", from_tab)); |
249 | 248 |
250 // Ensure the call gets up on both sides. | 249 // Ensure the call gets up on both sides. |
251 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()", | 250 EXPECT_TRUE(PollingWaitUntil("getPeerConnectionReadyState()", |
252 "active", from_tab)); | 251 "active", from_tab)); |
253 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()", | 252 EXPECT_TRUE(PollingWaitUntil("getPeerConnectionReadyState()", |
254 "active", to_tab)); | 253 "active", to_tab)); |
255 } | 254 } |
256 | 255 |
257 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { | 256 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { |
258 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); | 257 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); |
259 } | 258 } |
260 | 259 |
261 void WebRtcTestBase::WaitUntilHangupVerified( | 260 void WebRtcTestBase::WaitUntilHangupVerified( |
262 content::WebContents* tab_contents) const { | 261 content::WebContents* tab_contents) const { |
263 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()", | 262 EXPECT_TRUE(PollingWaitUntil("getPeerConnectionReadyState()", |
264 "no-peer-connection", tab_contents)); | 263 "no-peer-connection", tab_contents)); |
265 } | 264 } |
266 | 265 |
267 void WebRtcTestBase::DetectErrorsInJavaScript() { | 266 void WebRtcTestBase::DetectErrorsInJavaScript() { |
268 detect_errors_in_javascript_ = true; | 267 detect_errors_in_javascript_ = true; |
269 } | 268 } |
270 | 269 |
271 void WebRtcTestBase::StartDetectingVideo( | 270 void WebRtcTestBase::StartDetectingVideo( |
272 content::WebContents* tab_contents, | 271 content::WebContents* tab_contents, |
273 const std::string& video_element) const { | 272 const std::string& video_element) const { |
274 std::string javascript = base::StringPrintf( | 273 std::string javascript = base::StringPrintf( |
275 "startDetection('%s', 320, 240)", video_element.c_str()); | 274 "startDetection('%s', 320, 240)", video_element.c_str()); |
276 EXPECT_EQ("ok-started", ExecuteJavascript(javascript, tab_contents)); | 275 EXPECT_EQ("ok-started", ExecuteJavascript(javascript, tab_contents)); |
277 } | 276 } |
278 | 277 |
279 void WebRtcTestBase::WaitForVideoToPlay( | 278 void WebRtcTestBase::WaitForVideoToPlay( |
280 content::WebContents* tab_contents) const { | 279 content::WebContents* tab_contents) const { |
281 EXPECT_TRUE(test::PollingWaitUntil("isVideoPlaying()", "video-playing", | 280 EXPECT_TRUE(PollingWaitUntil("isVideoPlaying()", "video-playing", |
282 tab_contents)); | 281 tab_contents)); |
283 } | 282 } |
OLD | NEW |