summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-18 17:00:37 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-18 17:00:37 +0000
commit859312428770b89c01c5e9b9e06d5f53f7cd3afe (patch)
tree69a2c84f8e567c6e2563ef135e187993b14556c6
parent4df46054105e71ecc6a80d29c8d56ef0778b5aa8 (diff)
downloadpdfium-859312428770b89c01c5e9b9e06d5f53f7cd3afe.tar.xz
Add JavaScript tests for event API.
Change-Id: Ic62fd1c6e55e6db5864e124fe3ba50e05b0020e1 Reviewed-on: https://pdfium-review.googlesource.com/c/44210 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r--testing/resources/javascript/event_properties.in179
-rw-r--r--testing/resources/javascript/event_properties_expected.txt49
2 files changed, 228 insertions, 0 deletions
diff --git a/testing/resources/javascript/event_properties.in b/testing/resources/javascript/event_properties.in
new file mode 100644
index 0000000000..495c16bc14
--- /dev/null
+++ b/testing/resources/javascript/event_properties.in
@@ -0,0 +1,179 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /AcroForm << /Fields [ 4 0 R 10 0 R ] /DR 5 0 R >>
+>>
+endobj
+{{object 2 0}} <<
+ /Count 1
+ /Kids [ 3 0 R ]
+ /Type /Pages
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources 5 0 R
+ /MediaBox [ 0 0 300 200 ]
+ /Contents 8 0 R
+ /Annots [ 4 0 R 10 0 R ]
+>>
+endobj
+{{object 4 0}} <<
+ /Type /Annot
+ /FT /Tx
+ /T (Text Box)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [ 100 100 200 130 ]
+ /Subtype /Widget
+ /AA <<
+ /F 9 0 R
+ >>
+>>
+endobj
+{{object 5 0}} <<
+ /Font 6 0 R
+>>
+endobj
+{{object 6 0}} <<
+ /F1 7 0 R
+>>
+endobj
+{{object 7 0}} <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+>>
+endobj
+{{object 8 0}} <<
+ {{streamlen}}
+>>
+stream
+endstream
+endobj
+{{object 9 0}} <<
+ /JS (
+ function expect(expression, expected) {
+ try {
+ var actual = eval(expression);
+ if (actual == expected) {
+ app.alert('PASS: ' + expression + ' = ' + actual);
+ } else {
+ app.alert('FAIL: ' + expression + ' = ' + actual + ', expected ' + expected + " ");
+ }
+ } catch (e) {
+ app.alert('ERROR: ' + e);
+ }
+ }
+
+ function expectError(expression) {
+ try {
+ var actual = eval(expression);
+ app.alert('FAIL: ' + expression + ' = ' + actual + ', expected to throw');
+ } catch (e) {
+ app.alert('PASS: ' + expression + ' threw ' + e);
+ }
+ }
+
+ try {
+ app.alert("*** starting test ***");
+
+ expect("event.change", "");
+ expect("event.change = 'boo'", "boo");
+ expect("event.change", "boo");
+
+ expect("event.changeEx", "");
+ expectError("event.changeEx = 'boo'");
+
+ expect("event.commitKey", "");
+ expectError("event.commitKey = 'boo'");
+
+ // FieldFull applies to events named Keystroke only.
+ // TODO(tsepez): figure out a way to set event names for tests.
+ expectError("event.fieldFull");
+ expectError("event.fieldFull = 'boo'");
+
+ expect("event.keyDown", "");
+ expectError("event.keyDown = 'boo'");
+
+ expect("event.modifier", "");
+ expectError("event.modifier = 'boo'");
+
+ expect("event.name", "Format");
+ expectError("event.name = 'boo'");
+
+ expect("event.rc", false);
+ expect("event.rc = 'boo'", "boo");
+ expect("event.rc", true);
+ expect("event.rc = false", false);
+
+ // TODO(tsepez): is silently ignoring update correct here?
+ expect("event.richChange", undefined);
+ expect("event.richChange = 'boo'", "boo");
+ expect("event.richChange", undefined);
+
+ // TODO(tsepez): is silently ignoring update correct here?
+ expect("event.richChangeEx", undefined);
+ expect("event.richChangeEx = 'boo'", "boo");
+ expect("event.richChangeEx", undefined);
+
+ // TODO(tsepez): is silently ignoring update correct here?
+ expect("event.richValue", undefined);
+ expect("event.richValue = 'boo'", "boo");
+ expect("event.richValue", undefined);
+
+ // selEnd applies to events named Keystroke only.
+ // TODO(tsepez): figure out a way to set event names for tests.
+ expect("event.selEnd", undefined);
+ expect("event.selEnd = 'boo'", "boo");
+ expect("event.selEnd", undefined);
+
+ // selEnd applies to events named Keystroke only.
+ // TODO(tsepez): figure out a way to set event names for tests.
+ expect("event.selStart", undefined);
+ expect("event.selStart = 'boo'", "boo");
+ expect("event.selStart", undefined);
+
+ expect("event.shift", false);
+ expectError("event.shift = 'boo'");
+
+ // TODO(tsepez): dig deeper into object.
+ expect("event.source", "[object Object]");
+ expectError("event.source = 'boo'");
+
+ // TODO(tsepez): dig deeper into object.
+ expect("event.target", "[object Object]");
+ expectError("event.target = 'boo'");
+
+ expect("event.targetName", "Text Box");
+ expectError("event.targetName = 'boo'");
+
+ expect("event.type", "Field");
+ expectError("event.type = 'boo'");
+
+ expect("event.value", "");
+ expect("event.value = 'boo'", "boo");
+ expect("event.value", "boo");
+
+ app.alert("*** ending test ***");
+ } catch (e) {
+ app.alert("Truly unexpected error occured: " + e);
+ }
+ )
+ /S /JavaScript
+>>
+endobj
+{{object 10 0}} <<
+ /Type /Annot
+ /FT /Tx
+ /T (Text2)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [ 100 40 200 70 ]
+ /Subtype /Widget
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/javascript/event_properties_expected.txt b/testing/resources/javascript/event_properties_expected.txt
new file mode 100644
index 0000000000..ca1cbeba4a
--- /dev/null
+++ b/testing/resources/javascript/event_properties_expected.txt
@@ -0,0 +1,49 @@
+Alert: *** starting test ***
+Alert: PASS: event.change =
+Alert: PASS: event.change = 'boo' = boo
+Alert: PASS: event.change = boo
+Alert: PASS: event.changeEx =
+Alert: PASS: event.changeEx = 'boo' threw event.changeEx: Operation not supported.
+Alert: PASS: event.commitKey = 0
+Alert: PASS: event.commitKey = 'boo' threw event.commitKey: Operation not supported.
+Alert: PASS: event.fieldFull threw event.fieldFull: unrecognized event
+Alert: PASS: event.fieldFull = 'boo' threw event.fieldFull: Operation not supported.
+Alert: PASS: event.keyDown = false
+Alert: PASS: event.keyDown = 'boo' threw event.keyDown: Operation not supported.
+Alert: PASS: event.modifier = false
+Alert: PASS: event.modifier = 'boo' threw event.modifier: Operation not supported.
+Alert: PASS: event.name = Format
+Alert: PASS: event.name = 'boo' threw event.name: Operation not supported.
+Alert: PASS: event.rc = false
+Alert: PASS: event.rc = 'boo' = boo
+Alert: PASS: event.rc = true
+Alert: PASS: event.rc = false = false
+Alert: PASS: event.richChange = undefined
+Alert: PASS: event.richChange = 'boo' = boo
+Alert: PASS: event.richChange = undefined
+Alert: PASS: event.richChangeEx = undefined
+Alert: PASS: event.richChangeEx = 'boo' = boo
+Alert: PASS: event.richChangeEx = undefined
+Alert: PASS: event.richValue = undefined
+Alert: PASS: event.richValue = 'boo' = boo
+Alert: PASS: event.richValue = undefined
+Alert: PASS: event.selEnd = undefined
+Alert: PASS: event.selEnd = 'boo' = boo
+Alert: PASS: event.selEnd = undefined
+Alert: PASS: event.selStart = undefined
+Alert: PASS: event.selStart = 'boo' = boo
+Alert: PASS: event.selStart = undefined
+Alert: PASS: event.shift = false
+Alert: PASS: event.shift = 'boo' threw event.shift: Operation not supported.
+Alert: PASS: event.source = [object Object]
+Alert: PASS: event.source = 'boo' threw event.source: Operation not supported.
+Alert: PASS: event.target = [object Object]
+Alert: PASS: event.target = 'boo' threw event.target: Operation not supported.
+Alert: PASS: event.targetName = Text Box
+Alert: PASS: event.targetName = 'boo' threw event.targetName: Operation not supported.
+Alert: PASS: event.type = Field
+Alert: PASS: event.type = 'boo' threw event.type: Operation not supported.
+Alert: PASS: event.value =
+Alert: PASS: event.value = 'boo' = boo
+Alert: PASS: event.value = boo
+Alert: *** ending test ***