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 | |
141 if (!testing_interface_) { | 140 if (!testing_interface_) { |
142 return "Testing blocking callbacks requires the testing interface. In " | 141 return "Testing blocking callbacks requires the testing interface. In " |
143 "Chrome, use the --enable-pepper-testing flag."; | 142 "Chrome, use the --enable-pepper-testing flag."; |
144 } | 143 } |
145 // These tests are only valid if running out-of-process (threading is not | 144 // These tests are only valid if running out-of-process (threading is not |
146 // supported in-process). For in-process, just consider it a pass. | 145 // supported in-process). For in-process, just consider it a pass. |
147 if (!testing_interface_->IsOutOfProcess()) | 146 if (!testing_interface_->IsOutOfProcess()) |
148 return std::string(); | 147 return std::string(); |
149 pp::MessageLoop background_loop(instance_); | 148 pp::MessageLoop background_loop(instance_); |
150 ThreadedTestRunner<T> runner(instance_->pp_instance(), | 149 ThreadedTestRunner<T> runner(instance_->pp_instance(), |
151 static_cast<T*>(this), test_to_run, background_loop); | 150 static_cast<T*>(this), test_to_run, background_loop); |
152 RunOnThreadInternal(&ThreadedTestRunner<T>::ThreadFunction, &runner, | 151 RunOnThreadInternal(&ThreadedTestRunner<T>::ThreadFunction, &runner, |
153 testing_interface_); | 152 testing_interface_); |
154 return runner.result(); | 153 return runner.result(); |
155 #else | |
156 // If threading's not enabled, just treat it as success. | |
157 return std::string(); | |
158 #endif | |
159 } | 154 } |
160 | 155 |
161 // Pointer to the instance that owns us. | 156 // Pointer to the instance that owns us. |
162 TestingInstance* instance_; | 157 TestingInstance* instance_; |
163 | 158 |
164 // NULL unless InitTestingInterface is called. | 159 // NULL unless InitTestingInterface is called. |
165 const PPB_Testing_Dev* testing_interface_; | 160 const PPB_Testing_Dev* testing_interface_; |
166 | 161 |
167 // TODO(dmichael): Remove this, it's for temporary backwards compatibility so | 162 // TODO(dmichael): Remove this, it's for temporary backwards compatibility so |
168 // I don't have to change all the tests at once. | 163 // I don't have to change all the tests at once. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 #define ASSERT_SUBTEST_SUCCESS(function) \ | 383 #define ASSERT_SUBTEST_SUCCESS(function) \ |
389 do { \ | 384 do { \ |
390 std::string result = (function); \ | 385 std::string result = (function); \ |
391 if (!result.empty()) \ | 386 if (!result.empty()) \ |
392 return result; \ | 387 return result; \ |
393 } while (false) | 388 } while (false) |
394 | 389 |
395 #define PASS() return std::string() | 390 #define PASS() return std::string() |
396 | 391 |
397 #endif // PPAPI_TESTS_TEST_CASE_H_ | 392 #endif // PPAPI_TESTS_TEST_CASE_H_ |
OLD | NEW |