content/base/test/test_bug564863.xhtml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE html [
     2 <!ATTLIST ns:x id ID #REQUIRED>
     3 <!ATTLIST ns2:x id_2 ID #REQUIRED>
     4 ]>
     5 <html xmlns="http://www.w3.org/1999/xhtml"
     6       xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     7       xmlns:svg="http://www.w3.org/2000/svg"
     8       xmlns:ns="urn:namespace"
     9       xmlns:ns2="urn:namespace">
    10 <!--
    11 https://bugzilla.mozilla.org/show_bug.cgi?id=564863
    12 -->
    13 <head>
    14   <title>Test for Bug 564863</title>
    15   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    16   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    17 <style>
    18 * {
    19   color: rgb(0, 0, 0);
    20 }
    21 #div_id {
    22   color: rgb(10, 10, 10);
    23 }
    24 #a_id {
    25   color: rgb(20, 20, 20);
    26 }
    27 #xul_id {
    28   color: rgb(30, 30, 30);
    29 }
    30 #svg_id {
    31   color: rgb(40, 40, 40);
    32 }
    33 #ns_id {
    34   color: rgb(50, 50, 50);
    35 }
    36 #ns2_id {
    37   color: rgb(60, 60, 60);
    38 }
    39 </style>
    40 </head>
    41 <body>
    42 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=564863">Mozilla Bug 564863</a>
    43 <!-- Elements to ensure we have nodeinfos with id-attribute set -->
    44 <div><ns:x id="ns-holder"/><ns2:x id_2="ns2-holder"/></div>
    46 <!-- DOM to muck around with for tests -->
    47 <p id="root">
    48 <div id="div_id" />
    49 <a id="a_id" />
    50 <xul:button id="xul_id" />
    51 <svg:svg><svg:g id="svg_id" /></svg:svg>
    52 <ns:x id="ns_id" />
    53 </p>
    55 <pre id="test">
    56 <script class="testbody" type="text/javascript">
    57 <![CDATA[
    59 root = $('root');
    60 div = root.children[0];
    61 a = root.children[1];
    62 xul = root.children[2];
    63 svg = root.children[3].firstChild;
    64 nsx = root.children[4];
    66 var div_cs = getComputedStyle(div, "");
    67 var a_cs = getComputedStyle(a, "");
    68 var xul_cs = getComputedStyle(xul, "");
    69 var svg_cs = getComputedStyle(svg, "");
    70 var nsx_cs = getComputedStyle(nsx, "");
    72 function checkHasId(test) {
    73   // Check computed style first to avoid flushes from hiding problems
    74   checkHasIdNoGEBI(test);
    76   is($("div_id"), div, "div getElementById " + test);
    77   is($("a_id"),   a,   "a getElementById " + test);
    78   is($("xul_id"), xul, "xul getElementById " + test);
    79   is($("svg_id"), svg, "svg getElementById " + test);
    80   is($("ns_id"),  nsx, "ns getElementById " + test);
    81 }
    83 function checkHasIdNoGEBI(test) {
    84   is(div_cs.color, "rgb(10, 10, 10)", "div color " + test);
    85   is(a_cs.color,   "rgb(20, 20, 20)", "a color " + test);
    86   is(xul_cs.color, "rgb(30, 30, 30)", "xul color " + test);
    87   is(svg_cs.color, "rgb(40, 40, 40)", "svg color " + test);
    88   is(nsx_cs.color, "rgb(50, 50, 50)", "nsx color " + test);
    90   is(div.id, "div_id", "div id " + test);
    91   is(a.id,   "a_id",   "a id " + test);
    92   is(xul.id, "xul_id", "xul id " + test);
    93   is(svg.id, "svg_id", "svg id " + test);
    94   is (nsx.getAttribute("id"), "ns_id", "ns id " + test);
    95 }
    97 function checkHasNoId(removed, test) {
    98   is(div_cs.color, "rgb(0, 0, 0)", "div color " + test);
    99   is(a_cs.color,   "rgb(0, 0, 0)", "a color " + test);
   100   is(xul_cs.color, "rgb(0, 0, 0)", "xul color " + test);
   101   is(svg_cs.color, "rgb(0, 0, 0)", "svg color " + test);
   102   is(nsx_cs.color, "rgb(0, 0, 0)", "nsx color " + test);
   104   attrValue = removed ? null : "";
   106   is(div.id, "", "div id " + test);
   107   is(a.id,   "", "a id " + test);
   108   is(xul.id, "", "xul id " + test);
   109   is(svg.id, "", "svg id " + test);
   111   is(div.getAttribute("id"), attrValue, "div getAttribute " + test);
   112   is(a.getAttribute("id"),   attrValue, "a getAttribute " + test);
   113   is(xul.getAttribute("id"), "",        "xul getAttribute " + test);
   114   is(svg.getAttribute("id"), attrValue, "svg getAttribute " + test);
   115   is(nsx.getAttribute("id"), attrValue, "ns getAttribute " + test);
   117   is($("div_id"), null, "div getElementById " + test);
   118   is($("a_id"),   null, "a getElementById " + test);
   119   is($("xul_id"), null, "xul getElementById " + test);
   120   is($("svg_id"), null, "svg getElementById " + test);
   121   is($("ns_id"),  null, "ns getElementById " + test);
   122 }
   124 // Check that dynamic modifications of attribute work
   126 checkHasId("in markup");
   128 div.id = "";
   129 a.id = "";
   130 xul.id = "";
   131 svg.id = "";
   132 nsx.setAttribute("id", "");
   134 checkHasNoId(false, "set to empty");
   136 div.id = "div_id";
   137 a.id = "a_id";
   138 xul.id = "xul_id";
   139 svg.id = "svg_id";
   140 nsx.setAttribute("id", "ns_id");
   142 checkHasId("set using .id");
   144 div.setAttribute("id", "");
   145 a.setAttribute("id",   "");
   146 xul.setAttribute("id", "");
   147 svg.setAttribute("id", "");
   148 nsx.setAttribute("id", "");
   150 checkHasNoId(false, "setAttribute to empty");
   152 div.id = "div_id";
   153 a.id = "a_id";
   154 xul.id = "xul_id";
   155 svg.id = "svg_id";
   156 nsx.setAttribute("id", "ns_id");
   158 checkHasId("set again using .id");
   160 div.removeAttribute("id");
   161 a.removeAttribute("id");
   162 xul.removeAttribute("id");
   163 svg.removeAttribute("id");
   164 nsx.removeAttribute("id");
   166 checkHasNoId(true, "removed attribute");
   168 div.setAttribute("id", "div_id");
   169 a.setAttribute("id",   "a_id");
   170 xul.setAttribute("id", "xul_id");
   171 svg.setAttribute("id", "svg_id");
   172 nsx.setAttribute("id", "ns_id");
   174 checkHasId("set using setAttribute");
   176 t1 = document.createElement("div");
   177 t1.id = "div_id";
   178 t2 = document.createElement("a");
   179 t2.id = "a_id";
   180 t3 = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button");
   181 t3.id = "xul_id";
   182 t4 = document.createElementNS("http://www.w3.org/2000/svg", "g");
   183 t4.id = "svg_id";
   184 t5 = document.createElementNS("urn:namespace", "ns:x");
   185 t5.setAttribute("id", "ns_id");
   187 // Check that inserting elements before/after existing work
   189 function insertAfter(newChild, existing) {
   190   existing.parentNode.insertBefore(newChild, existing.nextSibling);
   191 }
   192 function insertBefore(newChild, existing) {
   193   existing.parentNode.insertBefore(newChild, existing);
   194 }
   195 function removeNode(child) {
   196   child.parentNode.removeChild(child);
   197 }
   199 insertAfter(t1, div);
   200 insertAfter(t2, a);
   201 insertAfter(t3, xul);
   202 insertAfter(t4, svg);
   203 insertAfter(t5, nsx);
   205 checkHasId("inserted after");
   207 insertBefore(t1, div);
   208 insertBefore(t2, a);
   209 insertBefore(t3, xul);
   210 insertBefore(t4, svg);
   211 insertBefore(t5, nsx);
   213 checkHasIdNoGEBI("inserted before");
   214 is($("div_id"), t1, "div getElementById inserted before");
   215 is($("a_id"),   t2,   "a getElementById inserted before");
   216 is($("xul_id"), t3, "xul getElementById inserted before");
   217 is($("svg_id"), t4, "svg getElementById inserted before");
   218 is($("ns_id"),  t5, "ns getElementById inserted before");
   220 t1.removeAttribute("id");
   221 t2.removeAttribute("id");
   222 t3.removeAttribute("id");
   223 t4.removeAttribute("id");
   224 t5.removeAttribute("id");
   226 checkHasId("removed tx attribute");
   228 t1.setAttribute("id", "div_id");
   229 t2.setAttribute("id",   "a_id");
   230 t3.setAttribute("id", "xul_id");
   231 t4.setAttribute("id", "svg_id");
   232 t5.setAttribute("id", "ns_id");
   234 checkHasIdNoGEBI("setAttribute before");
   235 is($("div_id"), t1, "div getElementById setAttribute before");
   236 is($("a_id"),   t2,   "a getElementById setAttribute before");
   237 is($("xul_id"), t3, "xul getElementById setAttribute before");
   238 is($("svg_id"), t4, "svg getElementById setAttribute before");
   239 is($("ns_id"),  t5, "ns getElementById setAttribute before");
   241 removeNode(t1);
   242 removeNode(t2);
   243 removeNode(t3);
   244 removeNode(t4);
   245 removeNode(t5);
   247 checkHasId("removed temporaries");
   249 removeNode(div);
   250 removeNode(a);
   251 removeNode(xul);
   252 removeNode(svg);
   253 removeNode(nsx);
   255 checkHasIdNoGEBI("removed node");
   257 // Check that removing an element during UnsetAttr works
   258 is(div.id, "div_id", "div still has id set");
   259 var mutateFired = false;
   260 root.appendChild(div);
   261 div.addEventListener("DOMAttrModified", function(e) {
   262   div.removeEventListener("DOMAttrModified", arguments.callee, false);
   263   is(e.target, div, "target is div");
   264   is(div.id, "", "div no longer has id");
   265   is(div.getAttribute("id"), null, "div no longer has id attr");
   266   removeNode(div);
   267   is(div.parentNode, null, "div was removed");
   268   mutateFired = true;
   269 }, false);
   270 div.removeAttribute("id");
   271 ok(mutateFired, "mutation event fired");
   273 // Check same for XML elements
   274 is(nsx.getAttribute("id"), "ns_id", "nsx still has id set");
   275 mutateFired = false;
   276 root.appendChild(nsx);
   277 nsx.addEventListener("DOMAttrModified", function(e) {
   278   nsx.removeEventListener("DOMAttrModified", arguments.callee, false);
   279   is(e.target, nsx, "target is nsx");
   280   is(nsx.getAttribute("id"), null, "nsx no longer has id attr");
   281   removeNode(nsx);
   282   is(nsx.parentNode, null, "nsx was removed");
   283   mutateFired = true;
   284 }, false);
   285 nsx.removeAttribute("id");
   286 ok(mutateFired, "mutation event fired");
   289 // Re-add the id inside a mutation event on a XML element
   290 is($("ns_id"), null, "no nsx");
   291 is($("ns2_id"), null, "no nsx");
   292 nsx = document.createElementNS("urn:namespace", "ns:x");
   293 nsx.setAttribute("id", "ns_id");
   294 root.appendChild(nsx);
   295 is($("ns_id"), nsx, "new nsx is set up");
   296 mutateFired = false;
   297 nsx.addEventListener("DOMAttrModified", function(e) {
   298   nsx.removeEventListener("DOMAttrModified", arguments.callee, false);
   299   is(e.target, nsx, "target is nsx");
   300   is(nsx.getAttribute("id"), null, "nsx no longer has id attr");
   301   nsx.setAttribute("id", "other_id");
   302   mutateFired = true;
   303 }, false);
   304 nsx.removeAttribute("id");
   305 ok(mutateFired, "mutation event fired");
   306 is($("ns_id"), null, "ns_id was removed from table");
   307 is($("other_id"), nsx, "other_id was added");
   308 removeNode(nsx);
   309 is($("other_id"), null, "other_id was removed");
   311 // Re-add the id inside a mutation event on a HTML element
   312 is($("div_id"), null, "no div");
   313 div = document.createElement("div");
   314 div.id = "div_id";
   315 root.appendChild(div);
   316 is($("div_id"), div, "new div is set up");
   317 mutateFired = false;
   318 div.addEventListener("DOMAttrModified", function(e) {
   319   div.removeEventListener("DOMAttrModified", arguments.callee, false);
   320   is(e.target, div, "target is div");
   321   is(div.getAttribute("id"), null, "div no longer has id attr");
   322   is(div.id, "", "div no longer has id");
   323   div.id = "other_div_id";
   324   mutateFired = true;
   325 }, false);
   326 div.removeAttribute("id");
   327 ok(mutateFired, "mutation event fired");
   328 is($("div_id"), null, "div_id was removed from table");
   329 is($("other_div_id"), div, "other_div_id was added");
   330 removeNode(div);
   331 is($("other_div_id"), null, "other_div_id was removed");
   333 // Re-add the id inside a mutation event on a XUL element
   334 is($("xul_id"), null, "no xul");
   335 xul = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button");
   336 xul.id = "xul_id";
   337 root.appendChild(xul);
   338 is($("xul_id"), xul, "new xul is set up");
   339 mutateFired = false;
   340 xul.addEventListener("DOMAttrModified", function(e) {
   341   xul.removeEventListener("DOMAttrModified", arguments.callee, false);
   342   is(e.target, xul, "target is xul");
   343   is(xul.getAttribute("id"), "", "xul no longer has id attr");
   344   is(xul.id, "", "xul no longer has id");
   345   xul.id = "other_xul_id";
   346   mutateFired = true;
   347 }, false);
   348 xul.removeAttribute("id");
   349 ok(mutateFired, "mutation event fired");
   350 is($("xul_id"), null, "xul_id was removed from table");
   351 is($("other_xul_id"), xul, "other_xul_id was added");
   352 removeNode(xul);
   353 is($("other_xul_id"), null, "other_xul_id was removed");
   355 ]]>
   356 </script>
   357 </pre>
   358 </body>
   359 </html>

mercurial