1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_domparsing.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <meta charset=utf-8> 1.8 + <title>Test for the DOM Parsing and Serialization Standard</title> 1.9 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.11 +</head> 1.12 +<body> 1.13 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=816410">Mozilla Bug 816410</a> 1.14 +<p id="display"></p> 1.15 +<div id="content" style="display: none"> 1.16 + 1.17 +</div> 1.18 +<pre id="test"> 1.19 +<script type="application/javascript;version=1.7"> 1.20 +"use strict"; 1.21 +/** Test for Bug 816410 **/ 1.22 + 1.23 +function throws(fn, type, message) { 1.24 + try { 1.25 + fn(); 1.26 + ok(false, message); 1.27 + } catch (e) { 1.28 + if (type) { 1.29 + is(e.name, type, message); 1.30 + } else { 1.31 + ok(true, message); 1.32 + } 1.33 + } 1.34 +} 1.35 + 1.36 +let parser = new DOMParser(); 1.37 +is(typeof parser.parseFromString, "function", "parseFromString should exist"); 1.38 +is(typeof parser.parseFromBuffer, "undefined", "parseFromBuffer should NOT be visible from unprivileged callers"); 1.39 +is(typeof parser.parseFromStream, "undefined", "parseFromStream should NOT be visible from unprivileged callers"); 1.40 +is(typeof parser.init, "undefined", "init should NOT be visible from unprivileged callers"); 1.41 + 1.42 +// The three-arguments constructor should not be visible from 1.43 +// unprivileged callers for interoperability with other browsers. 1.44 +// But we have no way to do that right now. 1.45 +try { 1.46 + new DOMParser(undefined); 1.47 + new DOMParser(null); 1.48 + new DOMParser(false); 1.49 + new DOMParser(0); 1.50 + new DOMParser(""); 1.51 + new DOMParser({}); 1.52 +} catch (e) { 1.53 + todo(false, "DOMParser constructor should not throw for extra arguments"); 1.54 +} 1.55 + 1.56 +let serializer = new XMLSerializer(); 1.57 +is(typeof serializer.serializeToString, "function", "serializeToString should exist"); 1.58 +is(typeof serializer.serializeToStream, "undefined", "serializeToStream should NOT be visible from unprivileged callers"); 1.59 + 1.60 +// XMLSerializer constructor should not throw for extra arguments 1.61 +new XMLSerializer(undefined); 1.62 +new XMLSerializer(null); 1.63 +new XMLSerializer(false); 1.64 +new XMLSerializer(0); 1.65 +new XMLSerializer(""); 1.66 +new XMLSerializer({}); 1.67 + 1.68 +let tests = [ 1.69 + {input: "<html></html>", type: "text/html", 1.70 + expected: '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>'}, 1.71 + {input: "<xml></xml>", type: "text/xml", expected: "<xml/>"}, 1.72 + {input: "<xml></xml>", type: "application/xml", expected: "<xml/>"}, 1.73 + {input: "<html></html>", type: "application/xhtml+xml", expected: "<html/>"}, 1.74 + {input: "<svg></svg>", type: "image/svg+xml", expected: "<svg/>"}, 1.75 +]; 1.76 +for (let t of tests) { 1.77 + is(serializer.serializeToString(parser.parseFromString(t.input, t.type)), t.expected, 1.78 + "parseFromString test for " + t.type); 1.79 +} 1.80 + 1.81 +throws(function() { 1.82 + parser.parseFromString("<xml></xml>", "foo/bar"); 1.83 +}, "TypeError", "parseFromString should throw for the unknown type"); 1.84 +</script> 1.85 +</pre> 1.86 +</body> 1.87 +</html>