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 <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "ppapi/c/pp_resource.h" | 13 #include "ppapi/c/pp_resource.h" |
14 #include "ppapi/c/dev/ppb_testing_dev.h" | 14 #include "ppapi/c/dev/ppb_testing_dev.h" |
15 #include "ppapi/cpp/dev/message_loop_dev.h" | |
16 #include "ppapi/cpp/dev/scrollbar_dev.h" | 15 #include "ppapi/cpp/dev/scrollbar_dev.h" |
| 16 #include "ppapi/cpp/message_loop.h" |
17 #include "ppapi/cpp/view.h" | 17 #include "ppapi/cpp/view.h" |
18 #include "ppapi/tests/test_utils.h" | 18 #include "ppapi/tests/test_utils.h" |
19 #include "ppapi/tests/testing_instance.h" | 19 #include "ppapi/tests/testing_instance.h" |
20 | 20 |
21 #if (defined __native_client__) | 21 #if (defined __native_client__) |
22 #include "ppapi/cpp/var.h" | 22 #include "ppapi/cpp/var.h" |
23 #else | 23 #else |
24 #include "ppapi/cpp/private/var_private.h" | 24 #include "ppapi/cpp/private/var_private.h" |
25 #endif | 25 #endif |
26 | 26 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 std::string RunOnThread(std::string(T::*test_to_run)()) { | 118 std::string RunOnThread(std::string(T::*test_to_run)()) { |
119 #ifdef ENABLE_PEPPER_THREADING | 119 #ifdef ENABLE_PEPPER_THREADING |
120 if (!testing_interface_) { | 120 if (!testing_interface_) { |
121 return "Testing blocking callbacks requires the testing interface. In " | 121 return "Testing blocking callbacks requires the testing interface. In " |
122 "Chrome, use the --enable-pepper-testing flag."; | 122 "Chrome, use the --enable-pepper-testing flag."; |
123 } | 123 } |
124 // These tests are only valid if running out-of-process (threading is not | 124 // These tests are only valid if running out-of-process (threading is not |
125 // supported in-process). For in-process, just consider it a pass. | 125 // supported in-process). For in-process, just consider it a pass. |
126 if (!testing_interface_->IsOutOfProcess()) | 126 if (!testing_interface_->IsOutOfProcess()) |
127 return std::string(); | 127 return std::string(); |
128 pp::MessageLoop_Dev background_loop(instance_); | 128 pp::MessageLoop background_loop(instance_); |
129 ThreadedTestRunner<T> runner(instance_->pp_instance(), | 129 ThreadedTestRunner<T> runner(instance_->pp_instance(), |
130 static_cast<T*>(this), test_to_run, background_loop); | 130 static_cast<T*>(this), test_to_run, background_loop); |
131 RunOnThreadInternal(&ThreadedTestRunner<T>::ThreadFunction, &runner, | 131 RunOnThreadInternal(&ThreadedTestRunner<T>::ThreadFunction, &runner, |
132 testing_interface_); | 132 testing_interface_); |
133 return runner.result(); | 133 return runner.result(); |
134 #else | 134 #else |
135 // If threading's not enabled, just treat it as success. | 135 // If threading's not enabled, just treat it as success. |
136 return std::string(); | 136 return std::string(); |
137 #endif | 137 #endif |
138 } | 138 } |
(...skipping 18 matching lines...) Expand all Loading... |
157 } | 157 } |
158 | 158 |
159 private: | 159 private: |
160 template <class T> | 160 template <class T> |
161 class ThreadedTestRunner { | 161 class ThreadedTestRunner { |
162 public: | 162 public: |
163 typedef std::string(T::*TestMethodType)(); | 163 typedef std::string(T::*TestMethodType)(); |
164 ThreadedTestRunner(PP_Instance instance, | 164 ThreadedTestRunner(PP_Instance instance, |
165 T* test_case, | 165 T* test_case, |
166 TestMethodType test_to_run, | 166 TestMethodType test_to_run, |
167 pp::MessageLoop_Dev loop) | 167 pp::MessageLoop loop) |
168 : instance_(instance), | 168 : instance_(instance), |
169 test_case_(test_case), | 169 test_case_(test_case), |
170 test_to_run_(test_to_run), | 170 test_to_run_(test_to_run), |
171 loop_(loop) { | 171 loop_(loop) { |
172 } | 172 } |
173 const std::string& result() { return result_; } | 173 const std::string& result() { return result_; } |
174 static void ThreadFunction(void* runner) { | 174 static void ThreadFunction(void* runner) { |
175 static_cast<ThreadedTestRunner<T>*>(runner)->Run(); | 175 static_cast<ThreadedTestRunner<T>*>(runner)->Run(); |
176 } | 176 } |
177 | 177 |
178 private: | 178 private: |
179 void Run() { | 179 void Run() { |
180 PP_DCHECK(PP_OK == loop_.AttachToCurrentThread()); | 180 PP_DCHECK(PP_OK == loop_.AttachToCurrentThread()); |
181 result_ = (test_case_->*test_to_run_)(); | 181 result_ = (test_case_->*test_to_run_)(); |
182 // Now give the loop a chance to clean up. | 182 // Now give the loop a chance to clean up. |
183 loop_.PostQuit(true /* should_destroy */); | 183 loop_.PostQuit(true /* should_destroy */); |
184 loop_.Run(); | 184 loop_.Run(); |
185 // Tell the main thread to quit its nested message loop, now that the test | 185 // Tell the main thread to quit its nested message loop, now that the test |
186 // is complete. | 186 // is complete. |
187 TestCase::QuitMainMessageLoop(instance_); | 187 TestCase::QuitMainMessageLoop(instance_); |
188 } | 188 } |
189 | 189 |
190 std::string result_; | 190 std::string result_; |
191 PP_Instance instance_; | 191 PP_Instance instance_; |
192 T* test_case_; | 192 T* test_case_; |
193 TestMethodType test_to_run_; | 193 TestMethodType test_to_run_; |
194 pp::MessageLoop_Dev loop_; | 194 pp::MessageLoop loop_; |
195 }; | 195 }; |
196 | 196 |
197 // The internals for RunOnThread. This allows us to avoid including | 197 // The internals for RunOnThread. This allows us to avoid including |
198 // pp_thread.h in this header file, since it includes system headers like | 198 // pp_thread.h in this header file, since it includes system headers like |
199 // windows.h. | 199 // windows.h. |
200 // RunOnThreadInternal launches a new thread to run |thread_func|, waits | 200 // RunOnThreadInternal launches a new thread to run |thread_func|, waits |
201 // for it to complete using RunMessageLoop(), then joins. | 201 // for it to complete using RunMessageLoop(), then joins. |
202 void RunOnThreadInternal(void (*thread_func)(void*), | 202 void RunOnThreadInternal(void (*thread_func)(void*), |
203 void* thread_param, | 203 void* thread_param, |
204 const PPB_Testing_Dev* testing_interface); | 204 const PPB_Testing_Dev* testing_interface); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 #define ASSERT_SUBTEST_SUCCESS(function) \ | 333 #define ASSERT_SUBTEST_SUCCESS(function) \ |
334 do { \ | 334 do { \ |
335 std::string result = (function); \ | 335 std::string result = (function); \ |
336 if (!result.empty()) \ | 336 if (!result.empty()) \ |
337 return result; \ | 337 return result; \ |
338 } while (false) | 338 } while (false) |
339 | 339 |
340 #define PASS() return std::string() | 340 #define PASS() return std::string() |
341 | 341 |
342 #endif // PPAPI_TESTS_TEST_CASE_H_ | 342 #endif // PPAPI_TESTS_TEST_CASE_H_ |
OLD | NEW |