diff options
author | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 18:33:11 +0000 |
---|---|---|
committer | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 18:33:11 +0000 |
commit | 5cf0fb1d63998fa2d5bdd27629eb680a2e26c1b1 (patch) | |
tree | a333cc94d16624018c21690f662476b75cb29502 /webkit | |
parent | d0ffc9adc8368ecebb9cfe212e64a7a5549e4429 (diff) | |
download | chromium_src-5cf0fb1d63998fa2d5bdd27629eb680a2e26c1b1.zip chromium_src-5cf0fb1d63998fa2d5bdd27629eb680a2e26c1b1.tar.gz chromium_src-5cf0fb1d63998fa2d5bdd27629eb680a2e26c1b1.tar.bz2 |
Pepper WebSocket API: Add unit test to call Close()
- Add unit tests to validate Close() operation in various situations
- Bug fix to invoke ongoing receive completion callback on Close()
BUG=87310
TEST=ui_tests --gtest_filter='PPAPITest.WebSocket_*Close'
Review URL: http://codereview.chromium.org/8821008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113239 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/plugins/ppapi/ppb_websocket_impl.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.cc b/webkit/plugins/ppapi/ppb_websocket_impl.cc index f8fb190..9d4fc20 100644 --- a/webkit/plugins/ppapi/ppb_websocket_impl.cc +++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc @@ -212,6 +212,9 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code, if (!(code == WebSocket::CloseEventCodeNormalClosure || (WebSocket::CloseEventCodeMinimumUserDefined <= code && code <= WebSocket::CloseEventCodeMaximumUserDefined))) + // RFC 6455 limits applications to use reserved connection close code in + // section 7.4.2.. The WebSocket API (http://www.w3.org/TR/websockets/) + // defines this out of range error as InvalidAccessError in JavaScript. return PP_ERROR_NOACCESS; } @@ -234,6 +237,7 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code, // Install |callback|. close_callback_ = callback; + // Abort ongoing connect. if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) { state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_ABORTED); @@ -242,6 +246,13 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code, return PP_OK_COMPLETIONPENDING; } + // Abort ongoing receive. + if (wait_for_receive_) { + wait_for_receive_ = false; + receive_callback_var_ = NULL; + PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_ABORTED); + } + // Close connection. state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; WebString web_reason = WebString::fromUTF8(reason_string->value()); @@ -261,6 +272,10 @@ int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, if (!received_messages_.empty()) return DoReceive(); + // Check state again. In CLOSED state, no more messages will be received. + if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) + return PP_ERROR_BADARGUMENT; + // Returns PP_ERROR_FAILED after an error is received and received messages // is exhausted. if (error_was_received_) @@ -414,6 +429,7 @@ void PPB_WebSocket_Impl::didReceiveMessageError() { // But, if no messages are queued and ReceiveMessage() is now on going. // We must invoke the callback with error code here. wait_for_receive_ = false; + receive_callback_var_ = NULL; PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_FAILED); } @@ -454,7 +470,13 @@ void PPB_WebSocket_Impl::didClose(unsigned long unhandled_buffered_amount, state_ = PP_WEBSOCKETREADYSTATE_CLOSED_DEV; if (state == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) - PP_RunAndClearCompletionCallback(&connect_callback_, PP_OK); + PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_FAILED); + + if (wait_for_receive_) { + wait_for_receive_ = false; + receive_callback_var_ = NULL; + PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_ABORTED); + } if (state == PP_WEBSOCKETREADYSTATE_CLOSING_DEV) PP_RunAndClearCompletionCallback(&close_callback_, PP_OK); |