From 7259c048b9a3f0161fafcbe19c488ff0767de013 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 22 Oct 2018 23:29:48 +0000 Subject: Modernize app.* JS method tests. Also add several missing cases. Change-Id: I38aa1fdacf839975249957267ffb121ad609aec5 Reviewed-on: https://pdfium-review.googlesource.com/c/44430 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- testing/resources/javascript/app_methods.in | 150 ++++++++++----------- .../resources/javascript/app_methods_expected.txt | 53 ++++++-- 2 files changed, 109 insertions(+), 94 deletions(-) diff --git a/testing/resources/javascript/app_methods.in b/testing/resources/javascript/app_methods.in index c925dee651..e191055ee1 100644 --- a/testing/resources/javascript/app_methods.in +++ b/testing/resources/javascript/app_methods.in @@ -31,96 +31,82 @@ endobj {{streamlen}} >> stream - -app.alert("message", 1, 2, "title"); -app.alert({"cMsg": "message", "cTitle": "title"}); -app.alert({"cMsg": "message", "cTitle": "title", "nIcon": 3, "nType": 4}); -app.alert(undefined); -app.alert(null); -app.alert(true); -app.alert(false); -app.alert(42); -app.alert([1, 2, 3]); -app.alert([1, 2, {"color": "red"}]); -app.alert({"color": "red"}, 5, 6, "title"); -try { - app.alert(); -} catch (e) { - app.alert("Caught expected error " + e); +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()); + } } -try { - app.alert({}); -} catch (e) { - app.alert("Caught expected error " + e); + +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()); + } } + try { - app.alert({"color": "red", "size": 42}); -} catch (e) { - app.alert("Caught expected error " + e); -} + expect("app.alert('message', 1, 2, 'title')", 0); + expect("app.alert({'cMsg': 'message', 'cTitle': 'title'})", 0); + expect("app.alert({'cMsg': 'message', 'cTitle': 'title', 'nIcon': 3, 'nType': 4})", 0); + expect("app.alert(undefined)", 0); + expect("app.alert(null)", 0); + expect("app.alert(true)", 0); + expect("app.alert(false)", 0); + expect("app.alert(42)", 0); + expect("app.alert([1, 2, 3])", 0); + expect("app.alert([1, 2, {'color': 'red'}])", 0); + expect("app.alert({'color': 'red'}, 5, 6, 'title')", 0); + expectError("app.alert()"); + expectError("app.alert({})"); + expectError("app.alert({'color': 'red', 'size': 42})"); -app.beep(1); + expect("app.beep(1)", undefined); -app.mailMsg(true); -app.mailMsg(false, "user@example.com"); -app.mailMsg(false, "user@example.com", "cc@example.com", - "bcc@example.com", "subject", "body"); -app.mailMsg({"bUI": true}); -app.mailMsg({"bUI": false, "cTo": "user@example.com"}); -app.mailMsg({"bUI": false, - "cTo": "user@example.com", - "cCc": "cc@example.com", - "cBcc": "bcc@example.com", - "cSubject": "subject", - "cMsg": "body"}); -try { - app.mailMsg(); -} catch (e) { - app.alert("Caught expected error " + e); -} -try { - app.mailMsg(false); -} catch (e) { - app.alert("Caught expected error " + e); -} -try { - app.mailMsg({"color": "red", "size": 42}); -} catch (e) { - app.alert("Caught expected error " + e); -} + expectError("app.browseForDoc()"); + expect("app.execDialog()", undefined); + expect("app.findComponent()", undefined); + expect("app.goBack()", undefined); + expect("app.goForward()", undefined); + expect("app.launchURL()", undefined); + expectError("app.newDoc()"); + expect("app.newFDF()", undefined); + expectError("app.openDoc()"); + expect("app.openFDF()", undefined); + expectError("app.popUpMenuEx()"); + + expect("app.mailMsg(true)", undefined); + expect("app.mailMsg(false, 'user@example.com')", undefined); + expect("app.mailMsg(false, 'user@example.com', 'cc@example.com', " + + "'bcc@example.com', 'subject', 'body')", undefined); + expect("app.mailMsg({'bUI': true})", undefined); + expect("app.mailMsg({'bUI': false, 'cTo': 'user@example.com'})", undefined); + expect("app.mailMsg({'bUI': false, 'cTo': 'user@example.com', " + + "'cCc': 'cc@example.com', 'cBcc': 'bcc@example.com', " + + "'cSubject': 'subject', 'cMsg': 'body'})", undefined); + expectError("app.mailMsg()"); + expectError("app.mailMsg(false)"); + expectError("app.mailMsg({'color': 'red', 'size': 42})"); + + expect("app.response('question')", 'No'); + expect("app.response('question', 'title', 'default', true, 'label')", 'No'); + expect("app.response({'cQuestion': 'question'})", 'No'); + expect("app.response({'cQuestion': 'question', 'cTitle': 'title', " + + "'cDefault': 'default', 'bPassword': true, 'cLabel': 'label'})", 'No'); + expectError("app.response()"); + expectError("app.response({})"); -var result; -try { - result = app.response("question"); - app.alert("result: " + result); - result = app.response("question", "title", "default", true, "label"); - app.alert("result: " + result); - result = app.response({"cQuestion": "question"}); - app.alert("result: " + result); - result = app.response({ - "cQuestion": "question", - "cTitle": "title", - "cDefault": "default", - "bPassword": true, - "cLabel": "label" - }); - app.alert("result: " + result); -} catch (e) { - app.alert("unexpected error " + e); -} -try { - app.response(); - app.alert("unexpected success"); -} catch (e) { - app.alert("Caught expected error " + e); -} -try { - app.response({}); - app.alert("unexpected success"); } catch (e) { - app.alert("Caught expected error " + e); + app.alert('Truly unexpected error: ' + e); } - endstream endobj {{xref}} diff --git a/testing/resources/javascript/app_methods_expected.txt b/testing/resources/javascript/app_methods_expected.txt index ecd89ad72f..ef65a7df40 100644 --- a/testing/resources/javascript/app_methods_expected.txt +++ b/testing/resources/javascript/app_methods_expected.txt @@ -1,34 +1,63 @@ title[icon=1,type=2]: message +Alert: PASS: app.alert('message', 1, 2, 'title') = 0 title: message +Alert: PASS: app.alert({'cMsg': 'message', 'cTitle': 'title'}) = 0 title[icon=3,type=4]: message +Alert: PASS: app.alert({'cMsg': 'message', 'cTitle': 'title', 'nIcon': 3, 'nType': 4}) = 0 Alert: undefined +Alert: PASS: app.alert(undefined) = 0 Alert: null +Alert: PASS: app.alert(null) = 0 Alert: true +Alert: PASS: app.alert(true) = 0 Alert: false +Alert: PASS: app.alert(false) = 0 Alert: 42 +Alert: PASS: app.alert(42) = 0 Alert: [1, 2, 3] +Alert: PASS: app.alert([1, 2, 3]) = 0 Alert: [1, 2, [object Object]] +Alert: PASS: app.alert([1, 2, {'color': 'red'}]) = 0 title[icon=5,type=6]: [object Object] -Alert: Caught expected error app.alert: Incorrect number of parameters passed to function. -Alert: Caught expected error app.alert: Incorrect number of parameters passed to function. -Alert: Caught expected error app.alert: Incorrect number of parameters passed to function. +Alert: PASS: app.alert({'color': 'red'}, 5, 6, 'title') = 0 +Alert: PASS: app.alert() threw error app.alert: Incorrect number of parameters passed to function. +Alert: PASS: app.alert({}) threw error app.alert: Incorrect number of parameters passed to function. +Alert: PASS: app.alert({'color': 'red', 'size': 42}) threw error app.alert: Incorrect number of parameters passed to function. BEEP!!! 1 +Alert: PASS: app.beep(1) = undefined +Alert: FAIL: app.browseForDoc() = undefined, expected to throw error +Alert: PASS: app.execDialog() = undefined +Alert: PASS: app.findComponent() = undefined +Alert: PASS: app.goBack() = undefined +Alert: PASS: app.goForward() = undefined +Alert: PASS: app.launchURL() = undefined +Alert: PASS: app.newDoc() threw error app.newDoc: Operation not supported. +Alert: PASS: app.newFDF() = undefined +Alert: PASS: app.openDoc() threw error app.openDoc: Operation not supported. +Alert: PASS: app.openFDF() = undefined +Alert: PASS: app.popUpMenuEx() threw error app.popUpMenuEx: Operation not supported. Mail Msg: 1, to=, cc=, bcc=, subject=, body= +Alert: PASS: app.mailMsg(true) = undefined Mail Msg: 0, to=user@example.com, cc=, bcc=, subject=, body= +Alert: PASS: app.mailMsg(false, 'user@example.com') = undefined Mail Msg: 0, to=user@example.com, cc=cc@example.com, bcc=bcc@example.com, subject=subject, body=body +Alert: PASS: app.mailMsg(false, 'user@example.com', 'cc@example.com', 'bcc@example.com', 'subject', 'body') = undefined Mail Msg: 1, to=, cc=, bcc=, subject=, body= +Alert: PASS: app.mailMsg({'bUI': true}) = undefined Mail Msg: 0, to=user@example.com, cc=, bcc=, subject=, body= +Alert: PASS: app.mailMsg({'bUI': false, 'cTo': 'user@example.com'}) = undefined Mail Msg: 0, to=user@example.com, cc=cc@example.com, bcc=bcc@example.com, subject=subject, body=body -Alert: Caught expected error app.mailMsg: Incorrect number of parameters passed to function. -Alert: Caught expected error app.mailMsg: Incorrect number of parameters passed to function. -Alert: Caught expected error app.mailMsg: Incorrect number of parameters passed to function. +Alert: PASS: app.mailMsg({'bUI': false, 'cTo': 'user@example.com', 'cCc': 'cc@example.com', 'cBcc': 'bcc@example.com', 'cSubject': 'subject', 'cMsg': 'body'}) = undefined +Alert: PASS: app.mailMsg() threw error app.mailMsg: Incorrect number of parameters passed to function. +Alert: PASS: app.mailMsg(false) threw error app.mailMsg: Incorrect number of parameters passed to function. +Alert: PASS: app.mailMsg({'color': 'red', 'size': 42}) threw error app.mailMsg: Incorrect number of parameters passed to function. PDF: question, defaultValue=, label=, isPassword=0, length=2048 -Alert: result: No +Alert: PASS: app.response('question') = No title: question, defaultValue=default, label=label, isPassword=1, length=2048 -Alert: result: No +Alert: PASS: app.response('question', 'title', 'default', true, 'label') = No PDF: question, defaultValue=, label=, isPassword=0, length=2048 -Alert: result: No +Alert: PASS: app.response({'cQuestion': 'question'}) = No title: question, defaultValue=default, label=label, isPassword=1, length=2048 -Alert: result: No -Alert: Caught expected error app.response: Incorrect number of parameters passed to function. -Alert: Caught expected error app.response: Incorrect number of parameters passed to function. +Alert: PASS: app.response({'cQuestion': 'question', 'cTitle': 'title', 'cDefault': 'default', 'bPassword': true, 'cLabel': 'label'}) = No +Alert: PASS: app.response() threw error app.response: Incorrect number of parameters passed to function. +Alert: PASS: app.response({}) threw error app.response: Incorrect number of parameters passed to function. -- cgit v1.2.3