| 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 return response.substr(3); |
| 367 | |
| 368 if (!default_video_codec.empty()) { | |
| 369 response = ExecuteJavascript( | |
| 370 base::StringPrintf("verifyDefaultVideoCodec('%s', '%s')", | |
| 371 answer.c_str(), default_video_codec.c_str()), | |
| 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; | |
| 379 } | 358 } |
| 380 | 359 |
| 381 void WebRtcTestBase::ReceiveAnswer(const std::string& answer, | 360 void WebRtcTestBase::ReceiveAnswer(const std::string& answer, |
| 382 content::WebContents* from_tab) const { | 361 content::WebContents* from_tab) const { |
| 383 ASSERT_EQ( | 362 ASSERT_EQ( |
| 384 "ok-accepted-answer", | 363 "ok-accepted-answer", |
| 385 ExecuteJavascript( | 364 ExecuteJavascript( |
| 386 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()), | 365 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()), |
| 387 from_tab)); | 366 from_tab)); |
| 388 } | 367 } |
| 389 | 368 |
| 390 void WebRtcTestBase::GatherAndSendIceCandidates( | 369 void WebRtcTestBase::GatherAndSendIceCandidates( |
| 391 content::WebContents* from_tab, | 370 content::WebContents* from_tab, |
| 392 content::WebContents* to_tab) const { | 371 content::WebContents* to_tab) const { |
| 393 std::string ice_candidates = | 372 std::string ice_candidates = |
| 394 ExecuteJavascript("getAllIceCandidates()", from_tab); | 373 ExecuteJavascript("getAllIceCandidates()", from_tab); |
| 395 | 374 |
| 396 EXPECT_EQ("ok-received-candidates", ExecuteJavascript( | 375 EXPECT_EQ("ok-received-candidates", ExecuteJavascript( |
| 397 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()), | 376 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()), |
| 398 to_tab)); | 377 to_tab)); |
| 399 } | 378 } |
| 400 | 379 |
| 401 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab, | 380 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab, |
| 402 content::WebContents* to_tab, | 381 content::WebContents* to_tab) const { |
| 403 const std::string& video_codec) const { | 382 std::string local_offer = CreateLocalOffer(from_tab); |
| 404 std::string local_offer = CreateLocalOffer(from_tab, video_codec); | 383 std::string answer = CreateAnswer(local_offer, to_tab); |
| 405 std::string answer = CreateAnswer(local_offer, to_tab, video_codec); | |
| 406 ReceiveAnswer(answer, from_tab); | 384 ReceiveAnswer(answer, from_tab); |
| 407 | 385 |
| 408 // Send all ICE candidates (wait for gathering to finish if necessary). | 386 // Send all ICE candidates (wait for gathering to finish if necessary). |
| 409 GatherAndSendIceCandidates(to_tab, from_tab); | 387 GatherAndSendIceCandidates(to_tab, from_tab); |
| 410 GatherAndSendIceCandidates(from_tab, to_tab); | 388 GatherAndSendIceCandidates(from_tab, to_tab); |
| 411 } | 389 } |
| 412 | 390 |
| 413 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { | 391 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { |
| 414 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); | 392 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); |
| 415 } | 393 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 456 } |
| 479 | 457 |
| 480 void WebRtcTestBase::GenerateAndCloneCertificate( | 458 void WebRtcTestBase::GenerateAndCloneCertificate( |
| 481 content::WebContents* tab, const std::string& keygen_algorithm) const { | 459 content::WebContents* tab, const std::string& keygen_algorithm) const { |
| 482 std::string javascript = base::StringPrintf( | 460 std::string javascript = base::StringPrintf( |
| 483 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); | 461 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); |
| 484 std::string response = ExecuteJavascript(javascript, tab); | 462 std::string response = ExecuteJavascript(javascript, tab); |
| 485 EXPECT_EQ("ok-generated-and-cloned", response) << "Failed to generate and " | 463 EXPECT_EQ("ok-generated-and-cloned", response) << "Failed to generate and " |
| 486 "clone certificate: " << response; | 464 "clone certificate: " << response; |
| 487 } | 465 } |
| 466 |
| 467 void WebRtcTestBase::SetDefaultVideoCodec( |
| 468 content::WebContents* tab, |
| 469 const std::string& video_codec) const { |
| 470 EXPECT_EQ("ok-forced", |
| 471 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); |
| 472 } |
| 473 |
| 474 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { |
| 475 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); |
| 476 } |
| OLD | NEW |