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

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

Issue 9802027: WebSocket Pepper API: synchronous completion support (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add large data over 64KB to stressed test Created 8 years, 8 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
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 <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 ASSERT_TRUE(ws); 645 ASSERT_TRUE(ws);
646 ASSERT_EQ(PP_OK, connect_result); 646 ASSERT_EQ(PP_OK, connect_result);
647 647
648 // Prepare PP_Var objects to send. 648 // Prepare PP_Var objects to send.
649 const char* text = "hello pepper"; 649 const char* text = "hello pepper";
650 PP_Var text_var = CreateVarString(text); 650 PP_Var text_var = CreateVarString(text);
651 std::vector<uint8_t> binary(256); 651 std::vector<uint8_t> binary(256);
652 for (uint32_t i = 0; i < binary.size(); ++i) 652 for (uint32_t i = 0; i < binary.size(); ++i)
653 binary[i] = i; 653 binary[i] = i;
654 PP_Var binary_var = CreateVarBinary(binary); 654 PP_Var binary_var = CreateVarBinary(binary);
655 // Prepare very large binary data over 64KB. Object serializer in ppapi_proxy
656 // has a limitation of 64KB as maximum return PP_Var data size to SRPC.
657 // In case received data over 64KB exists, a specific code handles this large
658 // data via asynchronous callback from main thread. This data intends to test
659 // the code.
660 std::vector<uint8_t> large_binary(128 * 1024);
dmichael (off chromium) 2012/04/06 17:12:12 Win XP has been giving me fits when testing large
Takashi Toyoshima 2012/04/11 11:28:45 Oh, I see. 65k looks big enough. I change this siz
661 for (uint32_t i = 0; i < large_binary.size(); ++i)
662 large_binary[i] = i & 0xff;
663 PP_Var large_binary_var = CreateVarBinary(large_binary);
655 664
656 // Send many messages. 665 // Send many messages.
666 int32_t result;
657 for (int i = 0; i < 256; ++i) { 667 for (int i = 0; i < 256; ++i) {
658 int32_t result = websocket_interface_->SendMessage(ws, text_var); 668 result = websocket_interface_->SendMessage(ws, text_var);
659 ASSERT_EQ(PP_OK, result); 669 ASSERT_EQ(PP_OK, result);
660 result = websocket_interface_->SendMessage(ws, binary_var); 670 result = websocket_interface_->SendMessage(ws, binary_var);
661 ASSERT_EQ(PP_OK, result); 671 ASSERT_EQ(PP_OK, result);
662 } 672 }
673 result = websocket_interface_->SendMessage(ws, large_binary_var);
dmichael (off chromium) 2012/04/06 17:12:12 Would it be possible to also add a test where you
Takashi Toyoshima 2012/04/11 11:28:45 Done.
674 ASSERT_EQ(PP_OK, result);
663 ReleaseVar(text_var); 675 ReleaseVar(text_var);
664 ReleaseVar(binary_var); 676 ReleaseVar(binary_var);
677 ReleaseVar(large_binary_var);
665 678
666 // Receive echoed data. 679 // Receive echoed data.
667 for (int i = 0; i < 512; ++i) { 680 for (int i = 0; i <= 512; ++i) {
668 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 681 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
669 PP_Var received_message; 682 PP_Var received_message;
670 int32_t result = websocket_interface_->ReceiveMessage( 683 result = websocket_interface_->ReceiveMessage(
671 ws, &received_message, static_cast<pp::CompletionCallback>( 684 ws, &received_message, static_cast<pp::CompletionCallback>(
672 callback).pp_completion_callback()); 685 callback).pp_completion_callback());
673 ASSERT_TRUE(result == PP_OK || result == PP_OK_COMPLETIONPENDING); 686 ASSERT_TRUE(result == PP_OK || result == PP_OK_COMPLETIONPENDING);
674 if (result == PP_OK_COMPLETIONPENDING) 687 if (result == PP_OK_COMPLETIONPENDING)
675 result = callback.WaitForResult(); 688 result = callback.WaitForResult();
676 ASSERT_EQ(PP_OK, result); 689 ASSERT_EQ(PP_OK, result);
677 if (i & 1) { 690 if (i == 512) {
691 ASSERT_TRUE(AreEqualWithBinary(received_message, large_binary));
692 } else if (i & 1) {
678 ASSERT_TRUE(AreEqualWithBinary(received_message, binary)); 693 ASSERT_TRUE(AreEqualWithBinary(received_message, binary));
679 } else { 694 } else {
680 ASSERT_TRUE(AreEqualWithString(received_message, text)); 695 ASSERT_TRUE(AreEqualWithString(received_message, text));
681 } 696 }
682 ReleaseVar(received_message); 697 ReleaseVar(received_message);
683 } 698 }
684 core_interface_->ReleaseResource(ws); 699 core_interface_->ReleaseResource(ws);
685 700
686 PASS(); 701 PASS();
687 } 702 }
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 size_t last_event = events_on_closed - 1; 1164 size_t last_event = events_on_closed - 1;
1150 for (uint32_t i = 1; i < last_event; ++i) { 1165 for (uint32_t i = 1; i < last_event; ++i) {
1151 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); 1166 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type);
1152 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); 1167 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message));
1153 } 1168 }
1154 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); 1169 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type);
1155 ASSERT_TRUE(events[last_event].was_clean); 1170 ASSERT_TRUE(events[last_event].was_clean);
1156 1171
1157 PASS(); 1172 PASS();
1158 } 1173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698