summaryrefslogtreecommitdiffstats
path: root/dom/xbl/test/test_bug398492.xul
blob: a854d50fc920555026df984b5dad967ab1ef5d21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=398492
-->
<window title="Mozilla Bug 398492"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <bindings xmlns="http://www.mozilla.org/xbl">
    <binding id="test">
      <content>
        <xul:hbox id="xxx"
            xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
          <children/>
        </xul:hbox>
      </content>
    </binding>
  </bindings>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=398492"
     target="_blank">Mozilla Bug 398492</a>
  </body>

  <hbox id="testbox" style="-moz-binding: url(#test)">Text</hbox>
  
  <!-- test code goes here -->
  <script type="application/javascript"><![CDATA[

    /** Test for Bug 398492 **/
    SimpleTest.waitForExplicitFinish();

    function getXBLParent(node) {
      var utils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
                            .getService(Components.interfaces.inIDOMUtils);
      return utils.getParentForNode(node, true);
    }

    addLoadEvent(function() {
      var n = $("testbox");
      var kid = n.firstChild;
      var anonKid = document.getAnonymousNodes(n)[0];
      is(anonKid instanceof XULElement, true, "Must be a XUL element");
      is(anonKid, getXBLParent(kid), "Unexpected anonymous nodes");

      var n2 = n.cloneNode(true);
      var kid2 = n2.firstChild;
      var anonKid2 = document.getAnonymousNodes(n2)[0];
      is(anonKid2 instanceof XULElement, true,
         "Must be a XUL element after clone");
      is(anonKid2, getXBLParent(kid2),
         "Unexpected anonymous nodes after clone");

      var n3 = document.createElement("hbox");
      document.documentElement.appendChild(n3);
      var kid3 = document.createTextNode("Text");
      n3.appendChild(kid3);

      // Note - we rely on the fact that the binding is preloaded
      // by the other hbox here, so that the binding will be applied
      // sync.
      n3.style.MozBinding = "url(" + document.location.href + "#test)";
      n3.getBoundingClientRect(); // Flush styles.

      var anonKid3 = document.getAnonymousNodes(n3)[0];
      is(anonKid3 instanceof XULElement, true,
         "Must be a XUL element after addBinding");
      is(anonKid3, getXBLParent(kid3),
         "Unexpected anonymous nodes after addBinding");
      

      n.removeChild(kid);
      isnot(anonKid, getXBLParent(kid),
            "Should have removed kid from insertion point");

      n2.removeChild(kid2);
      isnot(anonKid2, getXBLParent(kid2),
            "Should have removed kid2 from insertion point");
    
      n3.removeChild(kid3);
      isnot(anonKid3, getXBLParent(kid3),
            "Should have removed kid3 from insertion point");
    
      SimpleTest.finish();
    });


  ]]></script>
</window>