319ae787569a5b32c77572d4a9b96331a6f93bc6
[WebKit-https.git] / Tools / Scripts / webkitpy / tool / servers / data / gardeningserver / main.js
1 (function() {
2
3 function dismissButterbar()
4 {
5     $('.butterbar').fadeOut('fast');
6 }
7
8 function displayOnButterbar(message)
9 {
10     $('.butterbar .status').text(message);
11     $('.butterbar').fadeIn();
12 }
13
14 function setIconState(hasFailures)
15 {
16     var faviconURL = 'favicon-' + (hasFailures ? 'red' : 'green') + '.png';
17     $('#favicon').attr('href', faviconURL);
18 }
19
20 function showResults(onsuccess)
21 {
22     results.fetchResultsByBuilder(config.builders, function(resultsByBuilder) {
23         var unexpectedFailures = results.unexpectedFailuresByTest(resultsByBuilder);
24         var hasFailures = !$.isEmptyObject(unexpectedFailures)
25         if (!hasFailures) {
26             $('.results').text('No failures. Party time!');
27             var partyTime = $('<div class="partytime"><img src="partytime.gif"></div>');
28             $('.results').append(partyTime);
29             partyTime.fadeIn(1200).delay(7000).fadeOut();
30         } else {
31             var regressions = $('<div class="results-summary regression"></div>');
32             $.each(unexpectedFailures, function(testName, resultNodesByBuilder) {
33                 var testSummary = ui.summarizeTest(testName, resultNodesByBuilder);
34                 regressions.append(testSummary);
35
36                 var builderNameList = base.keys(resultNodesByBuilder);
37                 results.unifyRegressionRanges(builderNameList, testName, function(oldestFailingRevision, newestPassingRevision) {
38                     $('.regression-range', testSummary).append(ui.summarizeRegressionRange(oldestFailingRevision, newestPassingRevision));
39                     if (!newestPassingRevision)
40                         return;
41                     checkout.existsAtRevision(checkout.subversionURLForTest(testName), newestPassingRevision, function(testExistedBeforeFailure) {
42                         $(testSummary).attr('data-new-test', !testExistedBeforeFailure);
43                     });
44                 });
45                 results.countFailureOccurances(builderNameList, testName, function(failureCount) {
46                     $(testSummary).attr(config.kFailureCountAttr, failureCount);
47                     $('.failure-count', testSummary).text(ui.failureCount(failureCount));
48                 });
49             });
50             $('.results').append(regressions);
51         }
52         setIconState(hasFailures);
53         onsuccess();
54     });
55 }
56
57 function showResultsDetail()
58 {
59     var testBlock = $(this).parents('.test');
60     var builderName = $(this).attr(config.kBuilderNameAttr);
61     var testName = $('.what', testBlock).text();
62
63     // FIXME: It's lame that we have two different representations of multiple failure types.
64     var failureTypes = testBlock.attr(config.kFailureTypesAttr);
65     var failureTypeList = failureTypes.split(' ');
66
67     var content = $('.results-detail .content');
68     if ($('.failure-details', content).attr(config.kBuilderNameAttr) == builderName &&
69         $('.failure-details', content).attr(config.kTestNameAttr) == testName &&
70         $('.failure-details', content).attr(config.kFailureTypesAttr) == failureTypes)
71         return;
72
73     displayOnButterbar('Loading...');
74
75     results.fetchResultsURLs(builderName, testName, failureTypeList, function(resultsURLs) {
76         var status = $('.results-detail .toolbar .status');
77
78         function updateResults()
79         {
80             status.text(testName + ' [' + builderName + ']');
81             content.empty();
82             content.append(ui.failureDetails(resultsURLs));
83             $('.failure-details', content).attr(config.kBuilderNameAttr, builderName);
84             $('.failure-details', content).attr(config.kTestNameAttr, testName);
85             $('.failure-details', content).attr(config.kFailureTypesAttr, failureTypes);
86         }
87
88         var children = content.children();
89         if (children.length && $('.results-detail').is(":visible")) {
90             // The results-detail pane is already open. Let's do a quick cross-fade.
91             status.fadeOut('fast');
92             children.fadeOut('fast', function() {
93                 updateResults();
94                 status.fadeIn('fast');
95                 content.children().hide().fadeIn('fast', dismissButterbar);
96             });
97         } else {
98             updateResults();
99             $('.results-detail').fadeIn('fast', dismissButterbar);
100         }
101     });
102 }
103
104 function hideResultsDetail()
105 {
106     $('.results-detail').fadeOut('fast', function() {
107         $('.results-detail .content').empty();
108     });
109 }
110
111 $('.regression .where a').live('click', showResultsDetail);
112 $('.results-detail .dismiss').live('click', hideResultsDetail);
113
114 $(document).ready(function() {
115     showResults(function() {
116         $('.butterbar').fadeOut();
117     });
118 });
119
120 })();