summaryrefslogtreecommitdiffstats
path: root/dom/xul/templates/tests/chrome/test_bug441785.xul
blob: 7be6df1989640b78765bfb23c88b208b26cecee6 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?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"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <tree flex="20" id="t" ref="urn:data:row" datasources="rdf:null" seltype="single">
     <treecols> 
      <treecol flex="1" id="id" label="id" sort="rdf:http://dummy/rdf#id" />
      <splitter class="tree-splitter"/>
      <treecol flex="1" id="title" label="title" sort="rdf:http://dummy/rdf#title" sortActive="true" sortDirection="ascending" /><splitter class="tree-splitter"/>
     </treecols>
     <template>
       <treechildren>
         <treeitem uri="rdf:*" seltype="single">
           <treerow >
             <treecell label="rdf:http://dummy/rdf#id"/>
             <treecell label="rdf:http://dummy/rdf#title"/>
           </treerow>
         </treeitem>
       </treechildren>
     </template>
   </tree>
   <tree flex="20" id="tc" ref="urn:data:row" datasources="rdf:null" seltype="single" flags="dont-build-content">
     <treecols> 
      <treecol flex="1" id="idc" label="id" sort="rdf:http://dummy/rdf#id" />
      <splitter class="tree-splitter"/>
      <treecol flex="1" id="titlec" label="title" sort="rdf:http://dummy/rdf#title" sortActive="true" sortDirection="ascending" /><splitter class="tree-splitter"/>
     </treecols>
     <template>
       <treechildren>
         <treeitem uri="rdf:*" seltype="single">
           <treerow >
             <treecell label="rdf:http://dummy/rdf#id"/>
             <treecell label="rdf:http://dummy/rdf#title"/>
           </treerow>
         </treeitem>
       </treechildren>
     </template>
   </tree>

<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>

<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      

<script type="application/x-javascript">
<![CDATA[

var buildCount = 0;

SimpleTest.waitForExplicitFinish();

var TemplateBuilderListener = {
  willRebuild: function(aBuilder) {
  },

  didRebuild: function(aBuilder) {
  ++buildCount;
    var remove = false;
    if (buildCount == 2) {
      remove =true;
      setTimeout(nextDataSource, 0);
    } else if (buildCount == 4) {
      remove = true;
      setTimeout(continueTest, 0);
    }
    if (remove) {
      var tree = document.getElementById('t');
      var treec = document.getElementById('tc');
      tree.builder.removeListener(TemplateBuilderListener);
      treec.builder.removeListener(TemplateBuilderListener);
    }
  },

  QueryInterface: function (aIID)
  {
    if (!aIID.equals(Components.interfaces.nsIXULBuilderListener) &&
        !aIID.equals(Components.interfaces.nsISupports))
      throw Components.results.NS_ERROR_NO_INTERFACE;
    return this;
  }
};

function runTest() {
  var tree = document.getElementById('t');
  var treec = document.getElementById('tc');

  try {
    var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].
                       getService(Components.interfaces.nsIRDFService);

    var s1 = window.location.href.replace(/test_bug441785.xul/, "bug441785-1.rdf");
    var ds1 = rdfService.GetDataSourceBlocking(s1);

    var s2 = window.location.href.replace(/test_bug441785.xul/, "bug441785-2.rdf");
    var ds2 = rdfService.GetDataSourceBlocking(s2);
  } catch (ex) { }

  tree.builder.addListener(TemplateBuilderListener);
  treec.builder.addListener(TemplateBuilderListener);
  tree.setAttribute('datasources', 'bug441785-1.rdf');
  treec.setAttribute('datasources', 'bug441785-1.rdf');
}

var oldtreefirstrow, oldtreecfirstrow;

function nextDataSource()
{
  var tree = document.getElementById('t');
  var treec = document.getElementById('tc');
  tree.treeBoxObject.scrollToRow(10);
  treec.treeBoxObject.scrollToRow(10);

  is(tree.treeBoxObject.getFirstVisibleRow(), 10, "first tree row count datasource 1");
  is(treec.treeBoxObject.getFirstVisibleRow(), 10, "second tree row count datasource 1");

  tree.builder.addListener(TemplateBuilderListener);
  treec.builder.addListener(TemplateBuilderListener);
  tree.setAttribute('datasources', 'bug441785-2.rdf');
  treec.setAttribute('datasources', 'bug441785-2.rdf');
}

function continueTest() {
  var tree = document.getElementById('t');
  var treec = document.getElementById('tc');

  is(tree.treeBoxObject.getFirstVisibleRow(), 0, "first tree row count datasource 2");
  is(treec.treeBoxObject.getFirstVisibleRow(), 0, "second tree row count datasource 2");

  try {
    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
            .getInterface(Components.interfaces.nsIDOMWindowUtils)
            .garbageCollect();
  } 
  catch (e) { }

  // Hit the bug, crash 
  // (not exactly the same kind of crash as 441785, but from the same cause)
  tree.parentNode.removeChild(tree);
  treec.parentNode.removeChild(treec);

  SimpleTest.finish();
}

window.addEventListener("load", runTest, false);

]]>
</script>
</window>