summaryrefslogtreecommitdiffstats
path: root/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results.html
blob: 33aa04a793b123f90a36bc0023f755003622bddf (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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
<!DocType html>
<style>
body {
    margin: 4px;
}

body > p:first-of-type {
    margin-top: 0;
}

tr:first-of-type:hover {
    opacity: 0.7
}

thead, tbody {
    background-color: #E3E9FF;
}

td {
    padding: 0 4px;
}

th:empty, td:empty {
    padding: 0;
}

th {
    -webkit-user-select: none;
    -moz-user-select: none;
}

label {
    margin-left: 10px;
}

.results-row {
    background-color: white;
}

.results-row iframe {
    width: 800px;
    height: 600px;
}

#options {
    position: absolute;
    top: 4px;
    right: 4px;
}

.expand-button {
    background-color: white;
    color: blue;
    width: 11px;
    height: 11px;
    border: 1px solid blue;
    display: inline-block;
    margin: 0 3px 0 0;
    position: relative;
}

.expand-button-text {
    position: absolute;
    top: -0.3em;
    left: 1px;
}

.result-container {
    display: inline-block;
    border: 1px solid gray;
}

.result-container iframe, .result-container img {
    border: 0;
    border-top: 1px solid lightgray;
    vertical-align: top;
}

.label {
    padding-left: 3px;
    font-weight: bold;
    font-size: small;
}

.pixel-zoom-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: -webkit-box;
}

.pixel-zoom-container > * {
    display: -webkit-box;
    -webkit-box-flex: 1;
    border: 1px inset lightgray;
    height: 100px;
    overflow: hidden;
    zoom: 300%;
    background-color: white;
}

.pixel-zoom-container img {
    width: 800px;
    height: 600px;
    vertical-align: top;
}
</style>

<script>
var g_results;
function ADD_RESULTS(input)
{
    g_results = input;
}
</script>

<script src="full_results.json"></script>

<script>
function stripExtension(test)
{
    var index = test.lastIndexOf('.');
    return test.substring(0, index);
}

function parentOfType(node, selector)
{
    while (node = node.parentElement) {
        if (node.webkitMatchesSelector(selector))
            return node;
    }
    return null;
}

function appendResultIframe(src, parent)
{
    // FIXME: use audio tags for AUDIO tests?
    var layoutTestsIndex = src.indexOf('LayoutTests');
    var name;
    if (layoutTestsIndex != -1) {
        var hasTrac = src.indexOf('trac.webkit.org') != -1;
        var prefix = hasTrac ? 'trac.webkit.org/.../' : '';
        name = prefix + src.substring(layoutTestsIndex + 'LayoutTests/'.length);
    } else {
        var lastDashIndex = src.lastIndexOf('-pretty');
        if (lastDashIndex == -1)
            lastDashIndex = src.lastIndexOf('-');
        name = src.substring(lastDashIndex + 1);
    }

    var tagName = (src.lastIndexOf('.png') == -1) ? 'iframe' : 'img';

    var container = document.createElement('div');
    container.className = 'result-container';
    container.innerHTML = '<div class=label>' + name + '</div><' + tagName + ' src="' + src + '?format=txt"></' + tagName + '>';
    parent.appendChild(container);
}

function expandExpectations(e)
{
    var expandLink = e.target;
    if (expandLink.className != 'expand-button-text')
        expandLink = expandLink.querySelector('.expand-button-text');

    var isExpand = expandLink.textContent == '+';
    var row = parentOfType(expandLink, 'tr');
    var parentTbody = row.parentNode;
    var existingResultsRow = parentTbody.querySelector('.results-row');
    
    if (!isExpand) {
        expandLink.textContent = '+';
        existingResultsRow.style.display = 'none';
        return;
    }
    
    var enDash = '\u2013';
    expandLink.textContent = enDash;
    if (existingResultsRow) {
        existingResultsRow.style.display = '';
        return;
    }
    
    var newRow = document.createElement('tr');
    newRow.className = 'results-row';
    var newCell = document.createElement('td');
    newCell.colSpan = row.querySelectorAll('td').length;

    appendResultIframe(row.querySelector('.test-link').href, newCell);

    var resultLinks = row.querySelectorAll('.result-link');
    for (var i = 0; i < resultLinks.length; i++)
        appendResultIframe(resultLinks[i].href, newCell);

    newRow.appendChild(newCell);
    parentTbody.appendChild(newRow);
}

