From 917e86adc3f824f518c999dcba20bfd4cbf18a18 Mon Sep 17 00:00:00 2001 From: "polina@google.com" Date: Thu, 30 Jun 2011 21:42:37 +0000 Subject: Add a flag field to PP_CompletionCallback to control if the callback should always be invoked asynchronously on success or error or skipped if the operation can complete synchronously without blocking. Keep the default behavior as-is until clients update their code. Bump revisions of all interfaces that take callbacks as args. Update browser interface function implementations and C++ layer to force callbacks if sync option is not set. Change ppapi/tests to run tests involving callbacks with both flag options. BUG=79376 TEST=ppapi_tests + bots Review URL: http://codereview.chromium.org/6899055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91205 0039d316-1c4b-4281-b951-d872f2087c98 --- ppapi/tests/test_transport.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'ppapi/tests/test_transport.cc') diff --git a/ppapi/tests/test_transport.cc b/ppapi/tests/test_transport.cc index fc41f17..d45112a 100644 --- a/ppapi/tests/test_transport.cc +++ b/ppapi/tests/test_transport.cc @@ -54,7 +54,7 @@ class StreamReader { buffer_.resize(kReadBufferSize); int result = transport_->Recv( &buffer_[0], buffer_.size(), - callback_factory_.NewCallback(&StreamReader::OnReadFinished)); + callback_factory_.NewOptionalCallback(&StreamReader::OnReadFinished)); if (result > 0) DidFinishRead(result); else @@ -104,7 +104,7 @@ bool TestTransport::Init() { void TestTransport::RunTest() { RUN_TEST(Create); RUN_TEST(Connect); - RUN_TEST(SendDataUdp); + RUN_TEST_FORCEASYNC(SendDataUdp); RUN_TEST(SendDataTcp); RUN_TEST(ConnectAndCloseUdp); RUN_TEST(ConnectAndCloseTcp); @@ -198,10 +198,15 @@ std::string TestTransport::TestSendDataUdp() { // Put packet index in the beginning. memcpy(&send_buffer[0], &i, sizeof(i)); - TestCompletionCallback send_cb(instance_->pp_instance()); - ASSERT_EQ( - transport2_->Send(&send_buffer[0], send_buffer.size(), send_cb), - static_cast(send_buffer.size())); + TestCompletionCallback send_cb(instance_->pp_instance(), force_async_); + int32_t result = transport2_->Send(&send_buffer[0], send_buffer.size(), + send_cb); + if (force_async_) { + ASSERT_EQ(result, PP_OK_COMPLETIONPENDING); + ASSERT_EQ(send_cb.WaitForResult(), static_cast(send_buffer.size())); + } else { + ASSERT_EQ(result, static_cast(send_buffer.size())); + } sent_packets[i] = send_buffer; } @@ -243,9 +248,11 @@ std::string TestTransport::TestSendDataTcp() { int pos = 0; while (pos < static_cast(send_buffer.size())) { - TestCompletionCallback send_cb(instance_->pp_instance()); + TestCompletionCallback send_cb(instance_->pp_instance(), force_async_); int result = transport2_->Send( &send_buffer[0] + pos, send_buffer.size() - pos, send_cb); + if (force_async_) + ASSERT_EQ(result, PP_OK_COMPLETIONPENDING); if (result == PP_OK_COMPLETIONPENDING) result = send_cb.WaitForResult(); ASSERT_TRUE(result > 0); -- cgit v1.1