tor-browser

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

test_bug352728.xhtml (5769B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <!--
      3 https://bugzilla.mozilla.org/show_bug.cgi?id=352728
      4 -->
      5 <head>
      6  <title>Test for Bug 352728</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      9 </head>
     10 <body>
     11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a>
     12 <p id="display"></p>
     13 <div id="content" style="display: none">
     14 
     15 </div>
     16 <pre id="test">
     17 <!-- First make sure that a script consisting of multiple CDATA sections is
     18     even supported -->
     19 <script class="testbody" type="text/javascript">
     20  var cdataTest1 = false;
     21  var cdataTest2 = false;
     22  var cdataTest3 = false;
     23 </script>
     24 
     25 <script class="testbody" type="text/javascript">
     26 <![CDATA[
     27  cdataTest1 = true;
     28 ]]>
     29  cdataTest2 = true;
     30 <![CDATA[
     31  cdataTest3 = true;
     32 ]]>
     33 </script>
     34 
     35 <script class="testbody" type="text/javascript">
     36  is(cdataTest1, true, "Check first CDATA section");
     37  is(cdataTest2, true, "Check in between CDATA sections");
     38  is(cdataTest3, true, "Check second CDATA section");
     39 </script>
     40 
     41 <script class="testbody" type="text/javascript">
     42 <![CDATA[
     43 
     44 /** Test for Bug 352728 */
     45 function checkTypes(aNode, aNodeType, aTypeArray)
     46 {
     47  for (var i = 0; i < aTypeArray.length; ++i) {
     48    ok(
     49      aNode instanceof aTypeArray[i],
     50      aNodeType + " type test " + i + " - " +
     51      aNodeType + " should be a " + aTypeArray[i]
     52    );
     53  }
     54 }
     55 
     56 function checkInterfaces(aNode, aNodeType, aInterfaceArray)
     57 {
     58  for (var i = 0; i < aInterfaceArray.length; ++i) {
     59    ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]],
     60       aNodeType + " interface test " + i + " - " +
     61       aNodeType + " should be a " + aInterfaceArray[i]);
     62  }
     63 }
     64 
     65 function testCharacterData(aNode, aText)
     66 {
     67  is(aNode.length, aText.length, "Text length should match");
     68  is(aNode.data, aText, "Text content should match");
     69  is(aNode.nodeValue, aText, "Check nodeValue");
     70  is(aNode.localName, undefined, "Check localName")
     71  is(aNode.namespaceURI, undefined, "Check namespaceURI");
     72 }
     73 
     74 function testComment(aText)
     75 {
     76  try {
     77    var comment = document.createComment(aText);
     78    var types = [ Comment, CharacterData, Node ];
     79    checkTypes(comment, "comment", types);
     80 
     81    var interfaces = [];
     82    checkInterfaces(comment, "comment", interfaces);
     83 
     84    testCharacterData(comment, aText);
     85    is(comment.nodeName, "#comment", "Check nodeName");
     86    is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType");
     87  } catch (e) {
     88    ok(false, "Correct functioning of comment stuff - something broke: " + e);
     89  }
     90 }
     91 
     92 function testCDATASection(aText, aShouldSucceed)
     93 {
     94  try {
     95    var cdataSection = document.createCDATASection(aText);
     96    var types = [ CDATASection, CharacterData, Node ];
     97    checkTypes(cdataSection, "CDATA section", types);
     98 
     99    var interfaces = [];
    100    checkInterfaces(cdataSection, "CDATA section", interfaces);
    101 
    102    testCharacterData(cdataSection, aText);
    103    is(cdataSection.nodeName, "#cdata-section", "Check nodeName");
    104    is(cdataSection.nodeType, Node.CDATA_SECTION_NODE, "Check nodeType");
    105 
    106    if (!aShouldSucceed) {
    107      ok(0, "Invalid CDATA section creation - " +
    108 ]]>
    109         "Shouldn't create CDATA section with embedded \"]]&gt;\"");
    110 <![CDATA[
    111    }
    112  } catch (e) {
    113    if (aShouldSucceed) {
    114      ok(false,
    115        "Correct functioning of CDATA section stuff - something broke: " + e);
    116    } else {
    117      is(e.name, "InvalidCharacterError", "Check exception");
    118      is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
    119    }
    120  }
    121 }
    122 
    123 function testPI(aTarget, aData, aShouldSucceed, aReason)
    124 {
    125  try {
    126    var pi = document.createProcessingInstruction(aTarget, aData);
    127    var types = [ ProcessingInstruction, Node ];
    128    checkTypes(pi, "processing instruction", types);
    129 
    130    var interfaces = [];
    131    checkInterfaces(pi, "processing instruction", interfaces);
    132 
    133    is(pi.target, aTarget, "Check target");
    134    is(pi.data, aData, "Check data");
    135    is(pi.nodeName, aTarget, "Check nodeName");
    136    is(pi.nodeValue, aData, "Check nodeValue");
    137    is(pi.localName, undefined, "Check localName")
    138    is(pi.namespaceURI, undefined, "Check namespaceURI");
    139 
    140    is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType");
    141 
    142    if (!aShouldSucceed) {
    143      ok(false, "Invalid processing instruction creation - " + aReason);
    144    }
    145  } catch (e) {
    146    if (aShouldSucceed) {
    147      ok(false,
    148         "Correct functioning of processing instruction stuff - " +
    149         "something broke: " + e);
    150    } else {
    151      is(e.name, "InvalidCharacterError", "Check exception");
    152      is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
    153    }
    154  }
    155 }
    156 
    157 testComment("Some text");
    158 testComment("Some text with a '-' in it");
    159 testComment("Some text with a '-' and a '-' and another '-'");
    160 testComment("Some text -- this should create a node!");
    161 testComment("<!-- This is an HTML comment -->");
    162 
    163 testCDATASection("Some text", true);
    164 testCDATASection("Some text with a '?' in it", true);
    165 testCDATASection("Some text with a '>' in it", true);
    166 testCDATASection("Some text with a '?' and a '>' in it", true);
    167 testCDATASection("Some text with a '? >' in it", true);
    168 testCDATASection("Some text -- ?> this should be ok", true);
    169 ]]>
    170 testCDATASection("Some text ]]&gt; this should not create a node!", false);
    171 
    172 <![CDATA[
    173 
    174 testPI("foo", "bar", true);
    175 testPI("foo:bar", "baz", true);
    176 testPI("foo", "bar?", true);
    177 testPI("foo", "bar>", true);
    178 testPI("foo", "bar? >", true);
    179 testPI("<aaa", "bar", false, "Target should not contain '<'");
    180 testPI("aaa>", "bar", false, "Target should not contain '>'");
    181 testPI("aa?", "bar", false, "Target should not contain '?'");
    182 testPI("foo", "bar?>", false, "Data should not contain '?>'");
    183 ]]>
    184 </script>
    185 </pre>
    186 </body>
    187 </html>