function testLink(test)
{
    var basePath;
    if (g_results.layout_tests_dir && location.toString().indexOf('file://') == 0)
        basePath = g_results.layout_tests_dir + '/';
    else
        basePath = 'http://trac.webkit.org/browser/trunk/LayoutTests/';
    return '<span class=expand-button onclick="expandExpectations(event)"><span class=expand-button-text>+</span></span>' +
        '<a class=test-link href="' + basePath + test + '">' + test + '</a>';
}

function resultLink(testPrefix, suffix, contents)
{
    return '<a class=result-link href="' + testPrefix + suffix + '">' + contents + '</a> ';
}

var g_hasTextFailures = false;
var g_hasImageFailures = false;

var g_testsWithStderr = [];
var g_newTests = [];
var g_hasHttpTests = false;

function tableRows()
{
    var html = '';
    for (var test in g_results.tests) {
        if (g_results.tests[test].has_stderr)
            g_testsWithStderr.push(test);

        g_hasHttpTests = g_hasHttpTests || test.indexOf('http/') == 0;

        var actual = g_results.tests[test].actual;
        if (actual == 'MISSING') {
            // FIXME: make sure that new-run-webkit-tests spits out an -actual.txt file for
            // tests with MISSING results.
            g_newTests.push(test);
            continue;
        }

        var expected = g_results.tests[test].expected || 'PASS';
        if (actual == 'PASS' && (!g_results.uses_expectations_file || expected == 'PASS'))
          continue;

        // FIXME: put unexpected passes in a separate table.

        var row = '<td>' + testLink(test) + '</td>';
        var test_prefix = stripExtension(test);

        row += '<td>';
        if (actual == 'CRASH')
            row += resultLink(test_prefix, '-stack.txt', 'stack');
        else if (actual == 'AUDIO') {
            row += resultLink(test_prefix, '-expected.wav', 'expected');
            row += resultLink(test_prefix, '-actual.wav', 'actual');
        } else if (actual.indexOf('TEXT') != -1 || actual == 'TIMEOUT') {
            // FIXME: only include timeout actual/expected results here if we actually spit out results for timeout tests.
            g_hasTextFailures = true;
            row += resultLink(test_prefix, '-expected.txt', 'expected') +
                resultLink(test_prefix, '-actual.txt', 'actual') +
                resultLink(test_prefix, '-diff.txt', 'diff');
      
            if (g_results.has_pretty_patch)
                row += resultLink(test_prefix, '-pretty-diff.html', 'pretty diff');

            if (g_results.has_wdiff)
                row += resultLink(test_prefix, '-wdiff.html', 'wdiff');
        }

        row += '</td><td>';

        if (actual.indexOf('IMAGE') != -1) {
            g_hasImageFailures = true;

            if (g_results.tests[test].is_mismatch_reftest) {
                row += resultLink(test_prefix, '-expected-mismatch.html', 'ref mismatch html') +
                    resultLink(test_prefix, '-actual.png', 'actual');
            } else {
                if (g_results.tests[test].is_reftest)
                    row += resultLink(test_prefix, '-expected.html', 'ref html');

                row += resultLink(test_prefix, '-expected.png', 'expected') +
                    resultLink(test_prefix, '-actual.png', 'actual') +
                    resultLink(test_prefix, '-diff.png', 'diff');
            }
        }

        row += '</td>';
        row += '<td>' + actual + '</td>';

        if (g_results.uses_expectations_file)
          row += '<td>' + expected + '</td>';

        var isExpected = actual == 'SKIP';
        if (!isExpected && g_results.uses_expectations_file) {
            var expectedArray = expected.split(' ');
            if (expectedArray.indexOf(actual) != -1)
                isExpected = true;
            else if (expectedArray.indexOf('FAIL') != -1)
                isExpected = actual == 'IMAGE' || actual == 'TEXT' || actual == 'IMAGE+TEXT';
        }
        html += '<tbody class="' + (isExpected ? 'expected' : '') + '"><tr>' + row + '</tr></tbody>';
    }
    return html;
}

