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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 EXPECT_EQ("ok-added", ExecuteJavascript("addLocalStream()", tab)); | 308 EXPECT_EQ("ok-added", ExecuteJavascript("addLocalStream()", tab)); |
309 } | 309 } |
310 | 310 |
311 void WebRtcTestBase::SetupPeerconnectionWithoutLocalStream( | 311 void WebRtcTestBase::SetupPeerconnectionWithoutLocalStream( |
312 content::WebContents* tab) const { | 312 content::WebContents* tab) const { |
313 EXPECT_EQ("ok-peerconnection-created", | 313 EXPECT_EQ("ok-peerconnection-created", |
314 ExecuteJavascript("preparePeerConnection()", tab)); | 314 ExecuteJavascript("preparePeerConnection()", tab)); |
315 } | 315 } |
316 | 316 |
317 std::string WebRtcTestBase::CreateLocalOffer( | 317 std::string WebRtcTestBase::CreateLocalOffer( |
318 content::WebContents* from_tab) const { | 318 content::WebContents* from_tab, |
319 std::string response = ExecuteJavascript("createLocalOffer({})", from_tab); | 319 std::string default_video_codec) const { |
| 320 if (default_video_codec.empty()) |
| 321 default_video_codec = "null"; |
| 322 else |
| 323 default_video_codec = "'" + default_video_codec + "'"; |
| 324 std::string javascript = base::StringPrintf( |
| 325 "createLocalOffer({}, %s)", default_video_codec.c_str()); |
| 326 std::string response = ExecuteJavascript(javascript, from_tab); |
320 EXPECT_EQ("ok-", response.substr(0, 3)) << "Failed to create local offer: " | 327 EXPECT_EQ("ok-", response.substr(0, 3)) << "Failed to create local offer: " |
321 << response; | 328 << response; |
322 | 329 |
323 std::string local_offer = response.substr(3); | 330 std::string local_offer = response.substr(3); |
324 return local_offer; | 331 return local_offer; |
325 } | 332 } |
326 | 333 |
327 std::string WebRtcTestBase::CreateAnswer(std::string local_offer, | 334 std::string WebRtcTestBase::CreateAnswer( |
328 content::WebContents* to_tab) const { | 335 std::string local_offer, |
| 336 content::WebContents* to_tab, |
| 337 std::string default_video_codec) const { |
329 std::string javascript = | 338 std::string javascript = |
330 base::StringPrintf("receiveOfferFromPeer('%s', {})", local_offer.c_str()); | 339 base::StringPrintf("receiveOfferFromPeer('%s', {})", local_offer.c_str()); |
331 std::string response = ExecuteJavascript(javascript, to_tab); | 340 std::string response = ExecuteJavascript(javascript, to_tab); |
332 EXPECT_EQ("ok-", response.substr(0, 3)) | 341 EXPECT_EQ("ok-", response.substr(0, 3)) |
333 << "Receiving peer failed to receive offer and create answer: " | 342 << "Receiving peer failed to receive offer and create answer: " |
334 << response; | 343 << response; |
335 | 344 |
336 std::string answer = response.substr(3); | 345 std::string answer = response.substr(3); |
| 346 |
| 347 if (!default_video_codec.empty()) { |
| 348 response = ExecuteJavascript( |
| 349 base::StringPrintf("verifyDefaultVideoCodec('%s', '%s')", |
| 350 answer.c_str(), default_video_codec.c_str()), |
| 351 to_tab); |
| 352 EXPECT_EQ("ok-", response.substr(0, 3)) |
| 353 << "Receiving peer failed to verify default codec: " |
| 354 << response; |
| 355 } |
| 356 |
337 return answer; | 357 return answer; |
338 } | 358 } |
339 | 359 |
340 void WebRtcTestBase::ReceiveAnswer(const std::string& answer, | 360 void WebRtcTestBase::ReceiveAnswer(const std::string& answer, |
341 content::WebContents* from_tab) const { | 361 content::WebContents* from_tab) const { |
342 ASSERT_EQ( | 362 ASSERT_EQ( |
343 "ok-accepted-answer", | 363 "ok-accepted-answer", |
344 ExecuteJavascript( | 364 ExecuteJavascript( |
345 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()), | 365 base::StringPrintf("receiveAnswerFromPeer('%s')", answer.c_str()), |
346 from_tab)); | 366 from_tab)); |
347 } | 367 } |
348 | 368 |
349 void WebRtcTestBase::GatherAndSendIceCandidates( | 369 void WebRtcTestBase::GatherAndSendIceCandidates( |
350 content::WebContents* from_tab, | 370 content::WebContents* from_tab, |
351 content::WebContents* to_tab) const { | 371 content::WebContents* to_tab) const { |
352 std::string ice_candidates = | 372 std::string ice_candidates = |
353 ExecuteJavascript("getAllIceCandidates()", from_tab); | 373 ExecuteJavascript("getAllIceCandidates()", from_tab); |
354 | 374 |
355 EXPECT_EQ("ok-received-candidates", ExecuteJavascript( | 375 EXPECT_EQ("ok-received-candidates", ExecuteJavascript( |
356 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()), | 376 base::StringPrintf("receiveIceCandidates('%s')", ice_candidates.c_str()), |
357 to_tab)); | 377 to_tab)); |
358 } | 378 } |
359 | 379 |
360 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab, | 380 void WebRtcTestBase::NegotiateCall(content::WebContents* from_tab, |
361 content::WebContents* to_tab) const { | 381 content::WebContents* to_tab, |
362 std::string local_offer = CreateLocalOffer(from_tab); | 382 const std::string& video_codec) const { |
363 std::string answer = CreateAnswer(local_offer, to_tab); | 383 std::string local_offer = CreateLocalOffer(from_tab, video_codec); |
| 384 std::string answer = CreateAnswer(local_offer, to_tab, video_codec); |
364 ReceiveAnswer(answer, from_tab); | 385 ReceiveAnswer(answer, from_tab); |
365 | 386 |
366 // Send all ICE candidates (wait for gathering to finish if necessary). | 387 // Send all ICE candidates (wait for gathering to finish if necessary). |
367 GatherAndSendIceCandidates(to_tab, from_tab); | 388 GatherAndSendIceCandidates(to_tab, from_tab); |
368 GatherAndSendIceCandidates(from_tab, to_tab); | 389 GatherAndSendIceCandidates(from_tab, to_tab); |
369 } | 390 } |
370 | 391 |
371 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { | 392 void WebRtcTestBase::HangUp(content::WebContents* from_tab) const { |
372 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); | 393 EXPECT_EQ("ok-call-hung-up", ExecuteJavascript("hangUp()", from_tab)); |
373 } | 394 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 #endif | 438 #endif |
418 } | 439 } |
419 | 440 |
420 bool WebRtcTestBase::OnWin8() const { | 441 bool WebRtcTestBase::OnWin8() const { |
421 #if defined(OS_WIN) | 442 #if defined(OS_WIN) |
422 return base::win::GetVersion() > base::win::VERSION_WIN7; | 443 return base::win::GetVersion() > base::win::VERSION_WIN7; |
423 #else | 444 #else |
424 return false; | 445 return false; |
425 #endif | 446 #endif |
426 } | 447 } |
OLD | NEW |