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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 329 |
330 void WebRtcTestBase::SetupPeerconnectionWithCertificateWithoutLocalStream( | 330 void WebRtcTestBase::SetupPeerconnectionWithCertificateWithoutLocalStream( |
331 content::WebContents* tab, | 331 content::WebContents* tab, |
332 const std::string& certificate) const { | 332 const std::string& certificate) const { |
333 std::string javascript = base::StringPrintf( | 333 std::string javascript = base::StringPrintf( |
334 "preparePeerConnectionWithCertificate(%s)", certificate.c_str()); | 334 "preparePeerConnectionWithCertificate(%s)", certificate.c_str()); |
335 EXPECT_EQ("ok-peerconnection-created", ExecuteJavascript(javascript, tab)); | 335 EXPECT_EQ("ok-peerconnection-created", ExecuteJavascript(javascript, tab)); |
336 } | 336 } |
337 | 337 |
338 std::string WebRtcTestBase::CreateLocalOffer( | 338 std::string WebRtcTestBase::CreateLocalOffer( |
339 content::WebContents* from_tab, | 339 content::WebContents* from_tab) const { |
340 std::string default_video_codec) const { | 340 std::string response = ExecuteJavascript("createLocalOffer({})", from_tab); |
341 if (default_video_codec.empty()) | |
342 default_video_codec = "null"; | |
343 else | |
344 default_video_codec = "'" + default_video_codec + "'"; | |
345 std::string javascript = base::StringPrintf( | |
346 "createLocalOffer({}, %s)", default_video_codec.c_str()); | |
347 std::string response = ExecuteJavascript(javascript, from_tab); | |
348 EXPECT_EQ("ok-", response.substr(0, 3)) << "Failed to create local offer: " | 341 EXPECT_EQ("ok-", response.substr(0, 3)) << "Failed to create local offer: " |
349 << response; | 342 << response; |
350 | 343 |
351 std::string local_offer = response.substr(3); | 344 std::string local_offer = response.substr(3); |
352 return local_offer; | 345 return local_offer; |
353 } | 346 } |
354 | 347 |
355 std::string WebRtcTestBase::CreateAnswer( | 348 std::string WebRtcTestBase::CreateAnswer(std::string local_offer, |
356 std::string local_offer, | 349 content::WebContents* to_tab) const { |
357 content::WebContents* to_tab, | |
358 std::string default_video_codec) const { | |
359 std::string javascript = | 350 std::string javascript = |
360 base::StringPrintf("receiveOfferFromPeer('%s', {})", local_offer.c_str()); | 351 base::StringPrintf("receiveOfferFromPeer('%s', {})", local_offer.c_str()); |
361 std::string response = ExecuteJavascript(javascript, to_tab); | 352 std::string response = ExecuteJavascript(javascript, to_tab); |
362 EXPECT_EQ("ok-", response.substr(0, 3)) | 353 EXPECT_EQ("ok-", response.substr(0, 3)) |
363 << "Receiving peer failed to receive offer and create answer: " | 354 << "Receiving peer failed to receive offer and create answer: " |
364 << response; | 355 << response; |
365 | 356 |
366 std::string answer = response.substr(3); | 357 std::string answer = response.substr(3); |
367 | 358 response = ExecuteJavascript( |
368 if (!default_video_codec.empty()) { | 359 base::StringPrintf("verifyDefaultVideoCodec('%s')", answer.c_str()), |
369 response = ExecuteJavascript( | 360 to_tab); |
370 base::StringPrintf("verifyDefaultVideoCodec('%s', '%s')", | 361 EXPECT_EQ("ok-", response.substr(0, 3)) |
371 answer.c_str(), default_video_codec.c_str()), | 362 << "Receiving peer failed to verify default codec: " << response; |
372 to_tab); | |
373 EXPECT_EQ("ok-", response.substr(0, 3)) | |
374 << "Receiving peer failed to verify default codec: " | |
375 << response; | |
376 } | |
377 | |
378 return answer; | 363 return answer; |
379 } | 364 } |
380 | 365 |
381 void WebRtcTestBase::ReceiveAnswer(const std::string& answer, | 366 void WebRtcTestBase::ReceiveAnswer(const std::string& answer, |
382 content::WebContents* from_tab) const { | 367 content::WebContents* from_tab) const { |
383 ASSERT_EQ( | 368 ASSERT_EQ( |
384 "ok-accepted-answer", | 369 "ok-accepted-answer", |
385 ExecuteJavascript( | 370 ExecuteJavascript( |
386 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()), | 371 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()), |
387 from_tab)); | 372 from_tab)); |
388 } | 373 } |
389 | 374 |
390 void WebRtcTestBase::GatherAndSendIceCandidates( | 375 void WebRtcTestBase::GatherAndSendIceCandidates( |
391 content::WebContents* from_tab, | 376 content::WebContents* from_tab, |
392 content::WebContents* to_tab) const { | 377 content::WebContents* to_tab) const { |
393 std::string ice_candidates = | 378 std::string ice_candidates = |
394 ExecuteJavascript("getAllIceCandidates()", from_tab); | 379 ExecuteJavascript("getAllIceCandidates()", from_tab); |
395 | 380 |
396 EXPECT_EQ("ok-received-candidates", ExecuteJavascript( | 381 EXPECT_EQ("ok-received-candidates", ExecuteJavascript( |
397 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()), | 382 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()), |
398 to_tab)); | 383 to_tab)); |
399 } | 384 } |
400 | 385 |
401 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab, | 386 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab, |
402 content::WebContents* to_tab, | 387 content::WebContents* to_tab) const { |
403 const std::string& video_codec) const { | 388 std::string local_offer = CreateLocalOffer(from_tab); |
404 std::string local_offer = CreateLocalOffer(from_tab, video_codec); | 389 std::string answer = CreateAnswer(local_offer, to_tab); |
405 std::string answer = CreateAnswer(local_offer, to_tab, video_codec); | |
406 ReceiveAnswer(answer, from_tab); | 390 ReceiveAnswer(answer, from_tab); |
407 | 391 |
408 // Send all ICE candidates (wait for gathering to finish if necessary). | 392 // Send all ICE candidates (wait for gathering to finish if necessary). |
409 GatherAndSendIceCandidates(to_tab, from_tab); | 393 GatherAndSendIceCandidates(to_tab, from_tab); |
410 GatherAndSendIceCandidates(from_tab, to_tab); | 394 GatherAndSendIceCandidates(from_tab, to_tab); |
411 } | 395 } |
412 | 396 |
413 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { | 397 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { |
414 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); | 398 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); |
415 } | 399 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 } | 462 } |
479 | 463 |
480 void WebRtcTestBase::GenerateAndCloneCertificate( | 464 void WebRtcTestBase::GenerateAndCloneCertificate( |
481 content::WebContents* tab, const std::string& keygen_algorithm) const { | 465 content::WebContents* tab, const std::string& keygen_algorithm) const { |
482 std::string javascript = base::StringPrintf( | 466 std::string javascript = base::StringPrintf( |
483 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); | 467 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); |
484 std::string response = ExecuteJavascript(javascript, tab); | 468 std::string response = ExecuteJavascript(javascript, tab); |
485 EXPECT_EQ("ok-generated-and-cloned", response) << "Failed to generate and " | 469 EXPECT_EQ("ok-generated-and-cloned", response) << "Failed to generate and " |
486 "clone certificate: " << response; | 470 "clone certificate: " << response; |
487 } | 471 } |
| 472 |
| 473 void WebRtcTestBase::SetDefaultVideoCodec( |
| 474 content::WebContents* tab, |
| 475 const std::string& video_codec) const { |
| 476 EXPECT_EQ("ok-forced", |
| 477 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); |
| 478 } |
| 479 |
| 480 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { |
| 481 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); |
| 482 } |
OLD | NEW |