Propagated changes from website\resources\scripts\global over to test\harness\*. In the future, the

website needs to be generated based on the contents of test\harness\*, not the other way around.
This commit is contained in:
David Fugate 2010-11-03 10:22:23 -07:00
parent c26f761a9f
commit 62cde7819a
8 changed files with 931 additions and 6728 deletions

View File

@ -1,32 +1,164 @@
//constants
var XML_TARGETTESTSUITENAME = 'ECMAScript Test262 Site';
var XML_TARGETTESTSUITEVERSION = '';
var XML_TARGETTESTSUITEDATE = '';
(function() { $(function () {
pageHelper.init();
$('.content-home').show();
// Adding attribute to the tabs (e.g. Home, Run etc.) and attaching the click event on buttons (e.g. Reset, Start etc.)
$('.nav-link').each(function (index) {
//Adding "targetDiv" attribute to the header tab and on that basis the div related to header tabs are displayed
if (index === 0) {
$(this).attr('targetDiv', '.content-home');
} else if (index === 1) {
$(this).attr('targetDiv', '.content-tests');
} else if (index === 2) {
$(this).attr('targetDiv', '.content-results');
$(this).attr('testRunning', 'false');
} else if (index === 3) {
$(this).attr('targetDiv', '.content-dev');
}
else {
$(this).attr('targetDiv', '.content-browsers');
}
window.PageHelper = {}; //Attaching the click event to the header tab that shows the respective div of header
$(this).click(function () {
var target = $(this).attr('targetDiv');
//If clicked tab is Result, it generates the results.
if ($(target).hasClass('content-results')) {
if ($(this).attr('testRunning') === 'true') { return; }
pageHelper.generateReportTable();
}
$('#contentContainer > div:visible').hide();
$('.navBar .selected').toggleClass('selected');
$(this).addClass('selected');
$(target).show();
//If clicked tab is Browsers Report, it shows the reports
if (target === '.content-browsers') {
$("body").addClass("busy");
setTimeout(function () {
buildTable();
}, 500);
}
});
});
window.TestConstants = { //Attach the click event to the start button. It starts, stops and pauses the tests
PAUSED: 'PAUSED', $('.button-start').click(function () {
RUNNING: 'RUNNING', $('#testsToRun').text(ES5Harness.getTotalTestsToRun());
STOPPED: 'STOPPED', $('#totalCounter').text(0);
RESET: 'RESET', $('#Pass').text(0);
RESUME: 'RESUME' $('#Fail').text(0);
$('#totalFailedCounter').text(0);
$('#failedToLoadCounter1').text(0);
$('#failedToLoadCounter').text(0);
//It stores the state of the test case in the data of button, whether running, paused or stopped. That is used later to get the present state
var testStatus = $(this).data('testStatus');
switch (testStatus) {
case undefined:
case "stopped":
ES5Harness.stop("stopped");
pageHelper.logger.find('tr').remove();
if (!ES5Harness.setChapter(pageHelper.update)) {
return false;
}
$(this).data('testStatus', "running");
ES5Harness.startTesting(pageHelper.update, "reset");
$(this).attr('src', 'resources/images/pause.png');
pageHelper.configureReportLink(true);
break;
case "running":
$(this).data('testStatus', "paused");
ES5Harness.stop("paused");
$(this).attr('src', 'resources/images/resume.png');
pageHelper.configureReportLink(false);
break;
case "paused":
$(this).data('testStatus', "running");
$(this).attr('src', 'resources/images/pause.png');
ES5Harness.startTesting(pageHelper.update, "resume");
pageHelper.configureReportLink(true);
break;
}
});
//Attach the click event to the reset button. It reset all the test to zero
$('.button-reset').click(
/*function () {
pageHelper.configureReportLink(false);
$('.button-start').data('testStatus', "stopped").attr('src', 'resources/images/start.png');
pageHelper.logger.find('tr').remove();
ES5Harness.stop("reset");
ES5Harness.resetSections();
$('#failedToLoadCounter1').text(0);
$('#failedToLoadCounter').text(0);
$('#totalFailedCounter').text(0);
pageHelper.failedToLoad = 0;
resetResults();
$('#nextActivity').text("");
} */
function () {
location.replace(location.protocol + '//' + location.host + '/default.html?run');
} }
);
//Attaching the click event to the "Download results as XML" link
$('#ancGenXMLReport').click(function (e) {
pageHelper.generateReportXml();
return false;
});
var logger = null; //load xml testcase path list when page loads
var loggerParent = null; ES5Harness && ES5Harness.loadTestList();
var progressBar = null; pageHelper.selectTab();
var failedToLoad = 0; });
var pageHelper = {
function getDomain() { //constants
return window.location.protocol + '//' + document.domain + '/'; XML_TARGETTESTSUITENAME: 'ECMAScript Test262 Site',
} XML_TARGETTESTSUITEVERSION: '',
XML_TARGETTESTSUITEDATE: '',
RED_LIMIT: 50,
YELLOW_LIMIT: 75,
GREEN_LIMIT: 99.9,
function configureReportLink(executing) { logger: undefined,
loggerParent: undefined,
progressBar: undefined,
failedToLoad: 0,
init: function () {
this.logger = $('#tableLogger');
this.loggerParent = this.logger.parent();
this.progressBar = $('#progressbar');
this.failedToLoad = 0;
},
//It sets the tab on the basis of url e.g. if URL is <domain name>\default.html?result, Result tab will be selected
selectTab: function () {
var queryStr = location.search.toLowerCase();
if (queryStr.indexOf("run") > 0) {
$("#run").click();
}
else if (queryStr.indexOf("result") > 0) {
$("#results").click();
}
else if (queryStr.indexOf("development") > 0) {
$("#development").click();
}
else if (queryStr.indexOf("browser") > 0) {
$("#browsers").click();
}
},
setVersionAndDate: function () {
//Set the version and date
$(".targetTestSuiteVersion").text(pageHelper.XML_TARGETTESTSUITEVERSION);
$(".targetTestSuiteDate").text(pageHelper.XML_TARGETTESTSUITEDATE);
},
//It sets title to the Results tab when tests are running
configureReportLink: function (executing) {
var reportLink = $('.test-report-link'); var reportLink = $('.test-report-link');
if (executing) { if (executing) {
reportLink.attr('testRunning', 'true'); reportLink.attr('testRunning', 'true');
@ -35,134 +167,29 @@ var XML_TARGETTESTSUITEDATE = '';
reportLink.parent().attr('title', ''); reportLink.parent().attr('title', '');
reportLink.attr('testRunning', 'false'); reportLink.attr('testRunning', 'false');
} }
} },
function init() { //This is used as callback function for passing in sth.js
$('.content-home').show(); update: function (detailsObj) {
$('#testsToRun').text(detailsObj.totalTestsToRun);
logger = $('#tableLogger');
loggerParent = logger.parent();
progressBar = $('#progressbar');
failedToLoad = 0;
$('.nav-link').each(function(index) {
if (index === 0) {
$(this).attr('targetDiv', '.content-home');
} else if (index === 1) {
$(this).attr('targetDiv', '.content-tests');
} else if (index === 2) {
$(this).attr('targetDiv', '.content-results');
$(this).attr('testRunning', 'false');
} else if (index === 3) {
$(this).attr('targetDiv', '.content-dev');
}
else {
$(this).attr('targetDiv', '.content-browsers');
}
$(this).click(function() {
var target = $(this).attr('targetDiv');
//Report page call here
if ($(target).hasClass('content-results')) {
if ($(this).attr('testRunning') === 'true') { return; }
generateReportTable();
}
$('#contentContainer > div:visible').hide();
$('.navBar .selected').toggleClass('selected');
$(this).addClass('selected');
$(target).show();
if (target === '.content-browsers') {
$("body").addClass("busy");
setTimeout(function() {
buildTable();
}, 500);
}
});
});
//attach the start button event
$('.button-start').click(function() {
$('#testsToRun').text(ES5Harness.getTotalTestsToRun());
$('#totalCounter').text(0);
$('#Pass').text(0);
$('#Fail').text(0);
$('#totalFailedCounter').text(0);
$('#failedToLoadCounter1').text(0);
$('#failedToLoadCounter').text(0);
var testStatus = $(this).data('testStatus');
switch (testStatus) {
case undefined:
case TestConstants.STOPPED:
ES5Harness.stop(TestConstants.STOPPED);
logger.find('tr').remove();
$(this).data('testStatus', TestConstants.RUNNING);
ES5Harness.startTesting(update, TestConstants.RESET);
$(this).attr('src', 'resources/images/pause.png');
configureReportLink(true);
break;
case TestConstants.RUNNING:
$(this).data('testStatus', TestConstants.PAUSED);
ES5Harness.stop(TestConstants.PAUSED);
$(this).attr('src', 'resources/images/resume.png');
configureReportLink(false);
break;
case TestConstants.PAUSED:
$(this).data('testStatus', TestConstants.RUNNING);
$(this).attr('src', 'resources/images/pause.png');
ES5Harness.startTesting(update, TestConstants.RESUME);
configureReportLink(true);
break;
}
});
//attach the start button event
$('.button-reset').click(function() {
configureReportLink(false);
$('.button-start').data('testStatus', TestConstants.STOPPED).attr('src', 'resources/images/start.png'); ;
logger.find('tr').remove();
ES5Harness.stop(TestConstants.RESET);
$('#failedToLoadCounter1').text(0);
$('#failedToLoadCounter').text(0);
$('#totalFailedCounter').text(0);
failedToLoad = 0;
});
$('#ancGenXMLReport').click(function(e) {
//e.preventDefault();
generateReportXml();
return false;
});
//delete all the below lines later
//$('#btnSetTimerValue').click(function(){
// ES5Harness.TIMER_PERIOD = parseInt($('#txtTimerValue').val());
//})
//load xml testcase path list
ES5Harness && ES5Harness.loadTestList();
}
function update(detailsObj) {
if (!isNaN(detailsObj.totalTestsRun)) { if (!isNaN(detailsObj.totalTestsRun)) {
$('#totalCounter').text(detailsObj.totalTestsRun); $('#totalCounter').text(detailsObj.totalTestsRun);
} }
if (detailsObj.completed) {
var btnStart = $('#btnStart').attr('src', 'resources/images/start.png');
btnStart.data('testStatus', TestConstants.STOPPED);
$('#totalFailedCounter').text(failedToLoad);
configureReportLink(false);
}
$('#Pass').text(detailsObj.totalTestsPassed); $('#Pass').text(detailsObj.totalTestsPassed);
$('#Fail').text(detailsObj.totalTestsFailed); $('#Fail').text(detailsObj.totalTestsFailed);
$('#failedToLoadCounter1').text(failedToLoad); $('#failedToLoadCounter1').text(pageHelper.failedToLoad);
$('#failedToLoadCounter').text(failedToLoad); $('#failedToLoadCounter').text(pageHelper.failedToLoad);
$('#nextActivity').text(detailsObj.nextActivity); $('#nextActivity').text(detailsObj.nextActivity);
if (detailsObj.completed) {
var btnStart = $('#btnStart').attr('src', 'resources/images/start.png');
btnStart.data('testStatus', "stopped");
$('#totalFailedCounter').text(pageHelper.failedToLoad);
pageHelper.configureReportLink(false);
$('#nextActivity').text("");
}
var altStyle = (logger.children().length % 2) === 0 ? ' ' : 'alternate'; var altStyle = (pageHelper.logger.children().length % 2) === 0 ? ' ' : 'alternate';
var appendStr = ''; var appendStr = '';
var length = 0; var length = 0;
if (detailsObj.failedTestCases && detailsObj.failedTestCases.length > 0) { if (detailsObj.failedTestCases && detailsObj.failedTestCases.length > 0) {
@ -173,7 +200,7 @@ var XML_TARGETTESTSUITEDATE = '';
testObj = detailsObj.failedTestCases.shift(); testObj = detailsObj.failedTestCases.shift();
appendStr += '<tbody><tr class=\"' + altStyle + '\"><td width=\"20%\">' + testObj.id + '</td><td>' + testObj.description + '</td><td align="right"><span class=\"Fail\">Fail</span></td></tr></tbody>'; appendStr += '<tbody><tr class=\"' + altStyle + '\"><td width=\"20%\">' + testObj.id + '</td><td>' + testObj.description + '</td><td align="right"><span class=\"Fail\">Fail</span></td></tr></tbody>';
} }
logger.append(appendStr); pageHelper.logger.append(appendStr);
} }
var testCasesPaths = this.ES5Harness.getFailToLoad(); var testCasesPaths = this.ES5Harness.getFailToLoad();
@ -184,20 +211,20 @@ var XML_TARGETTESTSUITEDATE = '';
testObj = testCasesPaths.shift(); testObj = testCasesPaths.shift();
altStyle = (altStyle !== ' ') ? ' ' : 'alternate'; altStyle = (altStyle !== ' ') ? ' ' : 'alternate';
appendStr += '<tbody><tr class=\"' + altStyle + '\"><td width=\"20%\">' + testObj + '</td><td>' + '' + '</td><td align="right"><span class=\"Fail\">Not Loaded</span></td></tr></tbody>'; appendStr += '<tbody><tr class=\"' + altStyle + '\"><td width=\"20%\">' + testObj + '</td><td>' + '' + '</td><td align="right"><span class=\"Fail\">Not Loaded</span></td></tr></tbody>';
failedToLoad++; pageHelper.failedToLoad++;
} }
logger.append(appendStr); pageHelper.logger.append(appendStr);
} }
loggerParent.attr("scrollTop", loggerParent.attr("scrollHeight")); pageHelper.loggerParent.attr("scrollTop", pageHelper.loggerParent.attr("scrollHeight"));
progressBar.reportprogress(detailsObj.totalTestsRun, detailsObj.totalTestCasesForProgressBar); pageHelper.progressBar.reportprogress(detailsObj.totalTestsRun, detailsObj.totalTestCasesForProgressBar);
} },
function generateReportXml() { //This is used to generate the xml for the results
generateReportXml: function () {
var reportWindow, //window that will output the xml data var reportWindow; //window that will output the xml data
xmlData, //array instead of string concatenation var xmlData; //array instead of string concatenation
dateNow, var dateNow;
xml; // stop condition of for loop stored in a local variable to improve performance var xml; // stop condition of for loop stored in a local variable to improve performance
dateNow = new Date(); dateNow = new Date();
@ -213,39 +240,45 @@ var XML_TARGETTESTSUITEDATE = '';
reportWindow = window.open(); reportWindow = window.open();
reportWindow.document.writeln("<title>ECMAScript Test262 XML</title>"); reportWindow.document.writeln("<title>ECMAScript Test262 XML</title>");
reportWindow.document.writeln("<div>Instructions: Update the BROWSERNAME value and submit to Hg. Send email to the <a href='mailto:body@ecmascript.org' >list</a> for assistance.</div>"); if (ES5Harness.getTotalTestsRun() !== parseInt(ES5Harness.getTotalTestsToRun())) {
reportWindow.document.write("<textarea id='results' style='width: 100%; height: 800px;'>"); reportWindow.document.writeln("<div><b>Test Results file cannot be generated because execution is not completed</b></div>");
reportWindow.document.write(xml);
xml = ""; }
function parseSection(section) { else {
xml += "<section id='" + section.id + "' name='" + section.name + "'>\r\n"; reportWindow.document.writeln("<div><br/></div>");
for (var i = 0; i < section.testCaseArray.length; i++) { reportWindow.document.write("<textarea id='results' style='width: 100%; height: 800px;'>");
xml += '<test>\r\n' + reportWindow.document.write(xml);
xml = "";
function parseSection(section) {
xml += "<section id='" + section.id + "' name='" + section.name + "'>\r\n";
for (var i = 0; i < section.testCaseArray.length; i++) {
xml += '<test>\r\n' +
' <testId>' + section.testCaseArray[i].id + '</testId>\r\n' + ' <testId>' + section.testCaseArray[i].id + '</testId>\r\n' +
' <res>' + section.testCaseArray[i].res + '</res>\r\n' + ' <res>' + section.testCaseArray[i].res + '</res>\r\n' +
'</test>\r\n'; '</test>\r\n';
} }
if (section.subSections !== undefined) { if (section.subSections !== undefined) {
for (var i = 0; i < section.subSections.length; i++) { for (var i = 0; i < section.subSections.length; i++) {
parseSection(section.subSections[i]); parseSection(section.subSections[i]);
xml += '</section>\r\n'; xml += '</section>\r\n';
}
} }
} }
for (var index = 0; index < sections.length; index++) {
parseSection(sections[index]);
xml += '</section>\r\n';
}
reportWindow.document.write(xml);
reportWindow.document.write('</Tests>\r\n</testRun>\r\n</textarea>\r\n');
reportWindow.document.close();
} }
for (var index = 0; index < sections.length; index++) { },
parseSection(sections[index]);
xml += '</section>\r\n';
}
reportWindow.document.write(xml);
reportWindow.document.write('</Tests>\r\n</testRun>\r\n</textarea>\r\n');
reportWindow.document.close();
}
function htmlEscape(str) { htmlEscape: function (str) {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;'); return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
} },
function numTests(section) { numTests: function (section) {
nTest = 0; nTest = 0;
for (var subSectionIndex = 0; subSectionIndex < section.subSections.length; subSectionIndex++) { for (var subSectionIndex = 0; subSectionIndex < section.subSections.length; subSectionIndex++) {
if (section.subSections[subSectionIndex].total !== 0) { if (section.subSections[subSectionIndex].total !== 0) {
@ -253,13 +286,10 @@ var XML_TARGETTESTSUITEDATE = '';
} }
} }
return nTest; return nTest;
} },
//It generates the report that is displayed in results tab
var RED_LIMIT = 50; generateReportTable: function () {
var YELLOW_LIMIT = 75;
var GREEN_LIMIT = 99.9;
function generateReportTable() {
var bResultsdisplayed = false; var bResultsdisplayed = false;
$('#backlinkDiv').hide(); $('#backlinkDiv').hide();
@ -267,119 +297,167 @@ var XML_TARGETTESTSUITEDATE = '';
var sections = window.sections; var sections = window.sections;
var dataTable = $('.results-data-table'); var dataTable = $('.results-data-table');
$('.results-data-table').find("tr").remove(); $('.results-data-table').find("tr").remove();
//set the total, pass and fail count //set the total, pass and fail count
$('.totalCases').text(ES5Harness.getTotalTestsRun()); $('.totalCases').text(ES5Harness.getTotalTestsRun());
$('.passedCases').text(ES5Harness.getTotalTestsPassed()); $('.passedCases').text(ES5Harness.getTotalTestsPassed());
$('.failedCases').text(ES5Harness.getTotalTestsFailed()); $('.failedCases').text(ES5Harness.getTotalTestsFailed());
$('#failedToLoadCounterDetails').text(failedToLoad); $('#failedToLoadCounterDetails').text(pageHelper.failedToLoad);
$('.crumbs #link1').remove(); try {
$('.crumbs #link2').remove(); $('.crumbs #link1').remove();
$('.crumbs #link3').remove(); $('.crumbs #link2').remove();
$('.crumbs #link3').remove();
}
catch (e) {
$('.crumbs #link1').text("");
$('.crumbs #link2').text("");
$('.crumbs #link3').text("");
}
//set the navigation bar //set the navigation bar
var anc1 = $('<a id="link1">Test Report ></a>'); var anc1 = $('<a id="link1">Test Report ></a>');
anc1.attr('href', 'javascript:PageHelper.generateReportTable();'); anc1.attr('href', 'javascript:pageHelper.generateReportTable();');
$('.crumbs').append(anc1); $('.crumbs').append(anc1);
$('.crumbs #link1').removeClass().addClass("setBlack"); $('.crumbs #link1').removeClass().addClass("setBlack");
var totalSubSectionPassed = 0; var totalSubSectionPassed = 0;
for (var sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) { for (var sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
if (numTests(sections[sectionIndex]) !== 0) { if (pageHelper.numTests(sections[sectionIndex]) !== 0) {
bResultsdisplayed = true; bResultsdisplayed = true;
dataTable.append('<tbody><tr><td class="tblHeader" colspan="2">' + 'Chapter ' + sections[sectionIndex].id + '- ' + sections[sectionIndex].name + '</td></tr></tbody>'); dataTable.append('<tbody><tr><td class="tblHeader" colspan="2">' + 'Chapter ' + sections[sectionIndex].id + '- ' + sections[sectionIndex].name + '</td></tr></tbody>');
var mainSectionPercentageStyle = "reportRed"; var mainSectionPercentageStyle = "reportRed";
// if there are any cases directly inside the chapter instead of in subsections // if there are any cases directly inside the chapter instead of in subsections
if (sections[sectionIndex].testCaseArray.length > 0) { if (sections[sectionIndex].testCaseArray.length > 0) {
for (var index = 0; index < sections[sectionIndex].subSections.length; index++) { for (var index = 0; index < sections[sectionIndex].subSections.length; index++) {
totalSubSectionPassed = totalSubSectionPassed + sections[sectionIndex].subSections[index].passed; totalSubSectionPassed = totalSubSectionPassed + sections[sectionIndex].subSections[index].passed;
} }
var calculatedLimit = (sections[sectionIndex].passed - totalSubSectionPassed) / sections[sectionIndex].testCaseArray.length * 100; var calculatedLimit = (sections[sectionIndex].passed - totalSubSectionPassed) / sections[sectionIndex].testCaseArray.length * 100;
if (calculatedLimit >= GREEN_LIMIT) { if (calculatedLimit >= pageHelper.GREEN_LIMIT) {
mainSectionPercentageStyle = "reportGreen"; mainSectionPercentageStyle = "reportGreen";
} }
else if (Math.round(calculatedLimit) >= YELLOW_LIMIT) { else if (Math.round(calculatedLimit) >= pageHelper.YELLOW_LIMIT) {
mainSectionPercentageStyle = "reportLightGreen"; mainSectionPercentageStyle = "reportLightGreen";
} }
else if (Math.round(calculatedLimit) >= RED_LIMIT) { else if (Math.round(calculatedLimit) >= pageHelper.RED_LIMIT) {
mainSectionPercentageStyle = "reportYellow"; mainSectionPercentageStyle = "reportYellow";
} }
else { else {
mainSectionPercentageStyle = "reportRed"; mainSectionPercentageStyle = "reportRed";
} }
dataTable.append('<tbody><tr><td><a href="javascript:PageHelper.generateDetailedReportTable(' + sectionIndex + ',-1);">' + "In Chapter " + sections[sectionIndex].id + '</a></td><td class="' + mainSectionPercentageStyle + '">' + (Math.round(calculatedLimit)) + '%' + '</td></tr></tbody>'); dataTable.append('<tbody><tr><td><a href="javascript:pageHelper.generateDetailedReportTable(' + sectionIndex + ',-1);">' + "In Chapter " + sections[sectionIndex].id + '</a></td><td class="' + mainSectionPercentageStyle + '">' + (Math.round(calculatedLimit)) + '%' + '</td></tr></tbody>');
} }
} }
for (var subSectionIndex = 0; subSectionIndex < sections[sectionIndex].subSections.length; subSectionIndex++) { for (var subSectionIndex = 0; subSectionIndex < sections[sectionIndex].subSections.length; subSectionIndex++) {
var styleClass; var styleClass;
if (sections[sectionIndex].subSections[subSectionIndex].total !== 0) { if (sections[sectionIndex].subSections[subSectionIndex].total !== 0) {
var passedPercentage = sections[sectionIndex].subSections[subSectionIndex].getPassPercentage();
if (passedPercentage >= GREEN_LIMIT) { var passedPercentage = 0;
//If there are subsections in subsection along with direct test cases, calculation is done like below
if (sections[sectionIndex].subSections[subSectionIndex].subSections) {
var totalPassedSubSections = sections[sectionIndex].subSections[subSectionIndex].passed;
var totalSubSections = sections[sectionIndex].subSections[subSectionIndex].total;
for (var subSubSectionIndex = 0; subSubSectionIndex < sections[sectionIndex].subSections[subSectionIndex].subSections.length; subSubSectionIndex++) {
totalPassedSubSections = totalPassedSubSections + sections[sectionIndex].subSections[subSectionIndex].subSections[subSubSectionIndex].passed;
totalSubSections = totalSubSections + sections[sectionIndex].subSections[subSectionIndex].subSections[subSubSectionIndex].total;
}
passedPercentage = totalPassedSubSections / totalSubSections * 100;
}
else {
passedPercentage = sections[sectionIndex].subSections[subSectionIndex].getPassPercentage();
}
if (passedPercentage >= pageHelper.GREEN_LIMIT) {
styleClass = "reportGreen"; styleClass = "reportGreen";
} }
else if (passedPercentage >= YELLOW_LIMIT) { else if (passedPercentage >= pageHelper.YELLOW_LIMIT) {
styleClass = "reportLightGreen"; styleClass = "reportLightGreen";
} }
else if (passedPercentage >= RED_LIMIT) { else if (passedPercentage >= pageHelper.RED_LIMIT) {
styleClass = "reportYellow"; styleClass = "reportYellow";
} }
else { else {
styleClass = "reportRed"; styleClass = "reportRed";
} }
dataTable.append('<tbody><tr><td class="sectionName"><a href="javascript:PageHelper.generateSubSectionReportTable(' + sectionIndex + ',' + subSectionIndex + ');">' + sections[sectionIndex].subSections[subSectionIndex].name + '</a></td><td class="' + styleClass + '">' + (Math.round(passedPercentage)) + '%' + '</td></tr></tbody>'); dataTable.append('<tbody><tr><td class="sectionName"><a href="javascript:pageHelper.generateSubSectionReportTable(' + sectionIndex + ',' + subSectionIndex + ');">' + sections[sectionIndex].subSections[subSectionIndex].name + '</a></td><td class="' + styleClass + '">' + (Math.round(passedPercentage)) + '%' + '</td></tr></tbody>');
bResultsdisplayed = true; bResultsdisplayed = true;
} }
} }
totalSubSectionPassed = 0; totalSubSectionPassed = 0;
} }
// append the legend if results have been displayed // append the legend if results have been displayed
if (bResultsdisplayed) { if (bResultsdisplayed) {
$('#legend').show(); $('#legend').show();
} }
}
function generateSubSectionReportTable(sectionIndex, subSectionIndex) { //Disappear the note if there are records in the result
if ($.trim(dataTable.text()) !== "")
$("#resultMessage").hide();
else
$("#resultMessage").show();
},
//It shows the sub section of the results
generateSubSectionReportTable: function (sectionIndex, subSectionIndex) {
var sections = window.sections; var sections = window.sections;
var dataTable = $('.results-data-table'); var dataTable = $('.results-data-table');
$('.results-data-table').find("tr").remove(); $('.results-data-table').find("tr").remove();
var styleClass; var styleClass;
var totalSubSectionPassed = 0; var totalSubSectionPassed = 0;
var totalSubSectionFailed = 0;
// if there is no subsections under a section(say 7.1) then directly display the detailed test report // if there is no subsections under a section(say 7.1) then directly display the detailed test report
if (!sections[sectionIndex].subSections[subSectionIndex].subSections) { if (!sections[sectionIndex].subSections[subSectionIndex].subSections) {
generateDetailedReportTable(sectionIndex, subSectionIndex); pageHelper.generateDetailedReportTable(sectionIndex, subSectionIndex);
} }
else { else {
try {
$('.crumbs #link2').remove(); $('.crumbs #link2').remove();
var anc2 = $('<a id="link2">' + " Chapter " + sections[sectionIndex].id + ": " + sections[sectionIndex].name + ": " + sections[sectionIndex].subSections[subSectionIndex].name + " > " + '</a>'); }
anc2.attr('href', 'javascript:PageHelper.generateSubSectionReportTable(' + sectionIndex + ',' + subSectionIndex + ');'); catch (e) {
$('.crumbs #link2').text("");
}
var anc2 = $("<a id='link2'>" + " Chapter " + sections[sectionIndex].id.toString() + ": " + sections[sectionIndex].name + ": " + sections[sectionIndex].subSections[subSectionIndex].name + " > " + "</a>");
anc2.attr('href', 'javascript:pageHelper.generateSubSectionReportTable(' + sectionIndex + ',' + subSectionIndex + ');');
$('.crumbs').append(anc2); $('.crumbs').append(anc2);
$('.crumbs #link2').removeClass().addClass("setBlack"); $('.crumbs #link2').removeClass().addClass("setBlack");
$('.crumbs #link1').removeClass().addClass("setBlue"); $('.crumbs #link1').removeClass().addClass("setBlue");
var anc = $('.crumbs').find('a'); var anc = $('.crumbs').find('a');
anc.click(function() { anc.click(function () {
$(this).next('a').remove(); $(this).next('a').remove();
}); });
$('.crumbs #link3').remove(); try {
$('.crumbs #link3').remove();
}
catch (e) {
$('.crumbs #link3').text("");
}
for (var index = 0; index < sections[sectionIndex].subSections[subSectionIndex].subSections.length; index++) {
totalSubSectionPassed = totalSubSectionPassed + sections[sectionIndex].subSections[subSectionIndex].subSections[index].passed;
totalSubSectionFailed = totalSubSectionFailed + sections[sectionIndex].subSections[subSectionIndex].subSections[index].failed;
}
var totalCasesInSection = sections[sectionIndex].subSections[subSectionIndex].total - totalSubSectionPassed - totalSubSectionFailed;
var totalPassedCasesInSection = sections[sectionIndex].subSections[subSectionIndex].passed - totalSubSectionPassed;
var totalFailedCasesInSection = sections[sectionIndex].subSections[subSectionIndex].failed - totalSubSectionFailed;
$('.totalCases').text(sections[sectionIndex].subSections[subSectionIndex].total); $('.totalCases').text(sections[sectionIndex].subSections[subSectionIndex].total);
$('.passedCases').text(sections[sectionIndex].subSections[subSectionIndex].passed); $('.passedCases').text(sections[sectionIndex].subSections[subSectionIndex].passed);
$('.failedCases').text(sections[sectionIndex].subSections[subSectionIndex].failed); $('.failedCases').text(sections[sectionIndex].subSections[subSectionIndex].failed);
for (var index = 0; index < sections[sectionIndex].subSections[subSectionIndex].subSections.length; index++) {
totalSubSectionPassed = totalSubSectionPassed + sections[sectionIndex].subSections[subSectionIndex].subSections[index].passed;
}
if (sections[sectionIndex].subSections[subSectionIndex].testCaseArray.length > 0) { if (sections[sectionIndex].subSections[subSectionIndex].testCaseArray.length > 0) {
var calculatedLimit = Math.round((sections[sectionIndex].subSections[subSectionIndex].passed - totalSubSectionPassed) / sections[sectionIndex].subSections[subSectionIndex].testCaseArray.length * 100);
// var calculatedLimit = Math.round((sections[sectionIndex].subSections[subSectionIndex].passed) / sections[sectionIndex].subSections[subSectionIndex].testCaseArray.length * 100);
var calculatedLimit = Math.round((totalPassedCasesInSection / totalCasesInSection) * 100);
if (calculatedLimit >= 75) { if (calculatedLimit >= 75) {
styleClass = "reportGreen"; styleClass = "reportGreen";
} }
@ -390,41 +468,33 @@ var XML_TARGETTESTSUITEDATE = '';
styleClass = "reportRed"; styleClass = "reportRed";
} }
dataTable.append('<tr><td class="tblSectionHeader"><a href="javascript:PageHelper.generateDetailedReportTable(' + sectionIndex + ',' + subSectionIndex + ');">' + "Section: " + sections[sectionIndex].subSections[subSectionIndex].id + " cases" + '</a></td><td class="' + styleClass + '">' + calculatedLimit + '%' + '</td></tr>'); dataTable.append('<tbody><tr><td class="tblSectionHeader"><a href="javascript:pageHelper.generateDetailedReportTable(' + sectionIndex + ',' + subSectionIndex + ');">' + "Section: " + sections[sectionIndex].subSections[subSectionIndex].id + " cases" + '</a></td><td class="' + styleClass + '">' + calculatedLimit + '%' + '</td></tr></tbody>');
} }
if (sections[sectionIndex].subSections[subSectionIndex].subSections) { if (sections[sectionIndex].subSections[subSectionIndex].subSections) {
for (var objIndex = 0; objIndex < sections[sectionIndex].subSections[subSectionIndex].subSections.length; objIndex++) { for (var objIndex = 0; objIndex < sections[sectionIndex].subSections[subSectionIndex].subSections.length; objIndex++) {
if (sections[sectionIndex].subSections[subSectionIndex].subSections[objIndex].total !== 0) { if (sections[sectionIndex].subSections[subSectionIndex].subSections[objIndex].total !== 0) {
var passedPercentage = sections[sectionIndex].subSections[subSectionIndex].subSections[objIndex].getPassPercentage(); var passedPercentage = sections[sectionIndex].subSections[subSectionIndex].subSections[objIndex].getPassPercentage();
if (passedPercentage >= YELLOW_LIMIT) { if (passedPercentage >= pageHelper.YELLOW_LIMIT) {
styleClass = "reportGreen"; styleClass = "reportGreen";
} }
else if (passedPercentage >= RED_LIMIT) { else if (passedPercentage >= pageHelper.RED_LIMIT) {
styleClass = "reportYellow"; styleClass = "reportYellow";
} }
else { else {
styleClass = "reportRed"; styleClass = "reportRed";
} }
dataTable.append('<tbody><tr><td class="tblSectionHeader"><a href="javascript:pageHelper.generateDetailedReportTable(' + sectionIndex + ',' + subSectionIndex + ',' + objIndex + ');">' + sections[sectionIndex].subSections[subSectionIndex].subSections[objIndex].name + '</a></td><td class="' + styleClass + '">' + (Math.round(passedPercentage)) + '%' + '</td></tr></tbody>');
dataTable.append('<tr><td class="tblSectionHeader"><a href="javascript:PageHelper.generateDetailedReportTable(' + sectionIndex + ',' + subSectionIndex + ',' + objIndex + ');">' + sections[sectionIndex].subSections[subSectionIndex].subSections[objIndex].name + '</a></td><td class="' + styleClass + '">' + (Math.round(passedPercentage)) + '%' + '</td></tr>');
} }
} }
} }
} }
pageHelper.doBackButtonTasks();
},
doBackButtonTasks(); generateDetailedReportTable: function (sectionIndex, subSectionIndex, subInnerSectionIndex) {
}
function doBackButtonTasks() {
$('#backlinkDiv').show();
var anchors = $('.crumbs a');
var contextAnchor = anchors[anchors.length - 2];
$('#backlinkDiv').attr('href', contextAnchor.href);
}
function generateDetailedReportTable(sectionIndex, subSectionIndex, subInnerSectionIndex) {
var sections = window.sections; var sections = window.sections;
var dataTable = $('.results-data-table'); var dataTable = $('.results-data-table');
@ -460,19 +530,11 @@ var XML_TARGETTESTSUITEDATE = '';
// cases directly under subsections example: 7.1 // cases directly under subsections example: 7.1
else if (sections[sectionIndex].subSections[subSectionIndex].testCaseArray.length > 0) { else if (sections[sectionIndex].subSections[subSectionIndex].testCaseArray.length > 0) {
subSectionObj = sections[sectionIndex].subSections[subSectionIndex]; subSectionObj = sections[sectionIndex].subSections[subSectionIndex];
for (var index = 0; index < sections[sectionIndex].subSections[subSectionIndex].subSections.length; index++) { $('.totalCases').text(subSectionObj.total);
subSectionPassed = subSectionPassed + sections[sectionIndex].subSections[subSectionIndex].subSections[index].passed; $('.passedCases').text(subSectionObj.passed);
subSectionfailed = subSectionfailed + sections[sectionIndex].subSections[subSectionIndex].subSections[index].failed; $('.failedCases').text(subSectionObj.failed);
}
$('.totalCases').text(subSectionObj.testCaseArray.length);
$('.passedCases').text(subSectionObj.passed - subSectionPassed);
$('.failedCases').text(subSectionObj.failed - subSectionfailed);
} }
// $('#backlinkDiv').remove();
var anc3 = $('<a id="link3">' + " Section: " + subSectionObj.id + " " + subSectionObj.name + '</a>'); var anc3 = $('<a id="link3">' + " Section: " + subSectionObj.id + " " + subSectionObj.name + '</a>');
$('.crumbs').append(anc3); $('.crumbs').append(anc3);
$('.crumbs #link3').removeClass().addClass("setBlack"); $('.crumbs #link3').removeClass().addClass("setBlack");
@ -491,7 +553,6 @@ var XML_TARGETTESTSUITEDATE = '';
dataTable.append('<tbody><tr><td>' + subSectionObj.testCaseArray[objIndex].id + '</td><td>' + subSectionObj.testCaseArray[objIndex].description + '</td><td class="' + resultStyle + '">' + subSectionObj.testCaseArray[objIndex].res + '</td><td><a href="javascript:ES5Harness.openSourceWindow(' + subSectionObj.testCaseArray[objIndex].registrationIndex + ');">[source]</a></td></tr></tbody>'); dataTable.append('<tbody><tr><td>' + subSectionObj.testCaseArray[objIndex].id + '</td><td>' + subSectionObj.testCaseArray[objIndex].description + '</td><td class="' + resultStyle + '">' + subSectionObj.testCaseArray[objIndex].res + '</td><td><a href="javascript:ES5Harness.openSourceWindow(' + subSectionObj.testCaseArray[objIndex].registrationIndex + ');">[source]</a></td></tr></tbody>');
} }
} }
// testcases directly under a chapter when there are no sections in a chapter // testcases directly under a chapter when there are no sections in a chapter
else { else {
anc3 = $('<a id="link3">' + " Chapter: " + sections[sectionIndex].id + ": " + sections[sectionIndex].name + '</a>'); anc3 = $('<a id="link3">' + " Chapter: " + sections[sectionIndex].id + ": " + sections[sectionIndex].name + '</a>');
@ -502,11 +563,12 @@ var XML_TARGETTESTSUITEDATE = '';
$('.crumbs #link1').removeClass().addClass("setBlue"); $('.crumbs #link1').removeClass().addClass("setBlue");
$('.sectionId').text("section: " + sections[sectionIndex].id); $('.sectionId').text("section: " + sections[sectionIndex].id);
for (subSectionIndex = 0; subSectionIndex < sections[sectionIndex].subSections.length; subSectionIndex++) {
for (var subSectionIndex = 0; subSectionIndex < sections[sectionIndex].subSections.length; subSectionIndex++) {
mainSectionPassed = mainSectionPassed + sections[sectionIndex].subSections[subSectionIndex].passed; mainSectionPassed = mainSectionPassed + sections[sectionIndex].subSections[subSectionIndex].passed;
mainSectionfailed = mainSectionfailed + sections[sectionIndex].subSections[subSectionIndex].failed; mainSectionfailed = mainSectionfailed + sections[sectionIndex].subSections[subSectionIndex].failed;
} }
$('.totalCases').text(sections[sectionIndex].testCaseArray.length); $('.totalCases').text(sections[sectionIndex].total - mainSectionPassed - mainSectionfailed);
$('.passedCases').text(sections[sectionIndex].passed - mainSectionPassed); $('.passedCases').text(sections[sectionIndex].passed - mainSectionPassed);
$('.failedCases').text(sections[sectionIndex].failed - mainSectionfailed); $('.failedCases').text(sections[sectionIndex].failed - mainSectionfailed);
@ -523,39 +585,43 @@ var XML_TARGETTESTSUITEDATE = '';
} }
} }
doBackButtonTasks(); pageHelper.doBackButtonTasks();
},
//It shows the back link
doBackButtonTasks: function () {
$('#backlinkDiv').show();
//The below logic is applied because .remove() is giving object error in the function "generateReportTable" that I could not find the reason.
//That is why I am keeping the links (#link1, #link2 and #link3) blank if any error .
var anchors = [];
$('.crumbs a').each(function (index, anchor) {
if ($(anchor).text() !== "") {
anchors[anchors.length] = anchor;
}
});
var contextAnchor = anchors[anchors.length - 2];
$('#backlinkDiv').attr('href', contextAnchor.href);
} }
};
//Register the variables in the namespce
window.PageHelper.init = init;
// window.$ERROR = $ERROR;
window.PageHelper.generateReportXml = generateReportXml;
window.PageHelper.generateDetailedReportTable = generateDetailedReportTable;
//window.PageHelper.logger = this.logger;
//window.PageHelper.loggerParent = this.loggerParent;
window.PageHelper.generateSubSectionReportTable = generateSubSectionReportTable;
window.PageHelper.generateReportTable = generateReportTable;
window.PageHelper.progressBar = this.progressBar;
})()
$(window).ready(function() {
PageHelper.init();
});
//Extend the array type //Extend the array type
Array.prototype.getCloneOfObject = function(oldObject) { getArrayCloneOfObject = function (oldObject)
{
var tempClone = {}; var tempClone = {};
if (typeof (oldObject) === "object")
if (typeof (oldObject) === "object") { {
for (prop in oldObject) { for (prop in oldObject)
if ((typeof (oldObject[prop]) === "object") && (oldObject[prop]).__isArray) { {
tempClone[prop] = this.getCloneOfArray(oldObject[prop]); if ((typeof (oldObject[prop]) === "object") && (oldObject[prop]).__isArray)
{
tempClone[prop] = getArrayCloneOfObject(oldObject[prop]);
} }
else if (typeof (oldObject[prop]) === "object") { else if (typeof (oldObject[prop]) === "object")
tempClone[prop] = this.getCloneOfObject(oldObject[prop]); {
tempClone[prop] = getArrayCloneOfObject(oldObject[prop]);
} }
else { else
{
tempClone[prop] = oldObject[prop]; tempClone[prop] = oldObject[prop];
} }
} }
@ -563,16 +629,18 @@ Array.prototype.getCloneOfObject = function(oldObject) {
return tempClone; return tempClone;
} }
Array.prototype.clone = function() { CloneArray = function (arrayObj)
{
var tempClone = []; var tempClone = [];
for (var arrIndex = 0; arrIndex <= arrayObj.length; arrIndex++)
for (var arrIndex = 0; arrIndex <= this.length; arrIndex++) { {
if (typeof (this[arrIndex]) === "object") { if (typeof (arrayObj[arrIndex]) === "object")
tempClone.push(this.getCloneOfObject(this[arrIndex])); {
} else { tempClone.push(getArrayCloneOfObject(arrayObj[arrIndex]));
tempClone.push(this[arrIndex]); } else
{
tempClone.push(arrayObj[arrIndex]);
} }
} }
return tempClone; return tempClone;
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,142 @@
/**
* jQuery BASE64 functions
*
* <code>
* Encodes the given data with base64.
* String $.base64Encode ( String str )
* <br />
* Decodes a base64 encoded data.
* String $.base64Decode ( String str )
* </code>
*
* Encodes and Decodes the given data in base64.
* This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.
* Base64-encoded data takes about 33% more space than the original data.
* This javascript code is used to encode / decode data using base64 (this encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean). Script is fully compatible with UTF-8 encoding. You can use base64 encoded data as simple encryption mechanism.
* If you plan using UTF-8 encoding in your project don't forget to set the page encoding to UTF-8 (Content-Type meta tag).
* This function orginally get from the WebToolkit and rewrite for using as the jQuery plugin.
*
* Example
* Code
* <code>
* $.base64Encode("I'm Persian.");
* </code>
* Result
* <code>
* "SSdtIFBlcnNpYW4u"
* </code>
* Code
* <code>
* $.base64Decode("SSdtIFBlcnNpYW4u");
* </code>
* Result
* <code>
* "I'm Persian."
* </code>
*
* @alias Muhammad Hussein Fattahizadeh < muhammad [AT] semnanweb [DOT] com >
* @link http://www.semnanweb.com/jquery-plugin/base64.html
* @see http://www.webtoolkit.info/
* @license http://www.gnu.org/licenses/gpl.html [GNU General Public License]
* @param {jQuery} {base64Encode:function(input))
* @param {jQuery} {base64Decode:function(input))
* @return string
*/
(function($){
var keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var uTF8Encode = function(string) {
string = string.replace(/\x0d\x0a/g, "\x0a");
var output = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
output += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
output += String.fromCharCode((c >> 6) | 192);
output += String.fromCharCode((c & 63) | 128);
} else {
output += String.fromCharCode((c >> 12) | 224);
output += String.fromCharCode(((c >> 6) & 63) | 128);
output += String.fromCharCode((c & 63) | 128);
}
}
return output;
};
var uTF8Decode = function(input) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < input.length ) {
c = input.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if ((c > 191) && (c < 224)) {
c2 = input.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = input.charCodeAt(i+1);
c3 = input.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
$.extend({
base64Encode: function(input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = uTF8Encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + keyString.charAt(enc1) + keyString.charAt(enc2) + keyString.charAt(enc3) + keyString.charAt(enc4);
}
return output;
},
base64Decode: function(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = keyString.indexOf(input.charAt(i++));
enc2 = keyString.indexOf(input.charAt(i++));
enc3 = keyString.indexOf(input.charAt(i++));
enc4 = keyString.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = uTF8Decode(output);
return output;
}
});
})(jQuery);

View File

@ -29,26 +29,24 @@
* Version: Alpha 2 * Version: Alpha 2
* Release: 2007-02-26 * Release: 2007-02-26
*/ */
(function($) { (function($) {
//Main Method //Main Method
$.fn.reportprogress = function(val,maxVal) { $.fn.reportprogress = function(val, maxVal) {
var max=100; var max = 100;
if(maxVal) if (maxVal) {
max=maxVal; max = maxVal;
return this.each( }
function(){ return this.each(
var div=$(this); function() {
var innerdiv=div.find(".progress"); var div = $(this);
var innerdiv = div.find(".progress");
if(innerdiv.length!=1){ if (innerdiv.length !== 1) {
innerdiv = $("<div class='progress'><span class='text'>&nbsp;</span></div>");
innerdiv=$("<div class='progress'><span class='text'>&nbsp;</span></div>"); div.append(innerdiv);
// $("<span class='text'>&nbsp;</span>").css("width",div.width()).appendTo(innerdiv); }
div.append(innerdiv); var width = Math.round(val / max * 100);
} innerdiv.css("width", width + "%");
var width=Math.round(val/max*100); div.find(".text").html(width + " %");
innerdiv.css("width",width+"%");
div.find(".text").html(width+" %");
} }
); );
}; };

View File

@ -10,7 +10,7 @@ var fileList = [];
var xslReportDetails = loadXMLDoc(TEST_REPORT_DETAILS_TABLE_XSL); var xslReportDetails = loadXMLDoc(TEST_REPORT_DETAILS_TABLE_XSL);
var xslTestList = loadXMLDoc(TEST_REPORT_INDIV_TESTS_TABLE_XSL); var xslTestList = loadXMLDoc(TEST_REPORT_INDIV_TESTS_TABLE_XSL);
// Populate fileList array by reading all xml files in "enginereports/testresults" directory on server // Populate fileList array by reading all xml files in "/enginereports/testresults" directory on server
function loadTestResultList() { function loadTestResultList() {
if (fileList.length === 0) { if (fileList.length === 0) {
var httpRequest = new XMLHttpRequest(); var httpRequest = new XMLHttpRequest();
@ -25,7 +25,7 @@ function loadTestResultList() {
var linkElements = tempDiv.getElementsByTagName("a"); var linkElements = tempDiv.getElementsByTagName("a");
for (var i = 0; i < linkElements.length; i++) { for (var i = 0; i < linkElements.length; i++) {
if (linkElements[i].pathname.match(".xml$")) { if (linkElements[i].pathname.match(".xml$")) {
fileList.push(linkElements[i].pathname); fileList.push(TEST_RESULT_PATH + linkElements[i].innerText);
} }
} }
} }

View File

@ -12,13 +12,27 @@ function Section(id, name, subSections) {
this.subSections = subSections; this.subSections = subSections;
this.testCaseArray = []; this.testCaseArray = [];
this.getPassPercentage = function () { this.getPassPercentage = function () {
if (this.total > 0) if (this.total > 0) {
return (this.passed / this.total) * 100; return (this.passed / this.total) * 100;
else }
else {
return 0; return 0;
}
}; };
} }
function resetResults() {
for (var secInd = 0; secInd < sections.length; secInd++) {
for (var subSecInd = 0; subSecInd < sections[secInd].subSections.length; subSecInd++) {
sections[secInd].subSections[subSecInd].total = 0;
sections[secInd].subSections[subSecInd].passed = 0;
sections[secInd].subSections[subSecInd].failed = 0;
}
}
}
//array to hold the sections data //array to hold the sections data
var sections = []; var sections = [];
@ -28,7 +42,7 @@ function addSection(node, nodeSections) {
var tocSubSections = []; var tocSubSections = [];
var nodes = node.childNodes; var nodes = node.childNodes;
for (var i = 0; i < nodes.length; i++) { for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeName == "sec") { if (nodes[i].nodeName === "sec") {
addSection(nodes[i], tocSubSections); addSection(nodes[i], tocSubSections);
} }
} }
@ -44,7 +58,7 @@ function addSection(node, nodeSections) {
// Load all sections from TOC xml // Load all sections from TOC xml
function loadSections() { function loadSections() {
// Constant for TOC file path // Constant for TOC file path
var TOCFILEPATH = "resources/scripts/global/ECMA-262-TOC.XML"; var TOCFILEPATH = "resources/scripts/global/ecma-262-toc.xml";
// Load TOC from xml // Load TOC from xml
var sectionsLoader = new XMLHttpRequest(); var sectionsLoader = new XMLHttpRequest();
@ -53,58 +67,65 @@ function loadSections() {
var xmlDoc = sectionsLoader.responseXML; var xmlDoc = sectionsLoader.responseXML;
var nodes = xmlDoc.documentElement.childNodes; var nodes = xmlDoc.documentElement.childNodes;
for (var i = 0; i < nodes.length; i++) { for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeName == "sec") { if (nodes[i].nodeName === "sec") {
addSection(nodes[i], sections); addSection(nodes[i], sections);
} }
} }
} }
function existsSection(section) { function existsSection(section) {
var retValue = false; var retValue = false;
holdArray = section.split("."); holdArray = section.split(".");
//subtract SECTION_TOC_OFFSET, since sections start from SECTION_TOC_OFFSET and section array from 0 //subtract SECTION_TOC_OFFSET, since sections start from SECTION_TOC_OFFSET and section array from 0
chapterId = holdArray[0] - SECTION_TOC_OFFSET; chapterId = holdArray[0] - SECTION_TOC_OFFSET;
if (holdArray.length > 0) { if (holdArray.length > 0) {
retValue = sections[chapterId] != undefined ? true : false; retValue = sections[chapterId] !== undefined ? true : false;
} }
if (retValue && (holdArray.length > 1)) { if (retValue && (holdArray.length > 1)) {
retValue = ((sections[chapterId].subSections != undefined) && (sections[chapterId].subSections[holdArray[1] - 1] != undefined)) ? true : false; retValue = ((sections[chapterId].subSections !== undefined) && (sections[chapterId].subSections[holdArray[1] - 1] !== undefined)) ? true : false;
} }
if (retValue && (holdArray.length > 2)) { if (retValue && (holdArray.length > 2)) {
retValue = ((sections[chapterId].subSections[holdArray[1] - 1].subSections != undefined ) && (sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1] != undefined)) ? true : false; retValue = ((sections[chapterId].subSections !== undefined) && (sections[chapterId].subSections[holdArray[1] - 1].subSections !== undefined) && (sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1] !== undefined)) ? true : false;
} }
return retValue; return retValue;
} }
function addCountToSection(section,type) { function addCountToSection(section, type) {
holdArray = section.split("."); holdArray = section.split(".");
//subtract SECTION_TOC_OFFSET, since sections start from SECTION_TOC_OFFSET and section array from 0 //subtract SECTION_TOC_OFFSET, since sections start from SECTION_TOC_OFFSET and section array from 0
chapterId = holdArray[0] - SECTION_TOC_OFFSET; chapterId = holdArray[0] - SECTION_TOC_OFFSET;
switch (type) { switch (type) {
case 'total': case 'total':
sections[chapterId].total++; sections[chapterId].total++;
if (holdArray.length == 2 & existsSection(section)) if (holdArray.length === 2 & existsSection(section)) {
sections[chapterId].subSections[holdArray[1] - 1].total++;
}
if (holdArray.length === 3 & existsSection(section)) {
sections[chapterId].subSections[holdArray[1] - 1].total++; sections[chapterId].subSections[holdArray[1] - 1].total++;
if (holdArray.length == 3 & existsSection(section))
sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].total++; sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].total++;
break; }
break;
case 'passed': case 'passed':
sections[chapterId].passed++; sections[chapterId].passed++;
if (holdArray.length == 2 & existsSection(section)) if (holdArray.length === 2 & existsSection(section)) {
sections[chapterId].subSections[holdArray[1] - 1].passed++;
}
if (holdArray.length === 3 & existsSection(section)) {
sections[chapterId].subSections[holdArray[1] - 1].passed++; sections[chapterId].subSections[holdArray[1] - 1].passed++;
if (holdArray.length == 3 & existsSection(section))
sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].passed++; sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].passed++;
}
break; break;
case 'failed': case 'failed':
sections[chapterId].failed++; sections[chapterId].failed++;
if (holdArray.length == 2 & existsSection(section)) if (holdArray.length === 2 & existsSection(section)) {
sections[chapterId].subSections[holdArray[1] - 1].failed++;
}
if (holdArray.length === 3 & existsSection(section)) {
sections[chapterId].subSections[holdArray[1] - 1].failed++; sections[chapterId].subSections[holdArray[1] - 1].failed++;
if (holdArray.length == 3 & existsSection(section))
sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].failed++; sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].failed++;
}
break; break;
} }
} }

View File

@ -7,7 +7,7 @@ function SputnikError(message) {
} }
SputnikError.prototype.toString = function () { SputnikError.prototype.toString = function () {
return "SputnikError: " + this.message; return "Test262 Error: " + this.message;
}; };
function testFailed(message) { function testFailed(message) {
@ -21,10 +21,11 @@ function testPrint(message) {
//adaptors for Test262 framework //adaptors for Test262 framework
function $Print(message) { function $PRINT(message) {
} }
function $INCLUDE(message) { }
function $ERROR(message) { function $ERROR(message) {
testFailed(message); testFailed(message);
} }
@ -120,6 +121,18 @@ var date_2000_start = 946684800000;
var date_2099_end = 4102444799999; var date_2099_end = 4102444799999;
var date_2100_start = 4102444800000; var date_2100_start = 4102444800000;
//the following values are normally generated by the sputnik.py driver
// for now, we'll just use 0 for everything
var $LocalTZ = 0;
var $DST_start_month = 0;
var $DST_start_sunday = 0;
var $DST_start_hour = 0;
var $DST_start_minutes = 0;
var $DST_end_month = 0;
var $DST_end_sunday = 0;
var $DST_end_hour = 0;
var $DST_end_minutes = 0;
//Date.library.js //Date.library.js
// Copyright 2009 the Sputnik authors. All rights reserved. // Copyright 2009 the Sputnik authors. All rights reserved.
@ -450,17 +463,6 @@ function ConstructDate(year, month, date, hours, minutes, seconds, ms){
} }
//the following values are normally generated by the sputnik.py driver
// for now, we'll just use 0 for everything
var $LocalTZ=0;
var $DST_start_month=0;
var $DST_start_sunday=0;
var $DST_start_hour=0;
var $DST_start_minutes=0;
var $DST_end_month=0;
var $DST_end_sunday=0;
var $DST_end_hour=0;
var $DST_end_minutes=0;
/**** Python code for initialize the above constants /**** Python code for initialize the above constants
// We may want to replicate the following in JavaScript. // We may want to replicate the following in JavaScript.

View File

@ -21,7 +21,7 @@
/* /*
sth: Simple Test Harness sth: Simple Test Harness
*/ */
sth.prototype.matchTestPath = function(filePath) { sth.prototype.matchTestPath = function (filePath) {
var cannonicalPath = filePath.slice(filePath.indexOf('TestCases')); var cannonicalPath = filePath.slice(filePath.indexOf('TestCases'));
var possibleMatch = this.testsByPath[cannonicalPath]; var possibleMatch = this.testsByPath[cannonicalPath];
if (possibleMatch) return possibleMatch; if (possibleMatch) return possibleMatch;
@ -31,99 +31,190 @@ sth.prototype.matchTestPath = function(filePath) {
return null; return null;
} }
function sth(globalObj) { function sth(globalObj) {
//private variables of this object/class
var callback,
scriptLoadTimer,
testRunTimer,
stopCommand,
tests,
buffer,
cachedGlobal,
globalState,
totalTestsRun,
totalTestsPassed,
totalTestsFailed,
failedTestCases,
allScriptTagsInjected,
testCasePaths,
possibleTestScripts,
totalTestCases,
executionCount,
failedToLoad,
loaderIframe,
xmlListLoaded,
xmlTestsLoaded,
aryTestCasePaths,
aryTestGroups,
failToLoadTests,
toublesomeTest,
requestPending;
//constants //constants
var LOAD_TIMER_PERIOD = 20, var LOAD_TIMER_PERIOD = 20,
RUN_TIMER_PERIOD = 20, RUN_TIMER_PERIOD = 20,
DEFER_STOP_COUNT = 10, DEFER_STOP_COUNT = 10,
DEFER_CHECK_TIMER_PERIOD = 50, DEFER_CHECK_TIMER_PERIOD = 50,
TESTLISTPATH = "resources/scripts/testcases/testcaseslist.xml"; TEST_LIST_PATH = "resources/scripts/testcases/testcaseslist.xml";
//private variables of this object/class
var callback,
scriptLoadTimer,
testRunTimer,
toublesomeTest,
requestPending,
globalState;
var stopCommand = false;
//It is an array that stores all the chapters' test cases when registerTest function is called.
//It is used later to retrieve the count of total test cases.
var tests = [];
//It is an array that stores all the chapters' test cases when registerTest function is called.
//It is used later to retrieve the test case to run unit test on it.
var buffer = [];
var cachedGlobal = globalObj;
var totalTestsRun = 0;
var totalTestsPassed = 0;
var totalTestsFailed = 0;
var failedTestCases = [];
var allScriptTagsInjected = false;
var testCasePaths = [];
var possibleTestScripts = 0;
var totalTestCases = 0;
var executionCount = 0;
var failedToLoad = 0;
var loaderIframe = null;
var xmlListLoaded = false;
var xmlTestsLoaded = false;
var aryTestCasePaths = [];
//It stores all the main xml path
var aryTestGroups = [];
//It also stores all the main xml path for buffer
var aryTestGroupsBuffer = [];
var failToLoadTests = [];
var cachedProperties = [
'undefined',
'NaN',
'Infinity',
'Object',
'Object.prototype',
'Object.prototype.toString',
'Array',
'Array.prototype',
'Array.prototype.toString',
'Function',
'Function.prototype',
'Function.prototype.toString',
'String',
'String.prototype',
'String.prototype.toString',
'String.fromCharCode',
'Number',
'Number.prototype.toString',
'Boolean',
'Boolean.prototype.toString',
'RegExp',
'RegExp.prototype',
'RegExp.prototype.toString',
'Math',
'Error',
'Error.prototype',
'Error.prototype.toString',
'eval',
'parseInt',
'parseFloat',
'isNaN',
'isFinite',
'EvalError',
'RangeError',
'ReferenceError',
'SyntaxError',
'TypeError',
'URIError',
'Date',
'Date.prototype',
'Date.UTC',
'Date.parse',
'Date.prototype.toLocaleTimeString',
'Date.prototype.toTimeString',
'Date.prototype.toTimeString',
'Date.prototype.valueOf',
'Date.prototype.toString',
'Date.prototype.toLocaleString',
'Date.prototype.toDateString',
'Date.prototype.constructor',
'Date.prototype.getFullYear',
'Date.prototype.getUTCFullYear',
'Date.prototype.getMonth',
'Date.prototype.getUTCMonth',
'Date.prototype.getTime',
'Date.prototype.getDate',
'Date.prototype.getUTCDate',
'Date.prototype.getUTCDay',
'Date.prototype.getDay',
'Date.prototype.getUTCHours',
'Date.prototype.getHours',
'Date.prototype.getMinutes',
'Date.prototype.getUTCMinutes',
'Date.prototype.getSeconds',
'Date.prototype.getUTCSeconds',
'Date.prototype.getMilliseconds',
'Date.prototype.getUTCMilliseconds',
'Date.prototype.getTimezoneOffset',
'Date.prototype.setFullYear',
'Date.prototype.setUTCFullYear',
'Date.prototype.setMonth',
'Date.prototype.setUTCMonth',
'Date.prototype.setTime',
'Date.prototype.setDate',
'Date.prototype.setUTCDate',
'Date.prototype.setUTCDay',
'Date.prototype.setDay',
'Date.prototype.setUTCHours',
'Date.prototype.setHours',
'Date.prototype.setMinutes',
'Date.prototype.setUTCMinutes',
'Date.prototype.setSeconds',
'Date.prototype.setUTCSeconds',
'Date.prototype.setMilliseconds',
'Date.prototype.setUTCMilliseconds',
'Date.prototype.toUTCString',
'Date.prototype.toISOString',
'Date.prototype.toJSON',
'Date.prototype.toLocaleDateString'
]
aryTestCasePaths = []; globalState = {};
aryTestGroups = [];
failToLoadTests = [];
stopCommand = false;
xmlListLoaded = false;
xmlTestsLoaded = false;
tests = [];
buffer = [];
totalTestsRun = 0;
totalTestsPassed = 0;
totalTestsFailed = 0;
failedTestCases = [];
allScriptTagsInjected = false;
testCasePaths = []; ;
possibleTestScripts = 0;
totalTestCases = 0;
executionCount = 0;
loaderIframe = null;
cachedGlobal = globalObj;
failedToLoad = 0;
globalState = { var tokens;
undefined: cachedGlobal.undefined, var base;
NaN: cachedGlobal.NaN, var prop;
Infinity: cachedGlobal.Infinity,
Object: cachedGlobal.Object, for (var i = 0; i < cachedProperties.length; i++) {
Array: cachedGlobal.Array, tokens = cachedProperties[i].split(".");
Function: cachedGlobal.Function, base = cachedGlobal;
String: cachedGlobal.String,
Number: cachedGlobal.Number, while (tokens.length > 1)
Boolean: cachedGlobal.Boolean, base = base[tokens.shift()];
RegExp: cachedGlobal.RegExp,
Math: cachedGlobal.Math, prop = tokens.shift();
Error: cachedGlobal.Error,
eval: cachedGlobal.eval, globalState[cachedProperties[i]] = base[prop];
parseInt: cachedGlobal.parseInt,
parseFloat: cachedGlobal.parseFloat,
isNaN: cachedGlobal.isNaN,
isFinite: cachedGlobal.isFinite,
EvalError: cachedGlobal.EvalError,
RangeError: cachedGlobal.RangeError,
ReferenceError: cachedGlobal.ReferenceError,
SyntaxError: cachedGlobal.SyntaxError,
TypeError: cachedGlobal.TypeError,
URIError: cachedGlobal.URIError
} }
//private methods //private methods
function clearTimers() { function clearTimers() {
window.clearTimeout(scriptLoadTimer); window.clearTimeout(scriptLoadTimer);
window.clearTimeout(testRunTimer); window.clearTimeout(testRunTimer);
} }
var currentTestId;
function restoreGlobals() { function restoreGlobals() {
for (var prop in globalState) var tokens;
if (cachedGlobal[prop] !== globalState[prop]) cachedGlobal[prop] = globalState[prop]; var base;
var prop;
for (var key in globalState) {
tokens = key.split(".");
base = cachedGlobal;
while (tokens.length > 1) {
prop = tokens.shift();
base = base[prop];
}
prop = tokens.shift();
if (base[prop] === base[prop] && base[prop] !== globalState[key])
{
base[prop] = globalState[key];
}
}
} }
function htmlEscape(str) { function htmlEscape(str) {
@ -152,27 +243,95 @@ function sth(globalObj) {
var t = new sth_test(to); var t = new sth_test(to);
t.registrationIndex = tests.length; t.registrationIndex = tests.length;
tests.push(t); tests.push(t);
buffer.push(t); buffer.push(t);
} }
this.run = function() { //If user enters chapter index, it sets the aryTestGroups, tests, buffer and initialize the subsections
//If user enters nothing, it executes all the test cases
this.setChapter = function () {
aryTestGroups = CloneArray(aryTestGroupsBuffer);
aryTestGroups.numTests = aryTestGroupsBuffer.numTests;
var userInputChapterIndex = $.trim($("#chapterId").val());
tests = [];
buffer = [];
//Initialize the subSections
for (var secInd = 0; secInd < sections.length; secInd++) {
for (var subSecInd = 0; subSecInd < sections[secInd].subSections.length; subSecInd++) {
sections[secInd].subSections[subSecInd].total = 0;
sections[secInd].subSections[subSecInd].passed = 0;
sections[secInd].subSections[subSecInd].failed = 0;
}
}
$(".results-data-table").html("");
stopCommand = false;
if (callback) {
//It executes a callback function with an object that contains all the information like total test cases to run, left test cases to run etc.
//That updates the information on the UI
callback(
{
totalTestsRun: 0,
totalTestsFailed: 0,
totalTestsPassed: 0,
totalTestsToRun: 0,
failedTestCases: 0,
totalTestsLoaded: 0,
failedToLoad: 0,
totalTestCasesForProgressBar: 0,
nextActivity: ""
});
}
if (userInputChapterIndex !== "") {
var mapedChapterIndex = null;
for (var chapterIndex = 0; chapterIndex < aryTestGroups.length; chapterIndex++) {
if (chapterIndex === parseInt(userInputChapterIndex)) {
mapedChapterIndex = chapterIndex;
}
}
if (mapedChapterIndex !== null) {
aryTestGroups = [];
aryTestGroups[0] = aryTestGroupsBuffer[mapedChapterIndex];
aryTestGroups.numTests = aryTestGroupsBuffer.numTests;
}
else {
$("#resultMessage").show();
alert("Chapter index is not valid. Please keep blank for execution of all the test cases or enter correct index");
return false;
}
}
return true;
}
this.run = function ()
{
var ut = undefined; // a particular unittest var ut = undefined; // a particular unittest
var res = false; // the result of running the unittest var res = false; // the result of running the unittest
var prereq = undefined; // any prerequisite specified by the unittest var prereq = undefined; // any prerequisite specified by the unittest
var pres = true; // the result of running that prerequite var pres = true; // the result of running that prerequite
var regEx2 = /^[sS]?[0-9]{1,2}([.]?[0-9]{1,2}){0,2}/gi; var alphaNumericWithDot = /^[sS]?[0-9]{1,2}([.]?[0-9]{1,2}){0,2}/gi;
var holdArray; var holdArray;
var subsectionId; var subsectionId;
var chapterId; var chapterId;
ut = buffer.shift(); ut = buffer.shift();
if (!ut) if (!ut)
{
return; return;
}
executionCount++; executionCount++;
//this.currentTest = ut; //this.currentTest = ut;
if (callback) callback( if (callback)
{
//It executes a callback function with an object that contains all the information like total test cases to run, left test cases to run etc.
//That updates the information on the UI
callback(
{ totalTestsRun: totalTestsRun, //Total run { totalTestsRun: totalTestsRun, //Total run
//totalRun : sth.tests.length, //totalRun : sth.tests.length,
totalTestsFailed: totalTestsFailed, totalTestsFailed: totalTestsFailed,
@ -184,70 +343,86 @@ function sth(globalObj) {
totalTestCasesForProgressBar: ((totalTestsRun / totalTestCases) * 100) < 99 ? totalTestCases : tests.length, totalTestCasesForProgressBar: ((totalTestsRun / totalTestCases) * 100) < 99 ? totalTestCases : tests.length,
nextActivity: "executing ... " + ut.id nextActivity: "executing ... " + ut.id
}); });
}
// if the test specifies a prereq, run that. // if the test specifies a prereq, run that.
pre = ut.pre; pre = ut.pre;
pres = true; pres = true;
if (pre !== undefined) { currentTestId = ut.id;
try { if (pre !== undefined)
{
try
{
pres = pre.call(ut); pres = pre.call(ut);
restoreGlobals(); restoreGlobals();
if (pres !== true) { if (pres !== true)
{
ut.res = 'Precondition failed'; ut.res = 'Precondition failed';
} }
} catch (e) { } catch (e)
{
restoreGlobals(); restoreGlobals();
pres = false; pres = false;
ut.res = 'Precondition failed with exception: ' + e.description; var errDes = (e.message) ? e.message : e.description;
ut.res = 'Precondition failed with exception: ' + errDes;
} }
} }
//read the chapter id and sub section id by spliting the testcase id //read the chapter id and sub section id by spliting the testcase id
match2 = ut.id.match(regEx2); match2 = ut.id.match(alphaNumericWithDot);
subsectionId = match2[0]; subsectionId = match2[0];
if (match2[0].toLowerCase().indexOf('s') != -1) { if (match2[0].toLowerCase().indexOf('s') != -1)
{
subsectionId = subsectionId.substring(1); subsectionId = subsectionId.substring(1);
} }
holdArray = subsectionId.split("."); holdArray = subsectionId.split(".");
chapterId = holdArray[0] - SECTION_TOC_OFFSET; chapterId = holdArray[0] - SECTION_TOC_OFFSET;
addCountToSection(subsectionId, "total"); addCountToSection(subsectionId, "total");
// if the prereq is met, run the testcase now. // if the prereq is met, run the testcase now.
if (pres === true) { if (pres === true)
try { {
try
{
res = ut.theTestcase.call(ut.testObj); res = ut.theTestcase.call(ut.testObj);
restoreGlobals(); restoreGlobals();
if (res === true || res === undefined) { if (res === true || res === undefined)
{
ut.res = 'pass'; ut.res = 'pass';
totalTestsPassed++; totalTestsPassed++;
addCountToSection(subsectionId, "passed"); addCountToSection(subsectionId, "passed");
} }
else { else
{
ut.res = 'fail'; ut.res = 'fail';
totalTestsFailed++; totalTestsFailed++;
failedTestCases[failedTestCases.length] = ut; failedTestCases[failedTestCases.length] = ut;
addCountToSection(subsectionId, "failed"); addCountToSection(subsectionId, "failed");
} }
} }
catch (e) { catch (e)
{
restoreGlobals(); restoreGlobals();
ut.res = 'failed with exception: ' + e.description; var errDes = (e.message) ? e.message : e.description;
ut.res = 'failed with exception: ' + errDes;
totalTestsFailed++; totalTestsFailed++;
failedTestCases[failedTestCases.length] = ut; failedTestCases[failedTestCases.length] = ut;
addCountToSection(subsectionId, "failed"); addCountToSection(subsectionId, "failed");
} }
} }
else { else
{
totalTestsFailed++; totalTestsFailed++;
failedTestCases[failedTestCases.length] = ut; failedTestCases[failedTestCases.length] = ut;
addCountToSection(subsectionId, "failed"); addCountToSection(subsectionId, "failed");
} }
if (holdArray.length > 1) { if (holdArray.length > 1)
if (holdArray.length == 3 & existsSection(subsectionId)) { {
if (holdArray.length === 3 & existsSection(subsectionId))
{
sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].testCaseArray[sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].testCaseArray.length] = ut; sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].testCaseArray[sections[chapterId].subSections[holdArray[1] - 1].subSections[holdArray[2] - 1].testCaseArray.length] = ut;
} }
else { else
{
sections[chapterId].subSections[holdArray[1] - 1].testCaseArray[sections[chapterId].subSections[holdArray[1] - 1].testCaseArray.length] = ut; sections[chapterId].subSections[holdArray[1] - 1].testCaseArray[sections[chapterId].subSections[holdArray[1] - 1].testCaseArray.length] = ut;
} }
} }
@ -258,7 +433,7 @@ function sth(globalObj) {
} }
this.startTesting = function(pageCallback, command) { this.startTesting = function (pageCallback, command) {
if (!xmlListLoaded) { if (!xmlListLoaded) {
this.loadTestList(); this.loadTestList();
return; return;
@ -273,9 +448,12 @@ function sth(globalObj) {
scriptLoader = null; scriptLoader = null;
} }
else { else {
scriptLoader.onreadystatechange = function() { scriptLoader.onreadystatechange = function () {
if (scriptLoader.readyState == 4) { if (scriptLoader.readyState == 4) {
if (callback) callback( if (callback) {
//It executes a callback function with an object that contains all the information like total test cases to run, left test cases to run etc.
//That updates the information on the UI
callback(
{ totalTestsRun: totalTestsRun, //Total run { totalTestsRun: totalTestsRun, //Total run
totalTestsFailed: totalTestsFailed, totalTestsFailed: totalTestsFailed,
totalTestsPassed: totalTestsPassed, totalTestsPassed: totalTestsPassed,
@ -286,14 +464,14 @@ function sth(globalObj) {
totalTestCasesForProgressBar: ((totalTestsRun / totalTestCases) * 100) < 99 ? totalTestCases : tests.length, totalTestCasesForProgressBar: ((totalTestsRun / totalTestCases) * 100) < 99 ? totalTestCases : tests.length,
nextActivity: "loading... " + scriptLoader.responseXML.getElementsByTagName("section")[0].getAttribute("name") nextActivity: "loading... " + scriptLoader.responseXML.getElementsByTagName("section")[0].getAttribute("name")
}); });
}
try { try {
var j = aryTestCasePaths.length; var j = aryTestCasePaths.length;
var newTests = scriptLoader.responseXML.getElementsByTagName("test"); var newTests = scriptLoader.responseXML.getElementsByTagName("test");
for (var i = 0; i < newTests.length; i++) { for (var i = 0; i < newTests.length; i++) {
var scriptCode = (newTests[i].firstChild.text != undefined) ? newTests[i].firstChild.text : newTests[i].firstChild.textContent; var scriptCode = (newTests[i].firstChild.text != undefined) ? newTests[i].firstChild.text : newTests[i].firstChild.textContent;
loaderIframe.append('<script>' + $.base64.decode(scriptCode) + '</script>'); loaderIframe.append('<script>' + $.base64Decode(scriptCode) + '</script>');
aryTestCasePaths[j++] = newTests[i].getAttribute("id"); aryTestCasePaths[j++] = newTests[i].getAttribute("id");
if (tests[tests.length - 1].id != newTests[i].getAttribute("id")) { if (tests[tests.length - 1].id != newTests[i].getAttribute("id")) {
failToLoadTests[failToLoadTests.length] = newTests[i].getAttribute("id"); failToLoadTests[failToLoadTests.length] = newTests[i].getAttribute("id");
@ -316,12 +494,12 @@ function sth(globalObj) {
totalTestCases = possibleTestScripts = aryTestGroups.numTests; totalTestCases = possibleTestScripts = aryTestGroups.numTests;
switch (command) { switch (command) {
case TestConstants.RUNNING: case "running":
case TestConstants.RESET: case "reset":
if (!testCasePaths.length > 0 && !allScriptTagsInjected) { if (!testCasePaths.length > 0 && !allScriptTagsInjected) {
testCasePaths = aryTestCasePaths.slice(0, aryTestCasePaths.length); testCasePaths = aryTestCasePaths.slice(0, aryTestCasePaths.length);
} else { } else {
buffer = tests.clone(); buffer = CloneArray(tests);
} }
break; break;
} }
@ -332,8 +510,6 @@ function sth(globalObj) {
loaderIframe = $('head'), loaderIframe = $('head'),
testPath; testPath;
function runNextTest() { function runNextTest() {
if (!xmlTestsLoaded) { if (!xmlTestsLoaded) {
testRunTimer = setTimeout(runNextTest, RUN_TIMER_PERIOD); testRunTimer = setTimeout(runNextTest, RUN_TIMER_PERIOD);
@ -344,7 +520,11 @@ function sth(globalObj) {
testRunTimer = setTimeout(runNextTest, RUN_TIMER_PERIOD); testRunTimer = setTimeout(runNextTest, RUN_TIMER_PERIOD);
return; return;
} }
if ($("#chapterId").val() !== "") {
totalTestCases = tests.length;
}
//It executes a callback function with an object that contains all the information like total test cases to run, left test cases to run etc.
//That updates the information on the UI
callback( callback(
{ totalTestsRun: totalTestsRun, //Total run { totalTestsRun: totalTestsRun, //Total run
//totalRun : sth.tests.length, //totalRun : sth.tests.length,
@ -369,18 +549,20 @@ function sth(globalObj) {
testRunTimer = setTimeout(runNextTest, DEFER_CHECK_TIMER_PERIOD); testRunTimer = setTimeout(runNextTest, DEFER_CHECK_TIMER_PERIOD);
return; return;
} }
//It executes a callback function with an object that contains all the information like total test cases to run, left test cases to run etc.
//That updates the information on the UI
callback( callback(
{ totalTestsRun: totalTestsRun, { totalTestsRun: totalTestsRun,
//totalRun : sth.tests.length, //totalRun : sth.tests.length,
totalTestsFailed: totalTestsFailed, totalTestsFailed: totalTestsFailed,
totalTestsPassed: totalTestsPassed, totalTestsPassed: totalTestsPassed,
totalTestsToRun: totalTestCases, totalTestsToRun: totalTestCases,
failedTestCases: failedTestCases, failedTestCases: failedTestCases,
completed: true, completed: true,
failedToLoad: failedToLoad, failedToLoad: failedToLoad,
totalTestCasesForProgressBar: tests.length, totalTestCasesForProgressBar: tests.length,
totalTestsLoaded: tests.length totalTestsLoaded: tests.length
}); });
sth.stop(); sth.stop();
} }
else if (!stopCommand) { else if (!stopCommand) {
@ -391,13 +573,14 @@ function sth(globalObj) {
testRunTimer = setTimeout(runNextTest, 0); testRunTimer = setTimeout(runNextTest, 0);
} }
//This function stops, resets and pauses on the basis of parameter passed to it.
this.stop = function(testStatus) { this.stop = function(testStatus) {
clearTimers(); clearTimers();
stopCommand = true; stopCommand = true;
var totalTestCasesForProgressBar = tests.length; var totalTestCasesForProgressBar = tests.length;
switch (testStatus) { switch (testStatus) {
case TestConstants.PAUSED: case "paused":
totalTestsRun = totalTestsRun; //Total run totalTestsRun = totalTestsRun; //Total run
totalTestsFailed = totalTestsFailed; totalTestsFailed = totalTestsFailed;
totalTestsPassed = totalTestsPassed; totalTestsPassed = totalTestsPassed;
@ -406,7 +589,7 @@ function sth(globalObj) {
totalTestsLoaded = tests.length; totalTestsLoaded = tests.length;
totalTestCasesForProgressBar = ((totalTestsRun / totalTestCases) * 100) < 99 ? totalTestCases : tests.length; totalTestCasesForProgressBar = ((totalTestsRun / totalTestCases) * 100) < 99 ? totalTestCases : tests.length;
break; break;
case TestConstants.RESET: case "reset":
totalTestsRun = 0; //Total run totalTestsRun = 0; //Total run
totalTestsFailed = 0; totalTestsFailed = 0;
totalTestsPassed = 0; totalTestsPassed = 0;
@ -416,7 +599,7 @@ function sth(globalObj) {
possibleTestScripts = totalTestCases; possibleTestScripts = totalTestCases;
loadSections(); loadSections();
break; break;
case TestConstants.STOPPED: case "stopped":
totalTestsRun = 0; totalTestsRun = 0;
totalTestsPassed = 0; totalTestsPassed = 0;
totalTestsFailed = 0; totalTestsFailed = 0;
@ -425,6 +608,8 @@ function sth(globalObj) {
} }
if (typeof callback !== 'undefined' && callback !== null) { if (typeof callback !== 'undefined' && callback !== null) {
//It executes a callback function with an object that contains all the information like total test cases to run, left test cases to run etc.
//That updates the information on the UI
callback( callback(
{ totalTestsRun: totalTestsRun, //Total run { totalTestsRun: totalTestsRun, //Total run
totalTestsFailed: totalTestsFailed, totalTestsFailed: totalTestsFailed,
@ -441,21 +626,25 @@ function sth(globalObj) {
this.getAllTests = function() { this.getAllTests = function() {
return tests; return tests;
} }
this.getFailToLoad = function() { this.getFailToLoad = function() {
return failToLoadTests; return failToLoadTests;
} }
this.decrementTotalScriptCount = function() { this.decrementTotalScriptCount = function() {
failedToLoad++; failedToLoad++;
} }
//It opens the source code for the test case that is run
this.openSourceWindow = function(idx) { this.openSourceWindow = function(idx) {
var ut = tests[idx]; var ut = tests[idx];
var popWnd = window.open("", "", "scrollbars=1, resizable=1"); var popWnd = window.open("", "", "scrollbars=1, resizable=1");
var innerHTML = ''; var innerHTML = '';
innerHTML += '<b>Test </b>'; innerHTML += '<b>Test </b>';
if (ut.id) if (ut.id) {
innerHTML += '<b>' + ut.id + '</b> <br /><br />'; innerHTML += '<b>' + ut.id + '</b> <br /><br />';
}
if (ut.description) { if (ut.description) {
innerHTML += '<b>Description</b>'; innerHTML += '<b>Description</b>';
@ -475,6 +664,7 @@ function sth(globalObj) {
popWnd.document.write(innerHTML); popWnd.document.write(innerHTML);
} }
//It loads all the chapters' xml that contains the informations of test cases
this.loadTestList = function(startTest) { this.loadTestList = function(startTest) {
var testsListLoader = new XMLHttpRequest(); var testsListLoader = new XMLHttpRequest();
var sth = this; var sth = this;
@ -482,18 +672,20 @@ function sth(globalObj) {
if (testsListLoader.readyState == 4) { if (testsListLoader.readyState == 4) {
oTests = testsListLoader.responseXML.getElementsByTagName('testGroup'); oTests = testsListLoader.responseXML.getElementsByTagName('testGroup');
var testSuite = testsListLoader.responseXML.getElementsByTagName('testSuite'); var testSuite = testsListLoader.responseXML.getElementsByTagName('testSuite');
XML_TARGETTESTSUITEVERSION = testSuite[0].getAttribute("version"); pageHelper.XML_TARGETTESTSUITEVERSION = testSuite[0].getAttribute("version");
XML_TARGETTESTSUITEDATE = testSuite[0].getAttribute("date"); pageHelper.XML_TARGETTESTSUITEDATE = testSuite[0].getAttribute("date");
//It sets version and date in Run and Result tab. It is called from here so that if user goes directly to Run or Results tab, version and date should reflect.
pageHelper.setVersionAndDate();
for (var i = 0; i < oTests.length; i++) { for (var i = 0; i < oTests.length; i++) {
aryTestGroups[i] = (oTests[i].text != undefined) ? oTests[i].text : oTests[i].textContent; aryTestGroups[i] = (oTests[i].text != undefined) ? oTests[i].text : oTests[i].textContent;
aryTestGroupsBuffer[i] = (oTests[i].text != undefined) ? oTests[i].text : oTests[i].textContent;
} }
xmlListLoaded = true; xmlListLoaded = true;
aryTestGroups.numTests = testsListLoader.responseXML.getElementsByTagName('testSuite')[0].getAttribute("numTests"); aryTestGroupsBuffer.numTests = aryTestGroups.numTests = testsListLoader.responseXML.getElementsByTagName('testSuite')[0].getAttribute("numTests");
startTest && sth.startTesting(); startTest && sth.startTesting();
} }
}; };
testsListLoader.open("GET", TESTLISTPATH, true); testsListLoader.open("GET", TEST_LIST_PATH, true);
testsListLoader.send(null); testsListLoader.send(null);
} }
} }
@ -501,7 +693,7 @@ function sth(globalObj) {
function sth_test(to, path) { function sth_test(to, path) {
//Create a sth_test from a test definition object, and path //Stores information in sth_test from a test definition object, and path
//TODO: Update sth framework to work more directly with test definitiion objects. //TODO: Update sth framework to work more directly with test definitiion objects.
//this.testObj = to; //this.testObj = to;
this.id = to.id; this.id = to.id;
@ -518,27 +710,41 @@ activeSth = new sth(window);
ES5Harness = activeSth; ES5Harness = activeSth;
loadSections(); loadSections();
function arrayContains(arr, expected) { function compareArray(aExpected, aActual) {
var found; if (aActual.length != aExpected.length) {
return false;
}
for (var i = 0; i < expected.length; i++) { aExpected.sort();
found = false; aActual.sort();
for (var j = 0; j < arr.length; j++) var s;
if (expected[i] === arr[j]) { for (var i = 0; i < aExpected.length; i++) {
found = true; if (aActual[i] != aExpected[i]) {
break; return false;
} }
if (!found)
return false
} }
return true; return true;
} }
function arrayContains(arr, expected) {
var found;
for (var i = 0; i < expected.length; i++) {
found = false;
for (var j = 0; j < arr.length; j++) {
if (expected[i] === arr[j]) {
found = true;
break;
}
}
if (!found) {
return false;
}
}
return true;
}
var supportsArrayIndexGettersOnArrays = undefined; var supportsArrayIndexGettersOnArrays = undefined;
function fnSupportsArrayIndexGettersOnArrays() { function fnSupportsArrayIndexGettersOnArrays() {
@ -562,9 +768,6 @@ function fnSupportsArrayIndexGettersOnArrays() {
return supportsArrayIndexGettersOnArrays; return supportsArrayIndexGettersOnArrays;
} }
var supportsArrayIndexGettersOnObjects = undefined; var supportsArrayIndexGettersOnObjects = undefined;
function fnSupportsArrayIndexGettersOnObjects() { function fnSupportsArrayIndexGettersOnObjects() {
if (typeof supportsArrayIndexGettersOnObjects !== "undefined") if (typeof supportsArrayIndexGettersOnObjects !== "undefined")
@ -604,11 +807,20 @@ function fnExists(f) {
var supportsStrict = undefined; var supportsStrict = undefined;
function fnSupportsStrict() { function fnSupportsStrict() {
"use strict"; "use strict";
if (supportsStrict !== undefined) return supportsStrict; if (supportsStrict !== undefined) {
try { eval('with ({}) {}'); supportsStrict = false; } catch (e) { supportsStrict = true; }; return supportsStrict;
}
try {
eval('with ({}) {}');
supportsStrict = false;
} catch (e) {
supportsStrict = true;
}
return supportsStrict; return supportsStrict;
} }
function fnGlobalObject() { function fnGlobalObject() {
return (function() { return this }).call(null); return (function() { return this }).call(null);
} }