summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authortoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-14 09:31:37 +0000
committertoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-14 09:31:37 +0000
commit69d223830c3f768e0447f41ab90945978774e69a (patch)
tree430799f77a63871981cde235aafb5e290a1bcb3c /ppapi/tests
parent78a316d6b7340f978556481ee11ca22343b79a5c (diff)
downloadchromium_src-69d223830c3f768e0447f41ab90945978774e69a.zip
chromium_src-69d223830c3f768e0447f41ab90945978774e69a.tar.gz
chromium_src-69d223830c3f768e0447f41ab90945978774e69a.tar.bz2
Use new TestCompletionCallback scheme to simplify tests implementation.
BUG= TEST=browser_tests --gtest_filter='PPAPI*WebSocket*' Review URL: https://chromiumcodereview.appspot.com/10386041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136842 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_websocket.cc351
1 files changed, 169 insertions, 182 deletions
diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc
index 93ce956..3092655 100644
--- a/ppapi/tests/test_websocket.cc
+++ b/ppapi/tests/test_websocket.cc
@@ -280,20 +280,19 @@ PP_Resource TestWebSocket::Connect(const std::string& url,
if (!ws)
return 0;
PP_Var url_var = CreateVarString(url);
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
uint32_t protocol_count = 0U;
if (protocol.size()) {
protocols[0] = CreateVarString(protocol);
protocol_count = 1U;
}
- *result = websocket_interface_->Connect(
+ callback.WaitForResult(websocket_interface_->Connect(
ws, url_var, protocols, protocol_count,
- callback.GetCallback().pp_completion_callback());
+ callback.GetCallback().pp_completion_callback()));
ReleaseVar(url_var);
if (protocol.size())
ReleaseVar(protocols[0]);
- if (*result == PP_OK_COMPLETIONPENDING)
- *result = callback.WaitForResult();
+ *result = callback.result();
return ws;
}
@@ -359,20 +358,21 @@ std::string TestWebSocket::TestInvalidConnect() {
PP_Resource ws = websocket_interface_->Create(instance_->pp_instance());
ASSERT_TRUE(ws);
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
- int32_t result = websocket_interface_->Connect(
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
+ callback.WaitForResult(websocket_interface_->Connect(
ws, PP_MakeUndefined(), protocols, 1U,
- callback.GetCallback().pp_completion_callback());
- ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
+ callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
- result = websocket_interface_->Connect(
+ callback.WaitForResult(websocket_interface_->Connect(
ws, PP_MakeUndefined(), protocols, 1U,
- callback.GetCallback().pp_completion_callback());
- ASSERT_EQ(PP_ERROR_INPROGRESS, result);
+ callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_ERROR_INPROGRESS, callback.result());
core_interface_->ReleaseResource(ws);
for (int i = 0; kInvalidURLs[i]; ++i) {
+ int32_t result;
ws = Connect(kInvalidURLs[i], &result, "");
ASSERT_TRUE(ws);
ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
@@ -396,18 +396,16 @@ std::string TestWebSocket::TestProtocols() {
PP_Resource ws = websocket_interface_->Create(instance_->pp_instance());
ASSERT_TRUE(ws);
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
- int32_t result = websocket_interface_->Connect(
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
+ callback.WaitForResult(websocket_interface_->Connect(
ws, url, bad_protocols, 2U,
- callback.GetCallback().pp_completion_callback());
- if (result == PP_OK_COMPLETIONPENDING)
- result = callback.WaitForResult();
- ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
+ callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
core_interface_->ReleaseResource(ws);
ws = websocket_interface_->Create(instance_->pp_instance());
ASSERT_TRUE(ws);
- result = websocket_interface_->Connect(
+ int32_t result = websocket_interface_->Connect(
ws, url, good_protocols, 2U, PP_BlockUntilComplete());
ASSERT_EQ(PP_ERROR_BLOCKS_MAIN_THREAD, result);
core_interface_->ReleaseResource(ws);
@@ -452,34 +450,35 @@ std::string TestWebSocket::TestValidConnect() {
std::string TestWebSocket::TestInvalidClose() {
PP_Var reason = CreateVarString("close for test");
- TestCompletionCallback callback(instance_->pp_instance());
- TestCompletionCallback another_callback(instance_->pp_instance());
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
+ TestCompletionCallback async_callback(instance_->pp_instance(), PP_REQUIRED);
// Close before connect.
PP_Resource ws = websocket_interface_->Create(instance_->pp_instance());
- int32_t result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
- callback.GetCallback().pp_completion_callback());
- ASSERT_EQ(PP_ERROR_FAILED, result);
+ callback.WaitForResult(websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_ERROR_FAILED, callback.result());
core_interface_->ReleaseResource(ws);
// Close with bad arguments.
+ int32_t result;
ws = Connect(GetFullURL(kEchoServerURL), &result, "");
ASSERT_TRUE(ws);
ASSERT_EQ(PP_OK, result);
- result = websocket_interface_->Close(ws, 1U, reason,
- callback.GetCallback().pp_completion_callback());
- ASSERT_EQ(PP_ERROR_NOACCESS, result);
+ callback.WaitForResult(websocket_interface_->Close(
+ ws, 1U, reason, callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_ERROR_NOACCESS, callback.result());
core_interface_->ReleaseResource(ws);
// Close with PP_VARTYPE_NULL.
ws = Connect(GetFullURL(kEchoServerURL), &result, "");
ASSERT_TRUE(ws);
ASSERT_EQ(PP_OK, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(),
- callback.GetCallback().pp_completion_callback());
- ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
+ callback.WaitForResult(websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(),
+ callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
core_interface_->ReleaseResource(ws);
// Close with PP_VARTYPE_NULL and ongoing receive message.
@@ -487,20 +486,21 @@ std::string TestWebSocket::TestInvalidClose() {
ASSERT_TRUE(ws);
ASSERT_EQ(PP_OK, result);
PP_Var receive_message_var;
- result = websocket_interface_->ReceiveMessage(ws, &receive_message_var,
- callback.GetCallback().pp_completion_callback());
+ result = websocket_interface_->ReceiveMessage(
+ ws, &receive_message_var,
+ async_callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(),
- another_callback.GetCallback().pp_completion_callback());
- ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
+ callback.WaitForResult(websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(),
+ callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
const char* send_message = "hi";
PP_Var send_message_var = CreateVarString(send_message);
result = websocket_interface_->SendMessage(ws, send_message_var);
ReleaseVar(send_message_var);
ASSERT_EQ(PP_OK, result);
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ async_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_OK, async_callback.result());
ASSERT_TRUE(AreEqualWithString(receive_message_var, send_message));
ReleaseVar(receive_message_var);
core_interface_->ReleaseResource(ws);
@@ -509,25 +509,23 @@ std::string TestWebSocket::TestInvalidClose() {
ws = Connect(GetFullURL(kEchoServerURL), &result, "");
ASSERT_TRUE(ws);
ASSERT_EQ(PP_OK, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
- callback.GetCallback().pp_completion_callback());
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ async_callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
// Call another Close() before previous one is in progress.
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
- another_callback.GetCallback().pp_completion_callback());
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_ERROR_INPROGRESS, result);
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ async_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_OK, async_callback.result());
// Call another Close() after previous one is completed.
// This Close() must do nothing and reports no error.
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
- callback.GetCallback().pp_completion_callback());
- if (result == PP_OK_COMPLETIONPENDING)
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_OK, callback.result());
core_interface_->ReleaseResource(ws);
ReleaseVar(reason);
@@ -539,49 +537,48 @@ std::string TestWebSocket::TestValidClose() {
PP_Var reason = CreateVarString("close for test");
PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str());
PP_Var protocols[] = { PP_MakeUndefined() };
- TestCompletionCallback callback(instance_->pp_instance());
- TestCompletionCallback another_callback(instance_->pp_instance());
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
+ TestCompletionCallback another_callback(
+ instance_->pp_instance(), callback_type());
// Close.
int32_t result;
PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, "");
ASSERT_TRUE(ws);
ASSERT_EQ(PP_OK, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
- callback.GetCallback().pp_completion_callback());
- ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ callback.GetCallback().pp_completion_callback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_OK, callback.result());
core_interface_->ReleaseResource(ws);
// Close with PP_VARTYPE_UNDEFINED.
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());
- ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
+ callback.GetCallback().pp_completion_callback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_OK, callback.result());
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, 0U,
- callback.GetCallback().pp_completion_callback());
+ result = websocket_interface_->Connect(
+ ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
another_callback.GetCallback().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);
+ callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_ERROR_ABORTED, callback.result());
+ another_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_OK, another_callback.result());
core_interface_->ReleaseResource(ws);
// Close in closing.
@@ -590,16 +587,16 @@ std::string TestWebSocket::TestValidClose() {
ws = Connect(GetFullURL(kEchoServerURL), &result, "");
ASSERT_TRUE(ws);
ASSERT_EQ(PP_OK, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
another_callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_ERROR_INPROGRESS, result);
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_OK, callback.result());
core_interface_->ReleaseResource(ws);
// Close with ongoing receive message.
@@ -607,34 +604,36 @@ std::string TestWebSocket::TestValidClose() {
ASSERT_TRUE(ws);
ASSERT_EQ(PP_OK, result);
PP_Var receive_message_var;
- result = websocket_interface_->ReceiveMessage(ws, &receive_message_var,
+ result = websocket_interface_->ReceiveMessage(
+ ws, &receive_message_var,
callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
another_callback.GetCallback().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);
+ callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_ERROR_ABORTED, callback.result());
+ another_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_OK, another_callback.result());
core_interface_->ReleaseResource(ws);
// Close with PP_VARTYPE_UNDEFINED and ongoing receive message.
ws = Connect(GetFullURL(kEchoServerURL), &result, "");
ASSERT_TRUE(ws);
ASSERT_EQ(PP_OK, result);
- result = websocket_interface_->ReceiveMessage(ws, &receive_message_var,
+ result = websocket_interface_->ReceiveMessage(
+ ws, &receive_message_var,
callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
another_callback.GetCallback().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);
+ callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_ERROR_ABORTED, callback.result());
+ another_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
+ ASSERT_EQ(PP_OK, another_callback.result());
core_interface_->ReleaseResource(ws);
// Server initiated closing handshake.
@@ -697,14 +696,11 @@ std::string TestWebSocket::TestTextSendReceive() {
ASSERT_EQ(PP_OK, result);
// Receive echoed 'hello pepper'.
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
PP_Var received_message;
- result = websocket_interface_->ReceiveMessage(ws, &received_message,
- callback.GetCallback().pp_completion_callback());
- ASSERT_FALSE(result != PP_OK && result != PP_OK_COMPLETIONPENDING);
- if (result == PP_OK_COMPLETIONPENDING)
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(websocket_interface_->ReceiveMessage(
+ ws, &received_message, callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_OK, callback.result());
ASSERT_TRUE(AreEqualWithString(received_message, message));
ReleaseVar(received_message);
core_interface_->ReleaseResource(ws);
@@ -729,14 +725,11 @@ std::string TestWebSocket::TestBinarySendReceive() {
ASSERT_EQ(PP_OK, result);
// Receive echoed binary.
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
PP_Var received_message;
- result = websocket_interface_->ReceiveMessage(ws, &received_message,
- callback.GetCallback().pp_completion_callback());
- ASSERT_TRUE(result == PP_OK || result == PP_OK_COMPLETIONPENDING);
- if (result == PP_OK_COMPLETIONPENDING)
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(websocket_interface_->ReceiveMessage(
+ ws, &received_message, callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_OK, callback.result());
ASSERT_TRUE(AreEqualWithBinary(received_message, binary));
ReleaseVar(received_message);
core_interface_->ReleaseResource(ws);
@@ -783,15 +776,13 @@ std::string TestWebSocket::TestStressedSendReceive() {
ReleaseVar(large_binary_var);
// Receive echoed data.
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
for (int i = 0; i <= 512; ++i) {
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
PP_Var received_message;
- result = websocket_interface_->ReceiveMessage(
- ws, &received_message, callback.GetCallback().pp_completion_callback());
- ASSERT_TRUE(result == PP_OK || result == PP_OK_COMPLETIONPENDING);
- if (result == PP_OK_COMPLETIONPENDING)
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(websocket_interface_->ReceiveMessage(
+ ws, &received_message,
+ callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_OK, callback.result());
if (i == 512) {
ASSERT_TRUE(AreEqualWithBinary(received_message, large_binary));
} else if (i & 1) {
@@ -832,16 +823,16 @@ std::string TestWebSocket::TestBufferedAmount() {
// Close connection.
std::string reason_str = "close while busy";
PP_Var reason = CreateVarString(reason_str.c_str());
- TestCompletionCallback callback(instance_->pp_instance());
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason,
callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING,
websocket_interface_->GetReadyState(ws));
- result = callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(result);
+ ASSERT_EQ(PP_OK, callback.result());
ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED,
websocket_interface_->GetReadyState(ws));
@@ -895,13 +886,14 @@ std::string TestWebSocket::TestAbortCalls() {
ASSERT_TRUE(ws);
PP_Var url_var = CreateVarString(url);
TestCompletionCallback connect_callback(
- instance_->pp_instance(), force_async_);
- result = websocket_interface_->Connect(ws, url_var, NULL, 0,
+ instance_->pp_instance(), callback_type());
+ result = websocket_interface_->Connect(
+ ws, url_var, NULL, 0,
connect_callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
core_interface_->ReleaseResource(ws);
- result = connect_callback.WaitForResult();
- ASSERT_EQ(PP_ERROR_ABORTED, result);
+ connect_callback.WaitForResult(result);
+ ASSERT_EQ(PP_ERROR_ABORTED, connect_callback.result());
ReleaseVar(url_var);
// Test the behavior for Close().
@@ -910,14 +902,14 @@ std::string TestWebSocket::TestAbortCalls() {
ASSERT_EQ(PP_OK, result);
PP_Var reason_var = CreateVarString("abort");
TestCompletionCallback close_callback(
- instance_->pp_instance(), force_async_);
- result = websocket_interface_->Close(ws,
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason_var,
+ instance_->pp_instance(), callback_type());
+ result = websocket_interface_->Close(
+ ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason_var,
close_callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
core_interface_->ReleaseResource(ws);
- result = close_callback.WaitForResult();
- ASSERT_EQ(PP_ERROR_ABORTED, result);
+ close_callback.WaitForResult(result);
+ ASSERT_EQ(PP_ERROR_ABORTED, close_callback.result());
ReleaseVar(reason_var);
// Test the behavior for ReceiveMessage().
@@ -927,13 +919,14 @@ std::string TestWebSocket::TestAbortCalls() {
ASSERT_EQ(PP_OK, result);
PP_Var receive_var;
TestCompletionCallback receive_callback(
- instance_->pp_instance(), force_async_);
- result = websocket_interface_->ReceiveMessage(ws, &receive_var,
+ instance_->pp_instance(), callback_type());
+ result = websocket_interface_->ReceiveMessage(
+ ws, &receive_var,
receive_callback.GetCallback().pp_completion_callback());
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
core_interface_->ReleaseResource(ws);
- result = receive_callback.WaitForResult();
- ASSERT_EQ(PP_ERROR_ABORTED, result);
+ receive_callback.WaitForResult(result);
+ ASSERT_EQ(PP_ERROR_ABORTED, receive_callback.result());
// Test the behavior where receive process might be in-flight.
const char* text = "yukarin";
@@ -950,25 +943,21 @@ std::string TestWebSocket::TestAbortCalls() {
result = websocket_interface_->SendMessage(ws, text_var);
ASSERT_EQ(PP_OK, result);
}
- std::auto_ptr<TestCompletionCallback> callback;
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
PP_Var var;
for (int i = 0; i < trial; ++i) {
- callback.reset(
- new TestCompletionCallback(instance_->pp_instance(), force_async_));
- result = websocket_interface_->ReceiveMessage(
- ws, &var, callback->GetCallback().pp_completion_callback());
- if (result == PP_OK_COMPLETIONPENDING)
- result = callback->WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(websocket_interface_->ReceiveMessage(
+ ws, &var, callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_OK, callback.result());
ASSERT_TRUE(AreEqualWithString(var, text));
ReleaseVar(var);
}
result = websocket_interface_->ReceiveMessage(
- ws, &var, callback->GetCallback().pp_completion_callback());
+ ws, &var, callback.GetCallback().pp_completion_callback());
core_interface_->ReleaseResource(ws);
if (result != PP_OK) {
- result = callback->WaitForResult();
- ASSERT_EQ(PP_ERROR_ABORTED, result);
+ callback.WaitForResult(result);
+ ASSERT_EQ(PP_ERROR_ABORTED, callback.result());
}
}
// Same test, but the last receiving message is large message over 64KiB.
@@ -983,25 +972,21 @@ std::string TestWebSocket::TestAbortCalls() {
result = websocket_interface_->SendMessage(ws, text_var);
ASSERT_EQ(PP_OK, result);
}
- std::auto_ptr<TestCompletionCallback> callback;
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
PP_Var var;
for (int i = 0; i < trial; ++i) {
- callback.reset(
- new TestCompletionCallback(instance_->pp_instance(), force_async_));
- result = websocket_interface_->ReceiveMessage(
- ws, &var, callback->GetCallback().pp_completion_callback());
- if (result == PP_OK_COMPLETIONPENDING)
- result = callback->WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ callback.WaitForResult(websocket_interface_->ReceiveMessage(
+ ws, &var, callback.GetCallback().pp_completion_callback()));
+ ASSERT_EQ(PP_OK, callback.result());
ASSERT_TRUE(AreEqualWithString(var, text));
ReleaseVar(var);
}
result = websocket_interface_->ReceiveMessage(
- ws, &var, callback->GetCallback().pp_completion_callback());
+ ws, &var, callback.GetCallback().pp_completion_callback());
core_interface_->ReleaseResource(ws);
if (result != PP_OK) {
- result = callback->WaitForResult();
- ASSERT_EQ(PP_ERROR_ABORTED, result);
+ callback.WaitForResult(result);
+ ASSERT_EQ(PP_ERROR_ABORTED, callback.result());
}
}
@@ -1027,15 +1012,15 @@ std::string TestWebSocket::TestCcInterfaces() {
ASSERT_TRUE(AreEqualWithString(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(GetFullURL(kCloseServerURL)), NULL, 0U,
- connect_callback);
- ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = connect_callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ TestCompletionCallback connect_callback(
+ instance_->pp_instance(), callback_type());
+ connect_callback.WaitForResult(ws.Connect(
+ pp::Var(GetFullURL(kCloseServerURL)), NULL, 0U, connect_callback));
+ CHECK_CALLBACK_BEHAVIOR(connect_callback);
+ ASSERT_EQ(PP_OK, connect_callback.result());
std::string text_message("hello C++");
- result = ws.SendMessage(pp::Var(text_message));
+ int32_t result = ws.SendMessage(pp::Var(text_message));
ASSERT_EQ(PP_OK, result);
std::vector<uint8_t> binary(256);
@@ -1046,38 +1031,40 @@ std::string TestWebSocket::TestCcInterfaces() {
ASSERT_EQ(PP_OK, result);
pp::Var text_receive_var;
- TestCompletionCallback text_receive_callback(instance_->pp_instance());
- result = ws.ReceiveMessage(&text_receive_var, text_receive_callback);
- if (result == PP_OK_COMPLETIONPENDING)
- result = text_receive_callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ TestCompletionCallback text_receive_callback(
+ instance_->pp_instance(), callback_type());
+ text_receive_callback.WaitForResult(
+ ws.ReceiveMessage(&text_receive_var, text_receive_callback));
+ ASSERT_EQ(PP_OK, text_receive_callback.result());
ASSERT_TRUE(
AreEqualWithString(text_receive_var.pp_var(), text_message.c_str()));
pp::Var binary_receive_var;
- TestCompletionCallback binary_receive_callback(instance_->pp_instance());
- result = ws.ReceiveMessage(&binary_receive_var, binary_receive_callback);
- if (result == PP_OK_COMPLETIONPENDING)
- result = binary_receive_callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ TestCompletionCallback binary_receive_callback(
+ instance_->pp_instance(), callback_type());
+ binary_receive_callback.WaitForResult(
+ ws.ReceiveMessage(&binary_receive_var, binary_receive_callback));
+ ASSERT_EQ(PP_OK, binary_receive_callback.result());
ASSERT_TRUE(AreEqualWithBinary(binary_receive_var.pp_var(), binary));
- TestCompletionCallback close_callback(instance_->pp_instance());
+ TestCompletionCallback close_callback(
+ instance_->pp_instance(), callback_type());
std::string reason("bye");
- result = ws.Close(
- PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason), close_callback);
- ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- result = close_callback.WaitForResult();
- ASSERT_EQ(PP_OK, result);
+ close_callback.WaitForResult(ws.Close(
+ PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason), close_callback));
+ CHECK_CALLBACK_BEHAVIOR(close_callback);
+ ASSERT_EQ(PP_OK, close_callback.result());
// Check initialized properties access.
ASSERT_EQ(0, ws.GetBufferedAmount());
ASSERT_EQ(PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, ws.GetCloseCode());
- ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str()));
+ ASSERT_TRUE(
+ AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str()));
ASSERT_EQ(true, ws.GetCloseWasClean());
ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), ""));
ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState());
- ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), GetFullURL(kCloseServerURL).c_str()));
+ ASSERT_TRUE(AreEqualWithString(
+ ws.GetURL().pp_var(), GetFullURL(kCloseServerURL).c_str()));
PASS();
}