Improve tests for CJX_LayoutPseudoModel. Check return from GetUnitFromString() to avoid tripping ASSERT() later on as uncovered by tests. Change-Id: I73881e792c48f1f1faae104078d5be4c73e1a5e7 Reviewed-on: https://pdfium-review.googlesource.com/c/50510 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp index 401daa0..f7a07e7 100644 --- a/fxjs/xfa/cjx_layoutpseudomodel.cpp +++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp
@@ -127,8 +127,11 @@ break; } - float fValue = - measure.ToUnit(CXFA_Measurement::GetUnitFromString(unit.AsStringView())); + XFA_Unit eUnit = CXFA_Measurement::GetUnitFromString(unit.AsStringView()); + if (eUnit == XFA_Unit::Unknown) + return CJS_Result::Failure(JSMessage::kValueError); + + float fValue = measure.ToUnit(eUnit); return CJS_Result::Success( runtime->NewNumber(FXSYS_round(fValue * 1000) / 1000.0f)); }
diff --git a/testing/resources/javascript/xfa_specific/xfa_layout_pseudomodel.in b/testing/resources/javascript/xfa_specific/xfa_layout_pseudomodel.in index 45d19d8..ea3a23b 100644 --- a/testing/resources/javascript/xfa_specific/xfa_layout_pseudomodel.in +++ b/testing/resources/javascript/xfa_specific/xfa_layout_pseudomodel.in
@@ -21,32 +21,89 @@ </pageSet> <event activity="docReady" ref="$host"> <script contentType="application/x-javascript"> + {{include ../expect.js}} {{include ../property_test_helpers.js}} testROProperty(xfa.layout, "ready", true); - try { - xfa.layout.absPage(1); - xfa.layout.absPageCount(); - xfa.layout.absPageCountInBatch(); - xfa.layout.absPageInBatch(1); - xfa.layout.absPageSpan(1); - xfa.layout.h(100, 'pt'); - xfa.layout.page(1); - xfa.layout.pageContent(1); - xfa.layout.pageCount(); - xfa.layout.pageSpan(1); - xfa.layout.relayout(); - xfa.layout.relayoutPageArea(); - xfa.layout.sheet(1); - xfa.layout.sheetCount(); - xfa.layout.sheetCountInBatch(); - xfa.layout.sheetInBatch(1); - xfa.layout.w(100, 'px'); - xfa.layout.x(100, 'mm'); - xfa.layout.y(100, 'bogus'); - app.alert("finished testing methods"); - } catch (e) { - app.alert("error testing methods: " + e); - } + + expectError("xfa.layout.absPage()"); + expectError("xfa.layout.absPage(1, 2)"); + expect("xfa.layout.absPage(1)", 0); + + expect("xfa.layout.absPageCount()", 2); + expect("xfa.layout.absPageCount('args', [42], 'ignored')", 2); + + expect("xfa.layout.absPageCountInBatch()", 0); + expect("xfa.layout.absPageCountInBatch('args', [42], 'ignored')", 0); + + expectError("xfa.layout.absPageInBatch()"); + expectError("xfa.layout.absPageInBatch(1, 2)"); + expect("xfa.layout.absPageInBatch(1)", 0); + + expectError("xfa.layout.absPageSpan()"); + expectError("xfa.layout.absPageSpan(1, 2)"); + expect("xfa.layout.absPageSpan(1)"); + + expectError("xfa.layout.h()"); + expectError("xfa.layout.h(4, 'is', 'toomany', 'args')"); + expectError("xfa.layout.h(my_doc, 'bogounits')", 0); + expect("xfa.layout.h(my_doc, 'cm')", 0); + expect("xfa.layout.h(my_doc, 'in', 2)", 0); + + expectError("xfa.layout.page()"); + expectError("xfa.layout.page(1, 2)"); + expect("xfa.layout.page(my_doc)", 1); + + expectError("xfa.layout.pageContent()"); + expectError("xfa.layout.pageContent(4, 'is', 'too', 'many')"); + expect("xfa.layout.pageContent(1)", "[object XFAObject]"); + expect("xfa.layout.pageContent(1).length", 2); + + expect("xfa.layout.pageCount()", 2); + expect("xfa.layout.pageCount('all', 'args', ['ignored'])", 2); + + expectError("xfa.layout.pageSpan()"); + expectError("xfa.layout.pageSpan(2, 'toomany')"); + expect("xfa.layout.pageSpan(my_doc)", 1); + + expect("xfa.layout.relayout()"); + expect("xfa.layout.relayout('args', ['ignored'], 42)"); + + expect("xfa.layout.relayoutPageArea()"); + expect("xfa.layout.relayoutPageArea('args', ['ignored'], 42)"); + + expectError("xfa.layout.sheet()"); + expectError("xfa.layout.sheet(1, 2)"); + expect("xfa.layout.sheet(my_doc)", 0); + + expect("xfa.layout.sheetCount()", 2); + expect("xfa.layout.sheetCount('args', ['ignored'], 42)", 2); + + expect("xfa.layout.sheetCountInBatch()", 0); + expect("xfa.layout.sheetCountInBatch('args', ['ignored'], 42)", 0); + + expectError("xfa.layout.sheetInBatch()"); + expectError("xfa.layout.sheetInBatch(2, 'toomany')"); + expect("xfa.layout.sheetInBatch(1)", 0); + + expectError("xfa.layout.w()"); + expectError("xfa.layout.w(4, 'is', 'toomany', 'args')"); + expectError("xfa.layout.w(my_doc, 'bogounits')", 0); + expect("xfa.layout.w(my_doc, 'cm')", 0); + expect("xfa.layout.w(my_doc, 'in', 2)", 0); + + expectError("xfa.layout.x()"); + expectError("xfa.layout.x(4, 'is', 'toomany', 'args')"); + expectError("xfa.layout.x(my_doc, 'bogounits')", 0); + expect("xfa.layout.x(my_doc, 'cm')", 0); + expect("xfa.layout.x(my_doc, 'in', 2)", 0); + + expectError("xfa.layout.y()"); + expectError("xfa.layout.y(4, 'is', 'toomany', 'args')"); + expectError("xfa.layout.y(my_doc, 'bogounits')", 0); + expect("xfa.layout.y(my_doc, 'cm')", 0); + expect("xfa.layout.y(my_doc, 'in', 2)", 0); + + app.alert("finished testing methods"); </script> </event> </subform>
diff --git a/testing/resources/javascript/xfa_specific/xfa_layout_pseudomodel_expected.txt b/testing/resources/javascript/xfa_specific/xfa_layout_pseudomodel_expected.txt index 249ad1d..fb2708f 100644 --- a/testing/resources/javascript/xfa_specific/xfa_layout_pseudomodel_expected.txt +++ b/testing/resources/javascript/xfa_specific/xfa_layout_pseudomodel_expected.txt
@@ -1,3 +1,62 @@ Alert: PASS: ready = true Alert: PASS: ready threw Error: Unable to set ready value. +Alert: PASS: xfa.layout.absPage() threw XFAObject.absPage: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.absPage(1, 2) threw XFAObject.absPage: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.absPage(1) = 0 +Alert: PASS: xfa.layout.absPageCount() = 2 +Alert: PASS: xfa.layout.absPageCount('args', [42], 'ignored') = 2 +Alert: PASS: xfa.layout.absPageCountInBatch() = 0 +Alert: PASS: xfa.layout.absPageCountInBatch('args', [42], 'ignored') = 0 +Alert: PASS: xfa.layout.absPageInBatch() threw XFAObject.absPageInBatch: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.absPageInBatch(1, 2) threw XFAObject.absPageInBatch: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.absPageInBatch(1) = 0 +Alert: PASS: xfa.layout.absPageSpan() threw XFAObject.absPageSpan: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.absPageSpan(1, 2) threw XFAObject.absPageSpan: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.absPageSpan(1) = undefined +Alert: PASS: xfa.layout.h() threw XFAObject.h: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.h(4, 'is', 'toomany', 'args') threw XFAObject.h: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.h(my_doc, 'bogounits') threw XFAObject.h: Incorrect parameter value. +Alert: PASS: xfa.layout.h(my_doc, 'cm') = 0 +Alert: PASS: xfa.layout.h(my_doc, 'in', 2) = 0 +Alert: PASS: xfa.layout.page() threw XFAObject.page: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.page(1, 2) threw XFAObject.page: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.page(my_doc) = 1 +Alert: PASS: xfa.layout.pageContent() threw XFAObject.pageContent: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.pageContent(4, 'is', 'too', 'many') threw XFAObject.pageContent: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.pageContent(1) = [object XFAObject] +Alert: PASS: xfa.layout.pageContent(1).length = 2 +Alert: PASS: xfa.layout.pageCount() = 2 +Alert: PASS: xfa.layout.pageCount('all', 'args', ['ignored']) = 2 +Alert: PASS: xfa.layout.pageSpan() threw XFAObject.pageSpan: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.pageSpan(2, 'toomany') threw XFAObject.pageSpan: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.pageSpan(my_doc) = 1 +Alert: PASS: xfa.layout.relayout() = undefined +Alert: PASS: xfa.layout.relayout('args', ['ignored'], 42) = undefined +Alert: PASS: xfa.layout.relayoutPageArea() = undefined +Alert: PASS: xfa.layout.relayoutPageArea('args', ['ignored'], 42) = undefined +Alert: PASS: xfa.layout.sheet() threw XFAObject.sheet: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.sheet(1, 2) threw XFAObject.sheet: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.sheet(my_doc) = 0 +Alert: PASS: xfa.layout.sheetCount() = 2 +Alert: PASS: xfa.layout.sheetCount('args', ['ignored'], 42) = 2 +Alert: PASS: xfa.layout.sheetCountInBatch() = 0 +Alert: PASS: xfa.layout.sheetCountInBatch('args', ['ignored'], 42) = 0 +Alert: PASS: xfa.layout.sheetInBatch() threw XFAObject.sheetInBatch: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.sheetInBatch(2, 'toomany') threw XFAObject.sheetInBatch: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.sheetInBatch(1) = 0 +Alert: PASS: xfa.layout.w() threw XFAObject.w: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.w(4, 'is', 'toomany', 'args') threw XFAObject.w: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.w(my_doc, 'bogounits') threw XFAObject.w: Incorrect parameter value. +Alert: PASS: xfa.layout.w(my_doc, 'cm') = 0 +Alert: PASS: xfa.layout.w(my_doc, 'in', 2) = 0 +Alert: PASS: xfa.layout.x() threw XFAObject.x: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.x(4, 'is', 'toomany', 'args') threw XFAObject.x: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.x(my_doc, 'bogounits') threw XFAObject.x: Incorrect parameter value. +Alert: PASS: xfa.layout.x(my_doc, 'cm') = 0 +Alert: PASS: xfa.layout.x(my_doc, 'in', 2) = 0 +Alert: PASS: xfa.layout.y() threw XFAObject.y: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.y(4, 'is', 'toomany', 'args') threw XFAObject.y: Incorrect number of parameters passed to function. +Alert: PASS: xfa.layout.y(my_doc, 'bogounits') threw XFAObject.y: Incorrect parameter value. +Alert: PASS: xfa.layout.y(my_doc, 'cm') = 0 +Alert: PASS: xfa.layout.y(my_doc, 'in', 2) = 0 Alert: finished testing methods