1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H
6 #define NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H
8 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_stdint.h"
12 // NOTE: if you use you TestableCallback you will need to enable
13 // testing interfaces in PPAPIBrowserTester(), e.g.
14 // "--enable-pepper-testing", c.f.
15 // tests/ppapi_browser/ppb_graphics2d/nacl.scons
19 // void TestProgressSimple() {
20 // TestableCallback callback(pp_instance(), true);
22 // rv = PPBURLLoader()->Open(loader, request, callback.GetCallback());
23 // EXPECT(rv == PP_OK_COMPLETIONPENDING);
25 // rv = callback.WaitForResult();
26 // EXPECT(rv == PP_OK);
30 class TestableCallback
{
32 TestableCallback(PP_Instance instance
, bool force_async
);
34 // Get the callback to be passed to an asynchronous PPAPI call
35 PP_CompletionCallback
GetCallback();
37 // Waits for the callback to be called and returns the
38 // result. Returns immediately if the callback was previously called
39 // and the result wasn't returned (i.e. each result value received
40 // by the callback is returned by WaitForResult() once and only
42 int32_t WaitForResult();
44 bool HasRun() const { return run_count_
!= 0; }
46 // Make instance runnable again.
52 int32_t Result() const { return result_
; }
55 static void Handler(void* user_data
, int32_t result
);
57 bool have_result_
; // is a result available?
58 int32_t result_
; // value of the result
59 bool force_async_
; // force callback to be always called
60 bool post_quit_task_
; // has cleanup beem performed
61 unsigned run_count_
; // number of times the callback has been called
62 PP_Instance instance_
;
65 #endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H