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

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

Issue 9724007: WebSocket Pepper API: fix data corruption at ReceiveMessage in NaCl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: reset optional flag 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
« no previous file with comments | « ppapi/tests/test_websocket.h ('k') | 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 <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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 RUN_TEST_WITH_REFERENCE_CHECK(UninitializedPropertiesAccess, filter); 189 RUN_TEST_WITH_REFERENCE_CHECK(UninitializedPropertiesAccess, filter);
190 RUN_TEST_WITH_REFERENCE_CHECK(InvalidConnect, filter); 190 RUN_TEST_WITH_REFERENCE_CHECK(InvalidConnect, filter);
191 RUN_TEST_WITH_REFERENCE_CHECK(Protocols, filter); 191 RUN_TEST_WITH_REFERENCE_CHECK(Protocols, filter);
192 RUN_TEST_WITH_REFERENCE_CHECK(GetURL, filter); 192 RUN_TEST_WITH_REFERENCE_CHECK(GetURL, filter);
193 RUN_TEST_WITH_REFERENCE_CHECK(ValidConnect, filter); 193 RUN_TEST_WITH_REFERENCE_CHECK(ValidConnect, filter);
194 RUN_TEST_WITH_REFERENCE_CHECK(InvalidClose, filter); 194 RUN_TEST_WITH_REFERENCE_CHECK(InvalidClose, filter);
195 RUN_TEST_WITH_REFERENCE_CHECK(ValidClose, filter); 195 RUN_TEST_WITH_REFERENCE_CHECK(ValidClose, filter);
196 RUN_TEST_WITH_REFERENCE_CHECK(GetProtocol, filter); 196 RUN_TEST_WITH_REFERENCE_CHECK(GetProtocol, filter);
197 RUN_TEST_WITH_REFERENCE_CHECK(TextSendReceive, filter); 197 RUN_TEST_WITH_REFERENCE_CHECK(TextSendReceive, filter);
198 RUN_TEST_WITH_REFERENCE_CHECK(BinarySendReceive, filter); 198 RUN_TEST_WITH_REFERENCE_CHECK(BinarySendReceive, filter);
199 RUN_TEST_WITH_REFERENCE_CHECK(StressedSendReceive, filter);
199 RUN_TEST_WITH_REFERENCE_CHECK(BufferedAmount, filter); 200 RUN_TEST_WITH_REFERENCE_CHECK(BufferedAmount, filter);
200 201
201 RUN_TEST_WITH_REFERENCE_CHECK(CcInterfaces, filter); 202 RUN_TEST_WITH_REFERENCE_CHECK(CcInterfaces, filter);
202 203
203 RUN_TEST_WITH_REFERENCE_CHECK(UtilityInvalidConnect, filter); 204 RUN_TEST_WITH_REFERENCE_CHECK(UtilityInvalidConnect, filter);
204 RUN_TEST_WITH_REFERENCE_CHECK(UtilityProtocols, filter); 205 RUN_TEST_WITH_REFERENCE_CHECK(UtilityProtocols, filter);
205 RUN_TEST_WITH_REFERENCE_CHECK(UtilityGetURL, filter); 206 RUN_TEST_WITH_REFERENCE_CHECK(UtilityGetURL, filter);
206 RUN_TEST_WITH_REFERENCE_CHECK(UtilityValidConnect, filter); 207 RUN_TEST_WITH_REFERENCE_CHECK(UtilityValidConnect, filter);
207 RUN_TEST_WITH_REFERENCE_CHECK(UtilityInvalidClose, filter); 208 RUN_TEST_WITH_REFERENCE_CHECK(UtilityInvalidClose, filter);
208 RUN_TEST_WITH_REFERENCE_CHECK(UtilityValidClose, filter); 209 RUN_TEST_WITH_REFERENCE_CHECK(UtilityValidClose, filter);
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 if (result == PP_OK_COMPLETIONPENDING) 631 if (result == PP_OK_COMPLETIONPENDING)
631 result = callback.WaitForResult(); 632 result = callback.WaitForResult();
632 ASSERT_EQ(PP_OK, result); 633 ASSERT_EQ(PP_OK, result);
633 ASSERT_TRUE(AreEqualWithBinary(received_message, binary)); 634 ASSERT_TRUE(AreEqualWithBinary(received_message, binary));
634 ReleaseVar(received_message); 635 ReleaseVar(received_message);
635 core_interface_->ReleaseResource(ws); 636 core_interface_->ReleaseResource(ws);
636 637
637 PASS(); 638 PASS();
638 } 639 }
639 640
641 std::string TestWebSocket::TestStressedSendReceive() {
642 // Connect to test echo server.
643 int32_t connect_result;
644 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, "");
645 ASSERT_TRUE(ws);
646 ASSERT_EQ(PP_OK, connect_result);
647
648 // Prepare PP_Var objects to send.
649 const char* text = "hello pepper";
650 PP_Var text_var = CreateVarString(text);
651 std::vector<uint8_t> binary(256);
652 for (uint32_t i = 0; i < binary.size(); ++i)
653 binary[i] = i;
654 PP_Var binary_var = CreateVarBinary(binary);
655
656 // Send amounts of messages.
dmichael (off chromium) 2012/03/23 17:38:14 Did you mean something like: "Send many messages."
Takashi Toyoshima 2012/03/26 08:41:51 Done.
657 for (int i = 0; i < 256; ++i) {
658 int32_t result = websocket_interface_->SendMessage(ws, text_var);
659 ASSERT_EQ(PP_OK, result);
660 result = websocket_interface_->SendMessage(ws, binary_var);
661 ASSERT_EQ(PP_OK, result);
662 }
663 ReleaseVar(text_var);
664 ReleaseVar(binary_var);
665
666 // Receive echoed binary.
dmichael (off chromium) 2012/03/23 17:38:14 binary -> data?
Takashi Toyoshima 2012/03/26 08:41:51 Done.
667 for (int i = 0; i < 512; ++i) {
668 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
669 PP_Var received_message;
670 int32_t result = websocket_interface_->ReceiveMessage(
671 ws, &received_message, static_cast<pp::CompletionCallback>(
672 callback).pp_completion_callback());
673 ASSERT_TRUE(result == PP_OK || result == PP_OK_COMPLETIONPENDING);
674 if (result == PP_OK_COMPLETIONPENDING)
675 result = callback.WaitForResult();
676 ASSERT_EQ(PP_OK, result);
677 if (i & 1) {
678 ASSERT_TRUE(AreEqualWithBinary(received_message, binary));
679 } else {
680 ASSERT_TRUE(AreEqualWithString(received_message, text));
681 }
682 ReleaseVar(received_message);
683 }
684 core_interface_->ReleaseResource(ws);
685
686 PASS();
687 }
688
640 std::string TestWebSocket::TestBufferedAmount() { 689 std::string TestWebSocket::TestBufferedAmount() {
641 // Connect to test echo server. 690 // Connect to test echo server.
642 int32_t connect_result; 691 int32_t connect_result;
643 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, ""); 692 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, "");
644 ASSERT_TRUE(ws); 693 ASSERT_TRUE(ws);
645 ASSERT_EQ(PP_OK, connect_result); 694 ASSERT_EQ(PP_OK, connect_result);
646 695
647 // Prepare a large message that is not aligned with the internal buffer 696 // Prepare a large message that is not aligned with the internal buffer
648 // sizes. 697 // sizes.
649 std::string message(8193, 'x'); 698 std::string message(8193, 'x');
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 size_t last_event = events_on_closed - 1; 1149 size_t last_event = events_on_closed - 1;
1101 for (uint32_t i = 1; i < last_event; ++i) { 1150 for (uint32_t i = 1; i < last_event; ++i) {
1102 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); 1151 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type);
1103 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); 1152 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message));
1104 } 1153 }
1105 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); 1154 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type);
1106 ASSERT_TRUE(events[last_event].was_clean); 1155 ASSERT_TRUE(events[last_event].was_clean);
1107 1156
1108 PASS(); 1157 PASS();
1109 } 1158 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_websocket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698