Index: ppapi/tests/test_utils.cc |
diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc |
index 9776e3459556dcd20287552b6085fd94d7f8bdd9..20a8a81e2f92f49991928ca9d15b71d42728e4cc 100644 |
--- a/ppapi/tests/test_utils.cc |
+++ b/ppapi/tests/test_utils.cc |
@@ -13,6 +13,7 @@ |
#endif |
#include "ppapi/c/pp_errors.h" |
+#include "ppapi/cpp/dev/message_loop_dev.h" |
#include "ppapi/cpp/module.h" |
#include "ppapi/cpp/var.h" |
@@ -138,7 +139,7 @@ int32_t TestCompletionCallback::WaitForResult() { |
errors_.clear(); |
if (!have_result_) { |
post_quit_task_ = true; |
- GetTestingInterface()->RunMessageLoop(instance_); |
+ RunMessageLoop(); |
} |
return result_; |
} |
@@ -150,7 +151,7 @@ void TestCompletionCallback::WaitForResult(int32_t result) { |
if (result == PP_OK_COMPLETIONPENDING) { |
if (!have_result_) { |
post_quit_task_ = true; |
- GetTestingInterface()->RunMessageLoop(instance_); |
+ RunMessageLoop(); |
} |
if (callback_type_ == PP_BLOCKING) { |
errors_.assign( |
@@ -200,6 +201,7 @@ pp::CompletionCallback TestCompletionCallback::GetCallback() { |
return pp::CompletionCallback(); |
else if (callback_type_ == PP_OPTIONAL) |
flags = PP_COMPLETIONCALLBACK_FLAG_OPTIONAL; |
+ target_loop_ = pp::MessageLoop_Dev::GetCurrent(); |
return pp::CompletionCallback(&TestCompletionCallback::Handler, |
const_cast<TestCompletionCallback*>(this), |
flags); |
@@ -229,7 +231,36 @@ void TestCompletionCallback::Handler(void* user_data, int32_t result) { |
callback->delegate_->OnCallback(user_data, result); |
if (callback->post_quit_task_) { |
callback->post_quit_task_ = false; |
- GetTestingInterface()->QuitMessageLoop(callback->instance_); |
+ callback->QuitMessageLoop(); |
+ } |
+ if (callback->target_loop_ != pp::MessageLoop_Dev::GetCurrent()) { |
+ // Note, in-process, loop_ and GetCurrent() will both be NULL, so should |
+ // still be equal. |
+ callback->errors_.assign( |
+ ReportError("TestCompletionCallback: Callback ran on the wrong message " |
+ "loop!", |
+ result)); |
} |
} |
+void TestCompletionCallback::RunMessageLoop() { |
+ pp::MessageLoop_Dev loop(pp::MessageLoop_Dev::GetCurrent()); |
+ // If we don't have a message loop, we're probably running in process, where |
+ // PPB_MessageLoop is not supported. Just use the Testing message loop. |
+ if (loop.is_null() || loop == pp::MessageLoop_Dev::GetForMainThread()) |
+ GetTestingInterface()->RunMessageLoop(instance_); |
+ else |
+ loop.Run(); |
+} |
+ |
+void TestCompletionCallback::QuitMessageLoop() { |
+ pp::MessageLoop_Dev loop(pp::MessageLoop_Dev::GetCurrent()); |
+ // If we don't have a message loop, we're probably running in process, where |
+ // PPB_MessageLoop is not supported. Just use the Testing message loop. |
+ if (loop.is_null() || loop == pp::MessageLoop_Dev::GetForMainThread()) { |
+ GetTestingInterface()->QuitMessageLoop(instance_); |
+ } else { |
+ const bool should_quit = false; |
+ loop.PostQuit(should_quit); |
+ } |
+} |