Add test for formcalc Post()/Put() functions.

- Fix longstanding length botch when converting result to widestring.
- Make FPDF_WIDESTRING definition consistent with above change.

Change-Id: I0b517cce18b2e2d5ad7a2ea372155231ac2296d9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/93430
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index d707ef5..deac212 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -576,7 +576,7 @@
 
   WideString wsRet =
       WideString::FromUTF16LE(reinterpret_cast<FPDF_WIDESTRING>(response.str),
-                              response.len / sizeof(FPDF_WIDESTRING));
+                              response.len / sizeof(FPDF_WCHAR));
 
   FPDF_BStr_Clear(&response);
   return wsRet;
diff --git a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
index b0fec2f..86d19c5 100644
--- a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
@@ -994,11 +994,15 @@
 }
 
 TEST_F(CFXJSE_FormCalcContextEmbedderTest, Post) {
-  // TODO(dsinclair): Is this supported?
+  ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
+  ExecuteExpectString(
+      "Post(\"http://example.com\", \"secret stuff\", \"text/plain\")",
+      "posted");
 }
 
 TEST_F(CFXJSE_FormCalcContextEmbedderTest, Put) {
-  // TODO(dsinclair): Is this supported?
+  ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
+  ExecuteExpectString("Put(\"http://example.com\", \"secret stuff\")", "");
 }
 
 TEST_F(CFXJSE_FormCalcContextEmbedderTest, InvalidFunctions) {
diff --git a/public/fpdfview.h b/public/fpdfview.h
index d7f6f07..19cf916 100644
--- a/public/fpdfview.h
+++ b/public/fpdfview.h
@@ -104,7 +104,7 @@
 
 // FPDFSDK always uses UTF-16LE encoded wide strings, each character uses 2
 // bytes (except surrogation), with the low byte first.
-typedef const unsigned short* FPDF_WIDESTRING;
+typedef const FPDF_WCHAR* FPDF_WIDESTRING;
 
 // Structure for persisting a string beyond the duration of a callback.
 // Note: although represented as a char*, string may be interpreted as
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index 8111945..718f88d 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -235,6 +235,8 @@
                              FPDF_WIDESTRING wsEncode,
                              FPDF_WIDESTRING wsHeader,
                              FPDF_BSTR* response) {
+  const char kString[] = "p\0o\0s\0t\0e\0d\0";
+  FPDF_BStr_Set(response, kString, sizeof(kString) - 1);
   return true;
 }