| 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 #include "ppapi/tests/test_utils.h" | 5 #include "ppapi/tests/test_utils.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #if defined(_MSC_VER) | 9 #if defined(_MSC_VER) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) | 92 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) |
| 93 : wait_for_result_called_(false), | 93 : wait_for_result_called_(false), |
| 94 have_result_(false), | 94 have_result_(false), |
| 95 result_(PP_OK_COMPLETIONPENDING), | 95 result_(PP_OK_COMPLETIONPENDING), |
| 96 // TODO(dmichael): The default should probably be PP_REQUIRED, but this is | 96 // TODO(dmichael): The default should probably be PP_REQUIRED, but this is |
| 97 // what the tests currently expect. | 97 // what the tests currently expect. |
| 98 callback_type_(PP_OPTIONAL), | 98 callback_type_(PP_OPTIONAL), |
| 99 post_quit_task_(false), | 99 post_quit_task_(false), |
| 100 run_count_(0), // TODO(dmichael): Remove when all tests are updated. |
| 100 instance_(instance) { | 101 instance_(instance) { |
| 101 } | 102 } |
| 102 | 103 |
| 103 TestCompletionCallback::TestCompletionCallback(PP_Instance instance, | 104 TestCompletionCallback::TestCompletionCallback(PP_Instance instance, |
| 104 bool force_async) | 105 bool force_async) |
| 105 : wait_for_result_called_(false), | 106 : wait_for_result_called_(false), |
| 106 have_result_(false), | 107 have_result_(false), |
| 107 result_(PP_OK_COMPLETIONPENDING), | 108 result_(PP_OK_COMPLETIONPENDING), |
| 108 callback_type_(force_async ? PP_REQUIRED : PP_OPTIONAL), | 109 callback_type_(force_async ? PP_REQUIRED : PP_OPTIONAL), |
| 109 post_quit_task_(false), | 110 post_quit_task_(false), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 WaitForResult(result); | 166 WaitForResult(result); |
| 166 int32_t final_result = result_; | 167 int32_t final_result = result_; |
| 167 if (result == PP_OK_COMPLETIONPENDING) { | 168 if (result == PP_OK_COMPLETIONPENDING) { |
| 168 if (final_result != PP_ERROR_ABORTED) { | 169 if (final_result != PP_ERROR_ABORTED) { |
| 169 errors_.assign( | 170 errors_.assign( |
| 170 ReportError("TestCompletionCallback: Expected PP_ERROR_ABORTED or " | 171 ReportError("TestCompletionCallback: Expected PP_ERROR_ABORTED or " |
| 171 "PP_OK. Ran asynchronously.", | 172 "PP_OK. Ran asynchronously.", |
| 172 final_result)); | 173 final_result)); |
| 173 return; | 174 return; |
| 174 } | 175 } |
| 175 } else if (result != PP_OK) { | 176 } else if (result < PP_OK) { |
| 176 errors_.assign( | 177 errors_.assign( |
| 177 ReportError("TestCompletionCallback: Expected PP_ERROR_ABORTED or" | 178 ReportError("TestCompletionCallback: Expected PP_ERROR_ABORTED or " |
| 178 "PP_OK. Ran synchronously.", | 179 "non-error response. Ran synchronously.", |
| 179 result)); | 180 result)); |
| 180 return; | 181 return; |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 | 184 |
| 184 pp::CompletionCallback TestCompletionCallback::GetCallback() { | 185 pp::CompletionCallback TestCompletionCallback::GetCallback() { |
| 185 Reset(); | 186 Reset(); |
| 186 int32_t flags = 0; | 187 int32_t flags = 0; |
| 187 if (callback_type_ == PP_BLOCKING) | 188 if (callback_type_ == PP_BLOCKING) |
| 188 return pp::CompletionCallback(); | 189 return pp::CompletionCallback(); |
| 189 else if (callback_type_ == PP_OPTIONAL) | 190 else if (callback_type_ == PP_OPTIONAL) |
| 190 flags = PP_COMPLETIONCALLBACK_FLAG_OPTIONAL; | 191 flags = PP_COMPLETIONCALLBACK_FLAG_OPTIONAL; |
| 191 return pp::CompletionCallback(&TestCompletionCallback::Handler, | 192 return pp::CompletionCallback(&TestCompletionCallback::Handler, |
| 192 const_cast<TestCompletionCallback*>(this), | 193 const_cast<TestCompletionCallback*>(this), |
| 193 flags); | 194 flags); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void TestCompletionCallback::Reset() { | 197 void TestCompletionCallback::Reset() { |
| 197 wait_for_result_called_ = false; | 198 wait_for_result_called_ = false; |
| 198 result_ = PP_OK_COMPLETIONPENDING; | 199 result_ = PP_OK_COMPLETIONPENDING; |
| 199 have_result_ = false; | 200 have_result_ = false; |
| 200 post_quit_task_ = false; | 201 post_quit_task_ = false; |
| 202 run_count_ = 0; // TODO(dmichael): Remove when all tests are updated. |
| 201 errors_.clear(); | 203 errors_.clear(); |
| 202 } | 204 } |
| 203 | 205 |
| 204 // static | 206 // static |
| 205 void TestCompletionCallback::Handler(void* user_data, int32_t result) { | 207 void TestCompletionCallback::Handler(void* user_data, int32_t result) { |
| 206 TestCompletionCallback* callback = | 208 TestCompletionCallback* callback = |
| 207 static_cast<TestCompletionCallback*>(user_data); | 209 static_cast<TestCompletionCallback*>(user_data); |
| 210 // If this check fails, it means that the callback was invoked twice or that |
| 211 // the PPAPI call completed synchronously, but also ran the callback. |
| 208 PP_DCHECK(!callback->have_result_); | 212 PP_DCHECK(!callback->have_result_); |
| 209 callback->result_ = result; | 213 callback->result_ = result; |
| 210 callback->have_result_ = true; | 214 callback->have_result_ = true; |
| 215 callback->run_count_++; // TODO(dmichael): Remove when all tests are updated. |
| 211 if (callback->post_quit_task_) { | 216 if (callback->post_quit_task_) { |
| 212 callback->post_quit_task_ = false; | 217 callback->post_quit_task_ = false; |
| 213 GetTestingInterface()->QuitMessageLoop(callback->instance_); | 218 GetTestingInterface()->QuitMessageLoop(callback->instance_); |
| 214 } | 219 } |
| 215 } | 220 } |
| 216 | 221 |
| OLD | NEW |