| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(_MSC_VER) |
| 9 #include <windows.h> |
| 10 #else |
| 11 #include <unistd.h> |
| 12 #endif |
| 8 | 13 |
| 9 #include "ppapi/c/pp_errors.h" | 14 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
| 11 | 16 |
| 17 const int kActionTimeoutMs = 10000; |
| 18 |
| 12 const PPB_Testing_Dev* GetTestingInterface() { | 19 const PPB_Testing_Dev* GetTestingInterface() { |
| 13 static const PPB_Testing_Dev* g_testing_interface = | 20 static const PPB_Testing_Dev* g_testing_interface = |
| 14 reinterpret_cast<PPB_Testing_Dev const*>( | 21 reinterpret_cast<PPB_Testing_Dev const*>( |
| 15 pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE)); | 22 pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE)); |
| 16 return g_testing_interface; | 23 return g_testing_interface; |
| 17 } | 24 } |
| 18 | 25 |
| 19 std::string ReportError(const char* method, int32_t error) { | 26 std::string ReportError(const char* method, int32_t error) { |
| 20 char error_as_string[12]; | 27 char error_as_string[12]; |
| 21 sprintf(error_as_string, "%d", static_cast<int>(error)); | 28 sprintf(error_as_string, "%d", static_cast<int>(error)); |
| 22 std::string result = method + std::string(" failed with error: ") + | 29 std::string result = method + std::string(" failed with error: ") + |
| 23 error_as_string; | 30 error_as_string; |
| 24 return result; | 31 return result; |
| 25 } | 32 } |
| 26 | 33 |
| 34 void PlatformSleep(int duration_ms) { |
| 35 #if defined(_MSC_VER) |
| 36 ::Sleep(duration_ms); |
| 37 #else |
| 38 usleep(duration_ms * 1000); |
| 39 #endif |
| 40 } |
| 41 |
| 27 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) | 42 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) |
| 28 : have_result_(false), | 43 : have_result_(false), |
| 29 result_(PP_OK_COMPLETIONPENDING), | 44 result_(PP_OK_COMPLETIONPENDING), |
| 30 force_async_(false), | 45 force_async_(false), |
| 31 post_quit_task_(false), | 46 post_quit_task_(false), |
| 32 run_count_(0), | 47 run_count_(0), |
| 33 instance_(instance) { | 48 instance_(instance) { |
| 34 } | 49 } |
| 35 | 50 |
| 36 TestCompletionCallback::TestCompletionCallback(PP_Instance instance, | 51 TestCompletionCallback::TestCompletionCallback(PP_Instance instance, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 65 TestCompletionCallback* callback = | 80 TestCompletionCallback* callback = |
| 66 static_cast<TestCompletionCallback*>(user_data); | 81 static_cast<TestCompletionCallback*>(user_data); |
| 67 callback->result_ = result; | 82 callback->result_ = result; |
| 68 callback->have_result_ = true; | 83 callback->have_result_ = true; |
| 69 callback->run_count_++; | 84 callback->run_count_++; |
| 70 if (callback->post_quit_task_) { | 85 if (callback->post_quit_task_) { |
| 71 callback->post_quit_task_ = false; | 86 callback->post_quit_task_ = false; |
| 72 GetTestingInterface()->QuitMessageLoop(callback->instance_); | 87 GetTestingInterface()->QuitMessageLoop(callback->instance_); |
| 73 } | 88 } |
| 74 } | 89 } |
| OLD | NEW |