Chromium Code Reviews| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 } | 328 } |
| 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(content::WebContents* from_tab, |
|
phoglund_chromium
2016/07/27 09:15:05
I'm concerned this is going to go out of control i
Ivo-OOO until feb 6
2016/07/27 14:12:43
Good point, I implemented option 2.
| |
| 339 content::WebContents* from_tab, | 339 std::string default_video_codec, |
| 340 std::string default_video_codec) const { | 340 bool opus_dtx) const { |
| 341 if (default_video_codec.empty()) | 341 if (default_video_codec.empty()) |
| 342 default_video_codec = "null"; | 342 default_video_codec = "null"; |
| 343 else | 343 else |
| 344 default_video_codec = "'" + default_video_codec + "'"; | 344 default_video_codec = "'" + default_video_codec + "'"; |
| 345 std::string javascript = base::StringPrintf( | 345 std::string javascript = base::StringPrintf("createLocalOffer({}, %s, %s)", |
| 346 "createLocalOffer({}, %s)", default_video_codec.c_str()); | 346 default_video_codec.c_str(), |
| 347 opus_dtx ? "true" : "false"); | |
| 347 std::string response = ExecuteJavascript(javascript, from_tab); | 348 std::string response = ExecuteJavascript(javascript, from_tab); |
| 348 EXPECT_EQ("ok-", response.substr(0, 3)) << "Failed to create local offer: " | 349 EXPECT_EQ("ok-", response.substr(0, 3)) << "Failed to create local offer: " |
| 349 << response; | 350 << response; |
| 350 | 351 |
| 351 std::string local_offer = response.substr(3); | 352 std::string local_offer = response.substr(3); |
| 352 return local_offer; | 353 return local_offer; |
| 353 } | 354 } |
| 354 | 355 |
| 355 std::string WebRtcTestBase::CreateAnswer( | 356 std::string WebRtcTestBase::CreateAnswer(std::string local_offer, |
| 356 std::string local_offer, | 357 content::WebContents* to_tab, |
| 357 content::WebContents* to_tab, | 358 std::string default_video_codec, |
| 358 std::string default_video_codec) const { | 359 bool opus_dtx) const { |
| 359 std::string javascript = | 360 std::string javascript = |
| 360 base::StringPrintf("receiveOfferFromPeer('%s', {})", local_offer.c_str()); | 361 base::StringPrintf("receiveOfferFromPeer('%s', {}, %s)", |
| 362 local_offer.c_str(), opus_dtx ? "true" : "false"); | |
| 361 std::string response = ExecuteJavascript(javascript, to_tab); | 363 std::string response = ExecuteJavascript(javascript, to_tab); |
| 362 EXPECT_EQ("ok-", response.substr(0, 3)) | 364 EXPECT_EQ("ok-", response.substr(0, 3)) |
| 363 << "Receiving peer failed to receive offer and create answer: " | 365 << "Receiving peer failed to receive offer and create answer: " |
| 364 << response; | 366 << response; |
| 365 | 367 |
| 366 std::string answer = response.substr(3); | 368 std::string answer = response.substr(3); |
| 367 | 369 |
| 368 if (!default_video_codec.empty()) { | 370 if (!default_video_codec.empty()) { |
| 369 response = ExecuteJavascript( | 371 response = ExecuteJavascript( |
| 370 base::StringPrintf("verifyDefaultVideoCodec('%s', '%s')", | 372 base::StringPrintf("verifyDefaultVideoCodec('%s', '%s')", |
| 371 answer.c_str(), default_video_codec.c_str()), | 373 answer.c_str(), default_video_codec.c_str()), |
| 372 to_tab); | 374 to_tab); |
| 373 EXPECT_EQ("ok-", response.substr(0, 3)) | 375 EXPECT_EQ("ok-", response.substr(0, 3)) |
| 374 << "Receiving peer failed to verify default codec: " | 376 << "Receiving peer failed to verify default codec: " |
| 375 << response; | 377 << response; |
| 376 } | 378 } |
| 379 if (opus_dtx) { | |
| 380 response = ExecuteJavascript( | |
| 381 base::StringPrintf("verifyOpusDtxEnabled('%s')", answer.c_str()), | |
| 382 to_tab); | |
| 383 EXPECT_EQ("ok-", response.substr(0, 3)) | |
|
phoglund_chromium
2016/07/27 09:15:05
Just check ok-verified. In the above the response
Ivo-OOO until feb 6
2016/07/27 14:12:43
I moved this code to the javascript side, so this
| |
| 384 << "Receiving peer failed to verify opus dtx: " << response; | |
| 385 } | |
| 377 | 386 |
| 378 return answer; | 387 return answer; |
| 379 } | 388 } |
| 380 | 389 |
| 381 void WebRtcTestBase::ReceiveAnswer(const std::string& answer, | 390 void WebRtcTestBase::ReceiveAnswer(const std::string& answer, |
| 382 content::WebContents* from_tab) const { | 391 content::WebContents* from_tab) const { |
| 383 ASSERT_EQ( | 392 ASSERT_EQ( |
| 384 "ok-accepted-answer", | 393 "ok-accepted-answer", |
| 385 ExecuteJavascript( | 394 ExecuteJavascript( |
| 386 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()), | 395 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()), |
| 387 from_tab)); | 396 from_tab)); |
| 388 } | 397 } |
| 389 | 398 |
| 390 void WebRtcTestBase::GatherAndSendIceCandidates( | 399 void WebRtcTestBase::GatherAndSendIceCandidates( |
| 391 content::WebContents* from_tab, | 400 content::WebContents* from_tab, |
| 392 content::WebContents* to_tab) const { | 401 content::WebContents* to_tab) const { |
| 393 std::string ice_candidates = | 402 std::string ice_candidates = |
| 394 ExecuteJavascript("getAllIceCandidates()", from_tab); | 403 ExecuteJavascript("getAllIceCandidates()", from_tab); |
| 395 | 404 |
| 396 EXPECT_EQ("ok-received-candidates", ExecuteJavascript( | 405 EXPECT_EQ("ok-received-candidates", ExecuteJavascript( |
| 397 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()), | 406 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()), |
| 398 to_tab)); | 407 to_tab)); |
| 399 } | 408 } |
| 400 | 409 |
| 401 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab, | 410 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab, |
| 402 content::WebContents* to_tab, | 411 content::WebContents* to_tab, |
| 403 const std::string& video_codec) const { | 412 const std::string& video_codec, |
| 404 std::string local_offer = CreateLocalOffer(from_tab, video_codec); | 413 bool opus_dtx) const { |
| 405 std::string answer = CreateAnswer(local_offer, to_tab, video_codec); | 414 std::string local_offer = CreateLocalOffer(from_tab, video_codec, opus_dtx); |
| 415 std::string answer = CreateAnswer(local_offer, to_tab, video_codec, opus_dtx); | |
| 406 ReceiveAnswer(answer, from_tab); | 416 ReceiveAnswer(answer, from_tab); |
| 407 | 417 |
| 408 // Send all ICE candidates (wait for gathering to finish if necessary). | 418 // Send all ICE candidates (wait for gathering to finish if necessary). |
| 409 GatherAndSendIceCandidates(to_tab, from_tab); | 419 GatherAndSendIceCandidates(to_tab, from_tab); |
| 410 GatherAndSendIceCandidates(from_tab, to_tab); | 420 GatherAndSendIceCandidates(from_tab, to_tab); |
| 411 } | 421 } |
| 412 | 422 |
| 413 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { | 423 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { |
| 414 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); | 424 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); |
| 415 } | 425 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 } | 488 } |
| 479 | 489 |
| 480 void WebRtcTestBase::GenerateAndCloneCertificate( | 490 void WebRtcTestBase::GenerateAndCloneCertificate( |
| 481 content::WebContents* tab, const std::string& keygen_algorithm) const { | 491 content::WebContents* tab, const std::string& keygen_algorithm) const { |
| 482 std::string javascript = base::StringPrintf( | 492 std::string javascript = base::StringPrintf( |
| 483 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); | 493 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); |
| 484 std::string response = ExecuteJavascript(javascript, tab); | 494 std::string response = ExecuteJavascript(javascript, tab); |
| 485 EXPECT_EQ("ok-generated-and-cloned", response) << "Failed to generate and " | 495 EXPECT_EQ("ok-generated-and-cloned", response) << "Failed to generate and " |
| 486 "clone certificate: " << response; | 496 "clone certificate: " << response; |
| 487 } | 497 } |
| OLD | NEW |