Chromium Code Reviews| 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. |