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

Unified Diff: ppapi/tests/test_websocket.cc

Issue 8821008: WebSocket Pepper API: Add unit test to call Close() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revised Created 9 years 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 94e2d457f63a6f6bc5fa8742189468691866eddc..b160f7506fa3dc0861823589fe0fd27eeb1bb2e2 100644
--- a/ppapi/tests/test_websocket.cc
+++ b/ppapi/tests/test_websocket.cc
@@ -17,19 +17,21 @@
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
-static const char kEchoServerURL[] =
+const char kEchoServerURL[] =
"ws://localhost:8880/websocket/tests/hybi/echo";
-static const char kProtocolTestServerURL[] =
+const char kProtocolTestServerURL[] =
"ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol=";
-static const char* kInvalidURLs[] = {
+const char* kInvalidURLs[] = {
dmichael (off chromium) 2011/12/06 17:07:34 'const char*' -> 'const char* const' (indicating t
Takashi Toyoshima 2011/12/06 17:47:18 Done.
"http://www.google.com/invalid_scheme",
"ws://www.google.com/invalid#fragment",
"ws://www.google.com:65535/invalid_port",
NULL
};
+const uint16_t kCloseCodeNormalClosure = 1000;
+
REGISTER_TEST_CASE(WebSocket);
bool TestWebSocket::Init() {
@@ -50,6 +52,8 @@ void TestWebSocket::RunTests(const std::string& filter) {
RUN_TEST(InvalidConnect, filter);
RUN_TEST(GetURL, filter);
RUN_TEST(ValidConnect, filter);
+ RUN_TEST(InvalidClose, filter);
+ RUN_TEST(ValidClose, filter);
RUN_TEST(GetProtocol, filter);
RUN_TEST(TextSendReceive, filter);
}
@@ -178,6 +182,105 @@ std::string TestWebSocket::TestValidConnect() {
PASS();
}
+std::string TestWebSocket::TestInvalidClose() {
+ PP_Var reason = CreateVar("close for test");
+ TestCompletionCallback callback(instance_->pp_instance());
+
+ // Close before connect.
+ PP_Resource ws = websocket_interface_->Create(instance_->pp_instance());
+ int32_t result = websocket_interface_->Close(
+ ws, kCloseCodeNormalClosure, reason,
+ static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
+ ASSERT_EQ(PP_ERROR_FAILED, result);
+ core_interface_->ReleaseResource(ws);
+
+ // Close with bad arguments.
+ ws = Connect(kEchoServerURL, &result, NULL);
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->Close(ws, 1, reason,
+ static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
+ ASSERT_EQ(PP_ERROR_NOACCESS, result);
+ core_interface_->ReleaseResource(ws);
+
+ ReleaseVar(reason);
+
+ PASS();
+}
+
+std::string TestWebSocket::TestValidClose() {
+ PP_Var reason = CreateVar("close for test");
+ PP_Var url = CreateVar(kEchoServerURL);
+ PP_Var protocols[] = { PP_MakeUndefined() };
+ TestCompletionCallback callback(instance_->pp_instance());
+ TestCompletionCallback another_callback(instance_->pp_instance());
+
+ // Close.
+ int32_t result;
+ PP_Resource ws = Connect(kEchoServerURL, &result, NULL);
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason,
+ static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = callback.WaitForResult();
dmichael (off chromium) 2011/12/06 17:07:34 Should you check the value of result is PP_OK?
Takashi Toyoshima 2011/12/06 17:47:18 Done.
+ core_interface_->ReleaseResource(ws);
+
+ // Close in connecting.
+ // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done
+ // successfully.
+ ws = websocket_interface_->Create(instance_->pp_instance());
+ result = websocket_interface_->Connect(ws, url, protocols, 0,
+ static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason,
+ static_cast<pp::CompletionCallback>(
+ another_callback).pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = callback.WaitForResult();
+ ASSERT_EQ(PP_ERROR_ABORTED, result);
+ result = another_callback.WaitForResult();
+ ASSERT_EQ(PP_OK, result);
+ core_interface_->ReleaseResource(ws);
+
+ // Close in closing.
+ // The first close will be done successfully, then the second one failed with
+ // with PP_ERROR_INPROGRESS immediately.
+ ws = Connect(kEchoServerURL, &result, NULL);
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason,
+ static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason,
+ static_cast<pp::CompletionCallback>(
+ another_callback).pp_completion_callback());
+ ASSERT_EQ(PP_ERROR_INPROGRESS, result);
+ result = callback.WaitForResult();
+ ASSERT_EQ(PP_OK, result);
+ core_interface_->ReleaseResource(ws);
+
+ // Close with ongoing receive message.
+ ws = Connect(kEchoServerURL, &result, NULL);
+ ASSERT_TRUE(ws);
+ ASSERT_EQ(PP_OK, result);
+ PP_Var receive_message_var;
+ result = websocket_interface_->ReceiveMessage(ws, &receive_message_var,
+ static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason,
+ static_cast<pp::CompletionCallback>(
+ another_callback).pp_completion_callback());
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+ result = callback.WaitForResult();
+ ASSERT_EQ(PP_ERROR_ABORTED, result);
+ result = another_callback.WaitForResult();
+ ASSERT_EQ(PP_OK, result);
+ core_interface_->ReleaseResource(ws);
+
dmichael (off chromium) 2011/12/06 17:07:34 I think you need to release 'reason' and 'url'
Takashi Toyoshima 2011/12/06 17:47:18 Done.
+ PASS();
+}
+
std::string TestWebSocket::TestGetProtocol() {
const char* expected_protocols[] = {
"x-chat",

Powered by Google App Engine
This is Rietveld 408576698