| OLD | NEW |
| 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 Loading... |
| 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 void OnCallback(void* user_data, int32_t result) = 0; |
| 68 }; |
| 65 explicit TestCompletionCallback(PP_Instance instance); | 69 explicit TestCompletionCallback(PP_Instance instance); |
| 66 // TODO(dmichael): Remove this constructor. | 70 // TODO(dmichael): Remove this constructor. |
| 67 TestCompletionCallback(PP_Instance instance, bool force_async); | 71 TestCompletionCallback(PP_Instance instance, bool force_async); |
| 68 | 72 |
| 69 TestCompletionCallback(PP_Instance instance, CallbackType callback_type); | 73 TestCompletionCallback(PP_Instance instance, CallbackType callback_type); |
| 70 | 74 |
| 75 // Sets a Delegate instance. OnCallback() of this instance will be invoked |
| 76 // when the completion callback is invoked. |
| 77 // The delegate will be reset when Reset() or GetCallback() is called. |
| 78 void SetDelegate(Delegate* delegate) { delegate_ = delegate; } |
| 79 |
| 71 // Waits for the callback to be called and returns the | 80 // Waits for the callback to be called and returns the |
| 72 // result. Returns immediately if the callback was previously called | 81 // result. Returns immediately if the callback was previously called |
| 73 // and the result wasn't returned (i.e. each result value received | 82 // and the result wasn't returned (i.e. each result value received |
| 74 // by the callback is returned by WaitForResult() once and only | 83 // by the callback is returned by WaitForResult() once and only |
| 75 // once). DEPRECATED: Please use the one below. | 84 // once). DEPRECATED: Please use the one below. |
| 76 // TODO(dmichael): Remove this one when all the tests are updated. | 85 // TODO(dmichael): Remove this one when all the tests are updated. |
| 77 int32_t WaitForResult(); | 86 int32_t WaitForResult(); |
| 78 | 87 |
| 79 // Wait for a result, given the return from the call which took this callback | 88 // 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 | 89 // as a parameter. If |result| is PP_OK_COMPLETIONPENDING, WaitForResult will |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 bool wait_for_result_called_; | 155 bool wait_for_result_called_; |
| 147 // Indicates whether we have already been invoked. | 156 // Indicates whether we have already been invoked. |
| 148 bool have_result_; | 157 bool have_result_; |
| 149 // The last result received (or PP_OK_COMPLETIONCALLBACK if none). | 158 // The last result received (or PP_OK_COMPLETIONCALLBACK if none). |
| 150 int32_t result_; | 159 int32_t result_; |
| 151 CallbackType callback_type_; | 160 CallbackType callback_type_; |
| 152 bool post_quit_task_; | 161 bool post_quit_task_; |
| 153 std::string errors_; | 162 std::string errors_; |
| 154 unsigned run_count_; | 163 unsigned run_count_; |
| 155 PP_Instance instance_; | 164 PP_Instance instance_; |
| 165 Delegate* delegate_; |
| 156 }; | 166 }; |
| 157 | 167 |
| 158 // Verifies that the callback didn't record any errors. If the callback is run | 168 // 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 | 169 // in an unexpected way (e.g., if it's invoked asynchronously when the call |
| 160 // should have blocked), this returns an appropriate error string. | 170 // should have blocked), this returns an appropriate error string. |
| 161 #define CHECK_CALLBACK_BEHAVIOR(callback) \ | 171 #define CHECK_CALLBACK_BEHAVIOR(callback) \ |
| 162 do { \ | 172 do { \ |
| 163 if ((callback).failed()) \ | 173 if ((callback).failed()) \ |
| 164 return (callback).errors(); \ | 174 return (callback).errors(); \ |
| 165 } while (false) | 175 } while (false) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 188 #error Please add support for your platform in ppapi/tests/test_utils.h | 198 #error Please add support for your platform in ppapi/tests/test_utils.h |
| 189 #endif | 199 #endif |
| 190 | 200 |
| 191 /* These are used to determine POSIX-like implementations vs Windows. */ | 201 /* These are used to determine POSIX-like implementations vs Windows. */ |
| 192 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ | 202 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ |
| 193 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__) | 203 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__) |
| 194 #define PPAPI_POSIX 1 | 204 #define PPAPI_POSIX 1 |
| 195 #endif | 205 #endif |
| 196 | 206 |
| 197 #endif // PPAPI_TESTS_TEST_UTILS_H_ | 207 #endif // PPAPI_TESTS_TEST_UTILS_H_ |
| OLD | NEW |