summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_utils.cc
diff options
context:
space:
mode:
authorygorshenin@google.com <ygorshenin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-15 15:29:19 +0000
committerygorshenin@google.com <ygorshenin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-15 15:29:19 +0000
commit961e89716c14bd6c7e1f3394b9696ee60810a676 (patch)
tree258a13f7cbd6a8b971f2fca1aad36dbcff9b2f9a /ppapi/tests/test_utils.cc
parent292a635a2c28ac2968940fb9e15f93be45ada4dd (diff)
downloadchromium_src-961e89716c14bd6c7e1f3394b9696ee60810a676.zip
chromium_src-961e89716c14bd6c7e1f3394b9696ee60810a676.tar.gz
chromium_src-961e89716c14bd6c7e1f3394b9696ee60810a676.tar.bz2
GetDocumentURL is added to PPB_Testing_Dev.
Fixed Test{TCP|UDP}SocketPrivateShared. BUG=105863 TEST= Review URL: http://codereview.chromium.org/8840007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114637 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests/test_utils.cc')
-rw-r--r--ppapi/tests/test_utils.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc
index d5df942..a98c693 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,36 @@ 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;
+
+ 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),