Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset=utf-8> |
michael@0 | 5 | <title>Test for the DOM Parsing and Serialization Standard</title> |
michael@0 | 6 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=816410">Mozilla Bug 816410</a> |
michael@0 | 11 | <p id="display"></p> |
michael@0 | 12 | <div id="content" style="display: none"> |
michael@0 | 13 | |
michael@0 | 14 | </div> |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | <script type="application/javascript;version=1.7"> |
michael@0 | 17 | "use strict"; |
michael@0 | 18 | /** Test for Bug 816410 **/ |
michael@0 | 19 | |
michael@0 | 20 | function throws(fn, type, message) { |
michael@0 | 21 | try { |
michael@0 | 22 | fn(); |
michael@0 | 23 | ok(false, message); |
michael@0 | 24 | } catch (e) { |
michael@0 | 25 | if (type) { |
michael@0 | 26 | is(e.name, type, message); |
michael@0 | 27 | } else { |
michael@0 | 28 | ok(true, message); |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | let parser = new DOMParser(); |
michael@0 | 34 | is(typeof parser.parseFromString, "function", "parseFromString should exist"); |
michael@0 | 35 | is(typeof parser.parseFromBuffer, "undefined", "parseFromBuffer should NOT be visible from unprivileged callers"); |
michael@0 | 36 | is(typeof parser.parseFromStream, "undefined", "parseFromStream should NOT be visible from unprivileged callers"); |
michael@0 | 37 | is(typeof parser.init, "undefined", "init should NOT be visible from unprivileged callers"); |
michael@0 | 38 | |
michael@0 | 39 | // The three-arguments constructor should not be visible from |
michael@0 | 40 | // unprivileged callers for interoperability with other browsers. |
michael@0 | 41 | // But we have no way to do that right now. |
michael@0 | 42 | try { |
michael@0 | 43 | new DOMParser(undefined); |
michael@0 | 44 | new DOMParser(null); |
michael@0 | 45 | new DOMParser(false); |
michael@0 | 46 | new DOMParser(0); |
michael@0 | 47 | new DOMParser(""); |
michael@0 | 48 | new DOMParser({}); |
michael@0 | 49 | } catch (e) { |
michael@0 | 50 | todo(false, "DOMParser constructor should not throw for extra arguments"); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | let serializer = new XMLSerializer(); |
michael@0 | 54 | is(typeof serializer.serializeToString, "function", "serializeToString should exist"); |
michael@0 | 55 | is(typeof serializer.serializeToStream, "undefined", "serializeToStream should NOT be visible from unprivileged callers"); |
michael@0 | 56 | |
michael@0 | 57 | // XMLSerializer constructor should not throw for extra arguments |
michael@0 | 58 | new XMLSerializer(undefined); |
michael@0 | 59 | new XMLSerializer(null); |
michael@0 | 60 | new XMLSerializer(false); |
michael@0 | 61 | new XMLSerializer(0); |
michael@0 | 62 | new XMLSerializer(""); |
michael@0 | 63 | new XMLSerializer({}); |
michael@0 | 64 | |
michael@0 | 65 | let tests = [ |
michael@0 | 66 | {input: "<html></html>", type: "text/html", |
michael@0 | 67 | expected: '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>'}, |
michael@0 | 68 | {input: "<xml></xml>", type: "text/xml", expected: "<xml/>"}, |
michael@0 | 69 | {input: "<xml></xml>", type: "application/xml", expected: "<xml/>"}, |
michael@0 | 70 | {input: "<html></html>", type: "application/xhtml+xml", expected: "<html/>"}, |
michael@0 | 71 | {input: "<svg></svg>", type: "image/svg+xml", expected: "<svg/>"}, |
michael@0 | 72 | ]; |
michael@0 | 73 | for (let t of tests) { |
michael@0 | 74 | is(serializer.serializeToString(parser.parseFromString(t.input, t.type)), t.expected, |
michael@0 | 75 | "parseFromString test for " + t.type); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | throws(function() { |
michael@0 | 79 | parser.parseFromString("<xml></xml>", "foo/bar"); |
michael@0 | 80 | }, "TypeError", "parseFromString should throw for the unknown type"); |
michael@0 | 81 | </script> |
michael@0 | 82 | </pre> |
michael@0 | 83 | </body> |
michael@0 | 84 | </html> |