summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authortoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-29 04:41:42 +0000
committertoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-29 04:41:42 +0000
commitcc2386c4e2a249c1dc8f55890c8f3c16a6a9d346 (patch)
tree880f8a6ff0233937f9225f3e387f6e2de5c894a8 /ppapi
parentd1a043626caa76ada7af34f21ac57a2dc308a92f (diff)
downloadchromium_src-cc2386c4e2a249c1dc8f55890c8f3c16a6a9d346.zip
chromium_src-cc2386c4e2a249c1dc8f55890c8f3c16a6a9d346.tar.gz
chromium_src-cc2386c4e2a249c1dc8f55890c8f3c16a6a9d346.tar.bz2
Allow to release WebSocket resource in completion callbacks invoked by Close().
- Protect |this| around invoking plugin callbacks - Add unit tests to check the case BUG= TEST=browser_tests Review URL: https://chromiumcodereview.appspot.com/10661026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/tests/test_utils.cc12
-rw-r--r--ppapi/tests/test_utils.h11
-rw-r--r--ppapi/tests/test_websocket.cc54
3 files changed, 74 insertions, 3 deletions
diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc
index cae96dc..b1744dc 100644
--- a/ppapi/tests/test_utils.cc
+++ b/ppapi/tests/test_utils.cc
@@ -98,7 +98,8 @@ TestCompletionCallback::TestCompletionCallback(PP_Instance instance)
callback_type_(PP_OPTIONAL),
post_quit_task_(false),
run_count_(0), // TODO(dmichael): Remove when all tests are updated.
- instance_(instance) {
+ instance_(instance),
+ delegate_(NULL) {
}
TestCompletionCallback::TestCompletionCallback(PP_Instance instance,
@@ -108,7 +109,8 @@ TestCompletionCallback::TestCompletionCallback(PP_Instance instance,
result_(PP_OK_COMPLETIONPENDING),
callback_type_(force_async ? PP_REQUIRED : PP_OPTIONAL),
post_quit_task_(false),
- instance_(instance) {
+ instance_(instance),
+ delegate_(NULL) {
}
TestCompletionCallback::TestCompletionCallback(PP_Instance instance,
@@ -118,7 +120,8 @@ TestCompletionCallback::TestCompletionCallback(PP_Instance instance,
result_(PP_OK_COMPLETIONPENDING),
callback_type_(callback_type),
post_quit_task_(false),
- instance_(instance) {
+ instance_(instance),
+ delegate_(NULL) {
}
int32_t TestCompletionCallback::WaitForResult() {
@@ -200,6 +203,7 @@ void TestCompletionCallback::Reset() {
have_result_ = false;
post_quit_task_ = false;
run_count_ = 0; // TODO(dmichael): Remove when all tests are updated.
+ delegate_ = NULL;
errors_.clear();
}
@@ -213,6 +217,8 @@ void TestCompletionCallback::Handler(void* user_data, int32_t result) {
callback->result_ = result;
callback->have_result_ = true;
callback->run_count_++; // TODO(dmichael): Remove when all tests are updated.
+ if (callback->delegate_)
+ callback->delegate_->OnCallback(user_data, result);
if (callback->post_quit_task_) {
callback->post_quit_task_ = false;
GetTestingInterface()->QuitMessageLoop(callback->instance_);
diff --git a/ppapi/tests/test_utils.h b/ppapi/tests/test_utils.h
index 1e2ec36..4168cec 100644
--- a/ppapi/tests/test_utils.h
+++ b/ppapi/tests/test_utils.h
@@ -62,12 +62,22 @@ class NestedEvent {
enum CallbackType { PP_REQUIRED, PP_OPTIONAL, PP_BLOCKING };
class TestCompletionCallback {
public:
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+ virtual void OnCallback(void* user_data, int32_t result) = 0;
+ };
explicit TestCompletionCallback(PP_Instance instance);
// TODO(dmichael): Remove this constructor.
TestCompletionCallback(PP_Instance instance, bool force_async);
TestCompletionCallback(PP_Instance instance, CallbackType callback_type);
+ // Sets a Delegate instance. OnCallback() of this instance will be invoked
+ // when the completion callback is invoked.
+ // The delegate will be reset when Reset() or GetCallback() is called.
+ void SetDelegate(Delegate* delegate) { delegate_ = delegate; }
+
// Waits for the callback to be called and returns the
// result. Returns immediately if the callback was previously called
// and the result wasn't returned (i.e. each result value received
@@ -153,6 +163,7 @@ class TestCompletionCallback {
std::string errors_;
unsigned run_count_;
PP_Instance instance_;
+ Delegate* delegate_;
};
// Verifies that the callback didn't record any errors. If the callback is run
diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc
index d3b189a..81ea021 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);