MDL-9123:
[moodle-linuxchix.git] / lib / simpletestlib / ui / js / webunit.js
blob9612d0b90b0cf91fdb260173de7e1091e2877be7
1 // jsreporter.js
2 // Script to support JsReporter class
3 // Relies heavily on the X library in x.js
4 // X v3.14.1, Cross-Browser DHTML Library from Cross-Browser.com
5 // Copyright (c) 2004 Jason E. Sweat (jsweat_php@yahoo.com)
6 //
7 // SimpleTest - http://simpletest.sf.net/
8 // Copyright (c) 2003,2004 Marcus Baker (marcus@lastcraft.com)
9 // $Id$
12 // Variables:
13 min_x=500;
14 min_y=400;
15 groups = new Array();
16 cases = new Array();
17 methods = new Array();
18 current_group=0;
19 current_case=0;
20 current_method=0;
22 Hash = {
23 Set : function(foo,bar) {this[foo] = bar;},
24 Get : function(foo) {return this[foo];}
27 // Functions:
28 function wait_start() {
29 var wait_x;
30 var wait_y;
32 wait_x = xWidth('wait');
33 wait_y = xHeight('wait');
34 xMoveTo('wait', (xClientWidth()-wait_x)/2, (xClientHeight()-wait_y)/2);
35 xShow('wait');
38 function layout() {
39 xResizeTo('webunit', max(xClientWidth()-30,min_x), max(xClientHeight()-20,min_y));
40 xMoveTo('webunit', 5, 5);
41 xResizeTo('tabs', xWidth('webunit')-10, xHeight('webunit')/3);
42 xLeft('tabs', 5);
43 xShow('webunit');
44 xShow('tabs');
45 activate_tab('fail');
46 xShow('visible_tab');
47 xZIndex('visible_tab', 2)
48 xResizeTo('msg', xWidth('webunit')-17, xHeight('webunit')/3-20);
49 xLeft('msg', 2);
50 xTop('msg',2*xHeight('webunit')/3);
51 xShow('msg');
54 function set_div_content(div, content) {
55 xGetElementById(div).innerHTML = content;
58 function copy_div_content(divsrc, divtrgt) {
59 xGetElementById(divtrgt).innerHTML = xGetElementById(divsrc).innerHTML;
62 function activate_tab(tab) {
63 if (tab == 'fail') {
64 copy_div_content('fail', 'visible_tab');
65 xGetElementById('failtab').className = 'activetab';
66 xZIndex('failtab', 3)
67 xGetElementById('treetab').className = 'inactivetab';
68 xZIndex('treetab', 1)
70 if (tab == 'tree') {
71 copy_div_content('tree', 'visible_tab');
72 xGetElementById('failtab').className = 'inactivetab';
73 xZIndex('failtab', 1)
74 xGetElementById('treetab').className = 'activetab';
75 xZIndex('treetab', 3)
79 function add_group(group_name) {
80 var add;
82 add = {
83 Set : function(foo,bar) {this[foo] = bar;},
84 Get : function(foo) {return this[foo];}
86 add.Set('desc', group_name);
87 add.Set('pass', true);
88 groups[groups.length] = add;
89 current_group = groups.length - 1;
90 cases[current_group] = new Array();
91 methods[current_group] = new Array();
94 function add_case(case_name) {
95 var curgroup;
96 var add;
98 add = {
99 Set : function(foo,bar) {this[foo] = bar;},
100 Get : function(foo) {return this[foo];}
102 add.Set('desc', case_name);
103 add.Set('pass', true);
104 curgroup = cases[current_group];
105 cases[current_group][curgroup.length] = add;
106 current_case = curgroup.length - 1;
107 methods[current_group][current_case] = new Array();
110 function add_method(method_name) {
111 var curcase;
112 var add;
114 add = {
115 Set : function(foo,bar) {this[foo] = bar;},
116 Get : function(foo) {return this[foo];}
118 add.Set('desc', method_name);
119 add.Set('pass', true);
120 add.Set('msg','');
121 curcase = methods[current_group][current_case];
122 methods[current_group][current_case][curcase.length] = add;
123 current_method = curcase.length - 1;
126 function add_fail(msg) {
127 var oldmsg;
128 add_log(msg);
129 groups[current_group].Set('pass', false);
130 cases[current_group][current_case].Set('pass', false);
131 methods[current_group][current_case][current_method].Set('pass', false);
132 oldmsg = methods[current_group][current_case][current_method].Get('msg');
133 methods[current_group][current_case][current_method].Set('msg', oldmsg+msg);
136 function add_log(msg) {
137 var faildiv;
138 faildiv = xGetElementById('fail');
139 faildiv.innerHTML = faildiv.innerHTML + msg;
142 function set_msg(gid, cid, mid) {
143 var passfail;
144 var msg=methods[gid][cid][mid].Get('msg');
145 if ('' == msg) {
146 passfail = (methods[gid][cid][mid].Get('pass')) ? 'pass' : 'fail';
147 msg = 'No output for <span class="' + passfail + '">'
148 + groups[gid].Get('desc') + '-&gt;'
149 + cases[gid][cid].Get('desc') + '-&gt;'
150 + methods[gid][cid][mid].Get('desc') + '</span><br />';
152 xGetElementById('msg').innerHTML = msg;
155 function make_tree() {
156 var content;
157 var passfail;
158 content = '<ul>';
159 for (x in groups) {
160 passfail = (groups[x].Get('pass')) ? 'pass' : 'fail';
161 content += '<li class="'+passfail+'">'+groups[x].Get('desc')+'<ul>';
162 for (y in cases[x]) {
163 passfail = (cases[x][y].Get('pass')) ? 'pass' : 'fail';
164 content += '<li class="'+passfail+'">'+cases[x][y].Get('desc')+'<ul>';
165 for (z in methods[x][y]) {
166 passfail = (methods[x][y][z].Get('pass')) ? 'pass' : 'fail';
167 content += '<li class="'+passfail+'"><a href="javascript:set_msg('+x+','+y+','+z+')">'+methods[x][y][z].Get('desc')+'</a></li>';
169 content += '</ul></li>';
171 content += '</ul></li>';
173 content += '</ul>';
174 xGetElementById('tree').innerHTML = content;
175 if (xGetElementById('treetab').className == 'activetab') {
176 activate_tab('tree');
177 } else {
178 activate_tab('fail');
182 function make_output(data) {
185 function make_fail_msg(id, msg) {
188 function max(n1, n2) {
189 if (n1 > n2) {
190 return n1;
191 } else {
192 return n2;