Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: ppapi/tests/test_websocket.cc

Issue 9586015: WebSocket Pepper API: unit test must use close code defined by API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string.h> 7 #include <string.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ppapi/c/dev/ppb_testing_dev.h" 10 #include "ppapi/c/dev/ppb_testing_dev.h"
(...skipping 24 matching lines...) Expand all
35 const char kProtocolTestServerURL[] = 35 const char kProtocolTestServerURL[] =
36 "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol="; 36 "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol=";
37 37
38 const char* const kInvalidURLs[] = { 38 const char* const kInvalidURLs[] = {
39 "http://www.google.com/invalid_scheme", 39 "http://www.google.com/invalid_scheme",
40 "ws://www.google.com/invalid#fragment", 40 "ws://www.google.com/invalid#fragment",
41 "ws://www.google.com:65535/invalid_port", 41 "ws://www.google.com:65535/invalid_port",
42 NULL 42 NULL
43 }; 43 };
44 44
45 // Connection close code is defined in WebSocket protocol specification.
46 // The magic number 1000 means gracefull closure without any error.
47 // See section 7.4.1. of RFC 6455.
48 const uint16_t kCloseCodeNormalClosure = 1000U;
49
50 // Internal packet sizes. 45 // Internal packet sizes.
51 const uint64_t kCloseFrameSize = 6; 46 const uint64_t kCloseFrameSize = 6;
52 const uint64_t kMessageFrameOverhead = 6; 47 const uint64_t kMessageFrameOverhead = 6;
53 48
54 namespace { 49 namespace {
55 50
56 struct WebSocketEvent { 51 struct WebSocketEvent {
57 enum EventType { 52 enum EventType {
58 EVENT_OPEN, 53 EVENT_OPEN,
59 EVENT_MESSAGE, 54 EVENT_MESSAGE,
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 PASS(); 421 PASS();
427 } 422 }
428 423
429 std::string TestWebSocket::TestInvalidClose() { 424 std::string TestWebSocket::TestInvalidClose() {
430 PP_Var reason = CreateVarString("close for test"); 425 PP_Var reason = CreateVarString("close for test");
431 TestCompletionCallback callback(instance_->pp_instance()); 426 TestCompletionCallback callback(instance_->pp_instance());
432 427
433 // Close before connect. 428 // Close before connect.
434 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); 429 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance());
435 int32_t result = websocket_interface_->Close( 430 int32_t result = websocket_interface_->Close(
436 ws, kCloseCodeNormalClosure, reason, 431 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
437 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 432 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
438 ASSERT_EQ(PP_ERROR_FAILED, result); 433 ASSERT_EQ(PP_ERROR_FAILED, result);
439 core_interface_->ReleaseResource(ws); 434 core_interface_->ReleaseResource(ws);
440 435
441 // Close with bad arguments. 436 // Close with bad arguments.
442 ws = Connect(kEchoServerURL, &result, NULL); 437 ws = Connect(kEchoServerURL, &result, NULL);
443 ASSERT_TRUE(ws); 438 ASSERT_TRUE(ws);
444 ASSERT_EQ(PP_OK, result); 439 ASSERT_EQ(PP_OK, result);
445 result = websocket_interface_->Close(ws, 1U, reason, 440 result = websocket_interface_->Close(ws, 1U, reason,
446 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 441 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
(...skipping 10 matching lines...) Expand all
457 PP_Var url = CreateVarString(kEchoServerURL); 452 PP_Var url = CreateVarString(kEchoServerURL);
458 PP_Var protocols[] = { PP_MakeUndefined() }; 453 PP_Var protocols[] = { PP_MakeUndefined() };
459 TestCompletionCallback callback(instance_->pp_instance()); 454 TestCompletionCallback callback(instance_->pp_instance());
460 TestCompletionCallback another_callback(instance_->pp_instance()); 455 TestCompletionCallback another_callback(instance_->pp_instance());
461 456
462 // Close. 457 // Close.
463 int32_t result; 458 int32_t result;
464 PP_Resource ws = Connect(kEchoServerURL, &result, NULL); 459 PP_Resource ws = Connect(kEchoServerURL, &result, NULL);
465 ASSERT_TRUE(ws); 460 ASSERT_TRUE(ws);
466 ASSERT_EQ(PP_OK, result); 461 ASSERT_EQ(PP_OK, result);
467 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, 462 result = websocket_interface_->Close(ws,
463 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
468 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 464 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
469 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 465 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
470 result = callback.WaitForResult(); 466 result = callback.WaitForResult();
471 ASSERT_EQ(PP_OK, result); 467 ASSERT_EQ(PP_OK, result);
472 core_interface_->ReleaseResource(ws); 468 core_interface_->ReleaseResource(ws);
473 469
474 // Close in connecting. 470 // Close in connecting.
475 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done 471 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done
476 // successfully. 472 // successfully.
477 ws = websocket_interface_->Create(instance_->pp_instance()); 473 ws = websocket_interface_->Create(instance_->pp_instance());
478 result = websocket_interface_->Connect(ws, url, protocols, 0U, 474 result = websocket_interface_->Connect(ws, url, protocols, 0U,
479 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 475 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
480 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 476 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
481 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, 477 result = websocket_interface_->Close(ws,
478 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
482 static_cast<pp::CompletionCallback>( 479 static_cast<pp::CompletionCallback>(
483 another_callback).pp_completion_callback()); 480 another_callback).pp_completion_callback());
484 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 481 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
485 result = callback.WaitForResult(); 482 result = callback.WaitForResult();
486 ASSERT_EQ(PP_ERROR_ABORTED, result); 483 ASSERT_EQ(PP_ERROR_ABORTED, result);
487 result = another_callback.WaitForResult(); 484 result = another_callback.WaitForResult();
488 ASSERT_EQ(PP_OK, result); 485 ASSERT_EQ(PP_OK, result);
489 core_interface_->ReleaseResource(ws); 486 core_interface_->ReleaseResource(ws);
490 487
491 // Close in closing. 488 // Close in closing.
492 // The first close will be done successfully, then the second one failed with 489 // The first close will be done successfully, then the second one failed with
493 // with PP_ERROR_INPROGRESS immediately. 490 // with PP_ERROR_INPROGRESS immediately.
494 ws = Connect(kEchoServerURL, &result, NULL); 491 ws = Connect(kEchoServerURL, &result, NULL);
495 ASSERT_TRUE(ws); 492 ASSERT_TRUE(ws);
496 ASSERT_EQ(PP_OK, result); 493 ASSERT_EQ(PP_OK, result);
497 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, 494 result = websocket_interface_->Close(ws,
495 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
498 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 496 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
499 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 497 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
500 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, 498 result = websocket_interface_->Close(ws,
499 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
501 static_cast<pp::CompletionCallback>( 500 static_cast<pp::CompletionCallback>(
502 another_callback).pp_completion_callback()); 501 another_callback).pp_completion_callback());
503 ASSERT_EQ(PP_ERROR_INPROGRESS, result); 502 ASSERT_EQ(PP_ERROR_INPROGRESS, result);
504 result = callback.WaitForResult(); 503 result = callback.WaitForResult();
505 ASSERT_EQ(PP_OK, result); 504 ASSERT_EQ(PP_OK, result);
506 core_interface_->ReleaseResource(ws); 505 core_interface_->ReleaseResource(ws);
507 506
508 // Close with ongoing receive message. 507 // Close with ongoing receive message.
509 ws = Connect(kEchoServerURL, &result, NULL); 508 ws = Connect(kEchoServerURL, &result, NULL);
510 ASSERT_TRUE(ws); 509 ASSERT_TRUE(ws);
511 ASSERT_EQ(PP_OK, result); 510 ASSERT_EQ(PP_OK, result);
512 PP_Var receive_message_var; 511 PP_Var receive_message_var;
513 result = websocket_interface_->ReceiveMessage(ws, &receive_message_var, 512 result = websocket_interface_->ReceiveMessage(ws, &receive_message_var,
514 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 513 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
515 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 514 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
516 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, 515 result = websocket_interface_->Close(ws,
516 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
517 static_cast<pp::CompletionCallback>( 517 static_cast<pp::CompletionCallback>(
518 another_callback).pp_completion_callback()); 518 another_callback).pp_completion_callback());
519 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 519 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
520 result = callback.WaitForResult(); 520 result = callback.WaitForResult();
521 ASSERT_EQ(PP_ERROR_ABORTED, result); 521 ASSERT_EQ(PP_ERROR_ABORTED, result);
522 result = another_callback.WaitForResult(); 522 result = another_callback.WaitForResult();
523 ASSERT_EQ(PP_OK, result); 523 ASSERT_EQ(PP_OK, result);
524 core_interface_->ReleaseResource(ws); 524 core_interface_->ReleaseResource(ws);
525 525
526 ReleaseVar(reason); 526 ReleaseVar(reason);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 buffered_amount = websocket_interface_->GetBufferedAmount(ws); 638 buffered_amount = websocket_interface_->GetBufferedAmount(ws);
639 // Buffered amount size 262144 is too big for the internal buffer size. 639 // Buffered amount size 262144 is too big for the internal buffer size.
640 if (buffered_amount > 262144) 640 if (buffered_amount > 262144)
641 break; 641 break;
642 } 642 }
643 643
644 // Close connection. 644 // Close connection.
645 std::string reason_str = "close while busy"; 645 std::string reason_str = "close while busy";
646 PP_Var reason = CreateVarString(reason_str.c_str()); 646 PP_Var reason = CreateVarString(reason_str.c_str());
647 TestCompletionCallback callback(instance_->pp_instance()); 647 TestCompletionCallback callback(instance_->pp_instance());
648 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, 648 result = websocket_interface_->Close(ws,
649 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
649 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 650 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
650 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 651 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
651 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, 652 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING,
652 websocket_interface_->GetReadyState(ws)); 653 websocket_interface_->GetReadyState(ws));
653 654
654 result = callback.WaitForResult(); 655 result = callback.WaitForResult();
655 ASSERT_EQ(PP_OK, result); 656 ASSERT_EQ(PP_OK, result);
656 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, 657 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED,
657 websocket_interface_->GetReadyState(ws)); 658 websocket_interface_->GetReadyState(ws));
658 659
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 TestCompletionCallback binary_receive_callback(instance_->pp_instance()); 730 TestCompletionCallback binary_receive_callback(instance_->pp_instance());
730 result = ws.ReceiveMessage(&binary_receive_var, binary_receive_callback); 731 result = ws.ReceiveMessage(&binary_receive_var, binary_receive_callback);
731 if (result == PP_OK_COMPLETIONPENDING) 732 if (result == PP_OK_COMPLETIONPENDING)
732 result = binary_receive_callback.WaitForResult(); 733 result = binary_receive_callback.WaitForResult();
733 ASSERT_EQ(PP_OK, result); 734 ASSERT_EQ(PP_OK, result);
734 ASSERT_TRUE(AreEqualWithBinary( 735 ASSERT_TRUE(AreEqualWithBinary(
735 binary_receive_var.pp_var(), binary_message, binary_length)); 736 binary_receive_var.pp_var(), binary_message, binary_length));
736 737
737 TestCompletionCallback close_callback(instance_->pp_instance()); 738 TestCompletionCallback close_callback(instance_->pp_instance());
738 std::string reason("bye"); 739 std::string reason("bye");
739 result = ws.Close(kCloseCodeNormalClosure, pp::Var(reason), close_callback); 740 result = ws.Close(
741 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason), close_callback);
740 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 742 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
741 result = close_callback.WaitForResult(); 743 result = close_callback.WaitForResult();
742 ASSERT_EQ(PP_OK, result); 744 ASSERT_EQ(PP_OK, result);
743 745
744 // Check initialized properties access. 746 // Check initialized properties access.
745 ASSERT_EQ(0, ws.GetBufferedAmount()); 747 ASSERT_EQ(0, ws.GetBufferedAmount());
746 ASSERT_EQ(kCloseCodeNormalClosure, ws.GetCloseCode()); 748 ASSERT_EQ(PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, ws.GetCloseCode());
747 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); 749 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str()));
748 ASSERT_EQ(true, ws.GetCloseWasClean()); 750 ASSERT_EQ(true, ws.GetCloseWasClean());
749 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); 751 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), ""));
750 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); 752 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), ""));
751 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState()); 753 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState());
752 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); 754 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL));
753 755
754 PASS(); 756 PASS();
755 } 757 }
756 758
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 840
839 PASS(); 841 PASS();
840 } 842 }
841 843
842 std::string TestWebSocket::TestUtilityInvalidClose() { 844 std::string TestWebSocket::TestUtilityInvalidClose() {
843 const pp::Var reason = pp::Var(std::string("close for test")); 845 const pp::Var reason = pp::Var(std::string("close for test"));
844 846
845 // Close before connect. 847 // Close before connect.
846 { 848 {
847 TestWebSocketAPI websocket(instance_); 849 TestWebSocketAPI websocket(instance_);
848 int32_t result = websocket.Close(kCloseCodeNormalClosure, reason); 850 int32_t result = websocket.Close(
851 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason);
849 ASSERT_EQ(PP_ERROR_FAILED, result); 852 ASSERT_EQ(PP_ERROR_FAILED, result);
850 ASSERT_EQ(0U, websocket.GetSeenEvents().size()); 853 ASSERT_EQ(0U, websocket.GetSeenEvents().size());
851 } 854 }
852 855
853 // Close with bad arguments. 856 // Close with bad arguments.
854 { 857 {
855 TestWebSocketAPI websocket(instance_); 858 TestWebSocketAPI websocket(instance_);
856 int32_t result = websocket.Connect(pp::Var(std::string(kEchoServerURL)), 859 int32_t result = websocket.Connect(pp::Var(std::string(kEchoServerURL)),
857 NULL, 0); 860 NULL, 0);
858 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 861 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
(...skipping 11 matching lines...) Expand all
870 std::string TestWebSocket::TestUtilityValidClose() { 873 std::string TestWebSocket::TestUtilityValidClose() {
871 std::string reason("close for test"); 874 std::string reason("close for test");
872 pp::Var url = pp::Var(std::string(kCloseServerURL)); 875 pp::Var url = pp::Var(std::string(kCloseServerURL));
873 876
874 // Close. 877 // Close.
875 { 878 {
876 TestWebSocketAPI websocket(instance_); 879 TestWebSocketAPI websocket(instance_);
877 int32_t result = websocket.Connect(url, NULL, 0U); 880 int32_t result = websocket.Connect(url, NULL, 0U);
878 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 881 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
879 websocket.WaitForConnected(); 882 websocket.WaitForConnected();
880 result = websocket.Close(kCloseCodeNormalClosure, pp::Var(reason)); 883 result = websocket.Close(
884 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason));
881 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 885 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
882 websocket.WaitForClosed(); 886 websocket.WaitForClosed();
883 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); 887 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents();
884 ASSERT_EQ(2U, events.size()); 888 ASSERT_EQ(2U, events.size());
885 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); 889 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type);
886 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[1].event_type); 890 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[1].event_type);
887 ASSERT_TRUE(events[1].was_clean); 891 ASSERT_TRUE(events[1].was_clean);
888 ASSERT_EQ(kCloseCodeNormalClosure, events[1].close_code); 892 ASSERT_EQ(PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, events[1].close_code);
889 ASSERT_TRUE(AreEqualWithString(events[1].var.pp_var(), reason.c_str())); 893 ASSERT_TRUE(AreEqualWithString(events[1].var.pp_var(), reason.c_str()));
890 } 894 }
891 895
892 // Close in connecting. 896 // Close in connecting.
893 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done 897 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done
894 // successfully. 898 // successfully.
895 { 899 {
896 TestWebSocketAPI websocket(instance_); 900 TestWebSocketAPI websocket(instance_);
897 int32_t result = websocket.Connect(url, NULL, 0U); 901 int32_t result = websocket.Connect(url, NULL, 0U);
898 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 902 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
899 result = websocket.Close(kCloseCodeNormalClosure, pp::Var(reason)); 903 result = websocket.Close(
904 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason));
900 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 905 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
901 websocket.WaitForClosed(); 906 websocket.WaitForClosed();
902 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); 907 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents();
903 ASSERT_TRUE(events.size() == 2 || events.size() == 3); 908 ASSERT_TRUE(events.size() == 2 || events.size() == 3);
904 int index = 0; 909 int index = 0;
905 if (events.size() == 3) 910 if (events.size() == 3)
906 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[index++].event_type); 911 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[index++].event_type);
907 ASSERT_EQ(WebSocketEvent::EVENT_ERROR, events[index++].event_type); 912 ASSERT_EQ(WebSocketEvent::EVENT_ERROR, events[index++].event_type);
908 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[index].event_type); 913 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[index].event_type);
909 ASSERT_FALSE(events[index].was_clean); 914 ASSERT_FALSE(events[index].was_clean);
910 } 915 }
911 916
912 // Close in closing. 917 // Close in closing.
913 // The first close will be done successfully, then the second one failed with 918 // The first close will be done successfully, then the second one failed with
914 // with PP_ERROR_INPROGRESS immediately. 919 // with PP_ERROR_INPROGRESS immediately.
915 { 920 {
916 TestWebSocketAPI websocket(instance_); 921 TestWebSocketAPI websocket(instance_);
917 int32_t result = websocket.Connect(url, NULL, 0U); 922 int32_t result = websocket.Connect(url, NULL, 0U);
918 result = websocket.Close(kCloseCodeNormalClosure, pp::Var(reason)); 923 result = websocket.Close(
924 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason));
919 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 925 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
920 result = websocket.Close(kCloseCodeNormalClosure, pp::Var(reason)); 926 result = websocket.Close(
927 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason));
921 ASSERT_EQ(PP_ERROR_INPROGRESS, result); 928 ASSERT_EQ(PP_ERROR_INPROGRESS, result);
922 websocket.WaitForClosed(); 929 websocket.WaitForClosed();
923 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); 930 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents();
924 ASSERT_TRUE(events.size() == 2 || events.size() == 3) 931 ASSERT_TRUE(events.size() == 2 || events.size() == 3)
925 int index = 0; 932 int index = 0;
926 if (events.size() == 3) 933 if (events.size() == 3)
927 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[index++].event_type); 934 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[index++].event_type);
928 ASSERT_EQ(WebSocketEvent::EVENT_ERROR, events[index++].event_type); 935 ASSERT_EQ(WebSocketEvent::EVENT_ERROR, events[index++].event_type);
929 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[index].event_type); 936 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[index].event_type);
930 ASSERT_FALSE(events[index].was_clean); 937 ASSERT_FALSE(events[index].was_clean);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 result = websocket.Send(pp::Var(message_str)); 1049 result = websocket.Send(pp::Var(message_str));
1043 ASSERT_EQ(PP_OK, result); 1050 ASSERT_EQ(PP_OK, result);
1044 buffered_amount = websocket.GetBufferedAmount(); 1051 buffered_amount = websocket.GetBufferedAmount();
1045 // Buffered amount size 262144 is too big for the internal buffer size. 1052 // Buffered amount size 262144 is too big for the internal buffer size.
1046 if (buffered_amount > 262144) 1053 if (buffered_amount > 262144)
1047 break; 1054 break;
1048 } 1055 }
1049 1056
1050 // Close connection. 1057 // Close connection.
1051 std::string reason_str = "close while busy"; 1058 std::string reason_str = "close while busy";
1052 result = websocket.Close(kCloseCodeNormalClosure, pp::Var(reason_str)); 1059 result = websocket.Close(
1060 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason_str));
1053 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, websocket.GetReadyState()); 1061 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, websocket.GetReadyState());
1054 websocket.WaitForClosed(); 1062 websocket.WaitForClosed();
1055 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, websocket.GetReadyState()); 1063 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, websocket.GetReadyState());
1056 1064
1057 uint64_t base_buffered_amount = websocket.GetBufferedAmount(); 1065 uint64_t base_buffered_amount = websocket.GetBufferedAmount();
1058 size_t events_on_closed = websocket.GetSeenEvents().size(); 1066 size_t events_on_closed = websocket.GetSeenEvents().size();
1059 1067
1060 // After connection closure, all sending requests fail and just increase 1068 // After connection closure, all sending requests fail and just increase
1061 // the bufferedAmount property. 1069 // the bufferedAmount property.
1062 result = websocket.Send(pp::Var(std::string(""))); 1070 result = websocket.Send(pp::Var(std::string("")));
(...skipping 14 matching lines...) Expand all
1077 size_t last_event = events_on_closed - 1; 1085 size_t last_event = events_on_closed - 1;
1078 for (uint32_t i = 1; i < last_event; ++i) { 1086 for (uint32_t i = 1; i < last_event; ++i) {
1079 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); 1087 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type);
1080 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message_char)); 1088 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message_char));
1081 } 1089 }
1082 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); 1090 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type);
1083 ASSERT_TRUE(events[last_event].was_clean); 1091 ASSERT_TRUE(events[last_event].was_clean);
1084 1092
1085 PASS(); 1093 PASS();
1086 } 1094 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698