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

Unified Diff: ppapi/tests/test_websocket.cc

Issue 10661026: WebSocket Pepper API: allow to release in completion callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remvoe redundant checker Created 8 years, 6 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_utils.cc ('k') | 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 d3b189a64b7df871f9fe28db962f0b9190f66405..81ea021166f9ef7d55d70583aa5fc6b4edc3a5fe 100644
--- a/ppapi/tests/test_websocket.cc
+++ b/ppapi/tests/test_websocket.cc
@@ -80,6 +80,25 @@ struct WebSocketEvent {
pp::Var var;
};
+class ReleaseResourceDelegate : public TestCompletionCallback::Delegate {
+ public:
+ explicit ReleaseResourceDelegate(const PPB_Core* core_interface,
+ PP_Resource resource)
+ : core_interface_(core_interface),
+ resource_(resource) {
+ }
+
+ // TestCompletionCallback::Delegate implementation.
+ virtual void OnCallback(void* user_data, int32_t result) {
+ if (resource_)
+ core_interface_->ReleaseResource(resource_);
+ }
+
+ private:
+ const PPB_Core* core_interface_;
+ PP_Resource resource_;
+};
+
class TestWebSocketAPI : public pp::WebSocketAPI {
public:
explicit TestWebSocketAPI(pp::Instance* instance)
@@ -938,6 +957,41 @@ std::string TestWebSocket::TestAbortCalls() {
receive_callback.WaitForResult(result);
ASSERT_EQ(PP_ERROR_ABORTED, receive_callback.result());
+ // Release the resource in the close completion callback.
+ ws = Connect(url, &result, "");
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
+ close_callback.GetCallback().pp_completion_callback());
+ ReleaseResourceDelegate close_delegate(core_interface_, ws);
+ close_callback.SetDelegate(&close_delegate);
+ close_callback.WaitForResult(result);
+ CHECK_CALLBACK_BEHAVIOR(close_callback);
+ ASSERT_EQ(PP_OK, close_callback.result());
+
+ // Release the resource in the aborting receive completion callback which is
+ // introduced by calling Close().
+ ws = Connect(url, &result, "");
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->ReceiveMessage(
+ ws, &receive_var,
+ receive_callback.GetCallback().pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ ReleaseResourceDelegate receive_delegate(core_interface_, ws);
+ receive_callback.SetDelegate(&receive_delegate);
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
+ close_callback.GetCallback().pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ receive_callback.WaitForResult(result);
+ CHECK_CALLBACK_BEHAVIOR(receive_callback);
+ ASSERT_EQ(PP_ERROR_ABORTED, receive_callback.result());
+ close_callback.WaitForResult(result);
+ CHECK_CALLBACK_BEHAVIOR(close_callback);
+ ASSERT_EQ(PP_ERROR_ABORTED, close_callback.result());
+
// Test the behavior where receive process might be in-flight.
const char* text = "yukarin";
PP_Var text_var = CreateVarString(text);
« no previous file with comments | « ppapi/tests/test_utils.cc ('k') | webkit/plugins/ppapi/ppb_websocket_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698