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 var ui = ui || {}; 27 ui.failures = ui.failures || {}; 28 29 (function(){ 30 31 var kBuildingResult = 'BUILDING'; 32 33 ui.failures.Builder = base.extends('a', { 34 init: function(builderName, failures) 35 { 36 var configuration = config.builders[builderName]; 37 if (configuration) { 38 if (configuration.version) 39 this._addSpan('version', configuration.version); 40 if (configuration.is64bit) 41 this._addSpan('architecture', '64-bit'); 42 this._configuration = configuration; 43 } else 44 this._addSpan('version', builderName); 45 46 this.className = 'failing-builder'; 47 this.href = ui.displayURLForBuilder(builderName); 48 ui.setTargetForLink(this); 49 if (failures) 50 this._addSpan('failures', ' ' + failures.join(', ')); 51 }, 52 _addSpan: function(className, text) 53 { 54 var span = this.appendChild(document.createElement('span')); 55 span.className = className; 56 span.textContent = text; 57 }, 58 equals: function(configuration) 59 { 60 return this._configuration && this._configuration.is64bit == configuration.is64bit && this._configuration.version == configuration.version; 61 } 62 }); 63 64 function cellContainsConfiguration(cell, configuration) 65 { 66 return Array.prototype.some.call(cell.children, function(configurationElement) { 67 return configurationElement.equals && configurationElement.equals(configuration); 68 }); 69 } 70 71 function cellByBuildType(row, configuration) 72 { 73 return row.cells[configuration.debug ? 2 : 1]; 74 } 75 76 ui.failures.FailureGrid = base.extends('table', { 77 init: function() 78 { 79 this.className = 'failures'; 80 var titles = this.createTHead().insertRow(); 81 titles.insertCell().textContent = 'type'; 82 titles.insertCell().textContent = 'release'; 83 titles.insertCell().textContent = 'debug'; 84 this._body = this.appendChild(document.createElement('tbody')); 85 this._reset(); 86 }, 87 _rowByResult: function(result) 88 { 89 var row = this._resultRows[result]; 90 $(row).show(); 91 if (row) 92 return row; 93 94 row = this._resultRows[result] = this._body.insertRow(0); 95 row.className = result; 96 var titleCell = row.insertCell(); 97 titleCell.appendChild(document.createElement('span')).textContent = result; 98 row.insertCell(); 99 row.insertCell(); 100 return row; 101 }, 102 update: function(resultsByBuilder) 103 { 104 if (this._pendingReset) 105 this._reset(); 106 107 if (!resultsByBuilder) 108 return; 109 110 Object.keys(resultsByBuilder).forEach(function(builderName) { 111 var configuration = config.builders[builderName]; 112 if (!configuration) 113 throw "Unknown builder name: " + builderName; 114 var row = this._rowByResult(resultsByBuilder[builderName].actual); 115 var cell = cellByBuildType(row, configuration); 116 if (cellContainsConfiguration(cell, configuration)) 117 return; 118 cell.appendChild(new ui.failures.Builder(builderName)); 119 }, this); 120 }, 121 purge: function() 122 { 123 this._pendingReset = true; 124 }, 125 _reset: function() 126 { 127 this._pendingReset = false; 128 this._resultRows = {}; 129 $(this._body).empty(); 130 // Add the BUILDING row eagerly so that it appears last. 131 this._rowByResult(kBuildingResult); 132 $(this._resultRows[kBuildingResult]).hide(); 133 } 134 }); 135 136 ui.failures.ListItem = base.extends('li', { 137 init: function(groupName, failingTestsList) 138 { 139 this._failingTestsList = failingTestsList; 140 this.appendChild(new ui.actions.List([ 141 new ui.actions.Examine().makeDefault(), 142 ])); 143 var label = this.appendChild(document.createElement('label')) 144 label.textContent = failingTestsList.length == 1 ? failingTestsList[0] : groupName; 145 }, 146 }); 147 148 ui.failures.List = base.extends('ul', { 149 init: function() 150 { 151 this.className = 'failures'; 152 this.textContent = 'Loading...'; 153 } 154 }); 155 156 })(); 157