From b14a2f2e28d94d4a85b762a5eac9414b2a328bc6 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 12 Oct 2018 23:21:58 +0000 Subject: Beef up coverage in CJS_Field. Still a long way to go, but hit the easy ones first. Alphabetize property names in cjs_field.cpp file. Change-Id: I1ede770a1e159d464287775cf9e19cbaf9f2a62f Reviewed-on: https://pdfium-review.googlesource.com/c/43978 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fxjs/cjs_field.cpp | 22 +-- fxjs/cjs_field.h | 2 +- testing/resources/javascript/field.in | 173 +++++++++++++++++++++++- testing/resources/javascript/field_expected.txt | 60 ++++++++ 4 files changed, 241 insertions(+), 16 deletions(-) diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp index ca8c62451c..35e2bb51b0 100644 --- a/fxjs/cjs_field.cpp +++ b/fxjs/cjs_field.cpp @@ -511,6 +511,7 @@ const JSPropertySpec CJS_Field::PropertySpecs[] = { {"richText", get_rich_text_static, set_rich_text_static}, {"richValue", get_rich_value_static, set_rich_value_static}, {"rotation", get_rotation_static, set_rotation_static}, + {"source", get_source_static, set_source_static}, {"strokeColor", get_stroke_color_static, set_stroke_color_static}, {"style", get_style_static, set_style_static}, {"submitName", get_submit_name_static, set_submit_name_static}, @@ -520,8 +521,7 @@ const JSPropertySpec CJS_Field::PropertySpecs[] = { {"type", get_type_static, set_type_static}, {"userName", get_user_name_static, set_user_name_static}, {"value", get_value_static, set_value_static}, - {"valueAsString", get_value_as_string_static, set_value_as_string_static}, - {"source", get_source_static, set_source_static}}; + {"valueAsString", get_value_as_string_static, set_value_as_string_static}}; const JSMethodSpec CJS_Field::MethodSpecs[] = { {"browseForFileToSubmit", browseForFileToSubmit_static}, @@ -1806,6 +1806,15 @@ CJS_Result CJS_Field::set_rotation(CJS_Runtime* pRuntime, return CJS_Result::Success(); } +CJS_Result CJS_Field::get_source(CJS_Runtime* pRuntime) { + return CJS_Result::Success(); +} + +CJS_Result CJS_Field::set_source(CJS_Runtime* pRuntime, + v8::Local vp) { + return CJS_Result::Success(); +} + CJS_Result CJS_Field::get_stroke_color(CJS_Runtime* pRuntime) { CPDF_FormField* pFormField = GetFirstFormField(); if (!pFormField) @@ -2566,15 +2575,6 @@ CJS_Result CJS_Field::signatureValidate( return CJS_Result::Failure(JSMessage::kNotSupportedError); } -CJS_Result CJS_Field::get_source(CJS_Runtime* pRuntime) { - return CJS_Result::Success(); -} - -CJS_Result CJS_Field::set_source(CJS_Runtime* pRuntime, - v8::Local vp) { - return CJS_Result::Success(); -} - void CJS_Field::AddDelay_Int(FIELD_PROP prop, int32_t n) { auto pNewData = pdfium::MakeUnique(prop, m_nFormControlIndex, m_FieldName); diff --git a/fxjs/cjs_field.h b/fxjs/cjs_field.h index d4abb693bf..290192afaa 100644 --- a/fxjs/cjs_field.h +++ b/fxjs/cjs_field.h @@ -80,6 +80,7 @@ class CJS_Field final : public CJS_Object { JS_STATIC_PROP(richText, rich_text, CJS_Field); JS_STATIC_PROP(richValue, rich_value, CJS_Field); JS_STATIC_PROP(rotation, rotation, CJS_Field); + JS_STATIC_PROP(source, source, CJS_Field); JS_STATIC_PROP(strokeColor, stroke_color, CJS_Field); JS_STATIC_PROP(style, style, CJS_Field); JS_STATIC_PROP(submitName, submit_name, CJS_Field); @@ -90,7 +91,6 @@ class CJS_Field final : public CJS_Object { JS_STATIC_PROP(userName, user_name, CJS_Field); JS_STATIC_PROP(value, value, CJS_Field); JS_STATIC_PROP(valueAsString, value_as_string, CJS_Field); - JS_STATIC_PROP(source, source, CJS_Field); JS_STATIC_METHOD(browseForFileToSubmit, CJS_Field); JS_STATIC_METHOD(buttonGetCaption, CJS_Field); diff --git a/testing/resources/javascript/field.in b/testing/resources/javascript/field.in index 62496abd1a..588ae334e5 100644 --- a/testing/resources/javascript/field.in +++ b/testing/resources/javascript/field.in @@ -92,7 +92,7 @@ endobj {{streamlen}} >> stream -function TestGetField() { +function testGetField() { try { var field = this.getField("MyField"); app.alert("field is " + field.name); @@ -104,7 +104,8 @@ function TestGetField() { app.alert("Unexpected error: " + e); } } -function TestGetArray() { + +function testGetArray() { try { var subs = this.getField("MyField").getArray(); app.alert("found " + subs.length + " sub-fields:"); @@ -115,8 +116,172 @@ function TestGetArray() { app.alert("Unexpected error: " + e); } } -TestGetField(); -TestGetArray(); + +function testReadProperty(field, prop, expected) { + try { + var actual = field[prop]; + if (actual == expected) { + app.alert('PASS: ' + prop + ' = ' + actual); + } else { + app.alert('FAIL: ' + prop + ' = ' + actual + ', expected = ' + expected); + } + } catch (e) { + app.alert('ERROR: ' + e.toString()); + } +} + +function testUnreadableProperty(field, prop) { + try { + var value = field[prop]; + app.alert('FAIL: ' + prop + ', expected to throw error'); + } catch (e) { + app.alert('PASS: ' + prop + ' threw error ' + e.toString()); + } +} + +function testWriteProperty(field, prop, newValue) { + try { + field[prop] = newValue; + var actual = field[prop]; + if (actual == newValue) { + app.alert('PASS: ' + prop + ' = ' + actual); + } else { + app.alert('FAIL: ' + prop + ' = ' + actual + ', expected = ' + newValue); + } + } catch (e) { + app.alert('ERROR: ' + e.toString()); + } +} + +function testWriteIgnoredProperty(field, prop, expected, newValue) { + try { + field[prop] = newValue; + var actual = field[prop]; + if (actual == expected) { + app.alert('PASS: ' + prop + ' = ' + actual); + } else { + app.alert('FAIL: ' + prop + ' = ' + actual + ', expected = ' + expected); + } + } catch (e) { + app.alert('ERROR: ' + e.toString()); + } +} + +function testUnwritableProperty(field, prop, newValue) { + try { + field[prop] = newValue; + app.alert('FAIL: ' + prop + ' = ' + newValue + ', expected to throw error'); + } catch (e) { + app.alert('PASS: ' + prop + ' threw error ' + e.toString()); + } +} + +function testRWProperty(field, prop, expected, newValue) { + testReadProperty(field, prop, expected); + testWriteProperty(field, prop, newValue); +} + +function testRIProperty(field, prop, expected, newValue) { + testReadProperty(field, prop, expected); + testWriteIgnoredProperty(field, prop, expected, newValue); +} + +function testROProperty(field, prop, expected) { + testReadProperty(field, prop, expected); + testUnwritableProperty(field, prop, 42); +} + +function testXXProperty(field, prop) { + testUnreadableProperty(field, prop); + testUnwritableProperty(field, prop, 42); +} + +function testProperties() { + try { + var field = this.getField("MyField"); + app.alert('Testing properties under delay'); + testRWProperty(field, "delay", false, true); + // TODO(tsepez): try this case, too. + // testPropertiesCase(field); + app.alert('Testing properties under non-delay'); + testRWProperty(field, "delay", true, false); + testPropertiesCase(field); + } catch (e) { + app.alert("Unexpected error: " + e); + } +} + +function testPropertiesCase(field) { + try { + // TODO(tsepez): devise tests and uncomment. + testRIProperty(field, "alignment", "left", "center"); + // testRWProperty(field, "borderStyle", "solid", "inset"); + // testROProperty(field, "buttonAlignX", "clams"); + // testROProperty(field, "buttonAlignY", "clams"); + // testROProperty(field, "buttonFitBounds", "clams"); + // testROProperty(field, "buttonPosition", "clams"); + // testROProperty(field, "buttonScaleHow", "clams"); + // testROProperty(field, "buttonScaleWhen", "clams"); + testRIProperty(field, "calcOrderIndex", -1, 100); + testRIProperty(field, "charLimit", 0, 100); + testRIProperty(field, "comb", false, true); + // testRIProperty(field, "commitOnSelChange", false, true); + // testROProperty(field, "currentValueIndices", "clams"); + testXXProperty(field, "defaultStyle"); + // testROProperty(field, "defaultValue", "clams"); + testRIProperty(field, "doNotScroll", false, true); + testRIProperty(field, "doNotSpellCheck", false, true); + // testROProperty(field, "display", "clams"); + testROProperty(field, "doc", "[object global]"); + // testROProperty(field, "editable", "clams"); + // testROProperty(field, "exportValues", "clams"); + // testROProperty(field, "hidden", "clams"); + testRIProperty(field, "fileSelect", false, true); + testRIProperty(field, "fillColor", "T", ["RGB", 0, 0, 0]); + // testROProperty(field, "lineWidth", "clams"); + // testROProperty(field, "highlight", "clams"); + testRIProperty(field, "multiline", false, true); + // testROProperty(field, "multipleSelection", "clams"); + testROProperty(field, "name", "MyField"); + // testROProperty(field, "numItems", "clams"); + testROProperty(field, "page", -1); + testRIProperty(field, "password", false, 42); + // testROProperty(field, "print", "clams"); + // testROProperty(field, "radiosInUnison", "clams"); + testRIProperty(field, "readonly", false, true); + // testRWProperty(field, "rect", [0,0,0,0], [0,0,0,0]); + // testROProperty(field, "required", "clams"); + testRIProperty(field, "richText", false, true); + testRIProperty(field, "richValue", undefined, "clams"); + testRIProperty(field, "rotation", 0, 42); + testRIProperty(field, "source", undefined, "clams"); + testRIProperty(field, "strokeColor", "T", ["RGB", 0, 0, 0]); + // testROProperty(field, "style", "clams"); + testRIProperty(field, "submitName", undefined, "clams"); + testRIProperty(field, "textColor", "T", ["RGB", 0, 0, 0]); + // testROProperty(field, "textFont", "clams"); + testRIProperty(field, "textSize", 0, 32); + testROProperty(field, "type", "text"); + testRIProperty(field, "userName", ""); + testRIProperty(field, "value", "", "clams"); + testROProperty(field, "valueAsString", ""); + } catch (e) { + app.alert("Unexpected error: " + e); + } +} + +function testMethods() { + try { + var field = this.getField("MyField"); + } catch (e) { + app.alert("Unexpected error: " + e); + } +} + +testGetField(); +testGetArray(); +testProperties(); +testMethods(); endstream endobj {{xref}} diff --git a/testing/resources/javascript/field_expected.txt b/testing/resources/javascript/field_expected.txt index 04aafd737e..db1f6c90c8 100644 --- a/testing/resources/javascript/field_expected.txt +++ b/testing/resources/javascript/field_expected.txt @@ -6,3 +6,63 @@ Alert: MyField.Sub_A Alert: MyField.Sub_B Alert: MyField.Sub_X Alert: MyField.Sub_Z +Alert: Testing properties under delay +Alert: PASS: delay = false +Alert: PASS: delay = true +Alert: Testing properties under non-delay +Alert: PASS: delay = true +Alert: PASS: delay = false +Alert: PASS: alignment = left +Alert: PASS: alignment = left +Alert: PASS: calcOrderIndex = -1 +Alert: PASS: calcOrderIndex = -1 +Alert: PASS: charLimit = 0 +Alert: PASS: charLimit = 0 +Alert: PASS: comb = false +Alert: PASS: comb = false +Alert: PASS: defaultStyle threw error Field.defaultStyle: Operation not supported. +Alert: PASS: defaultStyle threw error Field.defaultStyle: Operation not supported. +Alert: PASS: doNotScroll = false +Alert: PASS: doNotScroll = false +Alert: PASS: doNotSpellCheck = false +Alert: PASS: doNotSpellCheck = false +Alert: PASS: doc = [object global] +Alert: PASS: doc threw error Field.doc: Operation not supported. +Alert: PASS: fileSelect = false +Alert: PASS: fileSelect = false +Alert: PASS: fillColor = T +Alert: PASS: fillColor = T +Alert: PASS: multiline = false +Alert: PASS: multiline = false +Alert: PASS: name = MyField +Alert: PASS: name threw error Field.name: Operation not supported. +Alert: PASS: page = -1 +Alert: PASS: page threw error Field.page: Cannot assign to readonly property. +Alert: PASS: password = false +Alert: PASS: password = false +Alert: PASS: readonly = false +Alert: PASS: readonly = false +Alert: PASS: richText = false +Alert: PASS: richText = false +Alert: PASS: richValue = undefined +Alert: PASS: richValue = undefined +Alert: PASS: rotation = 0 +Alert: PASS: rotation = 0 +Alert: PASS: source = undefined +Alert: PASS: source = undefined +Alert: PASS: strokeColor = T +Alert: PASS: strokeColor = T +Alert: PASS: submitName = undefined +Alert: PASS: submitName = undefined +Alert: PASS: textColor = T +Alert: PASS: textColor = T +Alert: PASS: textSize = 0 +Alert: PASS: textSize = 0 +Alert: PASS: type = text +Alert: PASS: type threw error Field.type: Operation not supported. +Alert: PASS: userName = +Alert: PASS: userName = +Alert: PASS: value = +Alert: PASS: value = +Alert: PASS: valueAsString = +Alert: PASS: valueAsString threw error Field.valueAsString: Operation not supported. -- cgit v1.2.3