Cover some JS public methods that do not "commit".

The path taken sometimes depends on the nature of the event which
triggered the JS execution and the callback, so test the public
method callbacks under different types of triggering events. In
particular, pick an event that does not set the "will commit" bit
in the event recording structure. To trigger this, we need to
send a keystroke to the appropriate field.

Change-Id: I9aabefc1e391c5a89acddd6b3a96fe6337f142d7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/62212
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/testing/resources/javascript/public_methods.evt b/testing/resources/javascript/public_methods.evt
new file mode 100644
index 0000000..0c25248
--- /dev/null
+++ b/testing/resources/javascript/public_methods.evt
@@ -0,0 +1,4 @@
+mousedown,left,110,170
+mouseup,left,110,170
+charcode,65
+
diff --git a/testing/resources/javascript/public_methods.in b/testing/resources/javascript/public_methods.in
index e8d7ab6..140d020 100644
--- a/testing/resources/javascript/public_methods.in
+++ b/testing/resources/javascript/public_methods.in
@@ -41,7 +41,10 @@
   /Rect [ 100 160 200 190 ]
   /Subtype /Widget
   /AA <<
-    /F 9 0 R
+    /C 16 0 R
+    /F 17 0 R
+    /K 18 0 R
+    /V 19 0 R
   >>
 >>
 endobj
@@ -65,7 +68,45 @@
 stream
 endstream
 endobj
