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

Unified Diff: ppapi/tests/test_websocket.cc

Issue 10167028: WebSocket Pepper API: PPB_WebSocket::close must accept undefined reason (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove a TODO 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webkit/plugins/ppapi/ppb_websocket_impl.cc » ('j') | 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 8e0c29bbeb28f3d6305392b577b7fca2a39867d7..eff333ad5e3c02c738da6813fb7f6ff309495406 100644
--- a/ppapi/tests/test_websocket.cc
+++ b/ppapi/tests/test_websocket.cc
@@ -450,11 +450,12 @@ std::string TestWebSocket::TestValidConnect() {
std::string TestWebSocket::TestInvalidClose() {
PP_Var reason = CreateVarString("close for test");
TestCompletionCallback callback(instance_->pp_instance());
+ TestCompletionCallback another_callback(instance_->pp_instance());
// Close before connect.
PP_Resource ws = websocket_interface_->Create(instance_->pp_instance());
- int32_t result = websocket_interface_->Close(
- ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ int32_t result = websocket_interface_->Close(ws,
+ PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_ERROR_FAILED, result);
core_interface_->ReleaseResource(ws);
@@ -468,6 +469,39 @@ std::string TestWebSocket::TestInvalidClose() {
ASSERT_EQ(PP_ERROR_NOACCESS, result);
core_interface_->ReleaseResource(ws);
+ // Close with PP_VARTYPE_NULL.
+ ws = Connect(GetFullURL(kEchoServerURL), &result, "");
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->Close(ws,
+ PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(),
+ callback.GetCallback().pp_completion_callback());
+ ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
+ core_interface_->ReleaseResource(ws);
+
+ // Close with PP_VARTYPE_NULL and ongoing receive message.
+ ws = Connect(GetFullURL(kEchoServerURL), &result, "");
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ PP_Var receive_message_var;
+ result = websocket_interface_->ReceiveMessage(ws, &receive_message_var,
+ callback.GetCallback().pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = websocket_interface_->Close(ws,
+ PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(),
+ another_callback.GetCallback().pp_completion_callback());
+ ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
+ const char* send_message = "hi";
+ PP_Var send_message_var = CreateVarString(send_message);
+ result = websocket_interface_->SendMessage(ws, send_message_var);
+ ReleaseVar(send_message_var);
+ ASSERT_EQ(PP_OK, result);
+ result = callback.WaitForResult();
+ ASSERT_EQ(PP_OK, result);
+ ASSERT_TRUE(AreEqualWithString(receive_message_var, send_message));
+ ReleaseVar(receive_message_var);
+ core_interface_->ReleaseResource(ws);
+
ReleaseVar(reason);
PASS();
@@ -493,6 +527,18 @@ std::string TestWebSocket::TestValidClose() {
ASSERT_EQ(PP_OK, result);
core_interface_->ReleaseResource(ws);
+ // Close with PP_VARTYPE_UNDEFINED.
+ ws = Connect(GetFullURL(kEchoServerURL), &result, "");
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->Close(ws,
+ PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
+ callback.GetCallback().pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = callback.WaitForResult();
+ ASSERT_EQ(PP_OK, result);
+ core_interface_->ReleaseResource(ws);
+
// Close in connecting.
// The ongoing connect failed with PP_ERROR_ABORTED, then the close is done
// successfully.
@@ -546,6 +592,23 @@ std::string TestWebSocket::TestValidClose() {
ASSERT_EQ(PP_OK, result);
core_interface_->ReleaseResource(ws);
+ // Close with PP_VARTYPE_UNDEFINED and ongoing receive message.
+ ws = Connect(GetFullURL(kEchoServerURL), &result, "");
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->ReceiveMessage(ws, &receive_message_var,
+ callback.GetCallback().pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = websocket_interface_->Close(ws,
+ PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
+ another_callback.GetCallback().pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = callback.WaitForResult();
+ ASSERT_EQ(PP_ERROR_ABORTED, result);
+ result = another_callback.WaitForResult();
+ ASSERT_EQ(PP_OK, result);
+ core_interface_->ReleaseResource(ws);
+
ReleaseVar(reason);
ReleaseVar(url);
@@ -1311,4 +1374,3 @@ std::string TestWebSocket::TestUtilityBufferedAmount() {
PASS();
}
-
« no previous file with comments | « no previous file | webkit/plugins/ppapi/ppb_websocket_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698