summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/domparsing/xml-serialization.xhtml
blob: 852bbcc9fd1b1c91fd544dfc2fc462efc1195a4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>XML serialization</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script><![CDATA[
function serialize(node) {
  var serializer = new XMLSerializer();
  return serializer.serializeToString(node);
}

test(function() {
  var dt = document.createComment("--");
  assert_equals(serialize(dt), '<!------>');
}, "Comment: containing --");

test(function() {
  var dt = document.createComment("- x");
  assert_equals(serialize(dt), '<!--- x-->');
}, "Comment: starting with -");

test(function() {
  var dt = document.createComment("x -");
  assert_equals(serialize(dt), '<!--x --->');
}, "Comment: ending with -");

test(function() {
  var dt = document.createComment("-->");
  assert_equals(serialize(dt), '<!---->-->');
}, "Comment: containing -->");

test(function() {
  var dt = document.implementation.createDocumentType("html", "", "");
  assert_equals(serialize(dt), '<!DOCTYPE html>');
}, "DocumentType: empty public and system id");

test(function() {
  var dt = document.implementation.createDocumentType("html", "a", "");
  assert_equals(serialize(dt), '<!DOCTYPE html PUBLIC "a">');
}, "DocumentType: empty system id");

test(function() {
  var dt = document.implementation.createDocumentType("html", "", "a");
  assert_equals(serialize(dt), '<!DOCTYPE html SYSTEM "a">');
}, "DocumentType: empty public id");

test(function() {
  var dt = document.implementation.createDocumentType("html", "a", "b");
  assert_equals(serialize(dt), '<!DOCTYPE html PUBLIC "a" "b">');
}, "DocumentType: non-empty public and system id");

test(function() {
  var dt = document.implementation.createDocumentType("html", "'", "'");
  assert_equals(serialize(dt), "<!DOCTYPE html PUBLIC \"'\" \"'\">");
}, "DocumentType: 'APOSTROPHE' (U+0027)");

test(function() {
  var dt = document.implementation.createDocumentType("html", '"', '"');
  assert_equals(serialize(dt), '<!DOCTYPE html PUBLIC """ """>');
}, "DocumentType: 'QUOTATION MARK' (U+0022)");

test(function() {
  var dt = document.implementation.createDocumentType("html", '"\'', '\'"');
  assert_equals(serialize(dt), '<!DOCTYPE html PUBLIC ""\'" "\'"">');
}, "DocumentType: 'APOSTROPHE' (U+0027) and 'QUOTATION MARK' (U+0022)");

test(function() {
  var el = document.createElement("a");
  el.setAttribute("href", "\u3042\u3044\u3046 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
  assert_equals(serialize(el), "<a xmlns=\"http://www.w3.org/1999/xhtml\" href=\"\u3042\u3044\u3046 !&quot;#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\"></a>");
}, "Element: href attributes are not percent-encoded");

test(function() {
  var el = document.createElement("a");
  el.setAttribute("href", "?\u3042\u3044\u3046 !\"$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
  assert_equals(serialize(el), "<a xmlns=\"http://www.w3.org/1999/xhtml\" href=\"?\u3042\u3044\u3046 !&quot;$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\"></a>");
}, "Element: query parts in href attributes are not percent-encoded");

test(function() {
  var pi = document.createProcessingInstruction("a", "");
  assert_equals(serialize(pi), "<?a ?>");
}, "ProcessingInstruction: empty data");

test(function() {
  var pi = document.createProcessingInstruction("a", "b");
  assert_equals(serialize(pi), "<?a b?>");
}, "ProcessingInstruction: non-empty data");

test(function() {
  var pi = document.createProcessingInstruction("xml", "b");
  assert_equals(serialize(pi), "<?xml b?>");
}, "ProcessingInstruction: target contains xml");

test(function() {
  var pi = document.createProcessingInstruction("x:y", "b");
  assert_equals(serialize(pi), "<?x:y b?>");
}, "ProcessingInstruction: target contains a 'COLON' (U+003A)");
]]></script>
</body>
</html>