-{{object 9 0}} <<
+{{object 10 0}} <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /T (Text2)
+  /DA (0 0 0 rg /F1 12 Tf)
+  /Rect [100 0 200 30]
+  /V (123)
+>>
+endobj
+{{object 11 0}} <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /T (Text3)
+  /DA (0 0 0 rg /F1 12 Tf)
+  /Rect [100 40 200 70]
+  /V (456)
+>>
+endobj
+{{object 12 0}} <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /T (Text4)
+  /DA (0 0 0 rg /F1 12 Tf)
+  /Rect [100 80 200 110]
+  /V (407.96)
+>>
+endobj
+{{object 16 0}} <<
+  /S /JavaScript
+  /JS (
+    app.alert('Unexpected script 16');
+  )
+>>
+endobj
+{{object 17 0}} <<
+  /S /JavaScript
   /JS (
     function expect(initial, expression, expected) {
       try {
@@ -107,7 +148,7 @@
     }
 
     try {
-      app.alert("*** starting test ***");
+      app.alert("*** starting test 1 ***");
 
       expectError('', "AFDate_Format()");
       expectError('', "AFDate_Format(1, 2)");
@@ -545,42 +586,62 @@
       expectError('', "AFTime_KeystrokeEx(1, 2)");
       expectEventValue("12:04", "AFTime_KeystrokeEx('blooey')", "12:04");
 
-      app.alert("*** ending test ***");
+      app.alert("*** ending test 1 ***");
     } catch (e) {
       app.alert("Truly unexpected error occured: " + e);
     }
   )
+>>
+endobj
+{{object 18 0}} <<
   /S /JavaScript
+  /JS (
+    // Re-run tests that depend on the "will commit" status of the event
+    // that triggered their execution.
+    try {
+      app.alert("*** starting test 2 ***");
+
+      expectError('', "AFDate_Keystroke()");
+      expectError('', "AFDate_Keystroke(1, 2)");
+      expectEventValue("04/19", "AFDate_Keystroke(2)", "04/19");
+      expectEventValue("04/19/15", "AFDate_Keystroke('blooey')", "04/19/15");
+
+      app.alert("**********************");
+
+      expectError('', "AFNumber_Keystroke()");
+      expectError('', "AFNumber_Keystroke(1)");
+      expectError("abc", "AFNumber_Keystroke(1, 2)");
+      expectEventValue("123", "AFNumber_Keystroke(1, 2)", "123");
+      expectEventValue("123", "AFNumber_Keystroke(1, 2, 3)", "123");
+
+      app.alert("**********************");
+
+      expectError('', "AFSpecial_KeystrokeEx()", '');
+      expectEventValue("12345", "AFSpecial_KeystrokeEx('')", "12345");      // No notification.
+      expectEventValue("123", "AFSpecial_KeystrokeEx('9999')", "123");      // Notifies invalid.
+      expectEventValue("12345", "AFSpecial_KeystrokeEx('9999')", "12345");  // Notifies too long.
+      expectEventValue("abcd", "AFSpecial_KeystrokeEx('9999')", "abcd");    // Notifies invalid.
+      expectEventValue("1234", "AFSpecial_KeystrokeEx('9999')", "1234");
+      expectEventValue("abcd", "AFSpecial_KeystrokeEx('XXXX')", "abcd");
+
+      app.alert("**********************");
+
+      expectError('', "AFMergeChange()");
+      expectError('', "AFMergeChange(1, 2)");
+      expect("one", "AFMergeChange(undefined)", "Aone");
+
+      app.alert("*** ending test 2 ***");
+    } catch (e) {
+      app.alert("Truly unexpected error occured: " + e);
+    }
+  )
 >>
 endobj
-{{object 10 0}} <<
-  /Type /Annot
-  /FT /Tx
-  /T (Text2)
-  /DA (0 0 0 rg /F1 12 Tf)
-  /Rect [100 0 200 30]
-  /Subtype /Widget
-  /V (123)
->>
-endobj
-{{object 11 0}} <<
-  /Type /Annot
-  /FT /Tx
-  /T (Text3)
-  /DA (0 0 0 rg /F1 12 Tf)
-  /Rect [100 40 200 70]
-  /Subtype /Widget
-  /V (456)
->>
-endobj
-{{object 12 0}} <<
-  /Type /Annot
-  /FT /Tx
-  /T (Text4)
-  /DA (0 0 0 rg /F1 12 Tf)
-  /Rect [100 80 200 110]
-  /Subtype /Widget
-  /V (407.96)
+{{object 19 0}} <<
+  /S /JavaScript
+  /JS (
+    app.alert('Unexpected script 19');
+  )
 >>
 endobj
 {{xref}}
diff --git a/testing/resources/javascript/public_methods_expected.txt b/testing/resources/javascript/public_methods_expected.txt
index 1c8a315..17abeff 100644
--- a/testing/resources/javascript/public_methods_expected.txt
+++ b/testing/resources/javascript/public_methods_expected.txt
@@ -1,4 +1,4 @@
-Alert: *** starting test ***
+Alert: *** starting test 1 ***
 Alert: PASS: AFDate_Format() threw AFDate_Format: Incorrect number of parameters passed to function.
 Alert: PASS: AFDate_Format(1, 2) threw AFDate_Format: Incorrect number of parameters passed to function.
 Alert: PASS: AFDate_Format(1) = 1/1/70
@@ -369,4 +369,32 @@
 Alert: PASS: AFTime_KeystrokeEx() threw AFTime_KeystrokeEx: AFDate_KeystrokeEx's parameter size not correct
 Alert: PASS: AFTime_KeystrokeEx(1, 2) threw AFTime_KeystrokeEx: AFDate_KeystrokeEx's parameter size not correct
 Alert: PASS: AFTime_KeystrokeEx('blooey') = 12:04
-Alert: *** ending test ***
+Alert: *** ending test 1 ***
+Alert: *** starting test 2 ***
+Alert: PASS: AFDate_Keystroke() threw AFDate_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFDate_Keystroke(1, 2) threw AFDate_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFDate_Keystroke(2) = 04/19
+Alert: PASS: AFDate_Keystroke('blooey') = 04/19/15
+Alert: **********************
+Alert: PASS: AFNumber_Keystroke() threw AFNumber_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFNumber_Keystroke(1) threw AFNumber_Keystroke: Incorrect number of parameters passed to function.
+Alert: FAIL: AFNumber_Keystroke(1, 2) = undefined, expected to throw
+Alert: PASS: AFNumber_Keystroke(1, 2) = 123
+Alert: PASS: AFNumber_Keystroke(1, 2, 3) = 123
+Alert: **********************
+Alert: PASS: AFSpecial_KeystrokeEx() threw AFSpecial_KeystrokeEx: Incorrect number of parameters passed to function.
+Alert: PASS: AFSpecial_KeystrokeEx('') = 12345
+Alert: PASS: AFSpecial_KeystrokeEx('9999') = 123
+[icon=3,type=0]: The input value is too long.
+Alert: PASS: AFSpecial_KeystrokeEx('9999') = 12345
+[icon=3,type=0]: The input value is too long.
+Alert: PASS: AFSpecial_KeystrokeEx('9999') = abcd
+[icon=3,type=0]: The input value is too long.
+Alert: PASS: AFSpecial_KeystrokeEx('9999') = 1234
+[icon=3,type=0]: The input value is too long.
+Alert: PASS: AFSpecial_KeystrokeEx('XXXX') = abcd
+Alert: **********************
+Alert: PASS: AFMergeChange() threw AFMergeChange: Incorrect number of parameters passed to function.
+Alert: PASS: AFMergeChange(1, 2) threw AFMergeChange: Incorrect number of parameters passed to function.
+Alert: PASS: AFMergeChange(undefined) = Aone
+Alert: *** ending test 2 ***