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_CASE_H_ | 5 #ifndef PPAPI_TESTS_TEST_CASE_H_ |
6 #define PPAPI_TESTS_TEST_CASE_H_ | 6 #define PPAPI_TESTS_TEST_CASE_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // | 130 // |
131 // You should pass the error string from the test so far; if it is non-empty, | 131 // You should pass the error string from the test so far; if it is non-empty, |
132 // CheckResourcesAndVars will do nothing and return the same string. | 132 // CheckResourcesAndVars will do nothing and return the same string. |
133 std::string CheckResourcesAndVars(std::string errors); | 133 std::string CheckResourcesAndVars(std::string errors); |
134 | 134 |
135 PP_TimeTicks NowInTimeTicks(); | 135 PP_TimeTicks NowInTimeTicks(); |
136 | 136 |
137 // Run the given test method on a background thread and return the result. | 137 // Run the given test method on a background thread and return the result. |
138 template <class T> | 138 template <class T> |
139 std::string RunOnThread(std::string(T::*test_to_run)()) { | 139 std::string RunOnThread(std::string(T::*test_to_run)()) { |
| 140 #ifdef ENABLE_PEPPER_THREADING |
140 if (!testing_interface_) { | 141 if (!testing_interface_) { |
141 return "Testing blocking callbacks requires the testing interface. In " | 142 return "Testing blocking callbacks requires the testing interface. In " |
142 "Chrome, use the --enable-pepper-testing flag."; | 143 "Chrome, use the --enable-pepper-testing flag."; |
143 } | 144 } |
144 // These tests are only valid if running out-of-process (threading is not | 145 // These tests are only valid if running out-of-process (threading is not |
145 // supported in-process). For in-process, just consider it a pass. | 146 // supported in-process). For in-process, just consider it a pass. |
146 if (!testing_interface_->IsOutOfProcess()) | 147 if (!testing_interface_->IsOutOfProcess()) |
147 return std::string(); | 148 return std::string(); |
148 pp::MessageLoop background_loop(instance_); | 149 pp::MessageLoop background_loop(instance_); |
149 ThreadedTestRunner<T> runner(instance_->pp_instance(), | 150 ThreadedTestRunner<T> runner(instance_->pp_instance(), |
150 static_cast<T*>(this), test_to_run, background_loop); | 151 static_cast<T*>(this), test_to_run, background_loop); |
151 RunOnThreadInternal(&ThreadedTestRunner<T>::ThreadFunction, &runner, | 152 RunOnThreadInternal(&ThreadedTestRunner<T>::ThreadFunction, &runner, |
152 testing_interface_); | 153 testing_interface_); |
153 return runner.result(); | 154 return runner.result(); |
| 155 #else |
| 156 // If threading's not enabled, just treat it as success. |
| 157 return std::string(); |
| 158 #endif |
154 } | 159 } |
155 | 160 |
156 // Pointer to the instance that owns us. | 161 // Pointer to the instance that owns us. |
157 TestingInstance* instance_; | 162 TestingInstance* instance_; |
158 | 163 |
159 // NULL unless InitTestingInterface is called. | 164 // NULL unless InitTestingInterface is called. |
160 const PPB_Testing_Dev* testing_interface_; | 165 const PPB_Testing_Dev* testing_interface_; |
161 | 166 |
162 // TODO(dmichael): Remove this, it's for temporary backwards compatibility so | 167 // TODO(dmichael): Remove this, it's for temporary backwards compatibility so |
163 // I don't have to change all the tests at once. | 168 // I don't have to change all the tests at once. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 #define ASSERT_SUBTEST_SUCCESS(function) \ | 388 #define ASSERT_SUBTEST_SUCCESS(function) \ |
384 do { \ | 389 do { \ |
385 std::string result = (function); \ | 390 std::string result = (function); \ |
386 if (!result.empty()) \ | 391 if (!result.empty()) \ |
387 return result; \ | 392 return result; \ |
388 } while (false) | 393 } while (false) |
389 | 394 |
390 #define PASS() return std::string() | 395 #define PASS() return std::string() |
391 | 396 |
392 #endif // PPAPI_TESTS_TEST_CASE_H_ | 397 #endif // PPAPI_TESTS_TEST_CASE_H_ |
OLD | NEW |