/* jscoverage.js - code coverage for JavaScript Copyright (C) 2007 siliconforks.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ if (!('_$jscoverage' in window)) { window._$jscoverage = {}; } var gCurrentFile = null; var gCurrentLine = null; var gCurrentSource = null; var gCurrentLines = null; // http://www.quirksmode.org/js/findpos.html function findPos(obj) { var result = 0; do { result += obj.offsetTop; obj = obj.offsetParent; } while (obj); return result; } // http://www.quirksmode.org/viewport/compatibility.html function getViewportHeight() { if (self.innerHeight) { // all except Explorer return self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode return document.documentElement.clientHeight; } else if (document.body) { // other Explorers return document.body.clientHeight; } else { throw "Couldn't calculate viewport height"; } } function lengthyOperation(f) { var body = document.getElementsByTagName('body').item(0); body.className = 'busy'; setTimeout(function() { try { f(); } finally { body.className = ''; body = null; } }, 0); } function setSize() { var viewportHeight = getViewportHeight(); /* padding-top: 10px border-top-width: 1px border-bottom-width: 1px padding-bottom: 10px margin-bottom: 10px ---- 32px */ var tabPages = document.getElementById('tabPages'); var tabPagesHeight = (viewportHeight - findPos(tabPages) - 32) + 'px'; tabPages.style.height = tabPagesHeight; var browserIframe = document.getElementById('browserIframe'); browserIframe.height = viewportHeight - findPos(browserIframe) - 23; var coverageSummaryDiv = document.getElementById('summaryDiv'); coverageSummaryDiv.style.height = tabPagesHeight; var sourceDiv = document.getElementById('sourceDiv'); var sourceDivHeight = (viewportHeight - findPos(sourceDiv) - 23) + 'px'; sourceDiv.style.height = sourceDivHeight; } function body_load() { initTabControl(); setSize(); // check if a URL was passed in the query string if (location.search.length > 0) { var url = location.search.substring(1); // this will automatically propagate to the input field frames[0].location = url; } else if (test_url) { frames[0].location = test_url; } } function body_resize() { setSize(); } /******************************************************************************* tab 1 */ function updateBrowser() { var input = document.getElementById("location"); frames[0].location = input.value; } function updateInput() { var input = document.getElementById("location"); input.value = frames[0].location; } function input_keypress(e) { if (e.keyCode === 13) { updateBrowser(); } } function button_click() { updateBrowser(); } function browser_load() { updateInput(); } /******************************************************************************* tab 2 */ function createLink(file, line) { var link = document.createElement("a"); var url; var call; var text; if (line) { url = file + ".jscoverage.html?" + line; call = "get('" + file + "', " + line + ");"; text = line.toString(); } else { url = file + ".jscoverage.html"; call = "get('" + file + "');"; text = file; } link.setAttribute('href', 'javascript:' + call); link.appendChild(document.createTextNode(text)); return link; } function recalculateSummaryTab(cc) { if (! cc) { cc = window._$jscoverage; } if (! cc) { throw "No coverage information found."; } var tbody = document.getElementById("summaryTbody"); while (tbody.hasChildNodes()) { tbody.removeChild(tbody.firstChild); } for (var file in cc) { var i; var num_statements = 0; var num_executed = 0; var missing = []; var length = cc[file].length; for (i = 0; i < length; i++) { if (cc[file][i] === undefined) { continue; } else if (cc[file][i] === 0) { missing.push(i); } else { num_executed++; } num_statements++; } var percentage = parseInt(100 * num_executed / num_statements); var row = document.createElement("tr"); var cell = document.createElement("td"); var link = createLink(file); cell.appendChild(link); row.appendChild(cell); cell = document.createElement("td"); cell.className = 'numeric'; cell.appendChild(document.createTextNode(num_statements)); row.appendChild(cell); cell = document.createElement("td"); cell.className = 'numeric'; cell.appendChild(document.createTextNode(num_executed)); row.appendChild(cell); cell = document.createElement("td"); cell.className = 'numeric'; cell.appendChild(document.createTextNode(percentage + '%')); row.appendChild(cell); cell = document.createElement("td"); for (i = 0; i < missing.length; i++) { if (i !== 0) { cell.appendChild(document.createTextNode(", ")); } link = createLink(file, missing[i]); cell.appendChild(link); } row.appendChild(cell); tbody.appendChild(row); } } /******************************************************************************* tab 3 */ function makeTable() { var rows = []; var coverage = _$jscoverage[gCurrentFile]; var lines = gCurrentLines; var i; for (i = 0; i < lines.length; i++) { var lineNumber = i + 1; var row = '
' + lines[i] + '