forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults-template.html
358 lines (312 loc) · 15.8 KB
/
results-template.html
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<!doctype html>
<html>
<head>
<style type='text/css'>
table, tr, td
{
border-spacing: 1px;
padding: 0px;
}
td.textColumn
{
white-space: nowrap;
font-family: Courier, monospace;
}
#directories, #codeviewer
{
overflow: scroll;
background-color: white;
position: absolute;
width: 50%;
height: 100%;
}
#directories
{
left: 0%;
}
#codeviewer
{
left: 50%;
}
ul
{
padding: 1px 0px 1px 8px;
margin: 0px;
list-style-type: none;
}
li.file
{
/* 8px is to match the width of downArrow and rightArrow because files don't have an image before them. */
padding: 0px 0px 0px 8px;
}
div.graphsContainer
{
right: 0px;
width: 300px;
position: absolute;
display: inline-block;
}
div.codeCoverage
{
right: 0px;
width: 150px;
position: absolute;
display: inline-block;
}
div.branchCoverage
{
right: 150px;
width: 150px;
position: absolute;
display: inline-block;
}
</style>
<script type='text/javascript'>
// This is the contents of the images left of directories.
var downArrow = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QYHFioBcCRLNAAAAJhJREFUGNOFzrEKwjAURuHTJHUspekDZGmhdlawCEqoUDK19O1cnX0dFxcnQXyIOAhKSsUzXr4Lf3Q8nf3leuNXy8IgBmeRYh5IAYOziDxLsdv1LNo3K/IsRQAcdhu0TgKgdUJnG4A3ipVk7NoAjV2LkvKLAKrSUBcGgLowVKX5PASTe2eJF4re2XCcn3R/PKcnH3nvPX96AbbuOGLOrLT1AAAAAElFTkSuQmCC';
var rightArrow = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QYHFiojpUQK0AAAAKZJREFUGNNjmL1k/f+379//xweYlXXMGo6dvcDw/x8jg7y0OAMzMzMDOmBiYGBg+PP7P8OO/ccYOqctZLh2+x52RTDw9t0nhtlLNjDMWbqB4d2HD9gVwcDVW/cYumcsZXj56i0DAwMDAws2RdqqCgwBHo4MIiKCmIqEBPgYgrycGbTVFVE0sTAwMDCwMjMyONqYMbjYWjCwsmL6jmH24rX/37zBH04AHAxpneY+98AAAAAASUVORK5CYII=';
function getHeatBackgroundColor(hits, maxHits)
{
if (hits === -1)
return 'white'; // Non-code lines are white.
else if (hits === 0)
return 'orange'; // Unexecuted lines are orange.
else {
// Executed lines are between red and green.
var relativeHeat = Math.floor(hits / maxHits * 255);
return 'rgb(' + relativeHeat + ',' + (255 - relativeHeat) + ', 0)';
}
}
function getCoverageBackgroundColor(coverage)
{
var value = Math.floor(coverage * 255);
return 'rgb(' + (255 - value) + ',' + value + ', 0)';
}
function expandClicked(event)
{
var children = this.parentNode.lastChild;
if (children.style.display === '') {
children.style.display = 'none';
this.src = rightArrow;
} else {
children.style.display = '';
this.src = downArrow;
}
}
function processFile(fileData, contents)
{
var lines = contents.split('\n');
var hits = new Array();
var branchesNumerator = new Array();
var branchesDenominator = new Array();
for (var i = 0; i < lines.length; i++) {
hits[i] = -1;
branchesNumerator[i] = -1;
branchesDenominator[i] = -1;
}
for (var i = 0; i < fileData.hitLines.length; i++)
hits[fileData.hitLines[i] - 1] = fileData.hits[i];
for (var i = 0; i < fileData.branchLines.length; i++) {
branchesNumerator[fileData.branchLines[i] - 1] = fileData.branchesTaken[i];
branchesDenominator[fileData.branchLines[i] - 1] = fileData.branchesPossible[i];
}
var table = document.createElement('table');
for (var i = 0; i < lines.length; i++) {
var row = document.createElement('tr');
var branchesColumn = document.createElement('td');
if (branchesNumerator[i] != -1)
branchesColumn.appendChild(document.createTextNode('(' + branchesNumerator[i] + '/' + branchesDenominator[i] + ')'));
var hitsColumn = document.createElement('td');
if (hits[i] != -1)
hitsColumn.appendChild(document.createTextNode(hits[i]));
var textColumn = document.createElement('td');
textColumn.style.background = getHeatBackgroundColor(hits[i], fileData.maxHeat);
textColumn.style.className = 'textColumn';
textColumn.appendChild(document.createTextNode(lines[i]));
row.appendChild(branchesColumn);
row.appendChild(hitsColumn);
row.appendChild(textColumn);
table.appendChild(row);
}
return table;
}
function fileClicked(event)
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState === XMLHttpRequest.DONE) {
var codeviewer = document.getElementById('codeviewer');
codeviewer.replaceChild(processFile(xhr.fileData, xhr.responseText), codeviewer.firstChild);
}
}
xhr.fileData = event.target.fileData;
xhr.open('GET', '../../' + event.target.fileData.filename.substring(1), true);
xhr.send();
event.stopPropagation();
}
function makeGraphs(dirOrFile)
{
var codeCoverage = document.createElement('div');
codeCoverage.className = 'codeCoverage';
var codeCoveragePercent = dirOrFile.totalLines ? Math.floor(dirOrFile.totalHitLines / dirOrFile.totalLines * 100) + '%' : '-';
var codeCoverageText = codeCoveragePercent + ' (' + dirOrFile.totalHitLines + '/' + dirOrFile.totalLines + ')';
codeCoverage.appendChild(document.createTextNode(codeCoverageText));
codeCoverage.style.backgroundColor = getCoverageBackgroundColor(dirOrFile.coverage);
var branchCoverage = document.createElement('div');
branchCoverage.className = 'branchCoverage';
var branchCoveragePercent = dirOrFile.totalBranchesPossible ? Math.floor(dirOrFile.totalBranchesTaken / dirOrFile.totalBranchesPossible * 100) + '%' : '-';
branchCoverage.appendChild(document.createTextNode(branchCoveragePercent + ' (' + dirOrFile.totalBranchesTaken + '/' + dirOrFile.totalBranchesPossible + ')'));
branchCoverage.style.backgroundColor = getCoverageBackgroundColor(dirOrFile.branchCoverage);
var graphsContainer = document.createElement('div');
graphsContainer.className = 'graphsContainer';
graphsContainer.appendChild(codeCoverage);
graphsContainer.appendChild(branchCoverage);
return graphsContainer;
}
function makeFileListItem(fileData, filename)
{
var li = document.createElement('li');
li.className = 'file';
var a = document.createElement('a');
a.appendChild(document.createTextNode(filename));
a.href = '#';
a.addEventListener('click', fileClicked.bind(a));
a.fileData = fileData;
li.appendChild(a);
li.appendChild(makeGraphs(fileData));
return li;
}
function makeDirectoryListItem(dir, dirName)
{
var li = document.createElement('li');
var children = document.createElement('ul');
// Recursively add all sorted subdirectories and files.
var fileNames = dir.files ? Object.keys(dir.files).sort() : [];
var subdirNames = dir.subdirs ? Object.keys(dir.subdirs).sort() : [];
for (var i = 0; i < subdirNames.length; i++) {
var subdir = subdirNames[i];
children.appendChild(makeDirectoryListItem(dir.subdirs[subdir], subdir));
}
for (var i = 0; i < fileNames.length; i++) {
var file = fileNames[i];
children.appendChild(makeFileListItem(dir.files[file], file, dir.maxHeat, dir.totalHeat));
}
var img = document.createElement('img');
img.addEventListener('click', expandClicked.bind(img));
// These four directories are expanded by default.
if (dirName === '' || dirName === 'Source' || dirName === 'Tools' || dirName === 'WebKitBuild') {
img.src = downArrow;
children.style.display = '';
} else {
img.src = rightArrow;
children.style.display = 'none';
}
li.appendChild(img);
li.appendChild(document.createTextNode(dirName));
li.appendChild(makeGraphs(dir));
li.appendChild(children);
return li;
}
// Collect total coverage for a directory and its subdirectories.
function collectDirectoryTotals(directory)
{
directory.totalBranchesPossible = 0;
directory.totalBranchesTaken = 0;
directory.totalHitLines = 0;
directory.totalLines = 0;
directory.totalHeat = 0;
directory.maxHeat = 0;
if (directory.subdirs) {
for (var subdirName in directory.subdirs) {
var subdir = directory.subdirs[subdirName];
collectDirectoryTotals(subdir);
directory.totalBranchesPossible += subdir.totalBranchesPossible;
directory.totalBranchesTaken += subdir.totalBranchesTaken;
directory.totalHitLines += subdir.totalHitLines;
directory.totalLines += subdir.totalLines;
directory.totalHeat += subdir.totalHeat;
directory.maxHeat = Math.max(directory.maxHeat, subdir.maxHeat);
}
}
if (directory.files) {
for (var fileName in directory.files) {
var file = directory.files[fileName];
file.totalBranchesPossible = 0;
file.totalBranchesTaken = 0;
file.totalHitLines = 0;
file.totalLines = file.hitLines.length;
file.totalHeat = 0;
for (var i = 0; i < file.branchesPossible.length; i++) {
file.totalBranchesPossible += file.branchesPossible[i];
file.totalBranchesTaken += file.branchesTaken[i];
}
for (var i = 0; i < file.hits.length; i++) {
file.totalHeat += file.hits[i];
if (file.hits[i])
file.totalHitLines++;
}
directory.totalBranchesPossible += file.totalBranchesPossible;
directory.totalBranchesTaken += file.totalBranchesTaken;
directory.totalHitLines += file.totalHitLines;
directory.totalLines += file.totalLines;
directory.totalHeat += file.totalHeat;
directory.maxHeat = Math.max(directory.maxHeat, file.maxHeat);
}
}
directory.coverage = directory.totalHitLines / directory.totalLines;
directory.branchCoverage = directory.totalBranchesPossible ? directory.totalBranchesTaken / directory.totalBranchesPossible : 1;
}
function addFileToDirectory(filename, filedata, directory)
{
var slashIndex = filename.indexOf('/', 1);
if (slashIndex === -1) {
if (!directory.files)
directory.files = {};
directory.files[filename.substring(1)] = filedata;
} else {
if (!directory.subdirs)
directory.subdirs = {};
var subdirName = filename.substring(1, slashIndex);
if (!directory.subdirs[subdirName])
directory.subdirs[subdirName] = {};
addFileToDirectory(filename.substring(slashIndex), filedata, directory.subdirs[subdirName]);
}
}
function updateReport(data)
{
var rootDirectory = {};
for (var i = 0; i < data.length; i++)
addFileToDirectory(data[i].filename, data[i], rootDirectory);
collectDirectoryTotals(rootDirectory);
var report = document.createElement('div');
var codeCoverageHeader = document.createElement('div');
codeCoverageHeader.className = 'codeCoverage';
codeCoverageHeader.appendChild(document.createTextNode('Code Coverage'));
var branchCoverageHeader = document.createElement('div');
branchCoverageHeader.className = 'branchCoverage';
branchCoverageHeader.appendChild(document.createTextNode('Branch Coverage'));
var ul = document.createElement('ul');
ul.appendChild(makeDirectoryListItem(rootDirectory, ''));
report.appendChild(codeCoverageHeader);
report.appendChild(branchCoverageHeader);
report.appendChild(document.createTextNode('Directories'));
report.appendChild(ul);
var directories = document.getElementById('directories');
directories.replaceChild(report, directories.firstChild);
}
function bodyLoaded()
{
updateReport(JSON.parse(document.getElementById('json').textContent));
}
</script>
</head>
<body onload='bodyLoaded();'>
<div id='directories'>
loading data...
</div>
<div id='codeviewer'>
</div>
<script id='json' type='application/json'>%CoverageDataJSON%</script>
</body>
</html>