| Index: ppapi/tests/test_websocket.cc
|
| diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc
|
| index 29aca17730f6f41d5cdd2c6070f80d53f8e51912..6bbc5c138f1a6af6261122de4840cb90e7834577 100644
|
| --- a/ppapi/tests/test_websocket.cc
|
| +++ b/ppapi/tests/test_websocket.cc
|
| @@ -12,6 +12,7 @@
|
| #include "ppapi/c/pp_completion_callback.h"
|
| #include "ppapi/c/ppb_core.h"
|
| #include "ppapi/c/ppb_var.h"
|
| +#include "ppapi/cpp/dev/websocket_dev.h"
|
| #include "ppapi/cpp/instance.h"
|
| #include "ppapi/cpp/module.h"
|
| #include "ppapi/tests/test_utils.h"
|
| @@ -19,6 +20,8 @@
|
|
|
| const char kEchoServerURL[] =
|
| "ws://localhost:8880/websocket/tests/hybi/echo";
|
| +const char kCloseServerURL[] =
|
| + "ws://localhost:8880/websocket/tests/hybi/close";
|
|
|
| const char kProtocolTestServerURL[] =
|
| "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol=";
|
| @@ -33,7 +36,7 @@ const char* const kInvalidURLs[] = {
|
| // Connection close code is defined in WebSocket protocol specification.
|
| // The magic number 1000 means gracefull closure without any error.
|
| // See section 7.4.1. of RFC 6455.
|
| -const uint16_t kCloseCodeNormalClosure = 1000;
|
| +const uint16_t kCloseCodeNormalClosure = 1000U;
|
|
|
| REGISTER_TEST_CASE(WebSocket);
|
|
|
| @@ -60,6 +63,8 @@ void TestWebSocket::RunTests(const std::string& filter) {
|
| RUN_TEST(ValidClose, filter);
|
| RUN_TEST(GetProtocol, filter);
|
| RUN_TEST(TextSendReceive, filter);
|
| +
|
| + RUN_TEST(CcInterfaces, filter);
|
| }
|
|
|
| PP_Var TestWebSocket::CreateVar(const char* string) {
|
| @@ -94,7 +99,7 @@ PP_Resource TestWebSocket::Connect(
|
| int protocol_count = 0;
|
| if (protocol) {
|
| protocols[0] = CreateVar(protocol);
|
| - protocol_count = 1;
|
| + protocol_count = 1U;
|
| }
|
| *result = websocket_interface_->Connect(
|
| ws, url_var, protocols, protocol_count,
|
| @@ -137,15 +142,18 @@ std::string TestWebSocket::TestUninitializedPropertiesAccess() {
|
|
|
| PP_Var close_reason = websocket_interface_->GetCloseReason(ws);
|
| ASSERT_TRUE(AreEqual(close_reason, ""));
|
| + ReleaseVar(close_reason);
|
|
|
| PP_Bool close_was_clean = websocket_interface_->GetCloseWasClean(ws);
|
| ASSERT_EQ(PP_FALSE, close_was_clean);
|
|
|
| PP_Var extensions = websocket_interface_->GetExtensions(ws);
|
| ASSERT_TRUE(AreEqual(extensions, ""));
|
| + ReleaseVar(extensions);
|
|
|
| PP_Var protocol = websocket_interface_->GetProtocol(ws);
|
| ASSERT_TRUE(AreEqual(protocol, ""));
|
| + ReleaseVar(protocol);
|
|
|
| PP_WebSocketReadyState_Dev ready_state =
|
| websocket_interface_->GetReadyState(ws);
|
| @@ -153,6 +161,7 @@ std::string TestWebSocket::TestUninitializedPropertiesAccess() {
|
|
|
| PP_Var url = websocket_interface_->GetURL(ws);
|
| ASSERT_TRUE(AreEqual(url, ""));
|
| + ReleaseVar(url);
|
|
|
| PASS();
|
| }
|
| @@ -165,12 +174,12 @@ std::string TestWebSocket::TestInvalidConnect() {
|
|
|
| TestCompletionCallback callback(instance_->pp_instance(), force_async_);
|
| int32_t result = websocket_interface_->Connect(
|
| - ws, PP_MakeUndefined(), protocols, 1,
|
| + ws, PP_MakeUndefined(), protocols, 1U,
|
| static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
|
| ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
|
|
|
| result = websocket_interface_->Connect(
|
| - ws, PP_MakeUndefined(), protocols, 1,
|
| + ws, PP_MakeUndefined(), protocols, 1U,
|
| static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
|
| ASSERT_EQ(PP_ERROR_INPROGRESS, result);
|
|
|
| @@ -379,3 +388,58 @@ std::string TestWebSocket::TestTextSendReceive() {
|
| // TODO(toyoshim): Add tests for didReceiveMessageError().
|
|
|
| // TODO(toyoshim): Add other function tests.
|
| +
|
| +std::string TestWebSocket::TestCcInterfaces() {
|
| + // C++ bindings is simple straightforward, then just verifies interfaces work
|
| + // as a interface bridge fine.
|
| + pp::WebSocket_Dev ws(instance_);
|
| +
|
| + // Check uninitialized properties access.
|
| + ASSERT_EQ(0, ws.GetBufferedAmount());
|
| + ASSERT_EQ(0, ws.GetCloseCode());
|
| + ASSERT_TRUE(AreEqual(ws.GetCloseReason().pp_var(), ""));
|
| + ASSERT_EQ(false, ws.GetCloseWasClean());
|
| + ASSERT_TRUE(AreEqual(ws.GetExtensions().pp_var(), ""));
|
| + ASSERT_TRUE(AreEqual(ws.GetProtocol().pp_var(), ""));
|
| + ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ws.GetReadyState());
|
| + ASSERT_TRUE(AreEqual(ws.GetURL().pp_var(), ""));
|
| +
|
| + // Check communication interfaces (connect, send, receive, and close).
|
| + TestCompletionCallback connect_callback(instance_->pp_instance());
|
| + int32_t result = ws.Connect(pp::Var(std::string(kCloseServerURL)), NULL, 0U,
|
| + connect_callback);
|
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
|
| + result = connect_callback.WaitForResult();
|
| + ASSERT_EQ(PP_OK, result);
|
| +
|
| + std::string message("hello C++");
|
| + result = ws.SendMessage(pp::Var(message));
|
| + ASSERT_EQ(PP_OK, result);
|
| +
|
| + pp::Var receive_var;
|
| + TestCompletionCallback receive_callback(instance_->pp_instance());
|
| + result = ws.ReceiveMessage(&receive_var, receive_callback);
|
| + if (result == PP_OK_COMPLETIONPENDING)
|
| + result = receive_callback.WaitForResult();
|
| + ASSERT_EQ(PP_OK, result);
|
| + ASSERT_TRUE(AreEqual(receive_var.pp_var(), message.c_str()));
|
| +
|
| + TestCompletionCallback close_callback(instance_->pp_instance());
|
| + std::string reason("bye");
|
| + result = ws.Close(kCloseCodeNormalClosure, pp::Var(reason), close_callback);
|
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
|
| + result = close_callback.WaitForResult();
|
| + ASSERT_EQ(PP_OK, result);
|
| +
|
| + // Check initialized properties access.
|
| + ASSERT_EQ(0, ws.GetBufferedAmount());
|
| + ASSERT_EQ(kCloseCodeNormalClosure, ws.GetCloseCode());
|
| + ASSERT_TRUE(AreEqual(ws.GetCloseReason().pp_var(), reason.c_str()));
|
| + ASSERT_EQ(true, ws.GetCloseWasClean());
|
| + ASSERT_TRUE(AreEqual(ws.GetExtensions().pp_var(), ""));
|
| + ASSERT_TRUE(AreEqual(ws.GetProtocol().pp_var(), ""));
|
| + ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, ws.GetReadyState());
|
| + ASSERT_TRUE(AreEqual(ws.GetURL().pp_var(), kCloseServerURL));
|
| +
|
| + PASS();
|
| +}
|
|
|