content/base/test/test_bug469304.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=469304
     5 -->
     6 <head>
     7   <title>Test for Bug 469304</title>
     8   <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
     9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=469304">Mozilla Bug 469304</a>
    14 <p id="display"></p>
    15 <div id="content" style="display: none">
    17 </div>
    18 <pre id="test">
    19 <script type="application/javascript">
    21 /** Test for Bug 469304 **/
    22 function testGetAttribute() {
    23   var a1 = document.createAttribute("aa");
    24   a1.nodeValue = "lowercase";
    25   var a2 = document.createAttribute("AA");
    26   a2.nodeValue = "UPPERCASE";
    27   document.body.setAttributeNode(a1);
    28   document.body.setAttributeNode(a2);
    29   var log = document.getElementById("log");
    30   is(document.body.getAttribute('aa'), "UPPERCASE", "Wrong value (1)");
    31   is(document.body.getAttribute('AA'), "UPPERCASE", "Wrong value (2)");
    33   var s = "";
    34   for (var i = 0; i < document.body.attributes.length; ++i) {
    35     s += document.body.attributes[i].nodeName + "=" +
    36          document.body.attributes[i].nodeValue;
    37   }
    38   is(s, "AA=UPPERCASE", "Wrong attribute!");
    40   is(document.body.getAttributeNode("aa"), document.body.getAttributeNode("AA"),
    41      "Wrong node!");
    43   document.body.getAttributeNode("AA").nodeValue = "FOO";
    44   is(document.body.getAttribute("AA"), "FOO", "Wrong value!");
    46   document.body.removeAttributeNode(document.body.getAttributeNode("AA"));
    47   ok(!document.body.hasAttribute("AA"), "Should not have attribute!");
    48   ok(!document.body.getAttributeNode("AA"), "Should not have attribute node!");
    49   ok(!document.body.hasAttribute("aa"), "Should not have attribute!");
    50   ok(!document.body.getAttributeNode("aa"), "Should not have attribute node!");
    52   is(a2.nodeValue, "FOO", "Wrong value!");
    53   a2.nodeValue = "UPPERCASE";
    54   is(a2.nodeValue, "UPPERCASE", "Wrong value!");
    56   document.body.setAttributeNode(a2);
    57   is(document.body.getAttribute("AA"), "UPPERCASE", "wrong value!");
    58   ok(document.body.getAttributeNode("AA"), "Should have attribute node!");
    59   is(document.body.getAttribute("aa"), "UPPERCASE", "wrong value!");
    60   ok(document.body.getAttributeNode("aa"), "Should have attribute node!");
    61 }
    62 testGetAttribute();
    64 // A bit modified testcases from WebKit.
    65 function testGetAttributeCaseInsensitive() {
    66   var div = document.createElement('div');
    67   div.setAttribute("mixedCaseAttrib", "x");
    68   // Do original case lookup, and lowercase lookup.
    69   return div.getAttribute("mixedcaseattrib");
    70 }
    71 is(testGetAttributeCaseInsensitive(), "x", "(1)");
    73 function testGetAttributeNodeMixedCase() {
    74   var div = document.createElement('div');
    75   var a = div.ownerDocument.createAttribute("mixedCaseAttrib");
    76   a.nodeValue = "x";
    77   div.setAttributeNode(a);
    78   return div.getAttribute("mixedCaseAttrib");
    79 }
    80 is(testGetAttributeNodeMixedCase(), "x", "(2)");
    82 function testGetAttributeNodeLowerCase(div) {
    83   var div = document.createElement('div');
    84   var a = div.ownerDocument.createAttribute("lowercaseattrib");
    85   a.nodeValue = "x";
    86   div.setAttributeNode(a);
    87   return div.getAttribute("lowerCaseAttrib");
    88 }
    89 is(testGetAttributeNodeLowerCase(), "x", "(3)");
    91 function testSetAttributeNodeKeepsRef(div) {
    92   var div = document.createElement('div');
    93   var a = div.ownerDocument.createAttribute("attrib_name");
    94   a.nodeValue = "0";
    95   div.setAttributeNode(a);
    96   // Mutate the attribute node.
    97   a.nodeValue = "1";
    98   return div.getAttribute("attrib_name");
    99 }
   100 is(testSetAttributeNodeKeepsRef(), "1", "(4)");
   102 function testAttribNodeNamePreservesCase() {
   103   var div = document.createElement('div');
   104   var a = div.ownerDocument.createAttribute("A");
   105   a.nodeValue = "x";
   106   div.setAttributeNode(a);
   107   var result = [ a.name, a.nodeName ];
   108   return result.join(",");
   109 }
   110 is(testAttribNodeNamePreservesCase(), "A,A", "(5)");
   112 function testAttribNodeNamePreservesCaseGetNode() {
   113   var body = document.body;
   114   var a = body.ownerDocument.createAttribute("A");
   115   a.nodeValue = "x";
   116   body.setAttributeNode(a);
   117   a = document.body.getAttributeNode("A");
   118   if (!a)
   119       return "FAIL";
   120   var result = [ a.name, a.nodeName ];
   121   return result.join(",");
   122 }
   123 is(testAttribNodeNamePreservesCaseGetNode(), "A,A", "(6)");
   125 function testAttribNodeNamePreservesCaseGetNode2() {
   126   var body = document.body;
   127   var a = body.ownerDocument.createAttribute("B");
   128   a.nodeValue = "x";
   129   body.setAttributeNode(a);
   130   a = document.body.getAttributeNode("B");
   131   if (!a)
   132       return "FAIL";
   133   // Now create node second time
   134   a = body.ownerDocument.createAttribute("B");
   135   a.nodeValue = "x";
   136   body.setAttributeNode(a);
   137   a = document.body.getAttributeNode("B");
   138   var result = [ a.name, a.nodeName ];
   139   return result.join(",");
   140 }
   141 is(testAttribNodeNamePreservesCaseGetNode2(), "B,B", "(7)");
   143 function testAttribNodeNameGetMutate() {
   144   var body = document.body;
   145   var a = body.ownerDocument.createAttribute("c");
   146   a.nodeValue = "0";
   147   body.setAttributeNode(a);
   148   a = document.body.getAttributeNode("c");
   149   a.value = "1";
   150   a = document.body.getAttributeNode("c");
   151   return a.nodeValue;
   152 }
   153 is(testAttribNodeNameGetMutate(), "1", "(8)");
   155 var node = document.createElement("div");
   156 var attrib = document.createAttribute("myAttrib");
   157 attrib.nodeValue = "XXX";
   158 node.setAttributeNode(attrib);
   159 // Note, this is different to what WebKit does
   160 is((new XMLSerializer).serializeToString(node),
   161    "<div xmlns=\"http://www.w3.org/1999/xhtml\" myattrib=\"XXX\"></div>", "(9)");
   162 is(node.getAttributeNode('myAttrib').name, "myAttrib", "(10)");
   163 is(node.getAttributeNode('myattrib').name, "myAttrib", "(11)");
   164 is(attrib.name, "myAttrib", "(12)");
   166 var o = document.createElement("div");
   167 o.setAttribute("myAttrib","htmlattr");
   168 o.setAttributeNS("","myAttrib","123");
   169 is(o.getAttributeNodeNS("","myAttrib").nodeName, "myAttrib", "nodeName should be case-sensitive.");
   170 is(o.getAttributeNode("myAttrib").nodeName, "myattrib", "nodeName shouldn't be case-sensitive.");
   171 is(o.getAttributeNodeNS("","myAttrib").value, "123", "Should have got the case-sensitive attribute.");
   172 is(o.attributes.length, 2, "Should have two attributes.");
   173 o.setAttribute("myAttrib2", "htmlattr");
   174 o.setAttributeNS("", "myAttrib2", "123");
   175 is(o.attributes.length, 4, "Should have four attributes.");
   176 var an = o.attributes.removeNamedItem("myAttrib2");
   177 is(o.attributes.length, 3, "An attribute should have been removed.");
   178 is(an.value, "htmlattr", "The removed attribute should have been the case-insensitive attribute.");
   179 is(o.getAttribute("myAttrib2"), null, "Element shouldn't have case-insensitive attribute anymore.");
   180 var an2 = o.attributes.removeNamedItemNS("", "myAttrib2");
   181 is(an2.localName, "myAttrib2", "The removed attribute should be case-sensitive.");
   182 is(o.attributes.length, 2, "Element should have two attributes.");
   184 </script>
   185 </pre>
   186 </body>
   187 </html>

mercurial