diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /parser/xml/test/unit/test_xml_declaration.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'parser/xml/test/unit/test_xml_declaration.js')
-rw-r--r-- | parser/xml/test/unit/test_xml_declaration.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/parser/xml/test/unit/test_xml_declaration.js b/parser/xml/test/unit/test_xml_declaration.js new file mode 100644 index 000000000..4cad511fb --- /dev/null +++ b/parser/xml/test/unit/test_xml_declaration.js @@ -0,0 +1,82 @@ +function noop() {} + +function run_test() { + var evts; + + var contentHandler = { + attrs: null, + startDocument: function() { + evts.push("startDocument"); + }, + endDocument: noop, + + startElement: function startElement() { + evts.push("startElement"); + }, + + endElement: noop, + characters: noop, + processingInstruction: noop, + ignorableWhitespace: noop, + startPrefixMapping: noop, + endPrefixMapping: noop + }; + + function XMLDeclHandler(version, encoding, standalone) { + evts.splice(evts.length, 0, version, encoding, standalone); + } + + const nsISAXXMLReader = Components.interfaces.nsISAXXMLReader; + var saxReader = Components.classes["@mozilla.org/saxparser/xmlreader;1"] + .createInstance(nsISAXXMLReader); + saxReader.contentHandler = contentHandler; + saxReader.declarationHandler = XMLDeclHandler; + + evts = []; + saxReader.parseFromString("<root/>", "application/xml"); + do_check_eq(evts.length, 2); + do_check_eq(evts[0], "startDocument"); + do_check_eq(evts[1], "startElement"); + + evts = []; + saxReader.parseFromString("<?xml version='1.0'?><root/>", "application/xml"); + do_check_eq(evts.length, 5); + do_check_eq(evts[0], "startDocument"); + do_check_eq(evts[1], "1.0"); + do_check_eq(evts[2], ""); + do_check_false(evts[3]); + do_check_eq(evts[4], "startElement"); + + evts = []; + saxReader.parseFromString("<?xml version='1.0' encoding='UTF-8'?><root/>", "application/xml"); + do_check_eq(evts.length, 5); + do_check_eq(evts[0], "startDocument"); + do_check_eq(evts[1], "1.0"); + do_check_eq(evts[2], "UTF-8"); + do_check_false(evts[3]); + do_check_eq(evts[4], "startElement"); + + evts = []; + saxReader.parseFromString("<?xml version='1.0' standalone='yes'?><root/>", "application/xml"); + do_check_eq(evts.length, 5); + do_check_eq(evts[0], "startDocument"); + do_check_eq(evts[1], "1.0"); + do_check_eq(evts[2], ""); + do_check_true(evts[3]); + do_check_eq(evts[4], "startElement"); + + evts = []; + saxReader.parseFromString("<?xml version='1.0' encoding='UTF-8' standalone='yes'?><root/>", "application/xml"); + do_check_eq(evts.length, 5); + do_check_eq(evts[0], "startDocument"); + do_check_eq(evts[1], "1.0"); + do_check_eq(evts[2], "UTF-8"); + do_check_true(evts[3]); + do_check_eq(evts[4], "startElement"); + + evts = []; + // Not well-formed + saxReader.parseFromString("<?xml encoding='UTF-8'?><root/>", "application/xml"); + do_check_eq(evts.length, 1); + do_check_eq(evts[0], "startDocument"); +} |