tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xml-serialization.xhtml (4040B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <head>
      3  <title>XML serialization</title>
      4  <script src="/resources/testharness.js"></script>
      5  <script src="/resources/testharnessreport.js"></script>
      6 </head>
      7 <body>
      8 <div id="log"></div>
      9 <script><![CDATA[
     10 function serialize(node) {
     11  var serializer = new XMLSerializer();
     12  return serializer.serializeToString(node);
     13 }
     14 
     15 test(function() {
     16  var dt = document.createComment("--");
     17  assert_equals(serialize(dt), '<!------>');
     18 }, "Comment: containing --");
     19 
     20 test(function() {
     21  var dt = document.createComment("- x");
     22  assert_equals(serialize(dt), '<!--- x-->');
     23 }, "Comment: starting with -");
     24 
     25 test(function() {
     26  var dt = document.createComment("x -");
     27  assert_equals(serialize(dt), '<!--x --->');
     28 }, "Comment: ending with -");
     29 
     30 test(function() {
     31  var dt = document.createComment("-->");
     32  assert_equals(serialize(dt), '<!---->-->');
     33 }, "Comment: containing -->");
     34 
     35 test(function() {
     36  var dt = document.implementation.createDocumentType("html", "", "");
     37  assert_equals(serialize(dt), '<!DOCTYPE html>');
     38 }, "DocumentType: empty public and system id");
     39 
     40 test(function() {
     41  var dt = document.implementation.createDocumentType("html", "a", "");
     42  assert_equals(serialize(dt), '<!DOCTYPE html PUBLIC "a">');
     43 }, "DocumentType: empty system id");
     44 
     45 test(function() {
     46  var dt = document.implementation.createDocumentType("html", "", "a");
     47  assert_equals(serialize(dt), '<!DOCTYPE html SYSTEM "a">');
     48 }, "DocumentType: empty public id");
     49 
     50 test(function() {
     51  var dt = document.implementation.createDocumentType("html", "a", "b");
     52  assert_equals(serialize(dt), '<!DOCTYPE html PUBLIC "a" "b">');
     53 }, "DocumentType: non-empty public and system id");
     54 
     55 test(function() {
     56  var dt = document.implementation.createDocumentType("html", "'", "'");
     57  assert_equals(serialize(dt), "<!DOCTYPE html PUBLIC \"'\" \"'\">");
     58 }, "DocumentType: 'APOSTROPHE' (U+0027)");
     59 
     60 test(function() {
     61  var dt = document.implementation.createDocumentType("html", '"', '"');
     62  assert_equals(serialize(dt), '<!DOCTYPE html PUBLIC """ """>');
     63 }, "DocumentType: 'QUOTATION MARK' (U+0022)");
     64 
     65 test(function() {
     66  var dt = document.implementation.createDocumentType("html", '"\'', '\'"');
     67  assert_equals(serialize(dt), '<!DOCTYPE html PUBLIC ""\'" "\'"">');
     68 }, "DocumentType: 'APOSTROPHE' (U+0027) and 'QUOTATION MARK' (U+0022)");
     69 
     70 test(function() {
     71  var el = document.createElement("a");
     72  el.setAttribute("href", "\u3042\u3044\u3046 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
     73  assert_equals(serialize(el), "<a xmlns=\"http://www.w3.org/1999/xhtml\" href=\"\u3042\u3044\u3046 !&quot;#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\"></a>");
     74 }, "Element: href attributes are not percent-encoded");
     75 
     76 test(function() {
     77  var el = document.createElement("a");
     78  el.setAttribute("href", "?\u3042\u3044\u3046 !\"$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
     79  assert_equals(serialize(el), "<a xmlns=\"http://www.w3.org/1999/xhtml\" href=\"?\u3042\u3044\u3046 !&quot;$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\"></a>");
     80 }, "Element: query parts in href attributes are not percent-encoded");
     81 
     82 test(function() {
     83  var pi = document.createProcessingInstruction("a", "");
     84  assert_equals(serialize(pi), "<?a ?>");
     85 }, "ProcessingInstruction: empty data");
     86 
     87 test(function() {
     88  var pi = document.createProcessingInstruction("a", "b");
     89  assert_equals(serialize(pi), "<?a b?>");
     90 }, "ProcessingInstruction: non-empty data");
     91 
     92 test(function() {
     93  var pi = document.createProcessingInstruction("xml", "b");
     94  assert_equals(serialize(pi), "<?xml b?>");
     95 }, "ProcessingInstruction: target contains xml");
     96 
     97 test(function() {
     98  var pi = document.createProcessingInstruction("x:y", "b");
     99  assert_equals(serialize(pi), "<?x:y b?>");
    100 }, "ProcessingInstruction: target contains a 'COLON' (U+003A)");
    101 ]]></script>
    102 </body>
    103 </html>