Bug 1352572 - Add support in nptest plugin to test NPN_PostURL(file=true); r=bsmedberg
authorLie Ryan <lie.1296@gmail.com>
Thu, 27 Apr 2017 11:17:52 +0000
changeset 357221 389ba434b233a5b1bb1c09c968475da616f29725
parent 357220 721ffdb73f9eba0a45c2f775ec695c721ec8eb29
child 357222 e78a21fb49590165772ae39f68fef67779714654
push id31788
push userkwierso@gmail.com
push dateTue, 09 May 2017 20:48:49 +0000
treeherdermozilla-central@2b6f6881a24a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1352572
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1352572 - Add support in nptest plugin to test NPN_PostURL(file=true); r=bsmedberg MozReview-Commit-ID: BDifZ0vRdgj
dom/plugins/test/testplugin/README
dom/plugins/test/testplugin/nptest.cpp
--- a/dom/plugins/test/testplugin/README
+++ b/dom/plugins/test/testplugin/README
@@ -379,16 +379,23 @@ NPN_[Get/Post]URLNotify succeeds, and `f
 @url url to request
 @param doPost whether to call NPN_PostURLNotify
 @param postData null, or a string to send a postdata
 @writeCallback will be called when data is received for the stream
 @notifyCallback will be called when the urlnotify is received with the notify result
 @redirectCallback will be called from urlredirectnotify if a redirect is attempted
 @allowRedirects boolean value indicating whether or not to allow redirects
 
+* postFileToURLTest(url)
+Calls NPN_PostURL/NPN_PostURLNotify to make a POST request to the URL with
+request from postFile.
+The function will return `0` if NPN_PostURL/NPN_PostURLNotify succeeds, and
+the error code if it fails.
+@param url string, url to request
+
 * setPluginWantsAllStreams(wantsAllStreams)
 Set the value returned by the plugin for NPPVpluginWantsAllNetworkStreams.
 
 == Internal consistency ==
 
 * doInternalConsistencyCheck()
 Does internal consistency checking, returning an empty string if everything is
 OK, otherwise returning some kind of error string. On Windows, in windowed
--- a/dom/plugins/test/testplugin/nptest.cpp
+++ b/dom/plugins/test/testplugin/nptest.cpp
@@ -128,16 +128,17 @@ static bool setInvalidateDuringPaint(NPO
 static bool setSlowPaint(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getError(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool doInternalConsistencyCheck(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool setColor(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool throwExceptionNextInvoke(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool convertPointX(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool convertPointY(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
+static bool postFileToURLTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool setPluginWantsAllStreams(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool crashPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool crashOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getObjectValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getJavaCodebase(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool checkObjectValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool enableFPExceptions(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool asyncCallbackTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
@@ -201,16 +202,17 @@ static const NPUTF8* sPluginMethodIdenti
   "setSlowPaint",
   "getError",
   "doInternalConsistencyCheck",
   "setColor",
   "throwExceptionNextInvoke",
   "convertPointX",
   "convertPointY",
   "streamTest",
+  "postFileToURLTest",
   "setPluginWantsAllStreams",
   "crash",
   "crashOnDestroy",
   "getObjectValue",
   "getJavaCodebase",
   "checkObjectValue",
   "enableFPExceptions",
   "asyncCallbackTest",
@@ -275,16 +277,17 @@ static const ScriptableFunction sPluginM
   setSlowPaint,
   getError,
   doInternalConsistencyCheck,
   setColor,
   throwExceptionNextInvoke,
   convertPointX,
   convertPointY,
   streamTest,
+  postFileToURLTest,
   setPluginWantsAllStreams,
   crashPlugin,
   crashOnDestroy,
   getObjectValue,
   getJavaCodebase,
   checkObjectValue,
   enableFPExceptions,
   asyncCallbackTest,
@@ -2818,16 +2821,48 @@ streamTest(NPObject* npobj, const NPVari
     delete ndata;
     BOOLEAN_TO_NPVARIANT(false, *result);
   }
 
   return true;
 }
 
 static bool
+postFileToURLTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
+{
+  if (1 != argCount)
+    return false;
+
+  NPP npp = static_cast<TestNPObject*>(npobj)->npp;
+
+  string url;
+  {
+    if (!NPVARIANT_IS_STRING(args[0]))
+      return false;
+    NPString npurl = NPVARIANT_TO_STRING(args[0]);
+    // make a copy to ensure that the url string is null-terminated
+    url = string(npurl.UTF8Characters, npurl.UTF8Length);
+  }
+
+
+  NPError err;
+  {
+    string buf("/path/to/file");
+    err = NPN_PostURL(npp,
+                      url.c_str(),
+                      nullptr /* target */,
+                      buf.length(), buf.c_str(),
+                      true /* file */);
+  }
+
+  BOOLEAN_TO_NPVARIANT(NPERR_NO_ERROR == err, *result);
+  return true;
+}
+
+static bool
 setPluginWantsAllStreams(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
   if (1 != argCount)
     return false;
 
   if (!NPVARIANT_IS_BOOLEAN(args[0]))
     return false;
   bool wantsAllStreams = NPVARIANT_TO_BOOLEAN(args[0]);