Add a new page to build.webkit.org to help find when tests started failing
[WebKit-https.git] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / TestFailures / ViewController.js
1 /*
2  * Copyright (C) 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 function ViewController(buildbot) {
27     this._buildbot = buildbot;
28
29     var self = this;
30     addEventListener('load', function() { self.loaded() }, false);
31     addEventListener('hashchange', function() { self.parseHash(location.hash) }, false);
32 }
33
34 ViewController.prototype = {
35     loaded: function() {
36         this.parseHash(location.hash);
37     },
38
39     parseHash: function(hash) {
40         var match = /#\/(.*)/.exec(hash);
41         if (match)
42             this._displayBuilder(this._buildbot.builderNamed(match[1]));
43         else
44             this._displayTesters();
45     },
46
47     _displayBuilder: function(builder) {
48         var self = this;
49         builder.startFetchingBuildHistory(function(history) {
50             var list = document.createElement('ol');
51             Object.keys(history).forEach(function(buildName, buildIndex, buildNameArray) {
52                 if (!Object.keys(history[buildName]).length)
53                     return;
54                 var dlItems = [
55                     [document.createTextNode('Failed'), self._domForBuildName(builder, buildName)],
56                 ];
57                 if (buildIndex + 1 < buildNameArray.length)
58                     dlItems.push([document.createTextNode('Passed'), self._domForBuildName(builder, buildNameArray[buildIndex + 1])]);
59
60                 var item = document.createElement('li');
61                 item.appendChild(createDefinitionList(dlItems));
62                 list.appendChild(item);
63
64                 var testList = document.createElement('ol');
65                 for (var testName in history[buildName]) {
66                     var testItem = document.createElement('li');
67                     testItem.appendChild(self._domForFailedTest(builder, buildName, testName, history[buildName][testName]));
68                     testList.appendChild(testItem);
69                 }
70                 item.appendChild(testList);
71             });
72
73             var header = document.createElement('h1');
74             header.appendChild(document.createTextNode(builder.name));
75             document.body.innerHTML = '';
76             document.title = builder.name;
77             document.body.appendChild(header);
78             document.body.appendChild(list);
79         });
80     },
81
82     _displayTesters: function() {
83         this._buildbot.getTesterNames(function(names) {
84             var list = document.createElement('ul');
85             names.forEach(function(name) {
86                 var link = document.createElement('a');
87                 link.href = '#/' + name;
88                 link.appendChild(document.createTextNode(name));
89                 var item = document.createElement('li');
90                 item.appendChild(link);
91                 list.appendChild(item);
92             });
93
94             document.body.innerHTML = '';
95             document.title = 'Testers';
96             document.body.appendChild(list);
97         });
98     },
99
100     _domForBuildName: function(builder, buildName) {
101         var parsed = this._buildbot.parseBuildName(buildName);
102
103         var sourceLink = document.createElement('a');
104         sourceLink.href = 'http://trac.webkit.org/changeset/' + parsed.revision;
105         sourceLink.appendChild(document.createTextNode('r' + parsed.revision));
106
107         var buildLink = document.createElement('a');
108         buildLink.href = builder.buildURL(parsed.buildNumber);
109         buildLink.appendChild(document.createTextNode(parsed.buildNumber));
110
111         var resultsLink = document.createElement('a');
112         resultsLink.href = builder.resultsDirectoryURL(buildName) + 'results.html';
113         resultsLink.appendChild(document.createTextNode('results.html'));
114
115         var result = document.createDocumentFragment();
116         result.appendChild(sourceLink);
117         result.appendChild(document.createTextNode(' ('));
118         result.appendChild(buildLink);
119         result.appendChild(document.createTextNode(') ('));
120         result.appendChild(resultsLink);
121         result.appendChild(document.createTextNode(')'));
122
123         return result;
124     },
125
126     _domForFailedTest: function(builder, buildName, testName, failureType) {
127         var diagnosticInfo = builder.failureDiagnosisTextAndURL(buildName, testName, failureType);
128
129         var result = document.createDocumentFragment();
130         result.appendChild(document.createTextNode(testName));
131         result.appendChild(document.createTextNode(' ('));
132
133         var textNode = document.createTextNode(diagnosticInfo.text);
134         if ('url' in diagnosticInfo) {
135             var link = document.createElement('a');
136             link.href = diagnosticInfo.url;
137             link.appendChild(textNode);
138             result.appendChild(link);
139         } else
140             result.appendChild(textNode);
141
142         result.appendChild(document.createTextNode(')'));
143
144         return result;
145     },
146 };