OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/tests/test_websocket.h" | 5 #include "ppapi/tests/test_websocket.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 343 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
344 ASSERT_TRUE(ws); | 344 ASSERT_TRUE(ws); |
345 | 345 |
346 uint64_t bufferedAmount = websocket_interface_->GetBufferedAmount(ws); | 346 uint64_t bufferedAmount = websocket_interface_->GetBufferedAmount(ws); |
347 ASSERT_EQ(0U, bufferedAmount); | 347 ASSERT_EQ(0U, bufferedAmount); |
348 | 348 |
349 uint16_t close_code = websocket_interface_->GetCloseCode(ws); | 349 uint16_t close_code = websocket_interface_->GetCloseCode(ws); |
350 ASSERT_EQ(0U, close_code); | 350 ASSERT_EQ(0U, close_code); |
351 | 351 |
352 PP_Var close_reason = websocket_interface_->GetCloseReason(ws); | 352 PP_Var close_reason = websocket_interface_->GetCloseReason(ws); |
353 ASSERT_TRUE(AreEqualWithString(close_reason, "")); | 353 ASSERT_TRUE(AreEqualWithString(close_reason, std::string())); |
354 ReleaseVar(close_reason); | 354 ReleaseVar(close_reason); |
355 | 355 |
356 PP_Bool close_was_clean = websocket_interface_->GetCloseWasClean(ws); | 356 PP_Bool close_was_clean = websocket_interface_->GetCloseWasClean(ws); |
357 ASSERT_EQ(PP_FALSE, close_was_clean); | 357 ASSERT_EQ(PP_FALSE, close_was_clean); |
358 | 358 |
359 PP_Var extensions = websocket_interface_->GetExtensions(ws); | 359 PP_Var extensions = websocket_interface_->GetExtensions(ws); |
360 ASSERT_TRUE(AreEqualWithString(extensions, "")); | 360 ASSERT_TRUE(AreEqualWithString(extensions, std::string())); |
361 ReleaseVar(extensions); | 361 ReleaseVar(extensions); |
362 | 362 |
363 PP_Var protocol = websocket_interface_->GetProtocol(ws); | 363 PP_Var protocol = websocket_interface_->GetProtocol(ws); |
364 ASSERT_TRUE(AreEqualWithString(protocol, "")); | 364 ASSERT_TRUE(AreEqualWithString(protocol, std::string())); |
365 ReleaseVar(protocol); | 365 ReleaseVar(protocol); |
366 | 366 |
367 PP_WebSocketReadyState ready_state = | 367 PP_WebSocketReadyState ready_state = |
368 websocket_interface_->GetReadyState(ws); | 368 websocket_interface_->GetReadyState(ws); |
369 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ready_state); | 369 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ready_state); |
370 | 370 |
371 PP_Var url = websocket_interface_->GetURL(ws); | 371 PP_Var url = websocket_interface_->GetURL(ws); |
372 ASSERT_TRUE(AreEqualWithString(url, "")); | 372 ASSERT_TRUE(AreEqualWithString(url, std::string())); |
373 ReleaseVar(url); | 373 ReleaseVar(url); |
374 | 374 |
375 core_interface_->ReleaseResource(ws); | 375 core_interface_->ReleaseResource(ws); |
376 | 376 |
377 PASS(); | 377 PASS(); |
378 } | 378 } |
379 | 379 |
380 std::string TestWebSocket::TestInvalidConnect() { | 380 std::string TestWebSocket::TestInvalidConnect() { |
381 PP_Var protocols[] = { PP_MakeUndefined() }; | 381 PP_Var protocols[] = { PP_MakeUndefined() }; |
382 | 382 |
383 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 383 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
384 ASSERT_TRUE(ws); | 384 ASSERT_TRUE(ws); |
385 | 385 |
386 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 386 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
387 callback.WaitForResult(websocket_interface_->Connect( | 387 callback.WaitForResult(websocket_interface_->Connect( |
388 ws, PP_MakeUndefined(), protocols, 1U, | 388 ws, PP_MakeUndefined(), protocols, 1U, |
389 callback.GetCallback().pp_completion_callback())); | 389 callback.GetCallback().pp_completion_callback())); |
390 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result()); | 390 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result()); |
391 | 391 |
392 callback.WaitForResult(websocket_interface_->Connect( | 392 callback.WaitForResult(websocket_interface_->Connect( |
393 ws, PP_MakeUndefined(), protocols, 1U, | 393 ws, PP_MakeUndefined(), protocols, 1U, |
394 callback.GetCallback().pp_completion_callback())); | 394 callback.GetCallback().pp_completion_callback())); |
395 ASSERT_EQ(PP_ERROR_INPROGRESS, callback.result()); | 395 ASSERT_EQ(PP_ERROR_INPROGRESS, callback.result()); |
396 | 396 |
397 core_interface_->ReleaseResource(ws); | 397 core_interface_->ReleaseResource(ws); |
398 | 398 |
399 for (int i = 0; kInvalidURLs[i]; ++i) { | 399 for (int i = 0; kInvalidURLs[i]; ++i) { |
400 int32_t result; | 400 int32_t result; |
401 ws = Connect(kInvalidURLs[i], &result, ""); | 401 ws = Connect(kInvalidURLs[i], &result, std::string()); |
402 ASSERT_TRUE(ws); | 402 ASSERT_TRUE(ws); |
403 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); | 403 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); |
404 | 404 |
405 core_interface_->ReleaseResource(ws); | 405 core_interface_->ReleaseResource(ws); |
406 } | 406 } |
407 | 407 |
408 PASS(); | 408 PASS(); |
409 } | 409 } |
410 | 410 |
411 std::string TestWebSocket::TestProtocols() { | 411 std::string TestWebSocket::TestProtocols() { |
(...skipping 29 matching lines...) Expand all Loading... |
441 ReleaseVar(good_protocols[i]); | 441 ReleaseVar(good_protocols[i]); |
442 } | 442 } |
443 core_interface_->ReleaseResource(ws); | 443 core_interface_->ReleaseResource(ws); |
444 | 444 |
445 PASS(); | 445 PASS(); |
446 } | 446 } |
447 | 447 |
448 std::string TestWebSocket::TestGetURL() { | 448 std::string TestWebSocket::TestGetURL() { |
449 for (int i = 0; kInvalidURLs[i]; ++i) { | 449 for (int i = 0; kInvalidURLs[i]; ++i) { |
450 int32_t result; | 450 int32_t result; |
451 PP_Resource ws = Connect(kInvalidURLs[i], &result, ""); | 451 PP_Resource ws = Connect(kInvalidURLs[i], &result, std::string()); |
452 ASSERT_TRUE(ws); | 452 ASSERT_TRUE(ws); |
453 PP_Var url = websocket_interface_->GetURL(ws); | 453 PP_Var url = websocket_interface_->GetURL(ws); |
454 ASSERT_TRUE(AreEqualWithString(url, kInvalidURLs[i])); | 454 ASSERT_TRUE(AreEqualWithString(url, kInvalidURLs[i])); |
455 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); | 455 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); |
456 | 456 |
457 ReleaseVar(url); | 457 ReleaseVar(url); |
458 core_interface_->ReleaseResource(ws); | 458 core_interface_->ReleaseResource(ws); |
459 } | 459 } |
460 | 460 |
461 PASS(); | 461 PASS(); |
462 } | 462 } |
463 | 463 |
464 std::string TestWebSocket::TestValidConnect() { | 464 std::string TestWebSocket::TestValidConnect() { |
465 int32_t result; | 465 int32_t result; |
466 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 466 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
467 ASSERT_TRUE(ws); | 467 ASSERT_TRUE(ws); |
468 ASSERT_EQ(PP_OK, result); | 468 ASSERT_EQ(PP_OK, result); |
469 PP_Var extensions = websocket_interface_->GetExtensions(ws); | 469 PP_Var extensions = websocket_interface_->GetExtensions(ws); |
470 ASSERT_TRUE(AreEqualWithString(extensions, "")); | 470 ASSERT_TRUE(AreEqualWithString(extensions, std::string())); |
471 core_interface_->ReleaseResource(ws); | 471 core_interface_->ReleaseResource(ws); |
472 ReleaseVar(extensions); | 472 ReleaseVar(extensions); |
473 | 473 |
474 PASS(); | 474 PASS(); |
475 } | 475 } |
476 | 476 |
477 std::string TestWebSocket::TestInvalidClose() { | 477 std::string TestWebSocket::TestInvalidClose() { |
478 PP_Var reason = CreateVarString("close for test"); | 478 PP_Var reason = CreateVarString("close for test"); |
479 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 479 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
480 TestCompletionCallback async_callback(instance_->pp_instance(), PP_REQUIRED); | 480 TestCompletionCallback async_callback(instance_->pp_instance(), PP_REQUIRED); |
481 | 481 |
482 // Close before connect. | 482 // Close before connect. |
483 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 483 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
484 callback.WaitForResult(websocket_interface_->Close( | 484 callback.WaitForResult(websocket_interface_->Close( |
485 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 485 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
486 callback.GetCallback().pp_completion_callback())); | 486 callback.GetCallback().pp_completion_callback())); |
487 ASSERT_EQ(PP_ERROR_FAILED, callback.result()); | 487 ASSERT_EQ(PP_ERROR_FAILED, callback.result()); |
488 core_interface_->ReleaseResource(ws); | 488 core_interface_->ReleaseResource(ws); |
489 | 489 |
490 // Close with bad arguments. | 490 // Close with bad arguments. |
491 int32_t result; | 491 int32_t result; |
492 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 492 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
493 ASSERT_TRUE(ws); | 493 ASSERT_TRUE(ws); |
494 ASSERT_EQ(PP_OK, result); | 494 ASSERT_EQ(PP_OK, result); |
495 callback.WaitForResult(websocket_interface_->Close( | 495 callback.WaitForResult(websocket_interface_->Close( |
496 ws, 1U, reason, callback.GetCallback().pp_completion_callback())); | 496 ws, 1U, reason, callback.GetCallback().pp_completion_callback())); |
497 ASSERT_EQ(PP_ERROR_NOACCESS, callback.result()); | 497 ASSERT_EQ(PP_ERROR_NOACCESS, callback.result()); |
498 core_interface_->ReleaseResource(ws); | 498 core_interface_->ReleaseResource(ws); |
499 | 499 |
500 // Close with PP_VARTYPE_NULL. | 500 // Close with PP_VARTYPE_NULL. |
501 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 501 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
502 ASSERT_TRUE(ws); | 502 ASSERT_TRUE(ws); |
503 ASSERT_EQ(PP_OK, result); | 503 ASSERT_EQ(PP_OK, result); |
504 callback.WaitForResult(websocket_interface_->Close( | 504 callback.WaitForResult(websocket_interface_->Close( |
505 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(), | 505 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(), |
506 callback.GetCallback().pp_completion_callback())); | 506 callback.GetCallback().pp_completion_callback())); |
507 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result()); | 507 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result()); |
508 core_interface_->ReleaseResource(ws); | 508 core_interface_->ReleaseResource(ws); |
509 | 509 |
510 // Close with PP_VARTYPE_NULL and ongoing receive message. | 510 // Close with PP_VARTYPE_NULL and ongoing receive message. |
511 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 511 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
512 ASSERT_TRUE(ws); | 512 ASSERT_TRUE(ws); |
513 ASSERT_EQ(PP_OK, result); | 513 ASSERT_EQ(PP_OK, result); |
514 PP_Var receive_message_var; | 514 PP_Var receive_message_var; |
515 result = websocket_interface_->ReceiveMessage( | 515 result = websocket_interface_->ReceiveMessage( |
516 ws, &receive_message_var, | 516 ws, &receive_message_var, |
517 async_callback.GetCallback().pp_completion_callback()); | 517 async_callback.GetCallback().pp_completion_callback()); |
518 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 518 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
519 callback.WaitForResult(websocket_interface_->Close( | 519 callback.WaitForResult(websocket_interface_->Close( |
520 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(), | 520 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(), |
521 callback.GetCallback().pp_completion_callback())); | 521 callback.GetCallback().pp_completion_callback())); |
522 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result()); | 522 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result()); |
523 const char* send_message = "hi"; | 523 const char* send_message = "hi"; |
524 PP_Var send_message_var = CreateVarString(send_message); | 524 PP_Var send_message_var = CreateVarString(send_message); |
525 result = websocket_interface_->SendMessage(ws, send_message_var); | 525 result = websocket_interface_->SendMessage(ws, send_message_var); |
526 ReleaseVar(send_message_var); | 526 ReleaseVar(send_message_var); |
527 ASSERT_EQ(PP_OK, result); | 527 ASSERT_EQ(PP_OK, result); |
528 async_callback.WaitForResult(PP_OK_COMPLETIONPENDING); | 528 async_callback.WaitForResult(PP_OK_COMPLETIONPENDING); |
529 ASSERT_EQ(PP_OK, async_callback.result()); | 529 ASSERT_EQ(PP_OK, async_callback.result()); |
530 ASSERT_TRUE(AreEqualWithString(receive_message_var, send_message)); | 530 ASSERT_TRUE(AreEqualWithString(receive_message_var, send_message)); |
531 ReleaseVar(receive_message_var); | 531 ReleaseVar(receive_message_var); |
532 core_interface_->ReleaseResource(ws); | 532 core_interface_->ReleaseResource(ws); |
533 | 533 |
534 // Close twice. | 534 // Close twice. |
535 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 535 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
536 ASSERT_TRUE(ws); | 536 ASSERT_TRUE(ws); |
537 ASSERT_EQ(PP_OK, result); | 537 ASSERT_EQ(PP_OK, result); |
538 result = websocket_interface_->Close( | 538 result = websocket_interface_->Close( |
539 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 539 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
540 async_callback.GetCallback().pp_completion_callback()); | 540 async_callback.GetCallback().pp_completion_callback()); |
541 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 541 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
542 // Call another Close() before previous one is in progress. | 542 // Call another Close() before previous one is in progress. |
543 result = websocket_interface_->Close( | 543 result = websocket_interface_->Close( |
544 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 544 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
545 callback.GetCallback().pp_completion_callback()); | 545 callback.GetCallback().pp_completion_callback()); |
(...skipping 16 matching lines...) Expand all Loading... |
562 std::string TestWebSocket::TestValidClose() { | 562 std::string TestWebSocket::TestValidClose() { |
563 PP_Var reason = CreateVarString("close for test"); | 563 PP_Var reason = CreateVarString("close for test"); |
564 PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str()); | 564 PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str()); |
565 PP_Var protocols[] = { PP_MakeUndefined() }; | 565 PP_Var protocols[] = { PP_MakeUndefined() }; |
566 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 566 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
567 TestCompletionCallback another_callback( | 567 TestCompletionCallback another_callback( |
568 instance_->pp_instance(), callback_type()); | 568 instance_->pp_instance(), callback_type()); |
569 | 569 |
570 // Close. | 570 // Close. |
571 int32_t result; | 571 int32_t result; |
572 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 572 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
573 ASSERT_TRUE(ws); | 573 ASSERT_TRUE(ws); |
574 ASSERT_EQ(PP_OK, result); | 574 ASSERT_EQ(PP_OK, result); |
575 callback.WaitForResult(websocket_interface_->Close( | 575 callback.WaitForResult(websocket_interface_->Close( |
576 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 576 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
577 callback.GetCallback().pp_completion_callback())); | 577 callback.GetCallback().pp_completion_callback())); |
578 CHECK_CALLBACK_BEHAVIOR(callback); | 578 CHECK_CALLBACK_BEHAVIOR(callback); |
579 ASSERT_EQ(PP_OK, callback.result()); | 579 ASSERT_EQ(PP_OK, callback.result()); |
580 core_interface_->ReleaseResource(ws); | 580 core_interface_->ReleaseResource(ws); |
581 | 581 |
582 // Close without code and reason. | 582 // Close without code and reason. |
583 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 583 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
584 ASSERT_TRUE(ws); | 584 ASSERT_TRUE(ws); |
585 ASSERT_EQ(PP_OK, result); | 585 ASSERT_EQ(PP_OK, result); |
586 callback.WaitForResult(websocket_interface_->Close( | 586 callback.WaitForResult(websocket_interface_->Close( |
587 ws, PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED, reason, | 587 ws, PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED, reason, |
588 callback.GetCallback().pp_completion_callback())); | 588 callback.GetCallback().pp_completion_callback())); |
589 ASSERT_EQ(PP_OK, callback.result()); | 589 ASSERT_EQ(PP_OK, callback.result()); |
590 core_interface_->ReleaseResource(ws); | 590 core_interface_->ReleaseResource(ws); |
591 | 591 |
592 // Close with PP_VARTYPE_UNDEFINED. | 592 // Close with PP_VARTYPE_UNDEFINED. |
593 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 593 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
594 ASSERT_TRUE(ws); | 594 ASSERT_TRUE(ws); |
595 ASSERT_EQ(PP_OK, result); | 595 ASSERT_EQ(PP_OK, result); |
596 callback.WaitForResult(websocket_interface_->Close( | 596 callback.WaitForResult(websocket_interface_->Close( |
597 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | 597 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), |
598 callback.GetCallback().pp_completion_callback())); | 598 callback.GetCallback().pp_completion_callback())); |
599 CHECK_CALLBACK_BEHAVIOR(callback); | 599 CHECK_CALLBACK_BEHAVIOR(callback); |
600 ASSERT_EQ(PP_OK, callback.result()); | 600 ASSERT_EQ(PP_OK, callback.result()); |
601 core_interface_->ReleaseResource(ws); | 601 core_interface_->ReleaseResource(ws); |
602 | 602 |
603 // Close in connecting. | 603 // Close in connecting. |
604 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done | 604 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done |
605 // successfully. | 605 // successfully. |
606 ws = websocket_interface_->Create(instance_->pp_instance()); | 606 ws = websocket_interface_->Create(instance_->pp_instance()); |
607 result = websocket_interface_->Connect( | 607 result = websocket_interface_->Connect( |
608 ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback()); | 608 ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback()); |
609 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 609 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
610 result = websocket_interface_->Close( | 610 result = websocket_interface_->Close( |
611 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 611 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
612 another_callback.GetCallback().pp_completion_callback()); | 612 another_callback.GetCallback().pp_completion_callback()); |
613 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 613 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
614 callback.WaitForResult(PP_OK_COMPLETIONPENDING); | 614 callback.WaitForResult(PP_OK_COMPLETIONPENDING); |
615 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); | 615 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); |
616 another_callback.WaitForResult(PP_OK_COMPLETIONPENDING); | 616 another_callback.WaitForResult(PP_OK_COMPLETIONPENDING); |
617 ASSERT_EQ(PP_OK, another_callback.result()); | 617 ASSERT_EQ(PP_OK, another_callback.result()); |
618 core_interface_->ReleaseResource(ws); | 618 core_interface_->ReleaseResource(ws); |
619 | 619 |
620 // Close in closing. | 620 // Close in closing. |
621 // The first close will be done successfully, then the second one failed with | 621 // The first close will be done successfully, then the second one failed with |
622 // with PP_ERROR_INPROGRESS immediately. | 622 // with PP_ERROR_INPROGRESS immediately. |
623 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 623 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
624 ASSERT_TRUE(ws); | 624 ASSERT_TRUE(ws); |
625 ASSERT_EQ(PP_OK, result); | 625 ASSERT_EQ(PP_OK, result); |
626 result = websocket_interface_->Close( | 626 result = websocket_interface_->Close( |
627 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 627 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
628 callback.GetCallback().pp_completion_callback()); | 628 callback.GetCallback().pp_completion_callback()); |
629 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 629 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
630 result = websocket_interface_->Close( | 630 result = websocket_interface_->Close( |
631 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 631 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
632 another_callback.GetCallback().pp_completion_callback()); | 632 another_callback.GetCallback().pp_completion_callback()); |
633 ASSERT_EQ(PP_ERROR_INPROGRESS, result); | 633 ASSERT_EQ(PP_ERROR_INPROGRESS, result); |
634 callback.WaitForResult(PP_OK_COMPLETIONPENDING); | 634 callback.WaitForResult(PP_OK_COMPLETIONPENDING); |
635 ASSERT_EQ(PP_OK, callback.result()); | 635 ASSERT_EQ(PP_OK, callback.result()); |
636 core_interface_->ReleaseResource(ws); | 636 core_interface_->ReleaseResource(ws); |
637 | 637 |
638 // Close with ongoing receive message. | 638 // Close with ongoing receive message. |
639 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 639 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
640 ASSERT_TRUE(ws); | 640 ASSERT_TRUE(ws); |
641 ASSERT_EQ(PP_OK, result); | 641 ASSERT_EQ(PP_OK, result); |
642 PP_Var receive_message_var; | 642 PP_Var receive_message_var; |
643 result = websocket_interface_->ReceiveMessage( | 643 result = websocket_interface_->ReceiveMessage( |
644 ws, &receive_message_var, | 644 ws, &receive_message_var, |
645 callback.GetCallback().pp_completion_callback()); | 645 callback.GetCallback().pp_completion_callback()); |
646 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 646 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
647 result = websocket_interface_->Close( | 647 result = websocket_interface_->Close( |
648 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 648 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
649 another_callback.GetCallback().pp_completion_callback()); | 649 another_callback.GetCallback().pp_completion_callback()); |
650 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 650 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
651 callback.WaitForResult(PP_OK_COMPLETIONPENDING); | 651 callback.WaitForResult(PP_OK_COMPLETIONPENDING); |
652 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); | 652 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); |
653 another_callback.WaitForResult(PP_OK_COMPLETIONPENDING); | 653 another_callback.WaitForResult(PP_OK_COMPLETIONPENDING); |
654 ASSERT_EQ(PP_OK, another_callback.result()); | 654 ASSERT_EQ(PP_OK, another_callback.result()); |
655 core_interface_->ReleaseResource(ws); | 655 core_interface_->ReleaseResource(ws); |
656 | 656 |
657 // Close with PP_VARTYPE_UNDEFINED and ongoing receive message. | 657 // Close with PP_VARTYPE_UNDEFINED and ongoing receive message. |
658 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 658 ws = Connect(GetFullURL(kEchoServerURL), &result, std::string()); |
659 ASSERT_TRUE(ws); | 659 ASSERT_TRUE(ws); |
660 ASSERT_EQ(PP_OK, result); | 660 ASSERT_EQ(PP_OK, result); |
661 result = websocket_interface_->ReceiveMessage( | 661 result = websocket_interface_->ReceiveMessage( |
662 ws, &receive_message_var, | 662 ws, &receive_message_var, |
663 callback.GetCallback().pp_completion_callback()); | 663 callback.GetCallback().pp_completion_callback()); |
664 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 664 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
665 result = websocket_interface_->Close( | 665 result = websocket_interface_->Close( |
666 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | 666 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), |
667 another_callback.GetCallback().pp_completion_callback()); | 667 another_callback.GetCallback().pp_completion_callback()); |
668 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 668 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
669 callback.WaitForResult(PP_OK_COMPLETIONPENDING); | 669 callback.WaitForResult(PP_OK_COMPLETIONPENDING); |
670 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); | 670 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); |
671 another_callback.WaitForResult(PP_OK_COMPLETIONPENDING); | 671 another_callback.WaitForResult(PP_OK_COMPLETIONPENDING); |
672 ASSERT_EQ(PP_OK, another_callback.result()); | 672 ASSERT_EQ(PP_OK, another_callback.result()); |
673 core_interface_->ReleaseResource(ws); | 673 core_interface_->ReleaseResource(ws); |
674 | 674 |
675 // Server initiated closing handshake. | 675 // Server initiated closing handshake. |
676 ws = Connect(GetFullURL(kCloseWithCodeAndReasonServerURL), &result, ""); | 676 ws = Connect( |
| 677 GetFullURL(kCloseWithCodeAndReasonServerURL), &result, std::string()); |
677 ASSERT_TRUE(ws); | 678 ASSERT_TRUE(ws); |
678 ASSERT_EQ(PP_OK, result); | 679 ASSERT_EQ(PP_OK, result); |
679 // Text messsage "1000 bye" requests the server to initiate closing handshake | 680 // Text messsage "1000 bye" requests the server to initiate closing handshake |
680 // with code being 1000 and reason being "bye". | 681 // with code being 1000 and reason being "bye". |
681 PP_Var close_request_var = CreateVarString("1000 bye"); | 682 PP_Var close_request_var = CreateVarString("1000 bye"); |
682 result = websocket_interface_->SendMessage(ws, close_request_var); | 683 result = websocket_interface_->SendMessage(ws, close_request_var); |
683 ReleaseVar(close_request_var); | 684 ReleaseVar(close_request_var); |
684 callback.WaitForResult(websocket_interface_->ReceiveMessage( | 685 callback.WaitForResult(websocket_interface_->ReceiveMessage( |
685 ws, &receive_message_var, | 686 ws, &receive_message_var, |
686 callback.GetCallback().pp_completion_callback())); | 687 callback.GetCallback().pp_completion_callback())); |
(...skipping 26 matching lines...) Expand all Loading... |
713 ReleaseVar(protocol); | 714 ReleaseVar(protocol); |
714 core_interface_->ReleaseResource(ws); | 715 core_interface_->ReleaseResource(ws); |
715 } | 716 } |
716 | 717 |
717 PASS(); | 718 PASS(); |
718 } | 719 } |
719 | 720 |
720 std::string TestWebSocket::TestTextSendReceive() { | 721 std::string TestWebSocket::TestTextSendReceive() { |
721 // Connect to test echo server. | 722 // Connect to test echo server. |
722 int32_t connect_result; | 723 int32_t connect_result; |
723 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, ""); | 724 PP_Resource ws = |
| 725 Connect(GetFullURL(kEchoServerURL), &connect_result, std::string()); |
724 ASSERT_TRUE(ws); | 726 ASSERT_TRUE(ws); |
725 ASSERT_EQ(PP_OK, connect_result); | 727 ASSERT_EQ(PP_OK, connect_result); |
726 | 728 |
727 // Send 'hello pepper' text message. | 729 // Send 'hello pepper' text message. |
728 const char* message = "hello pepper"; | 730 const char* message = "hello pepper"; |
729 PP_Var message_var = CreateVarString(message); | 731 PP_Var message_var = CreateVarString(message); |
730 int32_t result = websocket_interface_->SendMessage(ws, message_var); | 732 int32_t result = websocket_interface_->SendMessage(ws, message_var); |
731 ReleaseVar(message_var); | 733 ReleaseVar(message_var); |
732 ASSERT_EQ(PP_OK, result); | 734 ASSERT_EQ(PP_OK, result); |
733 | 735 |
734 // Receive echoed 'hello pepper'. | 736 // Receive echoed 'hello pepper'. |
735 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 737 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
736 PP_Var received_message; | 738 PP_Var received_message; |
737 callback.WaitForResult(websocket_interface_->ReceiveMessage( | 739 callback.WaitForResult(websocket_interface_->ReceiveMessage( |
738 ws, &received_message, callback.GetCallback().pp_completion_callback())); | 740 ws, &received_message, callback.GetCallback().pp_completion_callback())); |
739 ASSERT_EQ(PP_OK, callback.result()); | 741 ASSERT_EQ(PP_OK, callback.result()); |
740 ASSERT_TRUE(AreEqualWithString(received_message, message)); | 742 ASSERT_TRUE(AreEqualWithString(received_message, message)); |
741 ReleaseVar(received_message); | 743 ReleaseVar(received_message); |
742 core_interface_->ReleaseResource(ws); | 744 core_interface_->ReleaseResource(ws); |
743 | 745 |
744 PASS(); | 746 PASS(); |
745 } | 747 } |
746 | 748 |
747 std::string TestWebSocket::TestBinarySendReceive() { | 749 std::string TestWebSocket::TestBinarySendReceive() { |
748 // Connect to test echo server. | 750 // Connect to test echo server. |
749 int32_t connect_result; | 751 int32_t connect_result; |
750 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, ""); | 752 PP_Resource ws = |
| 753 Connect(GetFullURL(kEchoServerURL), &connect_result, std::string()); |
751 ASSERT_TRUE(ws); | 754 ASSERT_TRUE(ws); |
752 ASSERT_EQ(PP_OK, connect_result); | 755 ASSERT_EQ(PP_OK, connect_result); |
753 | 756 |
754 // Send binary message. | 757 // Send binary message. |
755 std::vector<uint8_t> binary(256); | 758 std::vector<uint8_t> binary(256); |
756 for (uint32_t i = 0; i < binary.size(); ++i) | 759 for (uint32_t i = 0; i < binary.size(); ++i) |
757 binary[i] = i; | 760 binary[i] = i; |
758 PP_Var message_var = CreateVarBinary(binary); | 761 PP_Var message_var = CreateVarBinary(binary); |
759 int32_t result = websocket_interface_->SendMessage(ws, message_var); | 762 int32_t result = websocket_interface_->SendMessage(ws, message_var); |
760 ReleaseVar(message_var); | 763 ReleaseVar(message_var); |
761 ASSERT_EQ(PP_OK, result); | 764 ASSERT_EQ(PP_OK, result); |
762 | 765 |
763 // Receive echoed binary. | 766 // Receive echoed binary. |
764 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 767 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
765 PP_Var received_message; | 768 PP_Var received_message; |
766 callback.WaitForResult(websocket_interface_->ReceiveMessage( | 769 callback.WaitForResult(websocket_interface_->ReceiveMessage( |
767 ws, &received_message, callback.GetCallback().pp_completion_callback())); | 770 ws, &received_message, callback.GetCallback().pp_completion_callback())); |
768 ASSERT_EQ(PP_OK, callback.result()); | 771 ASSERT_EQ(PP_OK, callback.result()); |
769 ASSERT_TRUE(AreEqualWithBinary(received_message, binary)); | 772 ASSERT_TRUE(AreEqualWithBinary(received_message, binary)); |
770 ReleaseVar(received_message); | 773 ReleaseVar(received_message); |
771 core_interface_->ReleaseResource(ws); | 774 core_interface_->ReleaseResource(ws); |
772 | 775 |
773 PASS(); | 776 PASS(); |
774 } | 777 } |
775 | 778 |
776 std::string TestWebSocket::TestStressedSendReceive() { | 779 std::string TestWebSocket::TestStressedSendReceive() { |
777 // Connect to test echo server. | 780 // Connect to test echo server. |
778 int32_t connect_result; | 781 int32_t connect_result; |
779 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, ""); | 782 PP_Resource ws = |
| 783 Connect(GetFullURL(kEchoServerURL), &connect_result, std::string()); |
780 ASSERT_TRUE(ws); | 784 ASSERT_TRUE(ws); |
781 ASSERT_EQ(PP_OK, connect_result); | 785 ASSERT_EQ(PP_OK, connect_result); |
782 | 786 |
783 // Prepare PP_Var objects to send. | 787 // Prepare PP_Var objects to send. |
784 const char* text = "hello pepper"; | 788 const char* text = "hello pepper"; |
785 PP_Var text_var = CreateVarString(text); | 789 PP_Var text_var = CreateVarString(text); |
786 std::vector<uint8_t> binary(256); | 790 std::vector<uint8_t> binary(256); |
787 for (uint32_t i = 0; i < binary.size(); ++i) | 791 for (uint32_t i = 0; i < binary.size(); ++i) |
788 binary[i] = i; | 792 binary[i] = i; |
789 PP_Var binary_var = CreateVarBinary(binary); | 793 PP_Var binary_var = CreateVarBinary(binary); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 ReleaseVar(received_message); | 833 ReleaseVar(received_message); |
830 } | 834 } |
831 core_interface_->ReleaseResource(ws); | 835 core_interface_->ReleaseResource(ws); |
832 | 836 |
833 PASS(); | 837 PASS(); |
834 } | 838 } |
835 | 839 |
836 std::string TestWebSocket::TestBufferedAmount() { | 840 std::string TestWebSocket::TestBufferedAmount() { |
837 // Connect to test echo server. | 841 // Connect to test echo server. |
838 int32_t connect_result; | 842 int32_t connect_result; |
839 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, ""); | 843 PP_Resource ws = |
| 844 Connect(GetFullURL(kEchoServerURL), &connect_result, std::string()); |
840 ASSERT_TRUE(ws); | 845 ASSERT_TRUE(ws); |
841 ASSERT_EQ(PP_OK, connect_result); | 846 ASSERT_EQ(PP_OK, connect_result); |
842 | 847 |
843 // Prepare a large message that is not aligned with the internal buffer | 848 // Prepare a large message that is not aligned with the internal buffer |
844 // sizes. | 849 // sizes. |
845 std::string message(8193, 'x'); | 850 std::string message(8193, 'x'); |
846 PP_Var message_var = CreateVarString(message); | 851 PP_Var message_var = CreateVarString(message); |
847 | 852 |
848 uint64_t buffered_amount = 0; | 853 uint64_t buffered_amount = 0; |
849 int32_t result; | 854 int32_t result; |
(...skipping 19 matching lines...) Expand all Loading... |
869 | 874 |
870 callback.WaitForResult(result); | 875 callback.WaitForResult(result); |
871 ASSERT_EQ(PP_OK, callback.result()); | 876 ASSERT_EQ(PP_OK, callback.result()); |
872 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, | 877 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, |
873 websocket_interface_->GetReadyState(ws)); | 878 websocket_interface_->GetReadyState(ws)); |
874 | 879 |
875 uint64_t base_buffered_amount = websocket_interface_->GetBufferedAmount(ws); | 880 uint64_t base_buffered_amount = websocket_interface_->GetBufferedAmount(ws); |
876 | 881 |
877 // After connection closure, all sending requests fail and just increase | 882 // After connection closure, all sending requests fail and just increase |
878 // the bufferedAmount property. | 883 // the bufferedAmount property. |
879 PP_Var empty_string = CreateVarString(""); | 884 PP_Var empty_string = CreateVarString(std::string()); |
880 result = websocket_interface_->SendMessage(ws, empty_string); | 885 result = websocket_interface_->SendMessage(ws, empty_string); |
881 ASSERT_EQ(PP_ERROR_FAILED, result); | 886 ASSERT_EQ(PP_ERROR_FAILED, result); |
882 buffered_amount = websocket_interface_->GetBufferedAmount(ws); | 887 buffered_amount = websocket_interface_->GetBufferedAmount(ws); |
883 ASSERT_EQ(base_buffered_amount + kMessageFrameOverhead, buffered_amount); | 888 ASSERT_EQ(base_buffered_amount + kMessageFrameOverhead, buffered_amount); |
884 base_buffered_amount = buffered_amount; | 889 base_buffered_amount = buffered_amount; |
885 | 890 |
886 result = websocket_interface_->SendMessage(ws, reason); | 891 result = websocket_interface_->SendMessage(ws, reason); |
887 ASSERT_EQ(PP_ERROR_FAILED, result); | 892 ASSERT_EQ(PP_ERROR_FAILED, result); |
888 buffered_amount = websocket_interface_->GetBufferedAmount(ws); | 893 buffered_amount = websocket_interface_->GetBufferedAmount(ws); |
889 uint64_t reason_frame_size = kMessageFrameOverhead + reason_str.length(); | 894 uint64_t reason_frame_size = kMessageFrameOverhead + reason_str.length(); |
(...skipping 22 matching lines...) Expand all Loading... |
912 instance_->pp_instance(), callback_type()); | 917 instance_->pp_instance(), callback_type()); |
913 int32_t result = websocket_interface_->Connect( | 918 int32_t result = websocket_interface_->Connect( |
914 ws, url_var, NULL, 0, | 919 ws, url_var, NULL, 0, |
915 connect_callback.GetCallback().pp_completion_callback()); | 920 connect_callback.GetCallback().pp_completion_callback()); |
916 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 921 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
917 core_interface_->ReleaseResource(ws); | 922 core_interface_->ReleaseResource(ws); |
918 connect_callback.WaitForResult(result); | 923 connect_callback.WaitForResult(result); |
919 ASSERT_EQ(PP_ERROR_ABORTED, connect_callback.result()); | 924 ASSERT_EQ(PP_ERROR_ABORTED, connect_callback.result()); |
920 | 925 |
921 // Test the behavior for Close(). | 926 // Test the behavior for Close(). |
922 ws = Connect(url, &result, ""); | 927 ws = Connect(url, &result, std::string()); |
923 ASSERT_TRUE(ws); | 928 ASSERT_TRUE(ws); |
924 ASSERT_EQ(PP_OK, result); | 929 ASSERT_EQ(PP_OK, result); |
925 PP_Var reason_var = CreateVarString("abort"); | 930 PP_Var reason_var = CreateVarString("abort"); |
926 TestCompletionCallback close_callback( | 931 TestCompletionCallback close_callback( |
927 instance_->pp_instance(), callback_type()); | 932 instance_->pp_instance(), callback_type()); |
928 result = websocket_interface_->Close( | 933 result = websocket_interface_->Close( |
929 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason_var, | 934 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason_var, |
930 close_callback.GetCallback().pp_completion_callback()); | 935 close_callback.GetCallback().pp_completion_callback()); |
931 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 936 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
932 core_interface_->ReleaseResource(ws); | 937 core_interface_->ReleaseResource(ws); |
933 close_callback.WaitForResult(result); | 938 close_callback.WaitForResult(result); |
934 ASSERT_EQ(PP_ERROR_ABORTED, close_callback.result()); | 939 ASSERT_EQ(PP_ERROR_ABORTED, close_callback.result()); |
935 ReleaseVar(reason_var); | 940 ReleaseVar(reason_var); |
936 | 941 |
937 // Test the behavior for ReceiveMessage(). | 942 // Test the behavior for ReceiveMessage(). |
938 // Make sure the simplest case to wait for data which never arrives, here. | 943 // Make sure the simplest case to wait for data which never arrives, here. |
939 ws = Connect(url, &result, ""); | 944 ws = Connect(url, &result, std::string()); |
940 ASSERT_TRUE(ws); | 945 ASSERT_TRUE(ws); |
941 ASSERT_EQ(PP_OK, result); | 946 ASSERT_EQ(PP_OK, result); |
942 PP_Var receive_var; | 947 PP_Var receive_var; |
943 TestCompletionCallback receive_callback( | 948 TestCompletionCallback receive_callback( |
944 instance_->pp_instance(), callback_type()); | 949 instance_->pp_instance(), callback_type()); |
945 result = websocket_interface_->ReceiveMessage( | 950 result = websocket_interface_->ReceiveMessage( |
946 ws, &receive_var, | 951 ws, &receive_var, |
947 receive_callback.GetCallback().pp_completion_callback()); | 952 receive_callback.GetCallback().pp_completion_callback()); |
948 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 953 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
949 core_interface_->ReleaseResource(ws); | 954 core_interface_->ReleaseResource(ws); |
950 receive_callback.WaitForResult(result); | 955 receive_callback.WaitForResult(result); |
951 ASSERT_EQ(PP_ERROR_ABORTED, receive_callback.result()); | 956 ASSERT_EQ(PP_ERROR_ABORTED, receive_callback.result()); |
952 | 957 |
953 // Release the resource in the aborting receive completion callback which is | 958 // Release the resource in the aborting receive completion callback which is |
954 // introduced by calling Close(). | 959 // introduced by calling Close(). |
955 ws = Connect(url, &result, ""); | 960 ws = Connect(url, &result, std::string()); |
956 ASSERT_TRUE(ws); | 961 ASSERT_TRUE(ws); |
957 ASSERT_EQ(PP_OK, result); | 962 ASSERT_EQ(PP_OK, result); |
958 result = websocket_interface_->ReceiveMessage( | 963 result = websocket_interface_->ReceiveMessage( |
959 ws, &receive_var, | 964 ws, &receive_var, |
960 receive_callback.GetCallback().pp_completion_callback()); | 965 receive_callback.GetCallback().pp_completion_callback()); |
961 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 966 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
962 ReleaseResourceDelegate receive_delegate(core_interface_, ws); | 967 ReleaseResourceDelegate receive_delegate(core_interface_, ws); |
963 receive_callback.SetDelegate(&receive_delegate); | 968 receive_callback.SetDelegate(&receive_delegate); |
964 result = websocket_interface_->Close( | 969 result = websocket_interface_->Close( |
965 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | 970 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), |
(...skipping 13 matching lines...) Expand all Loading... |
979 | 984 |
980 std::string TestWebSocket::TestAbortSendMessageCall() { | 985 std::string TestWebSocket::TestAbortSendMessageCall() { |
981 // Test the behavior for SendMessage(). | 986 // Test the behavior for SendMessage(). |
982 // This function doesn't require a callback, but operation will be done | 987 // This function doesn't require a callback, but operation will be done |
983 // asynchronously in WebKit and browser process. | 988 // asynchronously in WebKit and browser process. |
984 std::vector<uint8_t> large_binary(65 * 1024); | 989 std::vector<uint8_t> large_binary(65 * 1024); |
985 PP_Var large_var = CreateVarBinary(large_binary); | 990 PP_Var large_var = CreateVarBinary(large_binary); |
986 | 991 |
987 int32_t result; | 992 int32_t result; |
988 std::string url = GetFullURL(kEchoServerURL); | 993 std::string url = GetFullURL(kEchoServerURL); |
989 PP_Resource ws = Connect(url, &result, ""); | 994 PP_Resource ws = Connect(url, &result, std::string()); |
990 ASSERT_TRUE(ws); | 995 ASSERT_TRUE(ws); |
991 ASSERT_EQ(PP_OK, result); | 996 ASSERT_EQ(PP_OK, result); |
992 result = websocket_interface_->SendMessage(ws, large_var); | 997 result = websocket_interface_->SendMessage(ws, large_var); |
993 ASSERT_EQ(PP_OK, result); | 998 ASSERT_EQ(PP_OK, result); |
994 core_interface_->ReleaseResource(ws); | 999 core_interface_->ReleaseResource(ws); |
995 ReleaseVar(large_var); | 1000 ReleaseVar(large_var); |
996 | 1001 |
997 PASS(); | 1002 PASS(); |
998 } | 1003 } |
999 | 1004 |
1000 std::string TestWebSocket::TestAbortCloseCall() { | 1005 std::string TestWebSocket::TestAbortCloseCall() { |
1001 // Release the resource in the close completion callback. | 1006 // Release the resource in the close completion callback. |
1002 int32_t result; | 1007 int32_t result; |
1003 std::string url = GetFullURL(kEchoServerURL); | 1008 std::string url = GetFullURL(kEchoServerURL); |
1004 PP_Resource ws = Connect(url, &result, ""); | 1009 PP_Resource ws = Connect(url, &result, std::string()); |
1005 ASSERT_TRUE(ws); | 1010 ASSERT_TRUE(ws); |
1006 ASSERT_EQ(PP_OK, result); | 1011 ASSERT_EQ(PP_OK, result); |
1007 TestCompletionCallback close_callback( | 1012 TestCompletionCallback close_callback( |
1008 instance_->pp_instance(), callback_type()); | 1013 instance_->pp_instance(), callback_type()); |
1009 result = websocket_interface_->Close( | 1014 result = websocket_interface_->Close( |
1010 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | 1015 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), |
1011 close_callback.GetCallback().pp_completion_callback()); | 1016 close_callback.GetCallback().pp_completion_callback()); |
1012 ReleaseResourceDelegate close_delegate(core_interface_, ws); | 1017 ReleaseResourceDelegate close_delegate(core_interface_, ws); |
1013 close_callback.SetDelegate(&close_delegate); | 1018 close_callback.SetDelegate(&close_delegate); |
1014 close_callback.WaitForResult(result); | 1019 close_callback.WaitForResult(result); |
(...skipping 12 matching lines...) Expand all Loading... |
1027 | 1032 |
1028 std::string url = GetFullURL(kEchoServerURL); | 1033 std::string url = GetFullURL(kEchoServerURL); |
1029 int32_t result; | 1034 int32_t result; |
1030 PP_Resource ws; | 1035 PP_Resource ws; |
1031 | 1036 |
1032 // Each trial sends |trial_count| + 1 messages and receives just |trial| | 1037 // Each trial sends |trial_count| + 1 messages and receives just |trial| |
1033 // number of message(s) before releasing the WebSocket. The WebSocket is | 1038 // number of message(s) before releasing the WebSocket. The WebSocket is |
1034 // released while the next message is going to be received. | 1039 // released while the next message is going to be received. |
1035 const int trial_count = 8; | 1040 const int trial_count = 8; |
1036 for (int trial = 1; trial <= trial_count; trial++) { | 1041 for (int trial = 1; trial <= trial_count; trial++) { |
1037 ws = Connect(url, &result, ""); | 1042 ws = Connect(url, &result, std::string()); |
1038 ASSERT_TRUE(ws); | 1043 ASSERT_TRUE(ws); |
1039 ASSERT_EQ(PP_OK, result); | 1044 ASSERT_EQ(PP_OK, result); |
1040 for (int i = 0; i <= trial_count; ++i) { | 1045 for (int i = 0; i <= trial_count; ++i) { |
1041 result = websocket_interface_->SendMessage(ws, text_var); | 1046 result = websocket_interface_->SendMessage(ws, text_var); |
1042 ASSERT_EQ(PP_OK, result); | 1047 ASSERT_EQ(PP_OK, result); |
1043 } | 1048 } |
1044 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 1049 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
1045 PP_Var var; | 1050 PP_Var var; |
1046 for (int i = 0; i < trial; ++i) { | 1051 for (int i = 0; i < trial; ++i) { |
1047 callback.WaitForResult(websocket_interface_->ReceiveMessage( | 1052 callback.WaitForResult(websocket_interface_->ReceiveMessage( |
1048 ws, &var, callback.GetCallback().pp_completion_callback())); | 1053 ws, &var, callback.GetCallback().pp_completion_callback())); |
1049 ASSERT_EQ(PP_OK, callback.result()); | 1054 ASSERT_EQ(PP_OK, callback.result()); |
1050 ASSERT_TRUE(AreEqualWithString(var, text)); | 1055 ASSERT_TRUE(AreEqualWithString(var, text)); |
1051 ReleaseVar(var); | 1056 ReleaseVar(var); |
1052 } | 1057 } |
1053 result = websocket_interface_->ReceiveMessage( | 1058 result = websocket_interface_->ReceiveMessage( |
1054 ws, &var, callback.GetCallback().pp_completion_callback()); | 1059 ws, &var, callback.GetCallback().pp_completion_callback()); |
1055 core_interface_->ReleaseResource(ws); | 1060 core_interface_->ReleaseResource(ws); |
1056 if (result != PP_OK) { | 1061 if (result != PP_OK) { |
1057 callback.WaitForResult(result); | 1062 callback.WaitForResult(result); |
1058 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); | 1063 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); |
1059 } | 1064 } |
1060 } | 1065 } |
1061 // Same test, but the last receiving message is large message over 64KiB. | 1066 // Same test, but the last receiving message is large message over 64KiB. |
1062 for (int trial = 1; trial <= trial_count; trial++) { | 1067 for (int trial = 1; trial <= trial_count; trial++) { |
1063 ws = Connect(url, &result, ""); | 1068 ws = Connect(url, &result, std::string()); |
1064 ASSERT_TRUE(ws); | 1069 ASSERT_TRUE(ws); |
1065 ASSERT_EQ(PP_OK, result); | 1070 ASSERT_EQ(PP_OK, result); |
1066 for (int i = 0; i <= trial_count; ++i) { | 1071 for (int i = 0; i <= trial_count; ++i) { |
1067 if (i == trial) | 1072 if (i == trial) |
1068 result = websocket_interface_->SendMessage(ws, large_var); | 1073 result = websocket_interface_->SendMessage(ws, large_var); |
1069 else | 1074 else |
1070 result = websocket_interface_->SendMessage(ws, text_var); | 1075 result = websocket_interface_->SendMessage(ws, text_var); |
1071 ASSERT_EQ(PP_OK, result); | 1076 ASSERT_EQ(PP_OK, result); |
1072 } | 1077 } |
1073 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 1078 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
(...skipping 21 matching lines...) Expand all Loading... |
1095 } | 1100 } |
1096 | 1101 |
1097 std::string TestWebSocket::TestCcInterfaces() { | 1102 std::string TestWebSocket::TestCcInterfaces() { |
1098 // C++ bindings is simple straightforward, then just verifies interfaces work | 1103 // C++ bindings is simple straightforward, then just verifies interfaces work |
1099 // as a interface bridge fine. | 1104 // as a interface bridge fine. |
1100 pp::WebSocket ws(instance_); | 1105 pp::WebSocket ws(instance_); |
1101 | 1106 |
1102 // Check uninitialized properties access. | 1107 // Check uninitialized properties access. |
1103 ASSERT_EQ(0, ws.GetBufferedAmount()); | 1108 ASSERT_EQ(0, ws.GetBufferedAmount()); |
1104 ASSERT_EQ(0, ws.GetCloseCode()); | 1109 ASSERT_EQ(0, ws.GetCloseCode()); |
1105 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), "")); | 1110 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), std::string())); |
1106 ASSERT_EQ(false, ws.GetCloseWasClean()); | 1111 ASSERT_EQ(false, ws.GetCloseWasClean()); |
1107 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); | 1112 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), std::string())); |
1108 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); | 1113 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), std::string())); |
1109 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ws.GetReadyState()); | 1114 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ws.GetReadyState()); |
1110 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), "")); | 1115 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), std::string())); |
1111 | 1116 |
1112 // Check communication interfaces (connect, send, receive, and close). | 1117 // Check communication interfaces (connect, send, receive, and close). |
1113 TestCompletionCallback connect_callback( | 1118 TestCompletionCallback connect_callback( |
1114 instance_->pp_instance(), callback_type()); | 1119 instance_->pp_instance(), callback_type()); |
1115 connect_callback.WaitForResult(ws.Connect( | 1120 connect_callback.WaitForResult(ws.Connect( |
1116 pp::Var(GetFullURL(kCloseServerURL)), NULL, 0U, | 1121 pp::Var(GetFullURL(kCloseServerURL)), NULL, 0U, |
1117 connect_callback.GetCallback())); | 1122 connect_callback.GetCallback())); |
1118 CHECK_CALLBACK_BEHAVIOR(connect_callback); | 1123 CHECK_CALLBACK_BEHAVIOR(connect_callback); |
1119 ASSERT_EQ(PP_OK, connect_callback.result()); | 1124 ASSERT_EQ(PP_OK, connect_callback.result()); |
1120 | 1125 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 close_callback.GetCallback())); | 1161 close_callback.GetCallback())); |
1157 CHECK_CALLBACK_BEHAVIOR(close_callback); | 1162 CHECK_CALLBACK_BEHAVIOR(close_callback); |
1158 ASSERT_EQ(PP_OK, close_callback.result()); | 1163 ASSERT_EQ(PP_OK, close_callback.result()); |
1159 | 1164 |
1160 // Check initialized properties access. | 1165 // Check initialized properties access. |
1161 ASSERT_EQ(0, ws.GetBufferedAmount()); | 1166 ASSERT_EQ(0, ws.GetBufferedAmount()); |
1162 ASSERT_EQ(PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, ws.GetCloseCode()); | 1167 ASSERT_EQ(PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, ws.GetCloseCode()); |
1163 ASSERT_TRUE( | 1168 ASSERT_TRUE( |
1164 AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); | 1169 AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); |
1165 ASSERT_EQ(true, ws.GetCloseWasClean()); | 1170 ASSERT_EQ(true, ws.GetCloseWasClean()); |
1166 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); | 1171 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), std::string())); |
1167 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState()); | 1172 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState()); |
1168 ASSERT_TRUE(AreEqualWithString( | 1173 ASSERT_TRUE(AreEqualWithString( |
1169 ws.GetURL().pp_var(), GetFullURL(kCloseServerURL).c_str())); | 1174 ws.GetURL().pp_var(), GetFullURL(kCloseServerURL).c_str())); |
1170 | 1175 |
1171 PASS(); | 1176 PASS(); |
1172 } | 1177 } |
1173 | 1178 |
1174 std::string TestWebSocket::TestUtilityInvalidConnect() { | 1179 std::string TestWebSocket::TestUtilityInvalidConnect() { |
1175 const pp::Var protocols[] = { pp::Var() }; | 1180 const pp::Var protocols[] = { pp::Var() }; |
1176 | 1181 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 std::string TestWebSocket::TestUtilityValidConnect() { | 1266 std::string TestWebSocket::TestUtilityValidConnect() { |
1262 const pp::Var protocols[] = { pp::Var() }; | 1267 const pp::Var protocols[] = { pp::Var() }; |
1263 TestWebSocketAPI websocket(instance_); | 1268 TestWebSocketAPI websocket(instance_); |
1264 int32_t result = websocket.Connect( | 1269 int32_t result = websocket.Connect( |
1265 pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); | 1270 pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); |
1266 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 1271 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
1267 websocket.WaitForConnected(); | 1272 websocket.WaitForConnected(); |
1268 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); | 1273 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); |
1269 ASSERT_EQ(1U, events.size()); | 1274 ASSERT_EQ(1U, events.size()); |
1270 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); | 1275 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); |
1271 ASSERT_TRUE(AreEqualWithString(websocket.GetExtensions().pp_var(), "")); | 1276 ASSERT_TRUE( |
| 1277 AreEqualWithString(websocket.GetExtensions().pp_var(), std::string())); |
1272 | 1278 |
1273 PASS(); | 1279 PASS(); |
1274 } | 1280 } |
1275 | 1281 |
1276 std::string TestWebSocket::TestUtilityInvalidClose() { | 1282 std::string TestWebSocket::TestUtilityInvalidClose() { |
1277 const pp::Var reason = pp::Var(std::string("close for test")); | 1283 const pp::Var reason = pp::Var(std::string("close for test")); |
1278 | 1284 |
1279 // Close before connect. | 1285 // Close before connect. |
1280 { | 1286 { |
1281 TestWebSocketAPI websocket(instance_); | 1287 TestWebSocketAPI websocket(instance_); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason)); | 1495 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason)); |
1490 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, websocket.GetReadyState()); | 1496 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, websocket.GetReadyState()); |
1491 websocket.WaitForClosed(); | 1497 websocket.WaitForClosed(); |
1492 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, websocket.GetReadyState()); | 1498 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, websocket.GetReadyState()); |
1493 | 1499 |
1494 uint64_t base_buffered_amount = websocket.GetBufferedAmount(); | 1500 uint64_t base_buffered_amount = websocket.GetBufferedAmount(); |
1495 size_t events_on_closed = websocket.GetSeenEvents().size(); | 1501 size_t events_on_closed = websocket.GetSeenEvents().size(); |
1496 | 1502 |
1497 // After connection closure, all sending requests fail and just increase | 1503 // After connection closure, all sending requests fail and just increase |
1498 // the bufferedAmount property. | 1504 // the bufferedAmount property. |
1499 result = websocket.Send(pp::Var(std::string(""))); | 1505 result = websocket.Send(pp::Var(std::string())); |
1500 ASSERT_EQ(PP_ERROR_FAILED, result); | 1506 ASSERT_EQ(PP_ERROR_FAILED, result); |
1501 buffered_amount = websocket.GetBufferedAmount(); | 1507 buffered_amount = websocket.GetBufferedAmount(); |
1502 ASSERT_EQ(base_buffered_amount + kMessageFrameOverhead, buffered_amount); | 1508 ASSERT_EQ(base_buffered_amount + kMessageFrameOverhead, buffered_amount); |
1503 base_buffered_amount = buffered_amount; | 1509 base_buffered_amount = buffered_amount; |
1504 | 1510 |
1505 result = websocket.Send(pp::Var(reason)); | 1511 result = websocket.Send(pp::Var(reason)); |
1506 ASSERT_EQ(PP_ERROR_FAILED, result); | 1512 ASSERT_EQ(PP_ERROR_FAILED, result); |
1507 buffered_amount = websocket.GetBufferedAmount(); | 1513 buffered_amount = websocket.GetBufferedAmount(); |
1508 uint64_t reason_frame_size = kMessageFrameOverhead + reason.length(); | 1514 uint64_t reason_frame_size = kMessageFrameOverhead + reason.length(); |
1509 ASSERT_EQ(base_buffered_amount + reason_frame_size, buffered_amount); | 1515 ASSERT_EQ(base_buffered_amount + reason_frame_size, buffered_amount); |
1510 | 1516 |
1511 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); | 1517 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); |
1512 ASSERT_EQ(events_on_closed, events.size()); | 1518 ASSERT_EQ(events_on_closed, events.size()); |
1513 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); | 1519 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); |
1514 size_t last_event = events_on_closed - 1; | 1520 size_t last_event = events_on_closed - 1; |
1515 for (uint32_t i = 1; i < last_event; ++i) { | 1521 for (uint32_t i = 1; i < last_event; ++i) { |
1516 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1522 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
1517 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1523 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
1518 } | 1524 } |
1519 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1525 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
1520 ASSERT_TRUE(events[last_event].was_clean); | 1526 ASSERT_TRUE(events[last_event].was_clean); |
1521 | 1527 |
1522 PASS(); | 1528 PASS(); |
1523 } | 1529 } |
OLD | NEW |