Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | function noop() {} |
michael@0 | 2 | |
michael@0 | 3 | function run_test() { |
michael@0 | 4 | var contentHandler = { |
michael@0 | 5 | attrs: null, |
michael@0 | 6 | reset: function() { |
michael@0 | 7 | this.attrs = []; |
michael@0 | 8 | }, |
michael@0 | 9 | startDocument: noop, |
michael@0 | 10 | endDocument: noop, |
michael@0 | 11 | |
michael@0 | 12 | startElement: function startElement(aNamespaceURI, aLocalName, aNodeName, aAttrs) { |
michael@0 | 13 | for (var i = 0; i < aAttrs.length; i++) |
michael@0 | 14 | this.attrs.push(aAttrs.getQName(i)); |
michael@0 | 15 | }, |
michael@0 | 16 | |
michael@0 | 17 | endElement: noop, |
michael@0 | 18 | characters: noop, |
michael@0 | 19 | processingInstruction: noop, |
michael@0 | 20 | ignorableWhitespace: noop, |
michael@0 | 21 | startPrefixMapping: noop, |
michael@0 | 22 | endPrefixMapping: noop |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | const nsISAXXMLReader = Components.interfaces.nsISAXXMLReader; |
michael@0 | 26 | const src = "<a:x xmlns:a='foo' y='bar'/>"; |
michael@0 | 27 | const NS_PREFIX = "http://xml.org/sax/features/namespace-prefixes"; |
michael@0 | 28 | |
michael@0 | 29 | var saxReader = Components.classes["@mozilla.org/saxparser/xmlreader;1"] |
michael@0 | 30 | .createInstance(nsISAXXMLReader); |
michael@0 | 31 | do_check_false(saxReader.getFeature(NS_PREFIX)); |
michael@0 | 32 | saxReader.contentHandler = contentHandler; |
michael@0 | 33 | contentHandler.reset(); |
michael@0 | 34 | saxReader.parseFromString(src, "application/xml"); |
michael@0 | 35 | do_check_eq(contentHandler.attrs.length, 1); |
michael@0 | 36 | do_check_eq(contentHandler.attrs[0], "y"); |
michael@0 | 37 | |
michael@0 | 38 | saxReader.setFeature(NS_PREFIX, true); |
michael@0 | 39 | do_check_true(saxReader.getFeature(NS_PREFIX)); |
michael@0 | 40 | contentHandler.reset(); |
michael@0 | 41 | saxReader.parseFromString(src, "application/xml"); |
michael@0 | 42 | do_check_eq(contentHandler.attrs.length, 2); |
michael@0 | 43 | do_check_eq(contentHandler.attrs[0], "xmlns:a"); |
michael@0 | 44 | do_check_eq(contentHandler.attrs[1], "y"); |
michael@0 | 45 | |
michael@0 | 46 | saxReader.setFeature(NS_PREFIX, false); |
michael@0 | 47 | do_check_false(saxReader.getFeature(NS_PREFIX)); |
michael@0 | 48 | contentHandler.reset(); |
michael@0 | 49 | saxReader.parseFromString(src, "application/xml"); |
michael@0 | 50 | do_check_eq(contentHandler.attrs.length, 1); |
michael@0 | 51 | do_check_eq(contentHandler.attrs[0], "y"); |
michael@0 | 52 | } |