- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 03 Mar 2009 20:13:26 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/autotest/client
In directory hutz:/tmp/cvs-serv15220
Added Files:
buildtest.js checktests.js functions.js sample.html
Log Message:
pre-pre-pre-pre alpha verison of automated test
--- NEW FILE: sample.html ---
<html>
<head>
<style type="text/css">
.valid {
background-color: #7f7;
}
.invalid {
background-color: #f77;
}
table {
border-width: 2px;
border-color: black;
border-style: solid;
border-spacing: 0;
border-collapse: collapse;
}
th, td {
border-width: 2px 1px 2px 1px;
border-color: black;
border-style: solid;
margin: 0px;
text-align: center;
vertical-align: center;
}
</style>
<script type="text/javascript" src="functions.js"></script>
<script type="text/javascript" src="checktests.js"></script>
<script type="text/javascript" src="buildtest.js"></script>
</head>
<body>
<div id="tableanchor">
<p onclick="getTestList('http://jigsaw.w3.org/css-validator/autotest/testsuite/xml/bugs.xml')">Create Test Table for Bugs</p>
<p onclick="getTestList('http://jigsaw.w3.org/css-validator/autotest/testsuite/xml/general.xml')">Create Test Table for General</p>
<p onclick="getTestList('http://jigsaw.w3.org/css-validator/autotest/testsuite/xml/propertiesCSS2.xml')">Create Test Table for CSS2</p>
</div>
</div>
</body>
</html>
--- NEW FILE: functions.js ---
function urlencode(raw) {
raw = escape(raw);
raw = raw.replace(/\+/g, '%2B');
raw = raw.replace(/\*/g, '%2A');
raw = raw.replace(/\//g, '%2F');
raw = raw.replace(/@/g, '%40');
return raw;
}
--- NEW FILE: buildtest.js ---
function getTestList(e) {
var xmlhttp = new XMLHttpRequest();
// xmlhttp.open("GET", "/css-validator/autotest/testsuite/xml/"+
// "bugs.xml",false);
xmlhttp.open("GET", e, false);
// xmlhttp.setRequestHeader('Accept','application/json')
// xmlhttp.onreadystatechange=function() {
// if (xmlhttp.readyState==4) {
// checkResults(testrow, resultrow, xmlhttp);
// }
// }
xmlhttp.send(null);
generateTestTable(xmlhttp);
}
// generate the table with the first row
// parameter the id of the table created
// the table is as follow:
// <table id="tableid">
// <tr>
// [0] <th>Test Case</th>
// [1] <th>Profile</th>
// [2] <th>Validity</th> (expected)
// [3] <th>Errors</th> (int) (FIXME or "-" ? ) (expected)
// [4] <th>Warnings</th> (int, expected).
// </tr>
function createTableFromID(tableid) {
var table = document.createElement("table");
table.setAttribute("id", tableid);
table.setAttribute("border", "2");
var tr = document.createElement("tr");
// first row
var cell = document.createElement("th");
var tnode = document.createTextNode("Test Case: "+tableid+" ");
cell.appendChild(tnode);
var anc = document.createElement("a");
anc.setAttribute("href", "javascript:gogo('"+tableid+"')");
tnode = document.createTextNode("[check]");
anc.appendChild(tnode);
cell.appendChild(anc);
tnode = document.createTextNode(" ");
cell.appendChild(tnode);
anc = document.createElement("a");
anc.setAttribute("href", "javascript:resetresults('"+tableid+"')");
tnode = document.createTextNode("[reset]");
anc.appendChild(tnode);
cell.appendChild(anc);
tr.appendChild(cell);
cell = document.createElement("th");
tnode = document.createTextNode("Profile");
cell.appendChild(tnode);
tr.appendChild(cell);
cell = document.createElement("th");
tnode = document.createTextNode("Validity");
cell.appendChild(tnode);
tr.appendChild(cell);
cell = document.createElement("th");
tnode = document.createTextNode("Errors");
cell.appendChild(tnode);
tr.appendChild(cell);
cell = document.createElement("th");
tnode = document.createTextNode("Warnings");
cell.appendChild(tnode);
tr.appendChild(cell);
table.appendChild(tr);
return table;
}
function getTestTable(typetag) {
var tableId = "default";
if (typetag) {
tableId = typetag.getAttribute("title");
}
var table = document.getElementById(tableId);
if (!table) {
table = createTableFromID(tableId);
var tableanchor = document.getElementById("tableanchor");
tableanchor.appendChild(table);
}
// and attach the newly created table at the right place
return table;
}
function generateTestTable(req) {
var testxml = req.responseXML;
var allTypes = testxml.getElementsByTagName("type");
// for each <type title="foo"> get the table, find test
// and add them
for (var i=0; i<allTypes.length; i++) {
var testTable = getTestTable(allTypes[i]);
var allTests = allTypes[i].getElementsByTagName("test");
fillTableWithTests(testxml.documentURI, testTable, allTests);
}
}
function fillTableWithTests(baseuri, table, allTests) {
var base_uri = baseuri.substring(0, baseuri.lastIndexOf("css-validator/autotest")) + "css-validator/autotest";
var validator_uri = baseuri.substring(0, baseuri.lastIndexOf("css-validator/autotest")) + "css-validator/"
for (var i=0; i<allTests.length; i++) {
var indivTest = allTests[i];
// check the profile
var cssprofile = "css21";
if (indivTest.hasAttribute("profile")) {
cssprofile = indivTest.getAttribute("profile");
}
// and the test case local file... or URI.
var testfile = indivTest.getElementsByTagName("file");
if (testfile.length != 0) {
testfile = base_uri + "/" + testfile[0].firstChild.data;
} else {
testfile = (indivTest.getElementsByTagName("url"))[0].firstChild.data;
}
// the description, if any
var testdesc = indivTest.getElementsByTagName("description");
if (testdesc.length != 0) {
testdesc = testdesc[0].firstChild.data;
} else {
testdesc = "No Description";
}
// validity
var validity = (indivTest.getElementsByTagName("result"))[0].getAttribute("valid");
// expected errors
var nberrors = indivTest.getElementsByTagName("errors");
if (nberrors.length != 0) {
nberrors = nberrors[0].firstChild.data;
} else {
nberrors = 0;
}
// expected warnings.
var nbwarnings = indivTest.getElementsByTagName("warnings");
if(nbwarnings.length != 0) {
nbwarnings = nbwarnings[0].firstChild.data;
} else {
nbwarnings = 0;
}
// now create the TR
// will be
// <tr>
// [0]<td rowspan="2">
// <a href="<testcase uri>">[Testcase]</a>
// <a href="<result page>">[Results]</a>
// <p>description</p>
// </td>
// [1]<td rowspan="2">profile</td>
// [2]<td>validity</td>
// [3]<td>errors</td>
// [4]<td>warnings</td>
// </tr>
var tr = document.createElement("tr");
tr.setAttribute("class", "expected");
var cell = document.createElement("td");
cell.setAttribute("rowspan","2");
var anc = document.createElement("a");
anc.setAttribute("href",testfile);
var text = document.createTextNode("[Testcase]");
anc.appendChild(text);
cell.appendChild(anc);
text = document.createTextNode(" - ");
cell.appendChild(text);
anc = document.createElement("a");
var checkuri = validator_uri+"validator?uri="+
urlencode(testfile)+"&profile="+
cssprofile+"&usermedium=all&warning=1";
// FIXME medium, warning level
anc.setAttribute("href",checkuri);
text = document.createTextNode("[Result]");
anc.appendChild(text);
cell.appendChild(anc);
anc = document.createElement("p");
anc.innerHTML = testdesc;
cell.appendChild(anc);
tr.appendChild(cell);
cell = document.createElement("td");
cell.setAttribute("rowspan","2");
text = document.createTextNode(cssprofile);
cell.appendChild(text);
tr.appendChild(cell);
cell = document.createElement("td");
text = document.createTextNode(validity);
cell.appendChild(text);
tr.appendChild(cell);
cell = document.createElement("td");
text = document.createTextNode(nberrors);
cell.appendChild(text);
tr.appendChild(cell);
cell = document.createElement("td");
text = document.createTextNode(nbwarnings);
cell.appendChild(text);
tr.appendChild(cell);
var result_row = getResultRow();
table.appendChild(result_row);
table.insertBefore(tr,result_row);
}
}
function getResultRow() {
var tr = document.createElement("tr");
tr.setAttribute("class", "result");
var cell = document.createElement("td");
var text = document.createTextNode("-");
cell.appendChild(text);
tr.appendChild(cell);
cell = document.createElement("td");
text = document.createTextNode("-");
cell.appendChild(text);
tr.appendChild(cell);
cell = document.createElement("td");
text = document.createTextNode("-");
cell.appendChild(text);
tr.appendChild(cell);
return tr;
}
--- NEW FILE: checktests.js ---
function checkResults(testrow, resultrow, req) {
var allTestTds = testrow.getElementsByTagName("td");
var allTds = resultrow.getElementsByTagName("td");
var validation_res = eval('(' + req.responseText + ')');
var gotRegression = false;
allTds[0].removeChild(allTds[0].firstChild);
allTds[0].appendChild(document.createTextNode(validation_res.cssvalidation.validity));
var isValid = new Boolean(validation_res.cssvalidation.validity);
var validExpected = (allTestTds[2].innerHTML == "true");
if (validExpected == validation_res.cssvalidation.validity) {
allTds[0].setAttribute("class", "valid");
} else {
allTds[0].setAttribute("class", "invalid");
gotRegression = true;
}
var errorsExpected = parseInt(allTestTds[3].innerHTML,10);
allTds[1].innerHTML = validation_res.cssvalidation.result.errorcount;
if ( errorsExpected == validation_res.cssvalidation.result.errorcount) {
allTds[1].setAttribute("class", "valid");
} else {
allTds[1].setAttribute("class", "invalid");
gotRegression = true;
}
var warningsExpected = parseInt(allTestTds[4].innerHTML,10);
allTds[2].innerHTML = validation_res.cssvalidation.result.warningcount;
if ( warningsExpected == validation_res.cssvalidation.result.warningcount) {
allTds[2].setAttribute("class", "valid");
} else {
allTds[2].setAttribute("class", "invalid");
gotRegression = true;
}
allTestTds[0].setAttribute("class", (gotRegression ? "invalid" : "valid"));
}
function checkURI(testrow, resultrow, encodedURI, cssprofile) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "/css-validator/validator?uri="+
encodedURI+
"&profile="+cssprofile+
"&usermedium=all&output=json&warning=1",false);
xmlhttp.setRequestHeader('Accept','application/json')
// xmlhttp.onreadystatechange=function() {
// if (xmlhttp.readyState==4) {
// checkResults(testrow, resultrow, xmlhttp);
// }
// }
xmlhttp.send(null);
checkResults(testrow, resultrow, xmlhttp);
}
function checkTest(testrow, resultrow) {
var allTds = testrow.getElementsByTagName("td");
var anchor = allTds[0].getElementsByTagName("a");
var uri = urlencode(anchor[0].getAttribute("href"));
var cssprofile = allTds[1].firstChild.data;
checkURI(testrow, resultrow, uri, cssprofile)
}
function gogo(tableid) {
var testTable = document.getElementById(tableid);
if (testTable) {
var allTests = testTable.getElementsByTagName('tr')
for (i=0; i< allTests.length; i++) {
var cname = allTests[i].className;
if (cname == "expected") {
checkTest(allTests[i], allTests[i+1]);
}
}
}
}
Received on Tuesday, 3 March 2009 20:13:38 UTC