Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / GardeningServer / scripts / garden-o-matic.js
1 /*
2  * Copyright (C) 2011 Google 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() {
27
28 var g_info = null;
29 var g_revisionHint = null;
30
31 var g_updateTimerId = 0;
32 var g_buildersFailing = null;
33
34 var g_unexpectedFailuresController = null;
35 var g_failuresController = null;
36
37 var g_nonLayoutTestFailureBuilders = null;
38
39 var g_updating = false;
40 var g_updateButton = null;
41
42 function updatePartyTime()
43 {
44     if (!g_unexpectedFailuresController.length() && !g_nonLayoutTestFailureBuilders.hasFailures())
45         $('#onebar').addClass('partytime');
46     else
47         $('#onebar').removeClass('partytime');
48 }
49
50 function updateTreeStatus()
51 {
52     var oldTreeStatus = document.querySelector('.treestatus');
53     oldTreeStatus.remove();
54
55     var newTreeStatus = new ui.TreeStatus();
56     document.querySelector('.topbar').appendChild(newTreeStatus);
57 }
58
59 function update()
60 {
61     if (g_updating)
62         return;
63
64     g_updating = true;
65     if (g_updateButton)
66         g_updateButton.disabled = true;
67
68     if (g_revisionHint)
69         g_revisionHint.dismiss();
70
71     var gtestIframe = document.querySelector('#chromium-gtests iframe');
72     if (gtestIframe)
73         gtestIframe.src = gtestIframe.src;
74
75     // FIXME: This should be a button with a progress element.
76     var numberOfTestsAnalyzed = 0;
77     var updating = new ui.notifications.Info('Loading commit data ...');
78
79     g_info.add(updating);
80
81     builders.buildersFailingNonLayoutTests(function(failuresList) {
82         g_nonLayoutTestFailureBuilders.update(failuresList);
83         updatePartyTime();
84     });
85
86     base.callInParallel([model.updateRecentCommits, model.updateResultsByBuilder], function() {
87         if (g_failuresController)
88             g_failuresController.update();
89
90         updating.update('Analyzing test failures ...');
91
92         model.analyzeUnexpectedFailures(function(failureAnalysis) {
93             updating.update('Analyzing test failures ... ' + ++numberOfTestsAnalyzed + ' tests analyzed.');
94             g_unexpectedFailuresController.update(failureAnalysis);
95         }, function() {
96             updatePartyTime();
97             g_unexpectedFailuresController.purge();
98
99             Object.keys(config.builders).forEach(function(builderName) {
100                 if (!model.state.resultsByBuilder[builderName])
101                     g_info.add(new ui.notifications.Info('Could not find test results for ' + builderName + ' in the last ' + config.kBuildNumberLimit + ' runs.'));
102             });
103
104             updating.dismiss();
105
106             g_revisionHint = new ui.notifications.Info('');
107             g_revisionHint.updateWithNode(new ui.revisionDetails());
108             g_info.add(g_revisionHint);
109
110             g_updating = false;
111             if (g_updateButton)
112                 g_updateButton.disabled = false;
113         });
114     });
115 }
116
117 $(document).ready(function() {
118     g_updateTimerId = window.setInterval(update, config.kUpdateFrequency);
119
120     window.setInterval(updateTreeStatus, config.kTreeStatusUpdateFrequency);
121
122     pixelzoomer.installEventListeners();
123
124     onebar = new ui.onebar();
125     onebar.attach();
126
127     // FIXME: This doesn't belong here.
128     var onebarController = {
129         showResults: function(resultsView)
130         {
131             var resultsContainer = onebar.results();
132             $(resultsContainer).empty().append(resultsView);
133             onebar.select('results');
134         }
135     };
136
137     var unexpectedFailuresView = new ui.notifications.Stream();
138     g_unexpectedFailuresController = new controllers.UnexpectedFailures(model.state, unexpectedFailuresView, onebarController);
139
140     g_info = new ui.notifications.Stream();
141     g_nonLayoutTestFailureBuilders = new controllers.FailingBuilders(g_info);
142
143     var unexpected = onebar.unexpected();
144     var topBar = document.createElement('div');
145     topBar.className = 'topbar';
146     unexpected.appendChild(topBar);
147
148     // FIXME: This should be an Action object.
149     var updateButton = document.body.insertBefore(document.createElement('button'), document.body.firstChild);
150     updateButton.addEventListener("click", update);
151     updateButton.textContent = 'update';
152     topBar.appendChild(updateButton);
153     g_updateButton = updateButton;
154
155     var treeStatus = new ui.TreeStatus();
156     topBar.appendChild(treeStatus);
157
158     unexpected.appendChild(g_info);
159     unexpected.appendChild(unexpectedFailuresView);
160
161     var expected = onebar.expected();
162     if (expected) {
163         var failuresView = new ui.failures.List();
164         g_failuresController = new controllers.ExpectedFailures(model.state, failuresView, onebarController);
165         expected.appendChild(failuresView);
166     }
167
168     update();
169 });
170
171 })();