Provide some diversity of arguments in mouse_events.in.

Add some data to the form to be transmitted, and also improve logging
to show that the arguments have an effect. In turn, fix bug shown by
this logging where NUL characters were being inserted into file name
strings on some platforms.

Change-Id: I6cb3c23950fb7f7d255cd33998ba4ee58440201d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/63430
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 8f9bdd1..07da61a 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -226,7 +226,8 @@
   if (nActualLen <= 0 || nActualLen > nRequiredLen)
     return WideString();
 
-  pBuff.resize(nActualLen);
+  // Don't include trailing NUL.
+  pBuff.resize(nActualLen - 1);
   return WideString::FromDefANSI(ByteStringView(pBuff));
 }
 
@@ -299,7 +300,8 @@
   if (nActualLen <= 0 || nActualLen > nRequiredLen)
     return WideString();
 
-  pBuff.resize(nActualLen);
+  // Don't include trailing NUL.
+  pBuff.resize(nActualLen - 1);
   return WideString::FromDefANSI(ByteStringView(pBuff));
 }
 
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index eb7db5b..e3e9c0d 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -307,7 +307,12 @@
                           void* formData,
                           int length,
                           FPDF_WIDESTRING url) {
-  printf("Doc Submit Form: url=%ls\n", GetPlatformWString(url).c_str());
+  printf("Doc Submit Form: url=%ls + %d data bytes:\n",
+         GetPlatformWString(url).c_str(), length);
+  uint8_t* ptr = reinterpret_cast<uint8_t*>(formData);
+  for (int i = 0; i < length; ++i)
+    printf(" %02x", ptr[i]);
+  printf("\n");
 }
 
 void ExampleDocGotoPage(IPDF_JSPLATFORM*, int page_number) {
diff --git a/testing/resources/javascript/mouse_events.in b/testing/resources/javascript/mouse_events.in
index 9480e94..4c6935e 100644
--- a/testing/resources/javascript/mouse_events.in
+++ b/testing/resources/javascript/mouse_events.in
@@ -26,7 +26,11 @@
 >>
 % Forms
 {{object 4 0}} <<
-  /Fields [5 0 R]
+  /Fields [
+    5 0 R
+    6 0 R
+    7 0 R
+  ]
 >>
 % Field with actions:
 % Cursor enter: E
@@ -36,10 +40,10 @@
 % Focus: Fo
 % Blur: Bl
 {{object 5 0}} <<
- /FT /Tx
- /T (MyField)
  /Type /Annot
  /Subtype /Widget
+ /FT /Tx
+ /T (MyField)
  /Rect [100 200 150 250]
  /AA <<
    /E 10 0 R
@@ -50,6 +54,24 @@
    /Bl 15 0 R
  >>
 >>
+{{object 6 0}} <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Tx
+ /T (name)
+ /Rect [400 400 500 429]
+ /V (Tralfaz)
+>>
+endobj
+{{object 7 0}} <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Tx
+ /T (age)
+ /Rect [400 440 500 469]
+ /V (12)
+>>
+endobj
 {{object 10 0}} <<
   /Type /Action
   /S /JavaScript
@@ -61,7 +83,6 @@
     } catch \(e\) {
        app.alert\("PASS: this.submitForm blocked with " + e\);
     }
-
     try {
        this.print\(\);
        app.alert\("ERROR: this.print\(\) must not be allowed to execute"\);
@@ -82,7 +103,6 @@
     } catch \(e\) {
        app.alert\("PASS: this.submitForm blocked with " + e\);
     }
-
     try {
        this.print\(\);
        app.alert\("ERROR: this.print\(\) must not be allowed to execute"\);
@@ -98,11 +118,10 @@
   /JS (
     app.alert\("down"\);
     try {
-       this.submitForm\("myform", true, true, ["name", "age"]\);
+       this.submitForm\("https://example.com", true, true, ["name", "age"]\);
     } catch \(e\) {
        app.alert\("ERROR: " + e\);
     }
-
     try {
        this.print\(\);
        this.print\(false, 1, 10, true, true, true, true, true\);
@@ -122,11 +141,11 @@
   /JS (
     app.alert\("up"\);
     try {
-       this.submitForm\("myform", true, true, ["name", "age"]\);
+       // Use different bUrl value this time around.
+       this.submitForm\("https://example.com", false, true, ["name", "age"]\);
     } catch \(e\) {
        app.alert\("ERROR: " + e\);
     }
-
     try {
        this.print\(\);
     } catch \(e\) {
@@ -146,7 +165,6 @@
     } catch \(e\) {
        app.alert\("PASS: this.submitForm blocked with " + e\);
     }
-
     try {
        this.print\(\);
        app.alert\("ERROR: this.print\(\) must not be allowed to execute"\);
@@ -167,7 +185,6 @@
     } catch \(e\) {
        app.alert\("PASS: this.submitForm blocked with " + e\);
     }
-
     try {
        this.print\(\);
        app.alert\("ERROR: this.print\(\) must not be allowed to execute"\);
diff --git a/testing/resources/javascript/mouse_events_expected.txt b/testing/resources/javascript/mouse_events_expected.txt
index 8e87e1a..2c88a82 100644
--- a/testing/resources/javascript/mouse_events_expected.txt
+++ b/testing/resources/javascript/mouse_events_expected.txt
@@ -8,7 +8,8 @@
 Alert: PASS: this.submitForm blocked with Document.submitForm: User gesture required.
 Alert: PASS: this.print blocked with Document.print: User gesture required.
 Alert: down
-Doc Submit Form: url=myform
+Doc Submit Form: url=https://example.com + 174 data bytes:
+ 25 46 44 46 2d 31 2e 32 0d 0a 31 20 30 20 6f 62 6a 0d 0a 3c 3c 2f 46 44 46 3c 3c 2f 46 3c 3c 2f 46 28 6d 79 66 69 6c 65 2e 70 64 66 29 2f 54 79 70 65 2f 46 69 6c 65 73 70 65 63 2f 55 46 28 6d 79 66 69 6c 65 2e 70 64 66 29 3e 3e 2f 46 69 65 6c 64 73 5b 3c 3c 2f 54 28 6e 61 6d 65 29 2f 56 28 54 72 61 6c 66 61 7a 29 3e 3e 3c 3c 2f 54 28 61 67 65 29 2f 56 28 31 32 29 3e 3e 5d 3e 3e 3e 3e 0d 0a 65 6e 64 6f 62 6a 0d 0a 0d 0a 74 72 61 69 6c 65 72 0d 0a 3c 3c 2f 52 6f 6f 74 20 31 20 30 20 52 3e 3e 0d 0a 25 25 45 4f 46 0d 0a
 Doc Print: 1, 0, 0, 0, 0, 0, 0, 0
 Doc Print: 0, 1, 10, 1, 1, 1, 1, 1
 Doc Print: 1, 0, 0, 0, 0, 0, 0, 0
@@ -17,7 +18,8 @@
 Alert: PASS: this.submitForm blocked with Document.submitForm: User gesture required.
 Alert: PASS: this.print blocked with Document.print: User gesture required.
 Alert: up
-Doc Submit Form: url=myform
+Doc Submit Form: url=https://example.com + 19 data bytes:
+ 6e 61 6d 65 3d 54 72 61 6c 66 61 7a 26 61 67 65 3d 31 32
 Doc Print: 1, 0, 0, 0, 0, 0, 0, 0
 Alert: exit
 Alert: PASS: this.submitForm blocked with Document.submitForm: User gesture required.