Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/media/webrtc_browsertest_base.cc

Issue 271653002: Rewrote WebRTC browser tests to not use peerconnection_server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit fixes Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // of the provided web contents and returns what it evaluated to. 241 // of the provided web contents and returns what it evaluated to.
242 std::string WebRtcTestBase::ExecuteJavascript( 242 std::string WebRtcTestBase::ExecuteJavascript(
243 const std::string& javascript, 243 const std::string& javascript,
244 content::WebContents* tab_contents) const { 244 content::WebContents* tab_contents) const {
245 std::string result; 245 std::string result;
246 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 246 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
247 tab_contents, javascript, &result)); 247 tab_contents, javascript, &result));
248 return result; 248 return result;
249 } 249 }
250 250
251 // The peer connection server lets our two tabs find each other and talk to 251 void WebRtcTestBase::SetupPeerconnectionWithLocalStream(
252 // each other (e.g. it is the application-specific "signaling solution"). 252 content::WebContents* tab) const {
253 void WebRtcTestBase::ConnectToPeerConnectionServer( 253 EXPECT_EQ("ok-peerconnection-created",
254 const std::string& peer_name, 254 ExecuteJavascript("preparePeerConnection()", tab));
255 content::WebContents* tab_contents) const { 255 EXPECT_EQ("ok-added", ExecuteJavascript("addLocalStream()", tab));
256 std::string javascript = base::StringPrintf(
257 "connect('http://localhost:%s', '%s');",
258 test::PeerConnectionServerRunner::kDefaultPort, peer_name.c_str());
259 EXPECT_EQ("ok-connected", ExecuteJavascript(javascript, tab_contents));
260 } 256 }
261 257
262 void WebRtcTestBase::EstablishCall(content::WebContents* from_tab, 258 std::string WebRtcTestBase::CreateLocalOffer(
259 content::WebContents* from_tab) const {
260 std::string response = ExecuteJavascript("createLocalOffer({})", from_tab);
261 EXPECT_EQ("ok-", response.substr(0, 3)) << "Failed to create local offer: "
262 << response;
263
264 std::string local_offer = response.substr(3);
265 return local_offer;
266 }
267
268 std::string WebRtcTestBase::CreateAnswer(std::string local_offer,
269 content::WebContents* to_tab) const {
270 std::string javascript =
271 base::StringPrintf("receiveOfferFromPeer('%s', {})", local_offer.c_str());
272 std::string response = ExecuteJavascript(javascript, to_tab);
273 EXPECT_EQ("ok-", response.substr(0, 3))
274 << "Receiving peer failed to receive offer and create answer: "
275 << response;
276
277 std::string answer = response.substr(3);
278 return answer;
279 }
280
281 void WebRtcTestBase::ReceiveAnswer(std::string answer,
282 content::WebContents* from_tab) const {
283 ASSERT_EQ(
284 "ok-accepted-answer",
285 ExecuteJavascript(
286 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()),
287 from_tab));
288 }
289
290 void WebRtcTestBase::GatherAndSendIceCandidates(
291 content::WebContents* from_tab,
292 content::WebContents* to_tab) const {
293 std::string ice_candidates =
294 ExecuteJavascript("getAllIceCandidates()", from_tab);
295
296 EXPECT_EQ("ok-received-candidates", ExecuteJavascript(
297 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()),
298 to_tab));
299 }
300
301 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab,
263 content::WebContents* to_tab) const { 302 content::WebContents* to_tab) const {
264 ConnectToPeerConnectionServer("peer 1", from_tab); 303 std::string local_offer = CreateLocalOffer(from_tab);
265 ConnectToPeerConnectionServer("peer 2", to_tab); 304 std::string answer = CreateAnswer(local_offer, to_tab);
305 ReceiveAnswer(answer, from_tab);
266 306
267 EXPECT_EQ("ok-peerconnection-created", 307 // Send all ICE candidates (wait for gathering to finish if necessary).
268 ExecuteJavascript("preparePeerConnection()", from_tab)); 308 GatherAndSendIceCandidates(to_tab, from_tab);
269 EXPECT_EQ("ok-added", ExecuteJavascript("addLocalStream()", from_tab)); 309 GatherAndSendIceCandidates(from_tab, to_tab);
270 EXPECT_EQ("ok-negotiating", ExecuteJavascript("negotiateCall()", from_tab));
271
272 // Ensure the call gets up on both sides.
273 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()",
274 "active", from_tab));
275 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()",
276 "active", to_tab));
277 } 310 }
278 311
279 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { 312 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const {
280 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); 313 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab));
281 } 314 }
282 315
283 void WebRtcTestBase::WaitUntilHangupVerified(
284 content::WebContents* tab_contents) const {
285 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()",
286 "no-peer-connection", tab_contents));
287 }
288
289 void WebRtcTestBase::DetectErrorsInJavaScript() { 316 void WebRtcTestBase::DetectErrorsInJavaScript() {
290 detect_errors_in_javascript_ = true; 317 detect_errors_in_javascript_ = true;
291 } 318 }
292 319
293 void WebRtcTestBase::StartDetectingVideo( 320 void WebRtcTestBase::StartDetectingVideo(
294 content::WebContents* tab_contents, 321 content::WebContents* tab_contents,
295 const std::string& video_element) const { 322 const std::string& video_element) const {
296 std::string javascript = base::StringPrintf( 323 std::string javascript = base::StringPrintf(
297 "startDetection('%s', 320, 240)", video_element.c_str()); 324 "startDetection('%s', 320, 240)", video_element.c_str());
298 EXPECT_EQ("ok-started", ExecuteJavascript(javascript, tab_contents)); 325 EXPECT_EQ("ok-started", ExecuteJavascript(javascript, tab_contents));
(...skipping 14 matching lines...) Expand all
313 EXPECT_TRUE(StartsWithASCII(result, "ok-", true)); 340 EXPECT_TRUE(StartsWithASCII(result, "ok-", true));
314 return result.substr(3); 341 return result.substr(3);
315 } 342 }
316 343
317 bool WebRtcTestBase::HasWebcamAvailableOnSystem( 344 bool WebRtcTestBase::HasWebcamAvailableOnSystem(
318 content::WebContents* tab_contents) const { 345 content::WebContents* tab_contents) const {
319 std::string result = 346 std::string result =
320 ExecuteJavascript("HasVideoSourceOnSystem();", tab_contents); 347 ExecuteJavascript("HasVideoSourceOnSystem();", tab_contents);
321 return result == "has-video-source"; 348 return result == "has-video-source";
322 } 349 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.h ('k') | chrome/browser/media/webrtc_browsertest_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698