Chromium Code Reviews| Index: ppapi/tests/test_utils.cc |
| diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc |
| index df13fde8b21399b85407f5ff8ad0af870189846d..aa7ba8a21df57553cdf2edfc2b0ba706c0268395 100644 |
| --- a/ppapi/tests/test_utils.cc |
| +++ b/ppapi/tests/test_utils.cc |
| @@ -13,6 +13,7 @@ |
| #include "ppapi/c/pp_errors.h" |
| #include "ppapi/cpp/module.h" |
| +#include "ppapi/cpp/var.h" |
| const int kActionTimeoutMs = 10000; |
| @@ -39,6 +40,37 @@ void PlatformSleep(int duration_ms) { |
| #endif |
| } |
| +bool GetLocalHostPort(PP_Instance instance, std::string* host, uint16_t* port) { |
| + if (!host || !port) |
| + return false; |
| + |
| + const PPB_Testing_Dev* testing = GetTestingInterface(); |
| + if (!testing) |
| + return false; |
| + |
| + PP_URLComponents_Dev components; |
| + pp::Var pp_url(pp::Var::PassRef(), |
| + testing->GetDocumentURL(instance, &components)); |
| + if (!pp_url.is_string()) |
| + return false; |
| + std::string url = pp_url.AsString(); |
| + |
| + if (components.host.len < 0) |
| + return false; |
| + host->assign(url.substr(components.host.begin, components.host.len)); |
| + |
| + if (components.port.len > 0) { |
|
yzshen1
2011/12/13 18:49:54
You could reverse the condition and return early o
ygorshenin
2011/12/14 17:41:10
Done.
|
| + int i = atoi(url.substr(components.port.begin, |
|
yzshen1
2011/12/13 18:49:54
Please add include for atoi.
ygorshenin
2011/12/14 17:41:10
Done.
|
| + components.port.len).c_str()); |
| + if (i < 0 || i > 65535) |
| + return false; |
| + *port = static_cast<uint16_t>(i); |
| + } else |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| TestCompletionCallback::TestCompletionCallback(PP_Instance instance) |
| : have_result_(false), |
| result_(PP_OK_COMPLETIONPENDING), |