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