test_xml_parser.js (1085B)
1 function run_test() { 2 for (var i = 0; i < tests.length && tests[i][0]; ++i) { 3 if (!tests[i][0].call()) { 4 do_throw(tests[i][1]); 5 } 6 } 7 } 8 9 var tests = [ 10 [test1, "Unable to parse basic XML document"], 11 [test2, "ParseXML doesn't return Document"], 12 [test3, "ParseXML return value's documentElement is not Element"], 13 [test4, ""], 14 [test5, ""], 15 [test6, ""], 16 [null], 17 ]; 18 19 function test1() { 20 return ParseXML("<root/>"); 21 } 22 23 function test2() { 24 return ChromeUtils.getClassName(ParseXML("<root/>")) === "XMLDocument"; 25 } 26 27 function test3() { 28 return Element.isInstance(ParseXML("<root/>").documentElement); 29 } 30 31 function test4() { 32 var doc = ParseXML("<root/>"); 33 Assert.equal(doc.documentElement.namespaceURI, null); 34 return true; 35 } 36 37 function test5() { 38 var doc = ParseXML("<root xmlns=''/>"); 39 Assert.equal(doc.documentElement.namespaceURI, null); 40 return true; 41 } 42 43 function test6() { 44 var doc = ParseXML("<root xmlns='ns1'/>"); 45 Assert.notEqual(doc.documentElement.namespaceURI, null); 46 Assert.equal(doc.documentElement.namespaceURI, "ns1"); 47 return true; 48 }