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_graphics_2d.cc | 50 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'ppapi/tests/test_graphics_2d.cc') diff --git a/ppapi/tests/test_graphics_2d.cc b/ppapi/tests/test_graphics_2d.cc index 28483b4..2917180 100644 --- a/ppapi/tests/test_graphics_2d.cc +++ b/ppapi/tests/test_graphics_2d.cc @@ -43,15 +43,15 @@ bool TestGraphics2D::Init() { } void TestGraphics2D::RunTest() { - instance_->LogTest("InvalidResource", TestInvalidResource()); - instance_->LogTest("InvalidSize", TestInvalidSize()); - instance_->LogTest("Humongous", TestHumongous()); - instance_->LogTest("InitToZero", TestInitToZero()); - instance_->LogTest("Describe", TestDescribe()); - instance_->LogTest("Paint", TestPaint()); - //instance_->LogTest("Scroll", TestScroll()); // TODO(brettw) implement. - instance_->LogTest("Replace", TestReplace()); - instance_->LogTest("Flush", TestFlush()); + RUN_TEST(InvalidResource); + RUN_TEST(InvalidSize); + RUN_TEST(Humongous); + RUN_TEST(InitToZero); + RUN_TEST(Describe); + RUN_TEST_FORCEASYNC_AND_NOT(Paint); + // RUN_TEST_FORCEASYNC_AND_NOT(Scroll); // TODO(brettw) implement. + RUN_TEST_FORCEASYNC_AND_NOT(Replace); + RUN_TEST_FORCEASYNC_AND_NOT(Flush); } void TestGraphics2D::QuitMessageLoop() { @@ -79,8 +79,11 @@ bool TestGraphics2D::IsDCUniformColor(const pp::Graphics2D& dc, } bool TestGraphics2D::FlushAndWaitForDone(pp::Graphics2D* context) { - pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this); + int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); + pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this, flags); int32_t rv = context->Flush(cc); + if (force_async_ && rv != PP_OK_COMPLETIONPENDING) + return false; if (rv == PP_OK) return true; if (rv != PP_OK_COMPLETIONPENDING) @@ -209,11 +212,11 @@ std::string TestGraphics2D::TestInvalidResource() { // Flush. if (graphics_2d_interface_->Flush( image.pp_resource(), - PP_MakeCompletionCallback(&FlushCallbackNOP, NULL)) == PP_OK) + PP_MakeOptionalCompletionCallback(&FlushCallbackNOP, NULL)) == PP_OK) return "Flush succeeded with a different resource"; if (graphics_2d_interface_->Flush( null_context.pp_resource(), - PP_MakeCompletionCallback(&FlushCallbackNOP, NULL)) == PP_OK) + PP_MakeOptionalCompletionCallback(&FlushCallbackNOP, NULL)) == PP_OK) return "Flush succeeded with a NULL resource"; // ReadImageData. @@ -526,16 +529,27 @@ std::string TestGraphics2D::TestFlush() { if (!FlushAndWaitForDone(&dc_nopaints)) return "Couldn't flush the nopaint device"; + int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); + // Test that multiple flushes fail if we don't get a callback in between. - rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); + rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL, + flags)); + if (force_async_ && rv != PP_OK_COMPLETIONPENDING) + return "Flush must complete asynchronously."; if (rv != PP_OK && rv != PP_OK_COMPLETIONPENDING) return "Couldn't flush first time for multiple flush test."; - if (rv != PP_OK) { - // If the first flush would block, then a second should fail. - rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); - if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) - return "Second flush succeeded before callback ran."; + if (rv == PP_OK_COMPLETIONPENDING) { + // If the first flush completes asynchronously, then a second should fail. + rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL, + flags)); + if (force_async_) { + if (rv != PP_OK_COMPLETIONPENDING) + return "Second flush must fail asynchronously."; + } else { + if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) + return "Second flush succeeded before callback ran."; + } } PASS(); -- cgit v1.1