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 #include "ppapi/tests/test_utils.h" | 5 #include "ppapi/tests/test_utils.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #if defined(_MSC_VER) | 9 #if defined(_MSC_VER) |
10 #include <windows.h> | 10 #include <windows.h> |
11 #else | 11 #else |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/cpp/dev/message_loop_dev.h" | |
17 #include "ppapi/cpp/module.h" | 16 #include "ppapi/cpp/module.h" |
18 #include "ppapi/cpp/var.h" | 17 #include "ppapi/cpp/var.h" |
19 | 18 |
20 const int kActionTimeoutMs = 10000; | 19 const int kActionTimeoutMs = 10000; |
21 | 20 |
22 const PPB_Testing_Dev* GetTestingInterface() { | 21 const PPB_Testing_Dev* GetTestingInterface() { |
23 static const PPB_Testing_Dev* g_testing_interface = | 22 static const PPB_Testing_Dev* g_testing_interface = |
24 static_cast<const PPB_Testing_Dev*>( | 23 static_cast<const PPB_Testing_Dev*>( |
25 pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE)); | 24 pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE)); |
26 return g_testing_interface; | 25 return g_testing_interface; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 193 } |
195 } | 194 } |
196 | 195 |
197 pp::CompletionCallback TestCompletionCallback::GetCallback() { | 196 pp::CompletionCallback TestCompletionCallback::GetCallback() { |
198 Reset(); | 197 Reset(); |
199 int32_t flags = 0; | 198 int32_t flags = 0; |
200 if (callback_type_ == PP_BLOCKING) | 199 if (callback_type_ == PP_BLOCKING) |
201 return pp::CompletionCallback(); | 200 return pp::CompletionCallback(); |
202 else if (callback_type_ == PP_OPTIONAL) | 201 else if (callback_type_ == PP_OPTIONAL) |
203 flags = PP_COMPLETIONCALLBACK_FLAG_OPTIONAL; | 202 flags = PP_COMPLETIONCALLBACK_FLAG_OPTIONAL; |
204 target_loop_ = pp::MessageLoop_Dev::GetCurrent(); | 203 target_loop_ = pp::MessageLoop::GetCurrent(); |
205 return pp::CompletionCallback(&TestCompletionCallback::Handler, | 204 return pp::CompletionCallback(&TestCompletionCallback::Handler, |
206 const_cast<TestCompletionCallback*>(this), | 205 const_cast<TestCompletionCallback*>(this), |
207 flags); | 206 flags); |
208 } | 207 } |
209 | 208 |
210 void TestCompletionCallback::Reset() { | 209 void TestCompletionCallback::Reset() { |
211 wait_for_result_called_ = false; | 210 wait_for_result_called_ = false; |
212 result_ = PP_OK_COMPLETIONPENDING; | 211 result_ = PP_OK_COMPLETIONPENDING; |
213 have_result_ = false; | 212 have_result_ = false; |
214 post_quit_task_ = false; | 213 post_quit_task_ = false; |
(...skipping 11 matching lines...) Expand all Loading... |
226 PP_DCHECK(!callback->have_result_); | 225 PP_DCHECK(!callback->have_result_); |
227 callback->result_ = result; | 226 callback->result_ = result; |
228 callback->have_result_ = true; | 227 callback->have_result_ = true; |
229 callback->run_count_++; // TODO(dmichael): Remove when all tests are updated. | 228 callback->run_count_++; // TODO(dmichael): Remove when all tests are updated. |
230 if (callback->delegate_) | 229 if (callback->delegate_) |
231 callback->delegate_->OnCallback(user_data, result); | 230 callback->delegate_->OnCallback(user_data, result); |
232 if (callback->post_quit_task_) { | 231 if (callback->post_quit_task_) { |
233 callback->post_quit_task_ = false; | 232 callback->post_quit_task_ = false; |
234 callback->QuitMessageLoop(); | 233 callback->QuitMessageLoop(); |
235 } | 234 } |
236 if (callback->target_loop_ != pp::MessageLoop_Dev::GetCurrent()) { | 235 if (callback->target_loop_ != pp::MessageLoop::GetCurrent()) { |
237 // Note, in-process, loop_ and GetCurrent() will both be NULL, so should | 236 // Note, in-process, loop_ and GetCurrent() will both be NULL, so should |
238 // still be equal. | 237 // still be equal. |
239 callback->errors_.assign( | 238 callback->errors_.assign( |
240 ReportError("TestCompletionCallback: Callback ran on the wrong message " | 239 ReportError("TestCompletionCallback: Callback ran on the wrong message " |
241 "loop!", | 240 "loop!", |
242 result)); | 241 result)); |
243 } | 242 } |
244 } | 243 } |
245 | 244 |
246 void TestCompletionCallback::RunMessageLoop() { | 245 void TestCompletionCallback::RunMessageLoop() { |
247 pp::MessageLoop_Dev loop(pp::MessageLoop_Dev::GetCurrent()); | 246 pp::MessageLoop loop(pp::MessageLoop::GetCurrent()); |
248 // If we don't have a message loop, we're probably running in process, where | 247 // If we don't have a message loop, we're probably running in process, where |
249 // PPB_MessageLoop is not supported. Just use the Testing message loop. | 248 // PPB_MessageLoop is not supported. Just use the Testing message loop. |
250 if (loop.is_null() || loop == pp::MessageLoop_Dev::GetForMainThread()) | 249 if (loop.is_null() || loop == pp::MessageLoop::GetForMainThread()) |
251 GetTestingInterface()->RunMessageLoop(instance_); | 250 GetTestingInterface()->RunMessageLoop(instance_); |
252 else | 251 else |
253 loop.Run(); | 252 loop.Run(); |
254 } | 253 } |
255 | 254 |
256 void TestCompletionCallback::QuitMessageLoop() { | 255 void TestCompletionCallback::QuitMessageLoop() { |
257 pp::MessageLoop_Dev loop(pp::MessageLoop_Dev::GetCurrent()); | 256 pp::MessageLoop loop(pp::MessageLoop::GetCurrent()); |
258 // If we don't have a message loop, we're probably running in process, where | 257 // If we don't have a message loop, we're probably running in process, where |
259 // PPB_MessageLoop is not supported. Just use the Testing message loop. | 258 // PPB_MessageLoop is not supported. Just use the Testing message loop. |
260 if (loop.is_null() || loop == pp::MessageLoop_Dev::GetForMainThread()) { | 259 if (loop.is_null() || loop == pp::MessageLoop::GetForMainThread()) { |
261 GetTestingInterface()->QuitMessageLoop(instance_); | 260 GetTestingInterface()->QuitMessageLoop(instance_); |
262 } else { | 261 } else { |
263 const bool should_quit = false; | 262 const bool should_quit = false; |
264 loop.PostQuit(should_quit); | 263 loop.PostQuit(should_quit); |
265 } | 264 } |
266 } | 265 } |
OLD | NEW |