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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/**
* TestRunner: A test runner for SimpleTest
* TODO:
*
* * Avoid moving iframes: That causes reloads on mozilla and opera.
*
*
**/
var TestRunner = {};
TestRunner.logEnabled = false;
TestRunner._iframes = {};
TestRunner._iframeDocuments = {};
TestRunner._iframeRows = {};
TestRunner._currentTest = 0;
TestRunner._urls = [];
TestRunner._testsDiv = DIV();
TestRunner._progressDiv = DIV();
TestRunner._summaryDiv = DIV(null,
H1(null, "Tests Summary"),
TABLE(null,
THEAD(null,
TR(null,
TH(null, "Test"),
TH(null, "Passed"),
TH(null, "Failed")
)
),
TFOOT(/*null, TR(null, TH(null, "-"), TH(null, "--"), TH(null, "---"))*/),
TBODY()
)
);
/**
* This function is called after generating the summary.
**/
TestRunner.onComplete = null;
/**
* If logEnabled is true, this is the logger that will be used.
**/
TestRunner.logger = MochiKit.Logging.logger;
/**
* Toggle element visibility
**/
TestRunner._toggle = function(el) {
if (el.className == "noshow") {
el.className = "";
el.style.cssText = "";
} else {
el.className = "noshow";
el.style.cssText = "width:0px; height:0px; border:0px;";
}
};
/**
* Creates the iframe that contains a test
**/
TestRunner._makeIframe = function (url) {
var iframe = document.createElement('iframe');
iframe.src = url;
iframe.name = url;
iframe.width = "500";
var tbody = TestRunner._summaryDiv.getElementsByTagName("tbody")[0];
var tr = TR(null, TD({'colspan': '3'}, iframe));
iframe._row = tr;
tbody.appendChild(tr);
return iframe;
};
/**
* TestRunner entry point.
*
* The arguments are the URLs of the test to be ran.
*
**/
TestRunner.runTests = function (/*url...*/) {
if (TestRunner.logEnabled)
TestRunner.logger.log("SimpleTest START");
var body = document.getElementsByTagName("body")[0];
appendChildNodes(body,
TestRunner._testsDiv,
TestRunner._progressDiv,
TestRunner._summaryDiv
);
for (var i = 0; i < arguments.length; i++) {
TestRunner._urls.push(arguments[i]);
}
TestRunner.runNextTest();
};
/**
* Run the next test. If no test remains, calls makeSummary
**/
TestRunner.runNextTest = function() {
if (TestRunner._currentTest < TestRunner._urls.length) {
var url = TestRunner._urls[TestRunner._currentTest];
var progress = SPAN(null,
"Running ", A({href:url}, url), "..."
);
if (TestRunner.logEnabled)
TestRunner.logger.log(scrapeText(progress));
TestRunner._progressDiv.appendChild(progress);
TestRunner._iframes[url] = TestRunner._makeIframe(url);
} else {
TestRunner.makeSummary();
if (TestRunner.onComplete) {
TestRunner.onComplete();
}
}
};
/**
* This stub is called by SimpleTest when a test is finished.
**/
TestRunner.testFinished = function (doc) {
appendChildNodes(TestRunner._progressDiv, SPAN(null, "Done"), BR());
var finishedURL = TestRunner._urls[TestRunner._currentTest];
if (TestRunner.logEnabled)
TestRunner.logger.debug("SimpleTest finished " + finishedURL);
TestRunner._iframeDocuments[finishedURL] = doc;
// TestRunner._iframes[finishedURL].style.display = "none";
if (finishedURL != null) {
TestRunner._toggle(TestRunner._iframes[finishedURL]);
TestRunner._currentTest++;
TestRunner.runNextTest();
}
};
/**
* Display the summary in the browser
**/
/*
TestRunner.makeSummary = function() {
if (TestRunner.logEnabled)
TestRunner.logger.log("SimpleTest FINISHED");
var rows = [];
for (var url in TestRunner._iframeDocuments) {
var doc = TestRunner._iframeDocuments[url];
var nOK = withDocument(doc,
partial(getElementsByTagAndClassName, 'div', 'test_ok')
).length;
var nNotOK = withDocument(doc,
partial(getElementsByTagAndClassName, 'div', 'test_not_ok')
).length;
var toggle = partial(TestRunner._toggle, TestRunner._iframes[url]);
var jsurl = "TestRunner._toggle(TestRunner._iframes['" + url + "'])";
var row = TR(
{'style': {'backgroundColor': nNotOK > 0 ? "#f00":"#0f0"}},
TD(null, url),
TD(null, nOK),
TD(null, nNotOK)
);
row.onclick = toggle;
var tbody = TestRunner._summaryDiv.getElementsByTagName("tbody")[0];
tbody.insertBefore(row, TestRunner._iframes[url]._row)
}
};
*/
TestRunner.makeSummary = function() {
var base = MochiKit.Base;
var dom = MochiKit.DOM;
var iter = MochiKit.Iter;
var total_Ok, total_not_Ok;
total_Ok = 0;
total_not_Ok = 0;
if (TestRunner.logEnabled)
TestRunner.logger.log("SimpleTest FINISHED");
var rows = [];
for (var url in TestRunner._iframeDocuments) {
var doc = TestRunner._iframeDocuments[url];
var nOK = withDocument(doc,
partial(getElementsByTagAndClassName, 'div', 'test_ok')
).length;
var nNotOK = withDocument(doc,
partial(getElementsByTagAndClassName, 'div', 'test_not_ok')
).length;
var toggle = partial(TestRunner._toggle, TestRunner._iframes[url]);
var jsurl = "TestRunner._toggle(TestRunner._iframes['" + url + "'])";
var row = TR(
{'style': {'backgroundColor': nNotOK > 0 ? "#f00":"#0f0"}},
TD(null, url),
TD(null, nOK),
TD(null, nNotOK)
);
row.onclick = toggle;
var tbody = TestRunner._summaryDiv.getElementsByTagName("tbody")[0];
tbody.insertBefore(row, TestRunner._iframes[url]._row);
total_Ok += nOK;
total_not_Ok += nNotOK;
}
{
var tfoot = TestRunner._summaryDiv.getElementsByTagName("tfoot")[0];
tfoot.appendChild(TR(null,
TH(null, ""),
TH({'style':"color:green;"}, total_Ok),
TH({'style':"color:" + ((total_not_Ok == 0) ? 'black' : 'red') + ";"}, total_not_Ok)
));
}
var testRunnerResults;
var i, c;
testRunnerResults = dom.DIV({'style': 'display:none; visibility:hidden;'}, null);
c = total_Ok;
for (i=0; i<c; i++) {
dom.appendChildNodes(testRunnerResults, dom.DIV({'class': 'test_ok'}, "ok"));
}
c = total_not_Ok;
for (i=0; i<c; i++) {
dom.appendChildNodes(testRunnerResults, dom.DIV({'class': 'test_not_ok'}, "fail"));
}
document.getElementsByTagName("body")[0].appendChild(testRunnerResults);
if (typeof(parent) != "undefined" && parent.TestRunner) {
parent.TestRunner.testFinished(document);
}
};
|