Bug 1352572 - Implement nptest.cpp:streamTest(postFile) parameter; r?bsmedberg draft
authorLie Ryan <lie.1296@gmail.com>
Thu, 27 Apr 2017 03:10:59 +0000
changeset 569539 967597277530b248ef3b4ec4a4f1352c1f3e2b9c
parent 569538 a060f42eb287942c9a789fa38db9624e46e9f6d1
child 569540 ebea78e67e1662f8c5b768abe95bee8b0777ef1e
push id56214
push userbmo:lie.1296@gmail.com
push dateThu, 27 Apr 2017 16:26:57 +0000
reviewersbsmedberg
bugs1352572
milestone55.0a1
Bug 1352572 - Implement nptest.cpp:streamTest(postFile) parameter; r?bsmedberg This is an optional parameter that can be used to test streams via file. It may be necessary to back out this change when NPAPI sandbox is completed as the testplugin may no longer be able to access files. MozReview-Commit-ID: FsYxhKKr4hS
dom/plugins/test/testplugin/README
dom/plugins/test/testplugin/nptest.cpp
--- a/dom/plugins/test/testplugin/README
+++ b/dom/plugins/test/testplugin/README
@@ -367,27 +367,28 @@ The attributes which control stream test
 
 "failurecode": one of the NPError constants.  Used to specify the error
   that will be returned by the "functiontofail".
 
 If the plugin is instantiated as a full-page plugin, the following defaults
 are used:
   streammode="seek" frame="testframe" range="100,100"
 
-* streamTest(url, doPost, postData, writeCallback, notifyCallback, redirectCallback, allowRedirects)
+* streamTest(url, doPost, postData, writeCallback, notifyCallback, redirectCallback, allowRedirects, postFile = false)
 This will test how NPN_GetURLNotify and NPN_PostURLNotify behave when they are
 called with arbitrary (malformed) URLs. The function will return `true` if
 NPN_[Get/Post]URLNotify succeeds, and `false` if it fails.
 @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
+@postFile boolean optional, defaults to false, set to true if postData contains a filename
 
 * 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
 
--- a/dom/plugins/test/testplugin/nptest.cpp
+++ b/dom/plugins/test/testplugin/nptest.cpp
@@ -2733,18 +2733,18 @@ convertPointY(NPObject* npobj, const NPV
 
   DOUBLE_TO_NPVARIANT(resultY, *result);
   return true;
 }
 
 static bool
 streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
-  // .streamTest(url, doPost, postData, writeCallback, notifyCallback, redirectCallback, allowRedirects)
-  if (7 != argCount)
+  // .streamTest(url, doPost, postData, writeCallback, notifyCallback, redirectCallback, allowRedirects, postFile = false)
+  if (!(7 <= argCount && argCount <= 8))
     return false;
 
   NPP npp = static_cast<TestNPObject*>(npobj)->npp;
 
   if (!NPVARIANT_IS_STRING(args[0]))
     return false;
   NPString url = NPVARIANT_TO_STRING(args[0]);
 
@@ -2791,16 +2791,24 @@ streamTest(NPObject* npobj, const NPVari
       return false;
     }
   }
 
   if (!NPVARIANT_IS_BOOLEAN(args[6]))
     return false;
   bool allowRedirects = NPVARIANT_TO_BOOLEAN(args[6]);
 
+  bool postFile = false;
+  if (argCount >= 8) {
+    if (!NPVARIANT_IS_BOOLEAN(args[7])) {
+      return false;
+    }
+    postFile = NPVARIANT_TO_BOOLEAN(args[7]);
+  }
+
   URLNotifyData* ndata = new URLNotifyData;
   ndata->cookie = "dynamic-cookie";
   ndata->writeCallback = writeCallback;
   ndata->notifyCallback = notifyCallback;
   ndata->redirectCallback = redirectCallback;
   ndata->size = 0;
   ndata->data = nullptr;
   ndata->allowRedirects = allowRedirects;
@@ -2809,17 +2817,17 @@ streamTest(NPObject* npobj, const NPVari
   char* urlstr = (char*) malloc(url.UTF8Length + 1);
   strncpy(urlstr, url.UTF8Characters, url.UTF8Length);
   urlstr[url.UTF8Length] = '\0';
 
   NPError err;
   if (doPost) {
     err = NPN_PostURLNotify(npp, urlstr, nullptr,
                             postData.UTF8Length, postData.UTF8Characters,
-                            false, ndata);
+                            postFile, ndata);
   }
   else {
     err = NPN_GetURLNotify(npp, urlstr, nullptr, ndata);
   }
 
   free(urlstr);
 
   if (NPERR_NO_ERROR == err) {