var html = '';
if (g_results.uses_expectations_file)
    html += '<div id=options><label><input class="unexpected-results" type=checkbox checked>Only show unexpected results</label></div>';

var tableRowsHtml = tableRows();

if (tableRowsHtml) {
    html += '<p>Tests where results did not match expected results:</p>' +
        '<table id="results-table"><thead><tr>' +
        '<th>test</th>' +
        '<th id="text-results-header">text results</th>' +
        '<th id="image-results-header">image results</th>' +
        '<th>failure type</th>';
        
    if (g_results.uses_expectations_file)
        html += '<th>expected failure type</th>';

    html += '</tr></thead>' + tableRowsHtml + '</table>';
}

function appendTestList(tests, header, tableId, fileSuffix, linkName)
{
    tests.sort();

    html += '<p>' + header + '</p><table id="' + tableId + '">';
    for (var i = 0; i < tests.length; i++) {
        var test = tests[i];
        html += '<tbody><tr><td>' + testLink(test) + '</td><td>';
        
        if (fileSuffix.indexOf('actual') == -1)
            html += resultLink(stripExtension(test), fileSuffix, linkName);
        else {
            var testObject = g_results.tests[test];
            if (testObject.is_missing_audio)
                html += resultLink(stripExtension(test), '-actual.wav', 'audio result');
            if (testObject.is_missing_text)
                html += resultLink(stripExtension(test), fileSuffix, linkName);
            if (testObject.is_missing_image)
                html += resultLink(stripExtension(test), '-actual.png', 'png result');
        } 
        
        html += '</td></tr></tbody>';
    }
    html += '</table>'
}

if (g_newTests.length)
    appendTestList(g_newTests, 'Tests that had no expected results (probably new):', 'new-tests-table', '-actual.txt', 'result');

if (g_testsWithStderr.length)
    appendTestList(g_testsWithStderr, 'Tests that had stderr output:', 'stderr-table', '-stderr.txt', 'stderr');

if (g_hasHttpTests) {
    html += '<p>httpd access log: <a href="access_log.txt">access_log.txt</a></p>' +
        '<p>httpd error log: <a href="error_log.txt">error_log.txt</a></p>';
}

document.write(html);

function toArray(nodeList)
{
    return Array.prototype.slice.call(nodeList);
}

function trim(string)
{
    return string.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
}

// Just a namespace for code management.
var TableSorter = {};

TableSorter._forwardArrow = '<svg style="width:10px;height:10px"><polygon points="0,0 10,0 5,10" style="fill:#aaa"></svg>';

TableSorter._backwardArrow = '<svg style="width:10px;height:10px"><polygon points="0,10 10,10 5,0" style="fill:#aaa"></svg>';

TableSorter._sortedContents = function(header, arrow)
{
    return arrow + ' ' + trim(header.textContent) + ' ' + arrow;
}

TableSorter._updateHeaderClassNames = function(newHeader)
{
    var sortHeader = document.querySelector('.sortHeader');
    if (sortHeader) {
        if (sortHeader == newHeader) {
            var isAlreadyReversed = sortHeader.classList.contains('reversed');
            if (isAlreadyReversed)
                sortHeader.classList.remove('reversed');
            else
                sortHeader.classList.add('reversed');
        } else {
            sortHeader.textContent = sortHeader.textContent;
            sortHeader.classList.remove('sortHeader');
            sortHeader.classList.remove('reversed');
        }
    }

    newHeader.classList.add('sortHeader');
}

TableSorter._textContent = function(tbodyRow, column)
{
    return tbodyRow.querySelectorAll('td')[column].textContent;
}

TableSorter._sortRows = function(newHeader, reversed)
{
    var testsTable = document.getElementById('results-table');
    var headers = toArray(testsTable.querySelectorAll('th'));
    var sortColumn = headers.indexOf(newHeader);

    var rows = toArray(testsTable.querySelectorAll('tbody'));

    rows.sort(function(a, b) {
        // Only need to support lexicographic sort for now.
        var aText = TableSorter._textContent(a, sortColumn);
        var bText = TableSorter._textContent(b, sortColumn);
        
        // Forward sort equal values by test name.
        if (sortColumn && aText == bText) {
            var aTestName = TableSorter._textContent(a, 0);
            var bTestName = TableSorter._textContent(b, 0);
            if (aTestName == bTestName)
                return 0;
            return aTestName < bTestName ? -1 : 1;
        }

        if (reversed)
            return aText < bText ? 1 : -1;
        else
            return aText < bText ? -1 : 1;
    });

    for (var i = 0; i < rows.length; i++)
        testsTable.appendChild(rows[i]);
}

