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

Side by Side Diff: ppapi/tests/test_utils.h

Issue 10661026: WebSocket Pepper API: allow to release in completion callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remvoe redundant checker Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/tests/test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_TESTS_TEST_UTILS_H_ 5 #ifndef PPAPI_TESTS_TEST_UTILS_H_
6 #define PPAPI_TESTS_TEST_UTILS_H_ 6 #define PPAPI_TESTS_TEST_UTILS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "ppapi/c/dev/ppb_testing_dev.h" 10 #include "ppapi/c/dev/ppb_testing_dev.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 bool waiting_; 55 bool waiting_;
56 bool signalled_; 56 bool signalled_;
57 // Disable copy and assign. 57 // Disable copy and assign.
58 NestedEvent(const NestedEvent&); 58 NestedEvent(const NestedEvent&);
59 NestedEvent& operator=(const NestedEvent&); 59 NestedEvent& operator=(const NestedEvent&);
60 }; 60 };
61 61
62 enum CallbackType { PP_REQUIRED, PP_OPTIONAL, PP_BLOCKING }; 62 enum CallbackType { PP_REQUIRED, PP_OPTIONAL, PP_BLOCKING };
63 class TestCompletionCallback { 63 class TestCompletionCallback {
64 public: 64 public:
65 class Delegate {
66 public:
67 virtual ~Delegate() {}
68 virtual void OnCallback(void* user_data, int32_t result) = 0;
69 };
65 explicit TestCompletionCallback(PP_Instance instance); 70 explicit TestCompletionCallback(PP_Instance instance);
66 // TODO(dmichael): Remove this constructor. 71 // TODO(dmichael): Remove this constructor.
67 TestCompletionCallback(PP_Instance instance, bool force_async); 72 TestCompletionCallback(PP_Instance instance, bool force_async);
68 73
69 TestCompletionCallback(PP_Instance instance, CallbackType callback_type); 74 TestCompletionCallback(PP_Instance instance, CallbackType callback_type);
70 75
76 // Sets a Delegate instance. OnCallback() of this instance will be invoked
77 // when the completion callback is invoked.
78 // The delegate will be reset when Reset() or GetCallback() is called.
79 void SetDelegate(Delegate* delegate) { delegate_ = delegate; }
80
71 // Waits for the callback to be called and returns the 81 // Waits for the callback to be called and returns the
72 // result. Returns immediately if the callback was previously called 82 // result. Returns immediately if the callback was previously called
73 // and the result wasn't returned (i.e. each result value received 83 // and the result wasn't returned (i.e. each result value received
74 // by the callback is returned by WaitForResult() once and only 84 // by the callback is returned by WaitForResult() once and only
75 // once). DEPRECATED: Please use the one below. 85 // once). DEPRECATED: Please use the one below.
76 // TODO(dmichael): Remove this one when all the tests are updated. 86 // TODO(dmichael): Remove this one when all the tests are updated.
77 int32_t WaitForResult(); 87 int32_t WaitForResult();
78 88
79 // Wait for a result, given the return from the call which took this callback 89 // Wait for a result, given the return from the call which took this callback
80 // as a parameter. If |result| is PP_OK_COMPLETIONPENDING, WaitForResult will 90 // as a parameter. If |result| is PP_OK_COMPLETIONPENDING, WaitForResult will
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 bool wait_for_result_called_; 156 bool wait_for_result_called_;
147 // Indicates whether we have already been invoked. 157 // Indicates whether we have already been invoked.
148 bool have_result_; 158 bool have_result_;
149 // The last result received (or PP_OK_COMPLETIONCALLBACK if none). 159 // The last result received (or PP_OK_COMPLETIONCALLBACK if none).
150 int32_t result_; 160 int32_t result_;
151 CallbackType callback_type_; 161 CallbackType callback_type_;
152 bool post_quit_task_; 162 bool post_quit_task_;
153 std::string errors_; 163 std::string errors_;
154 unsigned run_count_; 164 unsigned run_count_;
155 PP_Instance instance_; 165 PP_Instance instance_;
166 Delegate* delegate_;
156 }; 167 };
157 168
158 // Verifies that the callback didn't record any errors. If the callback is run 169 // Verifies that the callback didn't record any errors. If the callback is run
159 // in an unexpected way (e.g., if it's invoked asynchronously when the call 170 // in an unexpected way (e.g., if it's invoked asynchronously when the call
160 // should have blocked), this returns an appropriate error string. 171 // should have blocked), this returns an appropriate error string.
161 #define CHECK_CALLBACK_BEHAVIOR(callback) \ 172 #define CHECK_CALLBACK_BEHAVIOR(callback) \
162 do { \ 173 do { \
163 if ((callback).failed()) \ 174 if ((callback).failed()) \
164 return (callback).errors(); \ 175 return (callback).errors(); \
165 } while (false) 176 } while (false)
(...skipping 22 matching lines...) Expand all
188 #error Please add support for your platform in ppapi/tests/test_utils.h 199 #error Please add support for your platform in ppapi/tests/test_utils.h
189 #endif 200 #endif
190 201
191 /* These are used to determine POSIX-like implementations vs Windows. */ 202 /* These are used to determine POSIX-like implementations vs Windows. */
192 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ 203 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
193 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__) 204 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__)
194 #define PPAPI_POSIX 1 205 #define PPAPI_POSIX 1
195 #endif 206 #endif
196 207
197 #endif // PPAPI_TESTS_TEST_UTILS_H_ 208 #endif // PPAPI_TESTS_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | ppapi/tests/test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698