Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 | 8 |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 std::string result = method + std::string(" failed with error: ") + | 22 std::string result = method + std::string(" failed with error: ") + |
| 23 error_as_string; | 23 error_as_string; |
| 24 if (error == PP_ERROR_NOSPACE) | 24 if (error == PP_ERROR_NOSPACE) |
| 25 result += ". Did you run the test with --unlimited-quota-for-files?"; | 25 result += ". Did you run the test with --unlimited-quota-for-files?"; |
| 26 return result; | 26 return result; |
| 27 } | 27 } |
| 28 | 28 |
| 29 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) | 29 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) |
| 30 : have_result_(false), | 30 : have_result_(false), |
| 31 result_(PP_OK_COMPLETIONPENDING), | 31 result_(PP_OK_COMPLETIONPENDING), |
| 32 force_async_(false), | |
| 33 post_quit_task_(false), | |
| 34 run_count_(0), | |
| 35 instance_(instance) { | |
| 36 } | |
| 37 | |
| 38 TestCompletionCallback::TestCompletionCallback(PP_Instance instance, | |
| 39 bool force_async) | |
| 40 : result_(PP_OK_COMPLETIONPENDING), | |
|
brettw
2011/06/27 23:59:03
You forgot to initialize have_result. This caused
polina
2011/06/28 00:11:27
Lost somebody else's new field during a sync. Than
| |
| 41 force_async_(force_async), | |
| 32 post_quit_task_(false), | 42 post_quit_task_(false), |
| 33 run_count_(0), | 43 run_count_(0), |
| 34 instance_(instance) { | 44 instance_(instance) { |
| 35 } | 45 } |
| 36 | 46 |
| 37 int32_t TestCompletionCallback::WaitForResult() { | 47 int32_t TestCompletionCallback::WaitForResult() { |
| 38 if (!have_result_) { | 48 if (!have_result_) { |
| 39 result_ = PP_OK_COMPLETIONPENDING; // Reset | 49 result_ = PP_OK_COMPLETIONPENDING; // Reset |
| 40 post_quit_task_ = true; | 50 post_quit_task_ = true; |
| 41 GetTestingInterface()->RunMessageLoop(instance_); | 51 GetTestingInterface()->RunMessageLoop(instance_); |
| 42 } | 52 } |
| 43 have_result_ = false; | 53 have_result_ = false; |
| 44 return result_; | 54 return result_; |
| 45 } | 55 } |
| 46 | 56 |
| 47 TestCompletionCallback::operator pp::CompletionCallback() const { | 57 TestCompletionCallback::operator pp::CompletionCallback() const { |
| 58 int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); | |
| 48 return pp::CompletionCallback(&TestCompletionCallback::Handler, | 59 return pp::CompletionCallback(&TestCompletionCallback::Handler, |
| 49 const_cast<TestCompletionCallback*>(this)); | 60 const_cast<TestCompletionCallback*>(this), |
| 61 flags); | |
| 50 } | 62 } |
| 51 | 63 |
| 52 // static | 64 // static |
| 53 void TestCompletionCallback::Handler(void* user_data, int32_t result) { | 65 void TestCompletionCallback::Handler(void* user_data, int32_t result) { |
| 54 TestCompletionCallback* callback = | 66 TestCompletionCallback* callback = |
| 55 static_cast<TestCompletionCallback*>(user_data); | 67 static_cast<TestCompletionCallback*>(user_data); |
| 56 callback->result_ = result; | 68 callback->result_ = result; |
| 57 callback->have_result_ = true; | 69 callback->have_result_ = true; |
| 58 callback->run_count_++; | 70 callback->run_count_++; |
| 59 if (callback->post_quit_task_) { | 71 if (callback->post_quit_task_) { |
| 60 callback->post_quit_task_ = false; | 72 callback->post_quit_task_ = false; |
| 61 GetTestingInterface()->QuitMessageLoop(callback->instance_); | 73 GetTestingInterface()->QuitMessageLoop(callback->instance_); |
| 62 } | 74 } |
| 63 } | 75 } |
| OLD | NEW |