Index: ppapi/tests/test_utils.cc |
diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc |
index d5df942ccfff9ea23804cc8a56f69c675c34768d..d1c1cf502b9ff603ecd4296f878afb35e1618b02 100644 |
--- a/ppapi/tests/test_utils.cc |
+++ b/ppapi/tests/test_utils.cc |
@@ -5,6 +5,7 @@ |
#include "ppapi/tests/test_utils.h" |
#include <stdio.h> |
+#include <stdlib.h> |
#if defined(_MSC_VER) |
#include <windows.h> |
#else |
@@ -13,6 +14,7 @@ |
#include "ppapi/c/pp_errors.h" |
#include "ppapi/cpp/module.h" |
+#include "ppapi/cpp/var.h" |
const int kActionTimeoutMs = 10000; |
@@ -39,6 +41,38 @@ 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) |
+ return false; |
+ else { |
yzshen1
2011/12/14 19:16:54
nit: no need to use 'else'.
if (...)
return fal
brettw
2011/12/14 22:36:47
Yeah, we generally frown on using else after retur
ygorshenin
2011/12/15 11:48:22
Done.
ygorshenin
2011/12/15 11:48:22
Done.
|
+ int i = atoi(url.substr(components.port.begin, |
+ components.port.len).c_str()); |
+ if (i < 0 || i > 65535) |
+ return false; |
+ *port = static_cast<uint16_t>(i); |
+ } |
+ |
+ return true; |
+} |
+ |
TestCompletionCallback::TestCompletionCallback(PP_Instance instance) |
: have_result_(false), |
result_(PP_OK_COMPLETIONPENDING), |