Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/base/test/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 6 kB image not shown  

Quelle  test_bug564863.xhtml   Sprache: unbekannt

 
Untersuchungsergebnis.xhtml Download desUnknown {[0] [0] [0]}

<!DOCTYPE html [
<!ATTLIST ns:x id ID #REQUIRED>
<!ATTLIST ns2:x id_2 ID #REQUIRED>
]>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      xmlns:svg="http://www.w3.org/2000/svg"
      xmlns:ns="urn:namespace"
      xmlns:ns2="urn:namespace">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=564863
-->
<head>
  <title>Test for Bug 564863</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style>
* {
  color: rgb(000);
}
#div_id {
  color: rgb(101010);
}
#a_id {
  color: rgb(202020);
}
#svg_id {
  color: rgb(404040);
}
#ns_id {
  color: rgb(505050);
}
#ns2_id {
  color: rgb(606060);
}
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=564863">Mozilla Bug 564863</a>
<!-- Elements to ensure we have nodeinfos with id-attribute set -->
<div><ns:x id="ns-holder"/><ns2:x id_2="ns2-holder"/></div>

<!-- DOM to muck around with for tests -->
<p id="root">
<div id="div_id" />
<a id="a_id" />
<svg:svg><svg:g id="svg_id" /></svg:svg>
<ns:x id="ns_id" />
</p>

<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[

function test() {
  root = $('root');
  div = root.children[0];
  a = root.children[1];
  svg = root.children[2].firstChild;
  nsx = root.children[3];

  var div_cs = getComputedStyle(div, "");
  var a_cs = getComputedStyle(a, "");
  var svg_cs = getComputedStyle(svg, "");
  var nsx_cs = getComputedStyle(nsx, "");

  function checkHasId(test) {
    // Check computed style first to avoid flushes from hiding problems
    checkHasIdNoGEBI(test);

    is($("div_id"), div, "div getElementById " + test);
    is($("a_id"),   a,   "a getElementById " + test);
    is($("svg_id"), svg, "svg getElementById " + test);
    is($("ns_id"),  nsx, "ns getElementById " + test);
  }

  function checkHasIdNoGEBI(test) {
    const connected = test != "removed node";
    is(div_cs.color, connected ? "rgb(101010)" : "", "div color " + test);
    is(a_cs.color,   connected ? "rgb(202020)" : "", "a color " + test);
    is(svg_cs.color, connected ? "rgb(404040)" : "", "svg color " + test);
    is(nsx_cs.color, connected ? "rgb(505050)" : "", "nsx color " + test);

    is(div.id, "div_id", "div id " + test);
    is(a.id,   "a_id",   "a id " + test);
    is(svg.id, "svg_id", "svg id " + test);
    is (nsx.getAttribute("id"), "ns_id", "ns id " + test);
  }

  function checkHasNoId(removed, test) {
    is(div_cs.color, "rgb(000)", "div color " + test);
    is(a_cs.color,   "rgb(000)", "a color " + test);
    is(svg_cs.color, "rgb(000)", "svg color " + test);
    is(nsx_cs.color, "rgb(000)", "nsx color " + test);

    attrValue = removed ? null : "";

    is(div.id, "", "div id " + test);
    is(a.id,   "", "a id " + test);
    is(svg.id, "", "svg id " + test);

    is(div.getAttribute("id"), attrValue, "div getAttribute " + test);
    is(a.getAttribute("id"),   attrValue, "a getAttribute " + test);
    is(svg.getAttribute("id"), attrValue, "svg getAttribute " + test);
    is(nsx.getAttribute("id"), attrValue, "ns getAttribute " + test);

    is($("div_id"), null, "div getElementById " + test);
    is($("a_id"),   null, "a getElementById " + test);
    is($("svg_id"), null, "svg getElementById " + test);
    is($("ns_id"),  null, "ns getElementById " + test);
  }

  // Check that dynamic modifications of attribute work

  checkHasId("in markup");

  div.id = "";
  a.id = "";
  svg.id = "";
  nsx.setAttribute("id", "");

  checkHasNoId(false, "set to empty");

  div.id = "div_id";
  a.id = "a_id";
  svg.id = "svg_id";
  nsx.setAttribute("id", "ns_id");

  checkHasId("set using .id");

  div.setAttribute("id", "");
  a.setAttribute("id",   "");
  svg.setAttribute("id", "");
  nsx.setAttribute("id", "");

  checkHasNoId(false, "setAttribute to empty");

  div.id = "div_id";
  a.id = "a_id";
  svg.id = "svg_id";
  nsx.setAttribute("id", "ns_id");

  checkHasId("set again using .id");

  div.removeAttribute("id");
  a.removeAttribute("id");
  svg.removeAttribute("id");
  nsx.removeAttribute("id");

  checkHasNoId(true, "removed attribute");

  div.setAttribute("id", "div_id");
  a.setAttribute("id",   "a_id");
  svg.setAttribute("id", "svg_id");
  nsx.setAttribute("id", "ns_id");

  checkHasId("set using setAttribute");

  t1 = document.createElement("div");
  t1.id = "div_id";
  t2 = document.createElement("a");
  t2.id = "a_id";
  t4 = document.createElementNS("http://www.w3.org/2000/svg", "g");
  t4.id = "svg_id";
  t5 = document.createElementNS("urn:namespace", "ns:x");
  t5.setAttribute("id", "ns_id");

  // Check that inserting elements before/after existing work

  function insertAfter(newChild, existing) {
    existing.parentNode.insertBefore(newChild, existing.nextSibling);
  }
  function insertBefore(newChild, existing) {
    existing.parentNode.insertBefore(newChild, existing);
  }
  function removeNode(child) {
    child.remove();
  }

  insertAfter(t1, div);
  insertAfter(t2, a);
  insertAfter(t4, svg);
  insertAfter(t5, nsx);

  checkHasId("inserted after");

  insertBefore(t1, div);
  insertBefore(t2, a);
  insertBefore(t4, svg);
  insertBefore(t5, nsx);

  checkHasIdNoGEBI("inserted before");
  is($("div_id"), t1, "div getElementById inserted before");
  is($("a_id"),   t2,   "a getElementById inserted before");
  is($("svg_id"), t4, "svg getElementById inserted before");
  is($("ns_id"),  t5, "ns getElementById inserted before");

  t1.removeAttribute("id");
  t2.removeAttribute("id");
  t4.removeAttribute("id");
  t5.removeAttribute("id");

  checkHasId("removed tx attribute");

  t1.setAttribute("id", "div_id");
  t2.setAttribute("id",   "a_id");
  t4.setAttribute("id", "svg_id");
  t5.setAttribute("id", "ns_id");

  checkHasIdNoGEBI("setAttribute before");
  is($("div_id"), t1, "div getElementById setAttribute before");
  is($("a_id"),   t2,   "a getElementById setAttribute before");
  is($("svg_id"), t4, "svg getElementById setAttribute before");
  is($("ns_id"),  t5, "ns getElementById setAttribute before");

  removeNode(t1);
  removeNode(t2);
  removeNode(t4);
  removeNode(t5);

  checkHasId("removed temporaries");
  
  removeNode(div);
  removeNode(a);
  removeNode(svg);
  removeNode(nsx);

  checkHasIdNoGEBI("removed node");

  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
SimpleTest.executeSoon(test);

]]>
</script>
</pre>
</body>
</html>

[zur Elbe Produktseite wechseln0.59Quellennavigators]