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

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: reflects review comments 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.h » ('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..07c94c32e16a5564808e75a9bde9e837a898e8db 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) {
dmichael (off chromium) 2012/06/26 16:01:40 nit: OVERRIDE
Takashi Toyoshima 2012/06/27 08:09:05 This code is for NaCl targeted compilers, so I thi
+ 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)
@@ -574,6 +593,31 @@ std::string TestWebSocket::TestValidClose() {
ASSERT_EQ(PP_OK, callback.result());
core_interface_->ReleaseResource(ws);
+ // Release the resource before the completion callback is invoked.
Takashi Toyoshima 2012/06/27 08:09:05 I notice that we already have this first case in T
+ 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());
+ core_interface_->ReleaseResource(ws);
+ callback.WaitForResult(result);
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_ERROR_ABORTED, callback.result());
+
+ // Release the resource in the completion callback.
+ 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());
+ ReleaseResourceDelegate delegate(core_interface_, ws);
+ callback.SetDelegate(&delegate);
+ callback.WaitForResult(result);
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_OK, callback.result());
+
// Close in connecting.
// The ongoing connect failed with PP_ERROR_ABORTED, then the close is done
// successfully.
« no previous file with comments | « ppapi/tests/test_utils.cc ('k') | webkit/plugins/ppapi/ppb_websocket_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698