From e5350eff5c5cfe4d01686a4c787d764bde5dd23c Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 23 Apr 2015 18:14:26 -0700 Subject: Merge to XFA: Remove unused nParamNum values from JS method tables. Original Review URL: https://codereview.chromium.org/1084183008 TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1105813002 --- testing/resources/javascript/document_methods.in | 340 +++++++++++++++++++++ .../javascript/document_methods_expected.txt | 103 +++++++ 2 files changed, 443 insertions(+) create mode 100644 testing/resources/javascript/document_methods.in create mode 100644 testing/resources/javascript/document_methods_expected.txt (limited to 'testing/resources') diff --git a/testing/resources/javascript/document_methods.in b/testing/resources/javascript/document_methods.in new file mode 100644 index 0000000000..662c05c8e0 --- /dev/null +++ b/testing/resources/javascript/document_methods.in @@ -0,0 +1,340 @@ +{{header}} +{{object 1 0}} << + /Type /Catalog + /Pages 2 0 R + /OpenAction 10 0 R +>> +endobj +{{object 2 0}} << + /Type /Pages + /Count 4 + /Kids [ + 3 0 R + 4 0 R + 5 0 R + 6 0 R + ] +>> +endobj +% Page number 0. +{{object 3 0}} << + /Type /Page + /Parent 2 0 R + /Resources << + /Font <> + >> + /MediaBox [0 0 612 792] + /Contents 8 0 R +>> +% Page number 1. +{{object 4 0}} << + /Type /Page + /Parent 2 0 R + /Resources << + /Font <> + >> + /MediaBox [0 0 612 792] +>> +% Page number 2. +{{object 5 0}} << + /Type /Page + /Parent 2 0 R + /Resources << + /Font <> + >> + /MediaBox [0 0 612 792] +>> +% Page number 3. +{{object 6 0}} << + /Type /Page + /Parent 2 0 R + /Resources << + /Font <> + >> + /MediaBox [0 0 612 792] +>> +% Contents of the page. +{{object 8 0}} << +>> +stream +BT +20 50 Td +/F1 12 Tf +(Hello, world!) Tj +0 50 Td +endstream +endobj +% Info +{{object 9 0}} << + /Author (Joe Random Author) + /Creator (Joe Random Creator) +>> +endobj +% OpenAction action +{{object 10 0}} << + /Type /Action + /S /JavaScript + /JS 11 0 R +>> +endobj +% JS program to exexute +{{object 11 0}} << +>> +stream +function expect(str, expected) { + try { + var result = eval(str); + if (result == expected) { + app.alert('PASS: ' + str + ' = ' + result); + } else { + app.alert('FAIL: ' + str + ' = ' + result + ', expected = ' + expected); + } + } catch (e) { + app.alert('ERROR: ' + e.toString()); + } +} + +function expectError(str) { + try { + var result = eval(str); + app.alert('FAIL: ' + str + ' = ' + result + ', expected to throw error'); + } catch (e) { + app.alert('PASS: ' + str + ' threw error ' + e.toString()); + } +} + +// "Unsupported" methods are present in the document object, but not +// implemented. They always return |undefined| regardless of arguments. +function testUnsupported(str) { + expect('typeof ' + str, 'function'); + expect(str + '()', undefined); + expect(str + '(1, 2, "clams", [1, 2, 3])', undefined); +} + +function testAddIcon() { + // Method is present. + expect('typeof this.addIcon', 'function'); + + // Method takes exactly two arguments. + expectError('this.addIcon()'); + expectError('this.addIcon(1)'); + expectError('this.addIcon(1, 2, 3)'); + + // Second argument must actually be an icon. + expectError('this.addIcon("myicon", 3)'); + + // TODO(tsepez): test success cases. +} + +function testCalculateNow() { + // Method is present. + expect('typeof this.calculateNow', 'function'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testDeletePages() { + // Method is present. + expect('typeof this.deletePages', 'function'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testGetField() { + // Method is present. + expect('typeof this.getField', 'function'); + + // Method needs at least one argument. + expectError('this.getField()'); + + // TODO(tsepez): test success cases. +} + +function testGetIcon() { + // Method is present. + expect('typeof this.getIcon', 'function'); + + // Method needs exactly one argument. + expectError('this.getIcon()'); + expectError('this.getIcon(1, 2)'); + + // TODO(tsepez): test success cases. +} + +function testGetNthFieldName() { + // Method is present. + expect('typeof this.getNthFieldName', 'function'); + + // Method needs at least one argument. + expectError('this.getNthFieldName()'); + + // Argument can not be negative. + expectError('this.getNthFieldName(-1)'); + + // TODO(tsepez): test success cases. +} + +function testGetPageNthWord() { + // Method is present. + expect('typeof this.getPageNthWord', 'function'); + + // Method accepts any number of parameters. + expect('this.getPageNthWord(0, 0, true, "clams", [1, 2])', 'Hello,'); + + // Arguments can't be negative or out of range. + expectError('this.getPageNthWord(-1, 0, true)'); + expectError('this.getPageNthWord(6, 0, true)'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testGetPageNthWordQuads() { + // Method is present. + expect('typeof this.getPageNthWordQuads', 'function'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testGetPageNumWords() { + // Method is present. + expect('typeof this.getPageNumWords', 'function'); + + // Method accepts any number of parameters. + expect('this.getPageNumWords(0, "clams", [1, 2])', 2); + + // Arguments can't be negative or out of range. + expectError('this.getPageNumWords(-1)'); + expectError('this.getPageNumWords(6)'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testGetPrintParams() { + // Method is present. + expect('typeof this.getPrintParams', 'function'); + + // TODO(tsepez): test success cases. +} + +function testMailDoc() { + // Method is present. + expect('typeof this.mailDoc', 'function'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testMailForm() { + // Method is present. + expect('typeof this.mailForm', 'function'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testPrint() { + // Method is present. + expect('typeof this.print', 'function'); + + // TODO(tsepez): test success cases. +} + +function testRemoveField() { + // Method is present. + expect('typeof this.removeField', 'function'); + + // Method requires at least one argument. + expectError('this.removeField()'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testRemoveIcon() { + // Method is present. + expect('typeof this.removeIcon', 'function'); + + // Method requires at least one argument. + expectError('this.removeIcon()'); + + // TODO(tsepez): test success cases. +} + +function testResetForm() { + // Method is present. + expect('typeof this.resetForm', 'function'); + + // TODO(tsepez): test with no permissions. + // TODO(tsepez): test success cases. +} + +function testSubmitForm() { + // Method is present. + expect('typeof this.submitForm', 'function'); + + // Method requires at least one argument. + expectError('this.submitForm()'); + + // TODO(tsepez): test success cases. +} + +try { + app.alert('*** Testing Unsupported Methods ***'); + testUnsupported('this.addAnnot'); + testUnsupported('this.addField'); + testUnsupported('this.addLink'); + testUnsupported('this.closeDoc'); + testUnsupported('this.createDataObject'); + testUnsupported('this.exportAsFDF'); + testUnsupported('this.exportAsText'); + testUnsupported('this.exportAsXFDF'); + testUnsupported('this.extractPages'); + testUnsupported('this.getAnnot'); + testUnsupported('this.getAnnot3D'); + testUnsupported('this.getAnnots'); + testUnsupported('this.getLinks'); + testUnsupported('this.getOCGs'); + testUnsupported('this.getPageBox'); + testUnsupported('this.getURL'); + testUnsupported('this.importAnFDF'); + testUnsupported('this.importAnXFDF'); + testUnsupported('this.importTextData'); + testUnsupported('this.insertPages'); + testUnsupported('this.replacePages'); + testUnsupported('this.saveAs'); + + app.alert('*** Testing Supported Methods ***'); + testAddIcon(); + testCalculateNow(); + testDeletePages(); + testGetField(); + testGetIcon(); + testGetNthFieldName(); + testGetPageNthWord(); + testGetPageNthWordQuads(); + testGetPageNumWords(); + testGetPrintParams(); + testMailDoc(); + testMailForm(); + testPrint(); + testRemoveField(); + testRemoveIcon(); + testResetForm(); + testSubmitForm(); +} catch (e) { + app.alert('FATAL: ' + e.toString()); +} +endstream +endobj +{{xref}} +trailer << + /Root 1 0 R + /Info 9 0 R +>> +{{startxref}} +%%EOF diff --git a/testing/resources/javascript/document_methods_expected.txt b/testing/resources/javascript/document_methods_expected.txt new file mode 100644 index 0000000000..445b48d656 --- /dev/null +++ b/testing/resources/javascript/document_methods_expected.txt @@ -0,0 +1,103 @@ +Alert: *** Testing Unsupported Methods *** +Alert: PASS: typeof this.addAnnot = function +Alert: PASS: this.addAnnot() = undefined +Alert: PASS: this.addAnnot(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.addField = function +Alert: PASS: this.addField() = undefined +Alert: PASS: this.addField(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.addLink = function +Alert: PASS: this.addLink() = undefined +Alert: PASS: this.addLink(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.closeDoc = function +Alert: PASS: this.closeDoc() = undefined +Alert: PASS: this.closeDoc(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.createDataObject = function +Alert: PASS: this.createDataObject() = undefined +Alert: PASS: this.createDataObject(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.exportAsFDF = function +Alert: PASS: this.exportAsFDF() = undefined +Alert: PASS: this.exportAsFDF(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.exportAsText = function +Alert: PASS: this.exportAsText() = undefined +Alert: PASS: this.exportAsText(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.exportAsXFDF = function +Alert: PASS: this.exportAsXFDF() = undefined +Alert: PASS: this.exportAsXFDF(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.extractPages = function +Alert: PASS: this.extractPages() = undefined +Alert: PASS: this.extractPages(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.getAnnot = function +Alert: PASS: this.getAnnot() = undefined +Alert: PASS: this.getAnnot(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.getAnnot3D = function +Alert: PASS: this.getAnnot3D() = undefined +Alert: PASS: this.getAnnot3D(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.getAnnots = function +Alert: PASS: this.getAnnots() = undefined +Alert: PASS: this.getAnnots(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.getLinks = function +Alert: PASS: this.getLinks() = undefined +Alert: PASS: this.getLinks(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.getOCGs = function +Alert: PASS: this.getOCGs() = undefined +Alert: PASS: this.getOCGs(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.getPageBox = function +Alert: PASS: this.getPageBox() = undefined +Alert: PASS: this.getPageBox(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.getURL = function +Alert: PASS: this.getURL() = undefined +Alert: PASS: this.getURL(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.importAnFDF = function +Alert: PASS: this.importAnFDF() = undefined +Alert: PASS: this.importAnFDF(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.importAnXFDF = function +Alert: PASS: this.importAnXFDF() = undefined +Alert: PASS: this.importAnXFDF(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.importTextData = function +Alert: PASS: this.importTextData() = undefined +Alert: PASS: this.importTextData(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.insertPages = function +Alert: PASS: this.insertPages() = undefined +Alert: PASS: this.insertPages(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.replacePages = function +Alert: PASS: this.replacePages() = undefined +Alert: PASS: this.replacePages(1, 2, "clams", [1, 2, 3]) = undefined +Alert: PASS: typeof this.saveAs = function +Alert: PASS: this.saveAs() = undefined +Alert: PASS: this.saveAs(1, 2, "clams", [1, 2, 3]) = undefined +Alert: *** Testing Supported Methods *** +Alert: PASS: typeof this.addIcon = function +Alert: PASS: this.addIcon() threw error Document.addIcon: Incorrect number of parameters passed to function. +Alert: PASS: this.addIcon(1) threw error Document.addIcon: Incorrect number of parameters passed to function. +Alert: PASS: this.addIcon(1, 2, 3) threw error Document.addIcon: Incorrect number of parameters passed to function. +Alert: PASS: this.addIcon("myicon", 3) threw error Document.addIcon: Incorrect parameter type. +Alert: PASS: typeof this.calculateNow = function +Alert: PASS: typeof this.deletePages = function +Alert: PASS: typeof this.getField = function +Alert: PASS: this.getField() threw error Document.getField: Incorrect number of parameters passed to function. +Alert: PASS: typeof this.getIcon = function +Alert: PASS: this.getIcon() threw error Document.getIcon: Incorrect number of parameters passed to function. +Alert: PASS: this.getIcon(1, 2) threw error Document.getIcon: Incorrect number of parameters passed to function. +Alert: PASS: typeof this.getNthFieldName = function +Alert: PASS: this.getNthFieldName() threw error Document.getNthFieldName: Incorrect number of parameters passed to function. +Alert: PASS: this.getNthFieldName(-1) threw error Document.getNthFieldName: Incorrect parameter value. +Alert: PASS: typeof this.getPageNthWord = function +Alert: PASS: this.getPageNthWord(0, 0, true, "clams", [1, 2]) = Hello, +Alert: PASS: this.getPageNthWord(-1, 0, true) threw error Document.getPageNthWord: Incorrect parameter value. +Alert: PASS: this.getPageNthWord(6, 0, true) threw error Document.getPageNthWord: Incorrect parameter value. +Alert: PASS: typeof this.getPageNthWordQuads = function +Alert: PASS: typeof this.getPageNumWords = function +Alert: PASS: this.getPageNumWords(0, "clams", [1, 2]) = 2 +Alert: PASS: this.getPageNumWords(-1) threw error Document.getPageNumWords: Incorrect parameter value. +Alert: PASS: this.getPageNumWords(6) threw error Document.getPageNumWords: Incorrect parameter value. +Alert: PASS: typeof this.getPrintParams = function +Alert: PASS: typeof this.mailDoc = function +Alert: PASS: typeof this.mailForm = function +Alert: PASS: typeof this.print = function +Alert: PASS: typeof this.removeField = function +Alert: PASS: this.removeField() threw error Document.removeField: Incorrect number of parameters passed to function. +Alert: PASS: typeof this.removeIcon = function +Alert: PASS: this.removeIcon() threw error Document.removeIcon: Incorrect number of parameters passed to function. +Alert: PASS: typeof this.resetForm = function +Alert: PASS: typeof this.submitForm = function +Alert: PASS: this.submitForm() threw error Document.submitForm: Incorrect number of parameters passed to function. -- cgit v1.2.3