Bug 1352572 - Add support in nptest plugin to test NPN_PostURL(file=true); r?bsmedberg draft
authorLie Ryan <lie.1296@gmail.com>
Thu, 27 Apr 2017 11:17:52 +0000
changeset 569522 0b69bd8646896c719444e4b2398269ba857dc504
parent 561397 07b6b0eac4846cd33f3fbf0d20c468123f7a2d1b
child 569523 f0dd230e85b6baa346c66679a071be8e6f1f75f5
child 569537 8c436da4ab5c1a46bc4bff7fba0f32604007d57c
push id56209
push userbmo:lie.1296@gmail.com
push dateThu, 27 Apr 2017 16:02:13 +0000
reviewersbsmedberg
bugs1352572
milestone55.0a1
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 getAuthInfo(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
@@ -202,16 +203,17 @@ static const NPUTF8* sPluginMethodIdenti
   "setSlowPaint",
   "getError",
   "doInternalConsistencyCheck",
   "setColor",
   "throwExceptionNextInvoke",
   "convertPointX",
   "convertPointY",
   "streamTest",
+  "postFileToURLTest",
   "setPluginWantsAllStreams",
   "crash",
   "crashOnDestroy",
   "getObjectValue",
   "getJavaCodebase",
   "checkObjectValue",
   "enableFPExceptions",
   "getAuthInfo",
@@ -277,16 +279,17 @@ static const ScriptableFunction sPluginM
   setSlowPaint,
   getError,
   doInternalConsistencyCheck,
   setColor,
   throwExceptionNextInvoke,
   convertPointX,
   convertPointY,
   streamTest,
+  postFileToURLTest,
   setPluginWantsAllStreams,
   crashPlugin,
   crashOnDestroy,
   getObjectValue,
   getJavaCodebase,
   checkObjectValue,
   enableFPExceptions,
   getAuthInfo,
@@ -2835,16 +2838,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]);