| 1 |
function getTestList(uri) { |
| 2 |
var xmlhttp = new XMLHttpRequest(); |
| 3 |
// xmlhttp.open("GET", "/css-validator/autotest/testsuite/xml/"+ |
| 4 |
// "bugs.xml",false); |
| 5 |
xmlhttp.open("GET", uri, false); |
| 6 |
xmlhttp.setRequestHeader('Cache-Control','no-cache') |
| 7 |
// xmlhttp.setRequestHeader('Accept','application/json') |
| 8 |
// xmlhttp.onreadystatechange=function() { |
| 9 |
// if (xmlhttp.readyState==4) { |
| 10 |
// checkResults(testrow, resultrow, xmlhttp); |
| 11 |
// } |
| 12 |
// } |
| 13 |
xmlhttp.send(null); |
| 14 |
generateTestTable(xmlhttp); |
| 15 |
} |
| 16 |
|
| 17 |
// generate the table with the first row |
| 18 |
// parameter the id of the table created |
| 19 |
// the table is as follow: |
| 20 |
// <table id="tableid"> |
| 21 |
// <tr> |
| 22 |
// [0] <th>Test Case</th> |
| 23 |
// [1] <th>Profile</th> |
| 24 |
// [2] <th>Validity</th> (expected) |
| 25 |
// [3] <th>Errors</th> (int) (FIXME or "-" ? ) (expected) |
| 26 |
// [4] <th>Warnings</th> (int, expected). |
| 27 |
// </tr> |
| 28 |
function createTableFromID(tableid) { |
| 29 |
var table = document.createElement("table"); |
| 30 |
table.setAttribute("id", tableid); |
| 31 |
table.setAttribute("border", "2"); |
| 32 |
|
| 33 |
var tbody = document.createElement("tbody"); |
| 34 |
|
| 35 |
var tr = document.createElement("tr"); |
| 36 |
// first row |
| 37 |
var cell = document.createElement("th"); |
| 38 |
var tnode = document.createTextNode("Test Case: "+tableid+" "); |
| 39 |
cell.appendChild(tnode); |
| 40 |
var anc = document.createElement("a"); |
| 41 |
anc.setAttribute("href", "javascript:checkTableTests('"+tableid+"')"); |
| 42 |
tnode = document.createTextNode("[check]"); |
| 43 |
anc.appendChild(tnode); |
| 44 |
cell.appendChild(anc); |
| 45 |
tnode = document.createTextNode(" "); |
| 46 |
cell.appendChild(tnode); |
| 47 |
anc = document.createElement("a"); |
| 48 |
anc.setAttribute("href", "javascript:resetresults('"+tableid+"')"); |
| 49 |
tnode = document.createTextNode("[reset]"); |
| 50 |
anc.appendChild(tnode); |
| 51 |
cell.appendChild(anc); |
| 52 |
tr.appendChild(cell); |
| 53 |
|
| 54 |
cell = document.createElement("th"); |
| 55 |
tnode = document.createTextNode("Profile"); |
| 56 |
cell.appendChild(tnode); |
| 57 |
tr.appendChild(cell); |
| 58 |
|
| 59 |
cell = document.createElement("th"); |
| 60 |
tnode = document.createTextNode("Validity"); |
| 61 |
cell.appendChild(tnode); |
| 62 |
tr.appendChild(cell); |
| 63 |
|
| 64 |
cell = document.createElement("th"); |
| 65 |
tnode = document.createTextNode("Errors"); |
| 66 |
cell.appendChild(tnode); |
| 67 |
tr.appendChild(cell); |
| 68 |
|
| 69 |
cell = document.createElement("th"); |
| 70 |
tnode = document.createTextNode("Warnings"); |
| 71 |
cell.appendChild(tnode); |
| 72 |
tr.appendChild(cell); |
| 73 |
tbody.appendChild(tr); |
| 74 |
table.appendChild(tbody); |
| 75 |
|
| 76 |
return table; |
| 77 |
} |
| 78 |
|
| 79 |
function generateLinkToTable(tableId) { |
| 80 |
var controldiv = document.getElementById("controldiv"); |
| 81 |
if (controldiv) { |
| 82 |
var divul = controldiv.getElementsByTagName("ul"); |
| 83 |
if (divul.length > 0) { |
| 84 |
divul = divul[0]; |
| 85 |
} else { |
| 86 |
divul = document.createElement("ul"); |
| 87 |
controldiv.appendChild(divul); |
| 88 |
} |
| 89 |
var li = document.createElement("li"); |
| 90 |
var anc = document.createElement("a"); |
| 91 |
anc.setAttribute("href", "#"+tableId); |
| 92 |
var tnode = document.createTextNode(tableId); |
| 93 |
anc.appendChild(tnode); |
| 94 |
li.appendChild(anc); |
| 95 |
divul.appendChild(li); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
function getTestTable(typetag) { |
| 100 |
var tableId = "default"; |
| 101 |
if (typetag) { |
| 102 |
tableId = typetag.getAttribute("title"); |
| 103 |
} |
| 104 |
var table = document.getElementById(tableId); |
| 105 |
if (!table) { |
| 106 |
table = createTableFromID(tableId); |
| 107 |
var tableanchor = document.getElementById("tableanchor"); |
| 108 |
tableanchor.appendChild(table); |
| 109 |
generateLinkToTable(tableId); |
| 110 |
} |
| 111 |
// and attach the newly created table at the right place |
| 112 |
var tbody = table.getElementsByTagName("tbody"); |
| 113 |
if (tbody) { |
| 114 |
return tbody[0]; |
| 115 |
} |
| 116 |
return null; |
| 117 |
} |
| 118 |
|
| 119 |
function generateTestTable(req) { |
| 120 |
var testxml = req.responseXML; |
| 121 |
var docuri = testxml.documentURI; |
| 122 |
if (!docuri) { |
| 123 |
docuri = testxml.URL; // damn Safari... |
| 124 |
} |
| 125 |
var allTypes = testxml.getElementsByTagName("type"); |
| 126 |
// for each <type title="foo"> get the table, find test |
| 127 |
// and add them |
| 128 |
for (var i=0; i<allTypes.length; i++) { |
| 129 |
var testTable = getTestTable(allTypes[i]); |
| 130 |
var allTests = allTypes[i].getElementsByTagName("test"); |
| 131 |
fillTableWithTests(docuri, testTable, allTests); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
function fillTableWithTests(baseuri, table, allTests) { |
| 136 |
var base_uri = baseuri.substring(0, baseuri.lastIndexOf("css-validator/autotest")) + "css-validator/autotest"; |
| 137 |
var validator_uri = baseuri.substring(0, baseuri.lastIndexOf("css-validator/autotest")) + "css-validator/" |
| 138 |
for (var i=0; i<allTests.length; i++) { |
| 139 |
var indivTest = allTests[i]; |
| 140 |
// check the profile |
| 141 |
var cssprofile = "css21"; |
| 142 |
if (indivTest.hasAttribute("profile")) { |
| 143 |
cssprofile = indivTest.getAttribute("profile"); |
| 144 |
} |
| 145 |
// check the warning level |
| 146 |
var warningLevel = 1; |
| 147 |
if (indivTest.hasAttribute("warning")) { |
| 148 |
warningLevel = indivTest.getAttribute("warning"); |
| 149 |
} |
| 150 |
// check medium |
| 151 |
var medium = "all"; |
| 152 |
if (indivTest.hasAttribute("medium")) { |
| 153 |
medium = indivTest.getAttribute("medium"); |
| 154 |
} |
| 155 |
// and the test case local file... or URI. |
| 156 |
var testfile = indivTest.getElementsByTagName("file"); |
| 157 |
if (testfile.length != 0) { |
| 158 |
testfile = base_uri + "/" + testfile[0].firstChild.data; |
| 159 |
} else { |
| 160 |
testfile = (indivTest.getElementsByTagName("url"))[0].firstChild.data; |
| 161 |
} |
| 162 |
// the description, if any |
| 163 |
var testdesc = indivTest.getElementsByTagName("description"); |
| 164 |
if (testdesc.length != 0) { |
| 165 |
testdesc = testdesc[0].firstChild.data; |
| 166 |
} else { |
| 167 |
testdesc = "No Description"; |
| 168 |
} |
| 169 |
// validity |
| 170 |
var validity = (indivTest.getElementsByTagName("result"))[0].getAttribute("valid"); |
| 171 |
// expected errors |
| 172 |
var nberrors = indivTest.getElementsByTagName("errors"); |
| 173 |
if (nberrors.length != 0) { |
| 174 |
nberrors = nberrors[0].firstChild.data; |
| 175 |
} else { |
| 176 |
nberrors = 0; |
| 177 |
} |
| 178 |
|
| 179 |
// expected warnings. |
| 180 |
var nbwarnings = indivTest.getElementsByTagName("warnings"); |
| 181 |
if(nbwarnings.length != 0) { |
| 182 |
nbwarnings = nbwarnings[0].firstChild.data; |
| 183 |
} else { |
| 184 |
nbwarnings = 0; |
| 185 |
} |
| 186 |
// now create the TR |
| 187 |
// will be |
| 188 |
// <tr> |
| 189 |
// [0]<td rowspan="2"> |
| 190 |
// <a href="<testcase uri>">[Testcase]</a> |
| 191 |
// <a href="<result page>">[Results]</a> |
| 192 |
// <p>description</p> |
| 193 |
// </td> |
| 194 |
// [1]<td rowspan="2">profile</td> |
| 195 |
// [2]<td>validity</td> |
| 196 |
// [3]<td>errors</td> |
| 197 |
// [4]<td>warnings</td> |
| 198 |
// </tr> |
| 199 |
var tr = document.createElement("tr"); |
| 200 |
tr.setAttribute("class", "expected"); |
| 201 |
|
| 202 |
var cell = document.createElement("td"); |
| 203 |
cell.setAttribute("rowspan","2"); |
| 204 |
var anc = document.createElement("a"); |
| 205 |
anc.setAttribute("href",testfile); |
| 206 |
anc.setAttribute("medium", medium); |
| 207 |
anc.setAttribute("warning", warningLevel); |
| 208 |
var text = document.createTextNode("[Testcase]"); |
| 209 |
anc.appendChild(text); |
| 210 |
cell.appendChild(anc); |
| 211 |
|
| 212 |
text = document.createTextNode(" - "); |
| 213 |
cell.appendChild(text); |
| 214 |
|
| 215 |
anc = document.createElement("a"); |
| 216 |
var checkuri = validator_uri+"validator?uri="+ |
| 217 |
urlencode(testfile)+"&profile="+ |
| 218 |
cssprofile+"&usermedium="+medium+"&warning="+warningLevel; |
| 219 |
// FIXME medium, warning level |
| 220 |
anc.setAttribute("href",checkuri); |
| 221 |
text = document.createTextNode("[Result]"); |
| 222 |
anc.appendChild(text); |
| 223 |
cell.appendChild(anc); |
| 224 |
|
| 225 |
anc = document.createElement("p"); |
| 226 |
anc.innerHTML = testdesc; |
| 227 |
cell.appendChild(anc); |
| 228 |
tr.appendChild(cell); |
| 229 |
|
| 230 |
cell = document.createElement("td"); |
| 231 |
cell.setAttribute("rowspan","2"); |
| 232 |
text = document.createTextNode(cssprofile); |
| 233 |
cell.appendChild(text); |
| 234 |
tr.appendChild(cell); |
| 235 |
|
| 236 |
cell = document.createElement("td"); |
| 237 |
text = document.createTextNode(validity); |
| 238 |
cell.appendChild(text); |
| 239 |
tr.appendChild(cell); |
| 240 |
|
| 241 |
cell = document.createElement("td"); |
| 242 |
text = document.createTextNode(nberrors); |
| 243 |
cell.appendChild(text); |
| 244 |
tr.appendChild(cell); |
| 245 |
|
| 246 |
cell = document.createElement("td"); |
| 247 |
text = document.createTextNode(nbwarnings); |
| 248 |
cell.appendChild(text); |
| 249 |
tr.appendChild(cell); |
| 250 |
|
| 251 |
var result_row = getResultRow(); |
| 252 |
table.appendChild(result_row); |
| 253 |
table.insertBefore(tr,result_row); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
function getResultRow() { |
| 258 |
var tr = document.createElement("tr"); |
| 259 |
tr.setAttribute("class", "result"); |
| 260 |
var cell = document.createElement("td"); |
| 261 |
var text = document.createTextNode("-"); |
| 262 |
cell.appendChild(text); |
| 263 |
tr.appendChild(cell); |
| 264 |
|
| 265 |
cell = document.createElement("td"); |
| 266 |
text = document.createTextNode("-"); |
| 267 |
cell.appendChild(text); |
| 268 |
tr.appendChild(cell); |
| 269 |
|
| 270 |
cell = document.createElement("td"); |
| 271 |
text = document.createTextNode("-"); |
| 272 |
cell.appendChild(text); |
| 273 |
tr.appendChild(cell); |
| 274 |
|
| 275 |
return tr; |
| 276 |
} |