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

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: Use WeakPtr to protect |this| 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
Index: ppapi/tests/test_websocket.cc
diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc
index d3b189a64b7df871f9fe28db962f0b9190f66405..61c819deac25cad8c664c530fc90eeecbbd6ae9b 100644
--- a/ppapi/tests/test_websocket.cc
+++ b/ppapi/tests/test_websocket.cc
@@ -27,7 +27,6 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var_array_buffer.h"
#include "ppapi/cpp/websocket.h"
-#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
#include "ppapi/utility/websocket/websocket_api.h"
@@ -172,7 +171,13 @@ class TestWebSocketAPI : public pp::WebSocketAPI {
REGISTER_TEST_CASE(WebSocket);
+void TestWebSocket::OnCallback(void* user_data, int32_t result) {
+ if (resource_)
+ core_interface_->ReleaseResource(resource_);
+}
+
bool TestWebSocket::Init() {
+ resource_ = 0;
websocket_interface_ = static_cast<const PPB_WebSocket*>(
pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_INTERFACE));
var_interface_ = static_cast<const PPB_Var*>(
@@ -574,6 +579,31 @@ std::string TestWebSocket::TestValidClose() {
ASSERT_EQ(PP_OK, callback.result());
core_interface_->ReleaseResource(ws);
+ // Release the resource before completion callback invoked.
dmichael (off chromium) 2012/06/25 15:50:51 nit: before +the+ completion callback +is+ invoked
Takashi Toyoshima 2012/06/26 09:19:10 Done.
+ 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());
+ resource_ = ws;
+ callback.SetDelegate(this);
+ 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.

Powered by Google App Engine
This is Rietveld 408576698