Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: ppapi/native_client/tests/ppapi_test_lib/testable_callback.h

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/native_client/tests/ppapi_test_lib/testable_callback.h
===================================================================
--- ppapi/native_client/tests/ppapi_test_lib/testable_callback.h (revision 0)
+++ ppapi/native_client/tests/ppapi_test_lib/testable_callback.h (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (c) 2011 The Native Client Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H
+#define NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H
+
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_stdint.h"
+
+// NOTE: if you use you TestableCallback you will need to enable
+// testing interfaces in PPAPIBrowserTester(), e.g.
+// "--enable-pepper-testing", c.f.
+// tests/ppapi_browser/ppb_graphics2d/nacl.scons
+//
+// Example Usage:
+//
+// void TestProgressSimple() {
+// TestableCallback callback(pp_instance(), true);
+// ...
+// rv = PPBURLLoader()->Open(loader, request, callback.GetCallback());
+// EXPECT(rv == PP_OK_COMPLETIONPENDING);
+
+// rv = callback.WaitForResult();
+// EXPECT(rv == PP_OK);
+// ...
+// }
+
+class TestableCallback {
+ public:
+ TestableCallback(PP_Instance instance, bool force_async);
+
+ // Get the callback to be passed to an asynchronous PPAPI call
+ PP_CompletionCallback GetCallback();
+
+ // Waits for the callback to be called and returns the
+ // result. Returns immediately if the callback was previously called
+ // and the result wasn't returned (i.e. each result value received
+ // by the callback is returned by WaitForResult() once and only
+ // once).
+ int32_t WaitForResult();
+
+ bool HasRun() const { return run_count_ != 0; }
+
+ // Make instance runnable again.
+ void Reset() {
+ run_count_ = 0;
+ have_result_ = false;
+ }
+
+ int32_t Result() const { return result_; }
+
+ private:
+ static void Handler(void* user_data, int32_t result);
+
+ bool have_result_; // is a result available?
+ int32_t result_; // value of the result
+ bool force_async_; // force callback to be always called
+ bool post_quit_task_; // has cleanup beem performed
+ unsigned run_count_; // number of times the callback has been called
+ PP_Instance instance_;
+};
+
+#endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H

Powered by Google App Engine
This is Rietveld 408576698