Add some simple tests for CJS_Field methods.

More sophisticated tests may required specific object types
to be created by the PDF itself.

Change-Id: I7a8e00a4db38d8e0081463cf76bb993c19c34b03
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52551
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/testing/resources/javascript/field_methods.in b/testing/resources/javascript/field_methods.in
index 528c529..ca27e33 100644
--- a/testing/resources/javascript/field_methods.in
+++ b/testing/resources/javascript/field_methods.in
@@ -5,6 +5,8 @@
   {{streamlen}}
 >>
 stream
+{{include expect.js}}
+
 function testGetField() {
   try {
     var field = this.getField("MyField");
@@ -30,17 +32,53 @@
   }
 }
 
-function testMethods() {
-  try {
-    var field = this.getField("MyField");
-  } catch (e) {
-    app.alert("Unexpected error: " + e);
-  }
-}
-
 testGetField();
 testGetArray();
-testMethods();
+
+expect("this.getField('MyField.Sub_A').buttonGetCaption()", "");
+expect("this.getField('MyField.Sub_A').buttonGetIcon()", "[object Object]");
+expect("this.getField('MyField.Sub_A').buttonImportIcon()", undefined);
+
+expectError("this.getField('MyField').checkThisBox()");
+expectError("this.getField('MyField').checkThisBox({})");
+
+expectError("this.getField('MyField').defaultIsChecked()");
+expect("this.getField('MyField').defaultIsChecked(0)", false);
+
+expectError("this.getField('MyField').isBoxChecked()");
+expectError("this.getField('MyField').isBoxChecked(20)");
+expect("this.getField('MyField').isBoxChecked(0)", false);
+
+expectError("this.getField('MyField').isDefaultChecked()", false);
+expectError("this.getField('MyField').isDefaultChecked(20)", false);
+expect("this.getField('MyField').isDefaultChecked(0)", false);
+
+expect("this.getField('MyField').setFocus()", undefined);
+
+// TODO(tsepez): these need a different kind of object to pass
+expectError("this.getField('MyField.Sub_X').browseForFileToSubmit()");
+expectError("this.getField('MyField').checkThisBox(0, true)");
+expectError("this.getField('MyField').getItemAt(0)");
+
+app.alert("These always succeed without actually doing anything:");
+expect("this.getField('MyField').clearItems()", undefined);
+expect("this.getField('MyField').deleteItemAt()", undefined);
+expect("this.getField('MyField').insertItemAt()", undefined);
+expect("this.getField('MyField').setAction()", undefined);
+expect("this.getField('MyField').setItems()");
+
+app.alert("These always throw operation not supported errors:");
+expectError("this.getField('MyField').buttonSetCaption()");
+expectError("this.getField('MyField').buttonSetIcon()");
+expectError("this.getField('MyField').getLock()");
+expectError("this.getField('MyField').setLock()");
+expectError("this.getField('MyField').signatureGetModifications()");
+expectError("this.getField('MyField').signatureGetSeedValue()");
+expectError("this.getField('MyField').signatureInfo()");
+expectError("this.getField('MyField').signatureSetSeedValue()");
+expectError("this.getField('MyField').signatureSign()");
+expectError("this.getField('MyField').signatureValidate()");
+
 endstream
 endobj
 {{xref}}
diff --git a/testing/resources/javascript/field_methods_expected.txt b/testing/resources/javascript/field_methods_expected.txt
index 04aafd7..2f16c23 100644
--- a/testing/resources/javascript/field_methods_expected.txt
+++ b/testing/resources/javascript/field_methods_expected.txt
@@ -6,3 +6,37 @@
 Alert: MyField.Sub_B
 Alert: MyField.Sub_X
 Alert: MyField.Sub_Z
+Alert: PASS: this.getField('MyField.Sub_A').buttonGetCaption() = 
+Alert: PASS: this.getField('MyField.Sub_A').buttonGetIcon() = [object Object]
+Alert: PASS: this.getField('MyField.Sub_A').buttonImportIcon() = undefined
+Alert: PASS: this.getField('MyField').checkThisBox() threw Field.checkThisBox: Incorrect number of parameters passed to function.
+Alert: PASS: this.getField('MyField').checkThisBox({}) threw Field.checkThisBox: Object is of the wrong type.
+Alert: PASS: this.getField('MyField').defaultIsChecked() threw Field.defaultIsChecked: Incorrect number of parameters passed to function.
+Alert: PASS: this.getField('MyField').defaultIsChecked(0) = false
+Alert: PASS: this.getField('MyField').isBoxChecked() threw Field.isBoxChecked: Incorrect parameter value.
+Alert: PASS: this.getField('MyField').isBoxChecked(20) threw Field.isBoxChecked: Incorrect parameter value.
+Alert: PASS: this.getField('MyField').isBoxChecked(0) = false
+Alert: PASS: this.getField('MyField').isDefaultChecked() threw Field.isDefaultChecked: Incorrect parameter value.
+Alert: PASS: this.getField('MyField').isDefaultChecked(20) threw Field.isDefaultChecked: Incorrect parameter value.
+Alert: PASS: this.getField('MyField').isDefaultChecked(0) = false
+Alert: PASS: this.getField('MyField').setFocus() = undefined
+Alert: PASS: this.getField('MyField.Sub_X').browseForFileToSubmit() threw Field.browseForFileToSubmit: Object is of the wrong type.
+Alert: PASS: this.getField('MyField').checkThisBox(0, true) threw Field.checkThisBox: Object is of the wrong type.
+Alert: PASS: this.getField('MyField').getItemAt(0) threw Field.getItemAt: Object is of the wrong type.
+Alert: These always succeed without actually doing anything:
+Alert: PASS: this.getField('MyField').clearItems() = undefined
+Alert: PASS: this.getField('MyField').deleteItemAt() = undefined
+Alert: PASS: this.getField('MyField').insertItemAt() = undefined
+Alert: PASS: this.getField('MyField').setAction() = undefined
+Alert: PASS: this.getField('MyField').setItems() = undefined
+Alert: These always throw operation not supported errors:
+Alert: PASS: this.getField('MyField').buttonSetCaption() threw Field.buttonSetCaption: Operation not supported.
+Alert: PASS: this.getField('MyField').buttonSetIcon() threw Field.buttonSetIcon: Operation not supported.
+Alert: PASS: this.getField('MyField').getLock() threw Field.getLock: Operation not supported.
+Alert: PASS: this.getField('MyField').setLock() threw Field.setLock: Operation not supported.
+Alert: PASS: this.getField('MyField').signatureGetModifications() threw Field.signatureGetModifications: Operation not supported.
+Alert: PASS: this.getField('MyField').signatureGetSeedValue() threw Field.signatureGetSeedValue: Operation not supported.
+Alert: PASS: this.getField('MyField').signatureInfo() threw Field.signatureInfo: Operation not supported.
+Alert: PASS: this.getField('MyField').signatureSetSeedValue() threw Field.signatureSetSeedValue: Operation not supported.
+Alert: PASS: this.getField('MyField').signatureSign() threw Field.signatureSign: Operation not supported.
+Alert: PASS: this.getField('MyField').signatureValidate() threw Field.signatureValidate: Operation not supported.