Cover CJX_InstanceManager methods from javascript tests.

Mostly handling of bad parameters from JS.

Change-Id: Iac7dc8182c1b4b5dbfc45a759c59d85e630a0c29
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/66010
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/testing/resources/javascript/xfa_specific/instance_manager.in b/testing/resources/javascript/xfa_specific/instance_manager.in
new file mode 100644
index 0000000..a47827f
--- /dev/null
+++ b/testing/resources/javascript/xfa_specific/instance_manager.in
@@ -0,0 +1,95 @@
+{{header}}
+{{include ../../xfa_catalog_1_0.fragment}}
+{{include ../../xfa_object_2_0.fragment}}
+{{include ../../xfa_preamble_3_0.fragment}}
+{{include ../../xfa_config_4_0.fragment}}
+{{object 5 0}} <<
+  {{streamlen}}
+>>
+stream
+<template xmlns="http://www.xfa.org/schema/xfa-template/2.6/">
+  <subform layout="tb" locale="en_US" name="form1" restoreState="auto">
+    <pageSet>
+      <pageArea id="Page1" name="Page1">
+        <contentArea h="10.5in" w="8in" x="0.25in" y="0.25in"/>
+        <medium long="11in" short="8.5in" stock="letter"/>
+      </pageArea>
+    </pageSet>
+    <subform h="10.5in" w="8in" name="subform2">
+      <field h="9.0001mm" name="field1" w="47.625mm" x="6.35mm" y="92.075mm">
+        <ui>
+          <choiceList/>
+        </ui>
+        <items save="1">
+          <text>Single</text>
+          <text>Married</text>
+          <text>Other</text>
+        </items>
+      </field>
+      <field name="field3" h="10.625mm" w="30.625mm" x="5mm" y="50mm">
+      </field>
+      <subform name="field4" x="5mm" y="5mm">
+        <occur max="-1"/>
+        <field name="field5" w="64.77mm" h="6.35mm">
+        </field>
+      </subform>
+    </subform>
+    <event activity="docReady">
+      <script contentType="application/x-javascript"><![CDATA[
+        {{include ../expect.js}}
+        {{include ../property_test_helpers.js}}
+        {{include dump_tree.js}}
+
+        var mgr = xfa.resolveNode("xfa.form..field4").instanceManager;
+        dumpTree(mgr);
+
+        testRWProperty(mgr, "count", 1, 12);
+        testROProperty(mgr, "min", 1);
+        testROProperty(mgr, "max", -1);
+
+        expectError("mgr.setInstances()");
+        expectError("mgr.setInstances(-10)");
+        expectError("mgr.setInstances('clams')");
+        expectError("mgr.setInstances([1, 2, 3])");
+        // setInstances(10000000) will hang or hit OOM.
+        expect("mgr.setInstances(4)", undefined);
+        expect("mgr.count", 4);
+        expect("mgr.setInstances(2)", undefined);
+        expect("mgr.count", 2);
+
+        expectError("mgr.moveInstance()");
+        expectError("mgr.moveInstance(0)");
+        expectError("mgr.moveInstance('clams')");
+        expectError("mgr.moveInstance([1, 2, 3])");
+        expect("mgr.moveInstance(0, 1)", undefined);
+        expect("mgr.count", 2);
+
+        expectError("mgr.addInstance(1, 2, 3)");
+        expect("mgr.addInstance().className", "subform");
+        expect("mgr.addInstance(true).className", "subform");
+        expect("mgr.count", 4);
+
+        expectError("mgr.insertInstance()");
+        expectError("mgr.insertInstance(1, 2, 3)");
+        expect("mgr.insertInstance(1, true).className", "subform");
+        expect("mgr.count", 5);
+
+        expectError("mgr.removeInstance()");
+        expectError("mgr.removeInstance(1, 2)");
+        expect("mgr.removeInstance(0)", undefined);
+        expect("mgr.count", 4);
+        expect("mgr.removeInstance(0)", undefined);
+        expect("mgr.count", 3);
+      ]]></script>
+    </event>
+  </subform>
+</template>
+endstream
+endobj
+{{include ../../xfa_locale_6_0.fragment}}
+{{include ../../xfa_postamble_7_0.fragment}}
+{{include ../../xfa_pages_8_0.fragment}}
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/javascript/xfa_specific/instance_manager_expected.txt b/testing/resources/javascript/xfa_specific/instance_manager_expected.txt
new file mode 100644
index 0000000..60137e2
--- /dev/null
+++ b/testing/resources/javascript/xfa_specific/instance_manager_expected.txt
@@ -0,0 +1,36 @@
+Alert: instanceManager
+Alert: | occur
+Alert: PASS: count = 1
+Alert: PASS: count = 12
+Alert: PASS: min = 1
+Alert: PASS: min threw Error: Invalid property set operation.
+Alert: PASS: max = -1
+Alert: PASS: max threw Error: Invalid property set operation.
+Alert: PASS: mgr.setInstances() threw XFAObject.setInstances: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.setInstances(-10) threw Error: The element [min] has violated its allowable number of occurrences.
+Alert: PASS: mgr.setInstances('clams') threw Error: The element [min] has violated its allowable number of occurrences.
+Alert: PASS: mgr.setInstances([1, 2, 3]) threw Error: The element [min] has violated its allowable number of occurrences.
+Alert: PASS: mgr.setInstances(4) = undefined
+Alert: PASS: mgr.count = 4
+Alert: PASS: mgr.setInstances(2) = undefined
+Alert: PASS: mgr.count = 2
+Alert: PASS: mgr.moveInstance() threw XFAObject.moveInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.moveInstance(0) threw XFAObject.moveInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.moveInstance('clams') threw XFAObject.moveInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.moveInstance([1, 2, 3]) threw XFAObject.moveInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.moveInstance(0, 1) = undefined
+Alert: PASS: mgr.count = 2
+Alert: PASS: mgr.addInstance(1, 2, 3) threw XFAObject.addInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.addInstance().className = subform
+Alert: PASS: mgr.addInstance(true).className = subform
+Alert: PASS: mgr.count = 4
+Alert: PASS: mgr.insertInstance() threw XFAObject.insertInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.insertInstance(1, 2, 3) threw XFAObject.insertInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.insertInstance(1, true).className = subform
+Alert: PASS: mgr.count = 5
+Alert: PASS: mgr.removeInstance() threw XFAObject.removeInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.removeInstance(1, 2) threw XFAObject.removeInstance: Incorrect number of parameters passed to function.
+Alert: PASS: mgr.removeInstance(0) = undefined
+Alert: PASS: mgr.count = 4
+Alert: PASS: mgr.removeInstance(0) = undefined
+Alert: PASS: mgr.count = 3