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 : have_result_(false), |
| 41 result_(PP_OK_COMPLETIONPENDING), |
| 42 force_async_(force_async), |
32 post_quit_task_(false), | 43 post_quit_task_(false), |
33 run_count_(0), | 44 run_count_(0), |
34 instance_(instance) { | 45 instance_(instance) { |
35 } | 46 } |
36 | 47 |
37 int32_t TestCompletionCallback::WaitForResult() { | 48 int32_t TestCompletionCallback::WaitForResult() { |
38 if (!have_result_) { | 49 if (!have_result_) { |
39 result_ = PP_OK_COMPLETIONPENDING; // Reset | 50 result_ = PP_OK_COMPLETIONPENDING; // Reset |
40 post_quit_task_ = true; | 51 post_quit_task_ = true; |
41 GetTestingInterface()->RunMessageLoop(instance_); | 52 GetTestingInterface()->RunMessageLoop(instance_); |
42 } | 53 } |
43 have_result_ = false; | 54 have_result_ = false; |
44 return result_; | 55 return result_; |
45 } | 56 } |
46 | 57 |
47 TestCompletionCallback::operator pp::CompletionCallback() const { | 58 TestCompletionCallback::operator pp::CompletionCallback() const { |
| 59 int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); |
48 return pp::CompletionCallback(&TestCompletionCallback::Handler, | 60 return pp::CompletionCallback(&TestCompletionCallback::Handler, |
49 const_cast<TestCompletionCallback*>(this)); | 61 const_cast<TestCompletionCallback*>(this), |
| 62 flags); |
50 } | 63 } |
51 | 64 |
52 // static | 65 // static |
53 void TestCompletionCallback::Handler(void* user_data, int32_t result) { | 66 void TestCompletionCallback::Handler(void* user_data, int32_t result) { |
54 TestCompletionCallback* callback = | 67 TestCompletionCallback* callback = |
55 static_cast<TestCompletionCallback*>(user_data); | 68 static_cast<TestCompletionCallback*>(user_data); |
56 callback->result_ = result; | 69 callback->result_ = result; |
57 callback->have_result_ = true; | 70 callback->have_result_ = true; |
58 callback->run_count_++; | 71 callback->run_count_++; |
59 if (callback->post_quit_task_) { | 72 if (callback->post_quit_task_) { |
60 callback->post_quit_task_ = false; | 73 callback->post_quit_task_ = false; |
61 GetTestingInterface()->QuitMessageLoop(callback->instance_); | 74 GetTestingInterface()->QuitMessageLoop(callback->instance_); |
62 } | 75 } |
63 } | 76 } |
OLD | NEW |