TableSorter.sortColumn = function(columnNumber)
{
    var newHeader = document.getElementById('results-table').querySelectorAll('th')[columnNumber];
    TableSorter._sort(newHeader);
}

TableSorter.handleClick = function(e)
{
    var newHeader = e.target;
    if (newHeader.localName != 'th')
        return;
    TableSorter._sort(newHeader);
}

TableSorter._sort = function(newHeader)
{
    TableSorter._updateHeaderClassNames(newHeader);
    
    var reversed = newHeader.classList.contains('reversed');
    var sortArrow = reversed ? TableSorter._backwardArrow : TableSorter._forwardArrow;
    newHeader.innerHTML = TableSorter._sortedContents(newHeader, sortArrow);
    
    TableSorter._sortRows(newHeader, reversed);
}

if (document.getElementById('results-table'))
    document.getElementById('results-table').addEventListener('click', TableSorter.handleClick, false);
TableSorter.sortColumn(0);

var PixelZoomer = {};

PixelZoomer._createContainer = function(e)
{
    var tbody = parentOfType(e.target, 'tbody');
    var imageDiffLinks = tbody.querySelector('tr').querySelectorAll('a[href$=".png"]');
    
    var container = document.createElement('div');
    container.className = 'pixel-zoom-container';
    
    var html = '';
    for (var i = 0; i < imageDiffLinks.length; i++)
        html += '<div class=zoom-image-container><img src="' + imageDiffLinks[i].href + '"></div>';
    
    container.innerHTML = html;
    document.body.appendChild(container);

    PixelZoomer._position(e);
}

PixelZoomer._position = function(e)
{
    var pageX = e.clientX;
    var pageY = e.clientY;
    var targetLocation = e.target.getBoundingClientRect();
    var x = pageX - targetLocation.left;
    var y = pageY - targetLocation.top;

    var zoomContainers = document.querySelectorAll('.pixel-zoom-container > .zoom-image-container');
    for (var i = 0; i < zoomContainers.length; i++) {
        var container = zoomContainers[i];
        container.scrollLeft = x - container.offsetWidth / 2;
        container.scrollTop = y - container.offsetHeight / 2;
    }
}

PixelZoomer.handleMouseMove = function(e) {
    if (PixelZoomer._mouseMoveTimeout)
        clearTimeout(PixelZoomer._mouseMoveTimeout);

    if (parentOfType(e.target, '.pixel-zoom-container'))
        return;

    var container = document.querySelector('.pixel-zoom-container');
    if (!e.target.src || e.target.src.indexOf('.png') == -1) {
        if (container)
            container.parentNode.removeChild(container);
        return;
    }
    
    if (!container) {
        PixelZoomer._mouseMoveTimeout = setTimeout(function() {
            PixelZoomer._createContainer(e);
        }, 200);
        return;
    }
    
    PixelZoomer._position(e);
}

document.body.addEventListener('mousemove', PixelZoomer.handleMouseMove, false);


var unexpectedStyleNode = document.createElement('style');
document.body.appendChild(unexpectedStyleNode);

function updateExpectedResults()
{
    var checkBox = document.querySelector('.unexpected-results');
    if (!checkBox || checkBox.checked)
        unexpectedStyleNode.innerText = '.expected { display: none; }';
    else
        unexpectedStyleNode.innerText = '';
}

updateExpectedResults();
if (document.querySelector('.unexpected-results'))
    document.querySelector('.unexpected-results').addEventListener('change', updateExpectedResults, false);

if (!g_hasTextFailures)
  document.body.getElementById('text-results-header').textContent = '';
if (!g_hasImageFailures)
  document.body.getElementById('image-results-header').textContent = '';
</script>