Add JavaScript tests for file select fields.

- Re-order dictionary entries to match our convention while at it.

Change-Id: Ibb950660793db99e788f4be3dbda97ac23a1c5a3
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/63511
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/testing/resources/javascript/field.fragment b/testing/resources/javascript/field.fragment
index d366361..f301364 100644
--- a/testing/resources/javascript/field.fragment
+++ b/testing/resources/javascript/field.fragment
@@ -45,69 +45,70 @@
     9 0 R
     10 0 R
     11 0 R
+    12 0 R
   ]
 >>
 endobj
 {{object 6 0}} <<
+  /Type /Annot
+  /Subtype /Widget
   /FT /Tx
   /Parent 5 0 R
   /T (MyText)
-  /Type /Annot
-  /Subtype /Widget
   /Rect [200 201 220 221]
   /V (bleen)
   /DV (grue)
 >>
 endobj
 {{object 7 0}} <<
+  /Type /Annot
+  /Subtype /Widget
   /FT /Btn
   /Ff 65536
   /Parent 5 0 R
   /T (MyPushButton)
-  /Type /Annot
-  /Subtype /Widget
   /Rect [220 221 240 241]
 >>
 endobj
 {{object 8 0}} <<
+  /Type /Annot
+  /Subtype /Widget
   /FT /Btn
   /Ff 32768
   /Parent 5 0 R
   /T (MyRadio)
-  /Type /Annot
-  /Subtype /Widget
   /Rect [240 241 260 261]
 >>
 endobj
 {{object 9 0}} <<
+  /Type /Annot
+  /Subtype /Widget
   /FT /Btn
   /Ff 0
   /Parent 5 0 R
   /T (MyCheckBox)
-  /Type /Annot
-  /Subtype /Widget
   /Rect [260 261 280 281]
 >>
 endobj
 {{object 10 0}} <<
+  /Type /Annot
+  /Subtype /Widget
   /FT /Ch
   /Ff 2097152
   /Parent 5 0 R
   /T (MyMultiSelect)
-  /Type /Annot
-  /Subtype /Widget
   /Rect [ 280 281 300 301 ]
   /Opt [ (foo) (bar) (qux) ]
   /V (qux)
 >>
 endobj
 {{object 11 0}} <<
+  /Type /Annot
+  /Subtype /Widget
   /FT /Ch
   /Ff 0
   /Parent 5 0 R
   /T (MySingleSelect)
-  /Type /Annot
-  /Subtype /Widget
   /Rect [ 300 301 320 321 ]
   /Opt [
     [ (foo) (Foo) ]
@@ -116,6 +117,17 @@
   ]
 >>
 endobj
+{{object 12 0}} <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /Ff 1048576
+  /Parent 5 0 R
+  /T (MyFile)
+  /Rect [200 201 220 221]
+  /V ("/path/to/file.pdf")
+>>
+endobj
 % OpenAction action
 {{object 15 0}} <<
   /Type /Action
diff --git a/testing/resources/javascript/field_methods.in b/testing/resources/javascript/field_methods.in
index aebbf71..3197af9 100644
--- a/testing/resources/javascript/field_methods.in
+++ b/testing/resources/javascript/field_methods.in
@@ -40,6 +40,8 @@
 expect("this.getField('MyField.MyPushButton').buttonGetIcon()", "[object Object]");
 expect("this.getField('MyField.MyPushButton').buttonImportIcon()", undefined);
 
+expect("this.getField('MyField.MyFile').browseForFileToSubmit()", undefined);
+
 expectError("this.getField('MyField').checkThisBox()");
 expectError("this.getField('MyField').checkThisBox({})");
 
@@ -56,7 +58,7 @@
 
 expect("this.getField('MyField').setFocus()", undefined);
 
-// TODO(tsepez): these need a different kind of object to pass
+app.alert("These mismatched cases always throw");
 expectError("this.getField('MyField.MyText').browseForFileToSubmit()");
 expectError("this.getField('MyField').checkThisBox(0, true)");
 expectError("this.getField('MyField').getItemAt(0)");
diff --git a/testing/resources/javascript/field_methods_expected.txt b/testing/resources/javascript/field_methods_expected.txt
index f72c99c..70cb22e 100644
--- a/testing/resources/javascript/field_methods_expected.txt
+++ b/testing/resources/javascript/field_methods_expected.txt
@@ -1,8 +1,9 @@
 Alert: field is MyField
 Alert: button is MyField.MyPushButton
 Alert: nonesuch is undefined
-Alert: found 6 sub-fields:
+Alert: found 7 sub-fields:
 Alert: MyField.MyCheckBox
+Alert: MyField.MyFile
 Alert: MyField.MyMultiSelect
 Alert: MyField.MyPushButton
 Alert: MyField.MyRadio
@@ -11,6 +12,7 @@
 Alert: PASS: this.getField('MyField.MyPushButton').buttonGetCaption() = 
 Alert: PASS: this.getField('MyField.MyPushButton').buttonGetIcon() = [object Object]
 Alert: PASS: this.getField('MyField.MyPushButton').buttonImportIcon() = undefined
+Alert: PASS: this.getField('MyField.MyFile').browseForFileToSubmit() = 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.
@@ -22,6 +24,7 @@
 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: These mismatched cases always throw
 Alert: PASS: this.getField('MyField.MyText').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.
diff --git a/testing/resources/javascript/field_properties.in b/testing/resources/javascript/field_properties.in
index 4b3ee4e..2126384 100644
--- a/testing/resources/javascript/field_properties.in
+++ b/testing/resources/javascript/field_properties.in
@@ -14,6 +14,7 @@
     var radio = this.getField("MyField.MyRadio");
     var list = this.getField("MyField.MyMultiSelect");
     var check = this.getField("MyField.MyCheckBox");
+    var file = this.getField("MyField.MyFile");
     app.alert('Testing properties under delay');
     testRWProperty(field, "delay", false, true);
     // TODO(tsepez): try this case, too.
@@ -25,6 +26,7 @@
     testRadioButtonPropertiesCase(radio);
     testCheckBoxPropertiesCase(check);
     testListBoxPropertiesCase(list);
+    testFileSelectPropertiesCase(file);
   } catch (e) {
     app.alert("Unexpected error: " + e);
   }
@@ -135,6 +137,14 @@
   }
 }
 
+function testFileSelectPropertiesCase(field) {
+  try {
+    testRIProperty(field, "fileSelect", true);
+  } catch (e) {
+    app.alert("Unexpected error: " + e);
+  }
+}
+
 testProperties();
 endstream
 endobj
diff --git a/testing/resources/javascript/field_properties_expected.txt b/testing/resources/javascript/field_properties_expected.txt
index 676953e..3b2e6f6 100644
--- a/testing/resources/javascript/field_properties_expected.txt
+++ b/testing/resources/javascript/field_properties_expected.txt
@@ -118,3 +118,5 @@
 Alert: PASS: valueAsString threw Field.valueAsString: Operation not supported.
 Alert: PASS: currentValueIndices = 2
 Alert: PASS: currentValueIndices = 1
+Alert: PASS: fileSelect = true
+Alert: PASS: fileSelect = true