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

Unified 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: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/tests/test_websocket.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_websocket.cc
diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc
index 1992e3ebe269c6a95f58575111f19b8c9b5e3617..69502a192e18e15ada988f6557047b6e70995e7f 100644
--- a/ppapi/tests/test_websocket.cc
+++ b/ppapi/tests/test_websocket.cc
@@ -196,6 +196,7 @@ void TestWebSocket::RunTests(const std::string& filter) {
RUN_TEST_WITH_REFERENCE_CHECK(GetProtocol, filter);
RUN_TEST_WITH_REFERENCE_CHECK(TextSendReceive, filter);
RUN_TEST_WITH_REFERENCE_CHECK(BinarySendReceive, filter);
+ RUN_TEST_WITH_REFERENCE_CHECK(StressedSendReceive, filter);
RUN_TEST_WITH_REFERENCE_CHECK(BufferedAmount, filter);
RUN_TEST_WITH_REFERENCE_CHECK(CcInterfaces, filter);
@@ -637,6 +638,54 @@ std::string TestWebSocket::TestBinarySendReceive() {
PASS();
}
+std::string TestWebSocket::TestStressedSendReceive() {
+ // Connect to test echo server.
+ int32_t connect_result;
+ PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, "");
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, connect_result);
+
+ // Prepare PP_Var objects to send.
+ const char* text = "hello pepper";
+ PP_Var text_var = CreateVarString(text);
+ std::vector<uint8_t> binary(256);
+ for (uint32_t i = 0; i < binary.size(); ++i)
+ binary[i] = i;
+ PP_Var binary_var = CreateVarBinary(binary);
+
+ // Send many messages.
+ for (int i = 0; i < 256; ++i) {
+ int32_t result = websocket_interface_->SendMessage(ws, text_var);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->SendMessage(ws, binary_var);
+ ASSERT_EQ(PP_OK, result);
+ }
+ ReleaseVar(text_var);
+ ReleaseVar(binary_var);
+
+ // Receive echoed data.
+ for (int i = 0; i < 512; ++i) {
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ PP_Var received_message;
+ int32_t result = websocket_interface_->ReceiveMessage(
+ ws, &received_message, static_cast<pp::CompletionCallback>(
+ callback).pp_completion_callback());
+ ASSERT_TRUE(result == PP_OK || result == PP_OK_COMPLETIONPENDING);
+ if (result == PP_OK_COMPLETIONPENDING)
+ result = callback.WaitForResult();
+ ASSERT_EQ(PP_OK, result);
+ if (i & 1) {
+ ASSERT_TRUE(AreEqualWithBinary(received_message, binary));
+ } else {
+ ASSERT_TRUE(AreEqualWithString(received_message, text));
+ }
+ ReleaseVar(received_message);
+ }
+ core_interface_->ReleaseResource(ws);
+
+ PASS();
+}
+
std::string TestWebSocket::TestBufferedAmount() {
// Connect to test echo server.
int32_t connect_result;
« 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