Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(881)

Unified Diff: ppapi/tests/test_utils.cc

Issue 8840007: GetDocumentURL is added to PPB_Testing_Dev. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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),

Powered by Google App Engine
This is Rietveld 408576698