1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902
|
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
// requires jQuery
const kTestSuiteVersion = '20101001';
const kTestSuiteHome = '../' + kTestSuiteVersion + '/';
const kTestInfoDataFile = 'testinfo.data';
const kChapterData = [
{
'file' : 'about.html',
'title' : 'About the CSS 2.1 Specification',
},
{
'file' : 'intro.html',
'title' : 'Introduction to CSS 2.1',
},
{
'file' : 'conform.html',
'title' : 'Conformance: Requirements and Recommendations',
},
{
'file' : "syndata.html",
'title' : 'Syntax and basic data types',
},
{
'file' : 'selector.html' ,
'title' : 'Selectors',
},
{
'file' : 'cascade.html',
'title' : 'Assigning property values, Cascading, and Inheritance',
},
{
'file' : 'media.html',
'title' : 'Media types',
},
{
'file' : 'box.html' ,
'title' : 'Box model',
},
{
'file' : 'visuren.html',
'title' : 'Visual formatting model',
},
{
'file' :'visudet.html',
'title' : 'Visual formatting model details',
},
{
'file' : 'visufx.html',
'title' : 'Visual effects',
},
{
'file' : 'generate.html',
'title' : 'Generated content, automatic numbering, and lists',
},
{
'file' : 'page.html',
'title' : 'Paged media',
},
{
'file' : 'colors.html',
'title' : 'Colors and Backgrounds',
},
{
'file' : 'fonts.html',
'title' : 'Fonts',
},
{
'file' : 'text.html',
'title' : 'Text',
},
{
'file' : 'tables.html',
'title' : 'Tables',
},
{
'file' : 'ui.html',
'title' : 'User interface',
},
{
'file' : 'aural.html',
'title' : 'Appendix A. Aural style sheets',
},
{
'file' : 'refs.html',
'title' : 'Appendix B. Bibliography',
},
{
'file' : 'changes.html',
'title' : 'Appendix C. Changes',
},
{
'file' : 'sample.html',
'title' : 'Appendix D. Default style sheet for HTML 4',
},
{
'file' : 'zindex.html',
'title' : 'Appendix E. Elaborate description of Stacking Contexts',
},
{
'file' : 'propidx.html',
'title' : 'Appendix F. Full property table',
},
{
'file' : 'grammar.html',
'title' : 'Appendix G. Grammar of CSS',
},
{
'file' : 'other.html',
'title' : 'Other',
},
];
const kHTML4Data = {
'path' : 'html4',
'suffix' : '.htm'
};
const kXHTML1Data = {
'path' : 'xhtml1',
'suffix' : '.xht'
};
// Results popup
const kResultsSelector = [
{
'name': 'All Tests',
'handler' : function(self) { self.showResultsForAllTests(); },
'exporter' : function(self) { self.exportResultsForAllTests(); }
},
{
'name': 'Completed Tests',
'handler' : function(self) { self.showResultsForCompletedTests(); },
'exporter' : function(self) { self.exportResultsForCompletedTests(); }
},
{
'name': 'Passing Tests',
'handler' : function(self) { self.showResultsForTestsWithStatus('pass'); },
'exporter' : function(self) { self.exportResultsForTestsWithStatus('pass'); }
},
{
'name': 'Failing Tests',
'handler' : function(self) { self.showResultsForTestsWithStatus('fail'); },
'exporter' : function(self) { self.exportResultsForTestsWithStatus('fail'); }
},
{
'name': 'Skipped Tests',
'handler' : function(self) { self.showResultsForTestsWithStatus('skipped'); },
'exporter' : function(self) { self.exportResultsForTestsWithStatus('skipped'); }
},
{
'name': 'Invalid Tests',
'handler' : function(self) { self.showResultsForTestsWithStatus('invalid'); },
'exporter' : function(self) { self.exportResultsForTestsWithStatus('invalid'); }
},
{
'name': 'Tests where HTML4 and XHTML1 results differ',
'handler' : function(self) { self.showResultsForTestsWithMismatchedResults(); },
'exporter' : function(self) { self.exportResultsForTestsWithMismatchedResults(); }
},
{
'name': 'Tests Not Run',
'handler' : function(self) { self.showResultsForTestsNotRun(); },
'exporter' : function(self) { self.exportResultsForTestsNotRun(); }
}
];
function Test(testInfoLine)
{
var fields = testInfoLine.split('\t');
this.id = fields[0];
this.reference = fields[1];
this.title = fields[2];
this.flags = fields[3];
this.links = fields[4];
this.assertion = fields[5];
this.paged = false;
this.testHTML = true;
this.testXHTML = true;
if (this.flags) {
this.paged = this.flags.indexOf('paged') != -1;
if (this.flags.indexOf('nonHTML') != -1)
this.testHTML = false;
if (this.flags.indexOf('HTMLonly') != -1)
this.testXHTML = false;
}
this.completedHTML = false; // true if this test has a result (pass, fail or skip)
this.completedXHTML = false; // true if this test has a result (pass, fail or skip)
this.statusHTML = '';
this.statusXHTML = '';
if (!this.links)
this.links = "other.html"
}
Test.prototype.runForFormat = function(format)
{
if (format == 'html4')
return this.testHTML;
if (format == 'xhtml1')
return this.testXHTML;
return true;
}
Test.prototype.completedForFormat = function(format)
{
if (format == 'html4')
return this.completedHTML;
if (format == 'xhtml1')
return this.completedXHTML;
return true;
}
Test.prototype.statusForFormat = function(format)
{
if (format == 'html4')
return this.statusHTML;
if (format == 'xhtml1')
return this.statusXHTML;
return true;
}
function ChapterSection(link)
{
var result= link.match(/^([.\w]+)(#.+)?$/);
if (result != null) {
this.file = result[1];
this.anchor = result[2];
}
this.testCountHTML = 0;
this.testCountXHTML = 0;
this.tests = [];
}
ChapterSection.prototype.countTests = function()
{
this.testCountHTML = 0;
this.testCountXHTML = 0;
for (var i = 0; i < this.tests.length; ++i) {
var currTest = this.tests[i];
if (currTest.testHTML)
++this.testCountHTML;
if (currTest.testXHTML)
++this.testCountXHTML;
}
}
function Chapter(chapterInfo)
{
this.file = chapterInfo.file;
this.title = chapterInfo.title;
this.testCountHTML = 0;
this.testCountXHTML = 0;
this.sections = []; // array of ChapterSection
}
Chapter.prototype.description = function(format)
{
return this.title + ' (' + this.testCount(format) + ' tests, ' + this.untestedCount(format) + ' untested)';
}
Chapter.prototype.countTests = function()
{
this.testCountHTML = 0;
this.testCountXHTML = 0;
for (var i = 0; i < this.sections.length; ++i) {
var currSection = this.sections[i];
currSection.countTests();
this.testCountHTML += currSection.testCountHTML;
this.testCountXHTML += currSection.testCountXHTML;
}
}
Chapter.prototype.testCount = function(format)
{
if (format == 'html4')
return this.testCountHTML;
if (format == 'xhtml1')
return this.testCountXHTML;
return 0;
}
Chapter.prototype.untestedCount = function(format)
{
var completedProperty = format == 'html4' ? 'completedHTML' : 'completedXHTML';
var count = 0;
for (var i = 0; i < this.sections.length; ++i) {
var currSection = this.sections[i];
for (var j = 0; j < currSection.tests.length; ++j) {
count += currSection.tests[j].completedForFormat(format) ? 0 : 1;
}
}
return count;
}
// Utils
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
function TestSuite()
{
this.chapterSections = {}; // map of links to ChapterSections
this.tests = {}; // map of test id to test info
this.chapters = {}; // map of file name to chapter
this.currentChapter = null;
this.currentChapterTests = []; // array of tests for the current chapter.
this.currChapterTestIndex = -1; // index of test in the current chapter
this.format = '';
this.formatChanged('html4');
this.testInfoLoaded = false;
this.populatingDatabase = false;
var testInfoPath = kTestSuiteHome + kTestInfoDataFile;
this.loadTestInfo(testInfoPath);
}
TestSuite.prototype.loadTestInfo = function(testInfoPath)
{
var _self = this;
this.asyncLoad(testInfoPath, 'data', function(data, status) {
_self.testInfoDataLoaded(data, status);
});
}
TestSuite.prototype.testInfoDataLoaded = function(data, status)
{
if (status != 'success') {
alert("Failed to load testinfo.data. Database of tests will not be initialized.");
return;
}
this.parseTests(data);
this.buildChapters();
this.testInfoLoaded = true;
this.fillChapterPopup();
this.initializeControls();
this.openDatabase();
}
TestSuite.prototype.parseTests = function(data)
{
var lines = data.split('\n');
// First line is column labels
for (var i = 1; i < lines.length; ++i) {
var test = new Test(lines[i]);
if (test.id.length > 0)
this.tests[test.id] = test;
}
}
TestSuite.prototype.buildChapters = function()
{
for (var testID in this.tests) {
var currTest = this.tests[testID];
// FIXME: tests with more than one link will be presented to the user
// twice. Be smarter about avoiding this.
var testLinks = currTest.links.split(',');
for (var i = 0; i < testLinks.length; ++i) {
var link = testLinks[i];
var section = this.chapterSections[link];
if (!section) {
section = new ChapterSection(link);
this.chapterSections[link] = section;
}
section.tests.push(currTest);
}
}
for (var i = 0; i < kChapterData.length; ++i) {
var chapter = new Chapter(kChapterData[i]);
chapter.index = i;
this.chapters[chapter.file] = chapter;
}
for (var sectionName in this.chapterSections) {
var section = this.chapterSections[sectionName];
var file = section.file;
var chapter = this.chapters[file];
if (!chapter)
window.console.log('failed to find chapter ' + file + ' in chapter data.');
chapter.sections.push(section);
}
for (var chapterName in this.chapters) {
var currChapter = this.chapters[chapterName];
currChapter.sections.sort();
currChapter.countTests();
}
}
TestSuite.prototype.indexOfChapter = function(chapter)
{
for (var i = 0; i < kChapterData.length; ++i) {
if (kChapterData[i].file == chapter.file)
return i;
}
window.console.log('indexOfChapter for ' + chapter.file + ' failed');
return -1;
}
TestSuite.prototype.chapterAtIndex = function(index)
{
if (index < 0 || index >= kChapterData.length)
return null;
return this.chapters[kChapterData[index].file];
}
TestSuite.prototype.fillChapterPopup = function()
{
var select = document.getElementById('chapters')
select.innerHTML = ''; // Remove all children.
for (var i = 0; i < kChapterData.length; ++i) {
var chapterData = kChapterData[i];
var chapter = this.chapters[chapterData.file];
var option = document.createElement('option');
option.innerText = chapter.description(this.format);
option._chapter = chapter;
select.appendChild(option);
}
}
TestSuite.prototype.updateChapterPopup = function()
{
var select = document.getElementById('chapters')
var currOption = select.firstChild;
for (var i = 0; i < kChapterData.length; ++i) {
var chapterData = kChapterData[i];
var chapter = this.chapters[chapterData.file];
if (!chapter)
continue;
currOption.innerText = chapter.description(this.format);
currOption = currOption.nextSibling;
}
}
TestSuite.prototype.buildTestListForChapter = function(chapter)
{
this.currentChapterTests = this.testListForChapter(chapter);
}
TestSuite.prototype.testListForChapter = function(chapter)
{
var testList = [];
for (var i in chapter.sections) {
var currSection = chapter.sections[i];
for (var j = 0; j < currSection.tests.length; ++j) {
var currTest = currSection.tests[j];
if (currTest.runForFormat(this.format))
testList.push(currTest);
}
}
// FIXME: test may occur more than once.
testList.sort(function(a, b) {
return a.id.localeCompare(b.id);
});
return testList;
}
TestSuite.prototype.initializeControls = function()
{
var chaptersPopup = document.getElementById('chapters');
var _self = this;
chaptersPopup.addEventListener('change', function() {
_self.chapterPopupChanged();
}, false);
this.chapterPopupChanged();
// Results popup
var resultsPopup = document.getElementById('results-popup');
resultsPopup.innerHTML = '';
for (var i = 0; i < kResultsSelector.length; ++i) {
var option = document.createElement('option');
option.innerText = kResultsSelector[i].name;
resultsPopup.appendChild(option);
}
}
TestSuite.prototype.chapterPopupChanged = function()
{
var chaptersPopup = document.getElementById('chapters');
var selectedChapter = chaptersPopup.options[chaptersPopup.selectedIndex]._chapter;
this.setSelectedChapter(selectedChapter);
}
TestSuite.prototype.fillTestList = function()
{
var statusProperty = this.format == 'html4' ? 'statusHTML' : 'statusXHTML';
var testList = document.getElementById('test-list');
testList.innerHTML = '';
for (var i = 0; i < this.currentChapterTests.length; ++i) {
var currTest = this.currentChapterTests[i];
var option = document.createElement('option');
option.innerText = currTest.id;
option.className = currTest[statusProperty];
option._test = currTest;
testList.appendChild(option);
}
}
TestSuite.prototype.updateTestList = function()
{
var statusProperty = this.format == 'html4' ? 'statusHTML' : 'statusXHTML';
var testList = document.getElementById('test-list');
var options = testList.getElementsByTagName('option');
for (var i = 0; i < options.length; ++i) {
var currOption = options[i];
currOption.className = currOption._test[statusProperty];
}
}
TestSuite.prototype.setSelectedChapter = function(chapter)
{
this.currentChapter = chapter;
this.buildTestListForChapter(this.currentChapter);
this.currChapterTestIndex = -1;
this.fillTestList();
this.goToTestIndex(0);
var chaptersPopup = document.getElementById('chapters');
chaptersPopup.selectedIndex = this.indexOfChapter(chapter);
}
/* ------------------------------------------------------- */
TestSuite.prototype.passTest = function()
{
this.recordResult(this.currentTestName(), 'pass');
this.nextTest();
}
TestSuite.prototype.failTest = function()
{
this.recordResult(this.currentTestName(), 'fail');
this.nextTest();
}
TestSuite.prototype.invalidTest = function()
{
this.recordResult(this.currentTestName(), 'invalid');
this.nextTest();
}
TestSuite.prototype.skipTest = function(reason)
{
this.recordResult(this.currentTestName(), 'skipped', reason);
this.nextTest();
}
TestSuite.prototype.nextTest = function()
{
if (this.currChapterTestIndex < this.currentChapterTests.length - 1)
this.goToTestIndex(this.currChapterTestIndex + 1);
else {
var currChapterIndex = this.indexOfChapter(this.currentChapter);
this.goToChapterIndex(currChapterIndex + 1);
}
}
TestSuite.prototype.previousTest = function()
{
if (this.currChapterTestIndex > 0)
this.goToTestIndex(this.currChapterTestIndex - 1);
else {
var currChapterIndex = this.indexOfChapter(this.currentChapter);
if (currChapterIndex > 0)
this.goToChapterIndex(currChapterIndex - 1);
}
}
TestSuite.prototype.goToNextIncompleteTest = function()
{
var completedProperty = this.format == 'html4' ? 'completedHTML' : 'completedXHTML';
// Look to the end of this chapter.
for (var i = this.currChapterTestIndex + 1; i < this.currentChapterTests.length; ++i) {
if (!this.currentChapterTests[i][completedProperty]) {
this.goToTestIndex(i);
return;
}
}
// Start looking through later chapter
var currChapterIndex = this.indexOfChapter(this.currentChapter);
for (var c = currChapterIndex + 1; c < kChapterData.length; ++c) {
var chapterData = this.chapterAtIndex(c);
var testIndex = this.firstIncompleteTestIndex(chapterData);
if (testIndex != -1) {
this.goToChapterIndex(c);
this.goToTestIndex(testIndex);
break;
}
}
}
TestSuite.prototype.firstIncompleteTestIndex = function(chapter)
{
var completedProperty = this.format == 'html4' ? 'completedHTML' : 'completedXHTML';
var chapterTests = this.testListForChapter(chapter);
for (var i = 0; i < chapterTests.length; ++i) {
if (!chapterTests[i][completedProperty])
return i;
}
return -1;
}
/* ------------------------------------------------------- */
TestSuite.prototype.goToTestByName = function(testName)
{
var match = testName.match(/^(?:(html4|xhtml1)\/)?([\w-_]+)(\.xht|\.htm)?/);
if (!match)
return false;
var prefix = match[1];
var testId = match[2];
var extension = match[3];
var format = this.format;
if (prefix)
format = prefix;
else if (extension) {
if (extension == kXHTML1Data.suffix)
format = kXHTML1Data.path;
else if (extension == kHTML4Data.suffix)
format = kHTML4Data.path;
}
this.switchToFormat(format);
var test = this.tests[testId];
if (!test)
return false;
// Find the first chapter.
var links = test.links.split(',');
if (links.length == 0) {
window.console.log('test ' + test.id + 'had no links.');
return false;
}
var firstLink = links[0];
var result = firstLink.match(/^([.\w]+)(#.+)?$/);
if (result)
firstLink = result[1];
// Find the chapter and index of the test.
for (var i = 0; i < kChapterData.length; ++i) {
var chapterData = kChapterData[i];
if (chapterData.file == firstLink) {
this.goToChapterIndex(i);
for (var j = 0; j < this.currentChapterTests.length; ++j) {
var currTest = this.currentChapterTests[j];
if (currTest.id == testId) {
this.goToTestIndex(j);
return true;
}
}
}
}
return false;
}
TestSuite.prototype.goToTestIndex = function(index)
{
if (index >= 0 && index < this.currentChapterTests.length) {
this.currChapterTestIndex = index;
this.loadCurrentTest();
}
}
TestSuite.prototype.goToChapterIndex = function(chapterIndex)
{
if (chapterIndex >= 0 && chapterIndex < kChapterData.length) {
var chapterFile = kChapterData[chapterIndex].file;
this.setSelectedChapter(this.chapters[chapterFile]);
}
}
TestSuite.prototype.currentTestName = function()
{
if (this.currChapterTestIndex < 0 || this.currChapterTestIndex >= this.currentChapterTests.length)
return undefined;
return this.currentChapterTests[this.currChapterTestIndex].id;
}
TestSuite.prototype.loadCurrentTest = function()
{
var theTest = this.currentChapterTests[this.currChapterTestIndex];
if (!theTest) {
this.configureForManualTest();
this.clearTest();
return;
}
if (theTest.reference) {
this.configureForRefTest();
this.loadRef(theTest);
} else {
this.configureForManualTest();
}
this.loadTest(theTest);
this.updateProgressLabel();
document.getElementById('test-list').selectedIndex = this.currChapterTestIndex;
}
TestSuite.prototype.updateProgressLabel = function()
{
document.getElementById('test-index').innerText = this.currChapterTestIndex + 1;
document.getElementById('chapter-test-count').innerText = this.currentChapterTests.length;
}
TestSuite.prototype.configureForRefTest = function()
{
$('#test-content').addClass('with-ref');
}
TestSuite.prototype.configureForManualTest = function()
{
$('#test-content').removeClass('with-ref');
}
TestSuite.prototype.loadTest = function(test)
{
var iframe = document.getElementById('test-frame');
iframe.src = 'about:blank';
var url = this.urlForTest(test.id);
window.setTimeout(function() {
iframe.src = url;
}, 0);
document.getElementById('test-title').innerText = test.title;
document.getElementById('test-url').innerText = this.pathForTest(test.id);
document.getElementById('test-assertion').innerText = test.assertion;
document.getElementById('test-flags').innerText = test.flags;
this.processFlags(test);
}
TestSuite.prototype.processFlags = function(test)
{
if (test.paged)
$('#test-content').addClass('print');
else
$('#test-content').removeClass('print');
var showWarning = false;
var warning = '';
if (test.flags.indexOf('font') != -1)
warning = 'Requires a specific font to be installed.';
if (test.flags.indexOf('http') != -1) {
if (warning != '')
warning += ' ';
warning += 'Must be tested over HTTP, with custom HTTP headers.';
}
if (test.paged) {
if (warning != '')
warning += ' ';
warning += 'Test via the browser\'s Print Preview.';
}
document.getElementById('warning').innerText = warning;
if (warning.length > 0)
$('#test-content').addClass('warn');
else
$('#test-content').removeClass('warn');
}
TestSuite.prototype.clearTest = function()
{
var iframe = document.getElementById('test-frame');
iframe.src = 'about:blank';
document.getElementById('test-title').innerText = '';
document.getElementById('test-url').innerText = '';
document.getElementById('test-assertion').innerText = '';
document.getElementById('test-flags').innerText = '';
$('#test-content').removeClass('print');
$('#test-content').removeClass('warn');
document.getElementById('warning').innerText = '';
}
TestSuite.prototype.loadRef = function(test)
{
// Suites 20101001 and earlier used .xht refs, even for HTML tests, so strip off
// the extension and use the same format as the test.
var ref = test.reference.replace(/(\.xht)?$/, '');
var iframe = document.getElementById('ref-frame');
iframe.src = this.urlForTest(ref);
}
TestSuite.prototype.pathForTest = function(testName)
{
var prefix = this.formatInfo.path;
var suffix = this.formatInfo.suffix;
return prefix + '/' + testName + suffix;
}
TestSuite.prototype.urlForTest = function(testName)
{
return kTestSuiteHome + this.pathForTest(testName);
}
/* ------------------------------------------------------- */
TestSuite.prototype.recordResult = function(testName, resolution, comment)
{
if (!testName)
return;
this.beginAppendingOutput();
this.appendResultToOutput(this.formatInfo, testName, resolution, comment);
this.endAppendingOutput();
if (comment == undefined)
comment = '';
this.storeTestResult(testName, this.format, resolution, comment, navigator.userAgent);
var htmlStatus = null;
var xhtmlStatus = null;
if (this.format == 'html4')
htmlStatus = resolution;
if (this.format == 'xhtml1')
xhtmlStatus = resolution;
this.markTestCompleted(testName, htmlStatus, xhtmlStatus);
this.updateTestList();
this.updateSummaryData();
this.updateChapterPopup();
}
TestSuite.prototype.beginAppendingOutput = function()
{
}
TestSuite.prototype.endAppendingOutput = function()
{
var output = document.getElementById('output');
output.scrollTop = output.scrollHeight;
}
TestSuite.prototype.appendResultToOutput = function(formatData, testName, resolution, comment)
{
var output = document.getElementById('output');
var result = formatData.path + '/' + testName + formatData.suffix + '\t' + resolution;
if (comment)
result += '\t(' + comment + ')';
var line = document.createElement('p');
line.className = resolution;
line.appendChild(document.createTextNode(result));
output.appendChild(line);
}
TestSuite.prototype.clearOutput = function()
{
document.getElementById('output').innerHTML = '';
}
/* ------------------------------------------------------- */
TestSuite.prototype.switchToFormat = function(formatString)
{
if (formatString == 'html4')
document.harness.format.html4.checked = true;
else
document.harness.format.xhtml1.checked = true;
this.formatChanged(formatString);
}
TestSuite.prototype.formatChanged = function(formatString)
{
if (this.format == formatString)
return;
this.format = formatString;
if (formatString == 'html4')
this.formatInfo = kHTML4Data;
else
this.formatInfo = kXHTML1Data;
// try to keep the current test selected
var selectedTestName;
if (this.currChapterTestIndex >= 0 && this.currChapterTestIndex < this.currentChapterTests.length)
selectedTestName = this.currentChapterTests[this.currChapterTestIndex].id;
if (this.currentChapter) {
this.buildTestListForChapter(this.currentChapter);
this.fillTestList();
this.goToTestByName(selectedTestName);
}
this.updateChapterPopup();
this.updateTestList();
this.updateProgressLabel();
}
/* ------------------------------------------------------- */
TestSuite.prototype.asyncLoad = function(url, type, handler)
{
$.get(url, handler, type);
}
/* ------------------------------------------------------- */
TestSuite.prototype.exportResults = function(resultTypeIndex)
{
var resultInfo = kResultsSelector[resultTypeIndex];
if (!resultInfo)
return;
resultInfo.exporter(this);
}
TestSuite.prototype.exportHeader = function()
{
var result = '# Safari 5.0.2' + ' ' + navigator.platform + '\n';
result += '# ' + navigator.userAgent + '\n';
result += '# http://test.csswg.org/suites/css2.1/' + kTestSuiteVersion + '/\n';
result += 'testname\tresult\n';
return result;
}
TestSuite.prototype.createExportLine = function(formatData, testName, resolution, comment)
{
var result = formatData.path + '/' + testName + '\t' + resolution;
if (comment)
result += '\t(' + comment + ')';
return result;
}
TestSuite.prototype.exportQueryComplete = function(data)
{
window.open("data:text/plain," + escape(data))
}
TestSuite.prototype.resultsPopupChanged = function(index)
{
var resultInfo = kResultsSelector[index];
if (!resultInfo)
return;
this.clearOutput();
resultInfo.handler(this);
var enableExport = resultInfo.exporter != undefined;
document.getElementById('export-button').disabled = !enableExport;
}
/* ------------------------- Import ------------------------------- */
/*
Import format is the same as the export format, namely:
testname<tab>result
with optional trailing <tab>comment.
html4/absolute-non-replaced-height-002<tab>pass
xhtml1/absolute-non-replaced-height-002<tab>?
Lines starting with # are ignored.
The "testname<tab>result" line is ignored.
*/
TestSuite.prototype.importResults = function(data)
{
var testsToImport = [];
var lines = data.split('\n');
for (var i = 0; i < lines.length; ++i) {
var currLine = lines[i];
if (currLine.length == 0 || currLine.charAt(0) == '#')
continue;
var match = currLine.match(/^(html4|xhtml1)\/([\w-_]+)\t([\w?]+)\t?(.+)?$/);
if (match) {
var test = { 'id' : match[2] };
test.format = match[1];
test.result = match[3];
test.comment = match[4];
if (test.result != '?')
testsToImport.push(test);
} else {
window.console.log('failed to match line \'' + currLine + '\'');
}
}
this.importTestResults(testsToImport);
this.resetTestStatus();
this.updateSummaryData();
}
/* --------------------- Clear Results --------------------------- */
/*
Clear results format is either same as the export format, or
a list of bare test IDs (e.g. absolute-non-replaced-height-001)
in which case both HTML4 and XHTML1 results are cleared.
*/
TestSuite.prototype.clearResults = function(data)
{
var testsToClear = [];
var lines = data.split('\n');
for (var i = 0; i < lines.length; ++i) {
var currLine = lines[i];
if (currLine.length == 0 || currLine.charAt(0) == '#')
continue;
// Look for format/test with possible extension
var result = currLine.match(/^((html4|xhtml1)?)\/?([\w-_]+)/);
if (result) {
var testId = result[3];
var format = result[1];
var clearHTML = format.length == 0 || format == 'html4';
var clearXHTML = format.length == 0 || format == 'xhtml1';
var result = { 'id' : testId };
result.clearHTML = clearHTML;
result.clearXHTML = clearXHTML;
testsToClear.push(result);
} else {
window.console.log('failed to match line ' + currLine);
}
}
this.clearTestResults(testsToClear);
this.resetTestStatus();
this.updateSummaryData();
}
/* -------------------------------------------------------- */
TestSuite.prototype.exportResultsCompletion = function(exportTests)
{
// Lame workaround for ORDER BY not working
exportTests.sort(function(a, b) {
return a.test.localeCompare(b.test);
});
var exportLines = [];
for (var i = 0; i < exportTests.length; ++i) {
var currTest = exportTests[i];
if (currTest.html4 != '')
exportLines.push(currTest.html4);
if (currTest.xhtml1 != '')
exportLines.push(currTest.xhtml1);
}
var exportString = this.exportHeader() + exportLines.join('\n');
this.exportQueryComplete(exportString);
}
/* -------------------------------------------------------- */
TestSuite.prototype.showResultsForCompletedTests = function()
{
this.beginAppendingOutput();
var _self = this;
this.queryDatabaseForCompletedTests(
function(item) {
if (item.hstatus)
_self.appendResultToOutput(kHTML4Data, item.test, item.hstatus, item.hcomment);
if (item.xstatus)
_self.appendResultToOutput(kXHTML1Data, item.test, item.xstatus, item.xcomment);
},
function() {
_self.endAppendingOutput();
}
);
}
TestSuite.prototype.exportResultsForCompletedTests = function()
{
var exportTests = []; // each test will have html and xhtml items on it
var _self = this;
this.queryDatabaseForCompletedTests(
function(item) {
var htmlLine = '';
if (item.hstatus)
htmlLine= _self.createExportLine(kHTML4Data, item.test, item.hstatus, item.hcomment);
var xhtmlLine = '';
if (item.xstatus)
xhtmlLine = _self.createExportLine(kXHTML1Data, item.test, item.xstatus, item.xcomment);
exportTests.push({
'test' : item.test,
'html4' : htmlLine,
'xhtml1' : xhtmlLine });
},
function() {
_self.exportResultsCompletion(exportTests);
}
);
}
/* -------------------------------------------------------- */
TestSuite.prototype.showResultsForAllTests = function()
{
this.beginAppendingOutput();
var _self = this;
this.queryDatabaseForAllTests('test',
function(item) {
_self.appendResultToOutput(kHTML4Data, item.test, item.hstatus, item.hcomment);
_self.appendResultToOutput(kXHTML1Data, item.test, item.xstatus, item.xcomment);
},
function() {
_self.endAppendingOutput();
});
}
TestSuite.prototype.exportResultsForAllTests = function()
{
var exportTests = [];
var _self = this;
this.queryDatabaseForAllTests('test',
function(item) {
var htmlLine= _self.createExportLine(kHTML4Data, item.test, item.hstatus ? item.hstatus : '?', item.hcomment);
var xhtmlLine = _self.createExportLine(kXHTML1Data, item.test, item.xstatus ? item.xstatus : '?', item.xcomment);
exportTests.push({
'test' : item.test,
'html4' : htmlLine,
'xhtml1' : xhtmlLine });
},
function() {
_self.exportResultsCompletion(exportTests);
}
);
}
/* -------------------------------------------------------- */
TestSuite.prototype.showResultsForTestsNotRun = function()
{
this.beginAppendingOutput();
var _self = this;
this.queryDatabaseForTestsNotRun(
function(item) {
if (!item.hstatus)
_self.appendResultToOutput(kHTML4Data, item.test, '?', item.hcomment);
if (!item.xstatus)
_self.appendResultToOutput(kXHTML1Data, item.test, '?', item.xcomment);
},
function() {
_self.endAppendingOutput();
}
);
}
TestSuite.prototype.exportResultsForTestsNotRun = function()
{
var exportTests = [];
var _self = this;
this.queryDatabaseForTestsNotRun(
function(item) {
var htmlLine = '';
if (!item.hstatus)
htmlLine= _self.createExportLine(kHTML4Data, item.test, '?', item.hcomment);
var xhtmlLine = '';
if (!item.xstatus)
xhtmlLine = _self.createExportLine(kXHTML1Data, item.test, '?', item.xcomment);
exportTests.push({
'test' : item.test,
'html4' : htmlLine,
'xhtml1' : xhtmlLine });
},
function() {
_self.exportResultsCompletion(exportTests);
}
);
}
/* -------------------------------------------------------- */
TestSuite.prototype.showResultsForTestsWithStatus = function(status)
{
this.beginAppendingOutput();
var _self = this;
this.queryDatabaseForTestsWithStatus(status,
function(item) {
if (item.hstatus == status)
_self.appendResultToOutput(kHTML4Data, item.test, item.hstatus, item.hcomment);
if (item.xstatus == status)
_self.appendResultToOutput(kXHTML1Data, item.test, item.xstatus, item.xcomment);
},
function() {
_self.endAppendingOutput();
}
);
}
TestSuite.prototype.exportResultsForTestsWithStatus = function(status)
{
var exportTests = [];
var _self = this;
this.queryDatabaseForTestsWithStatus(status,
function(item) {
var htmlLine = '';
if (item.hstatus == status)
htmlLine= _self.createExportLine(kHTML4Data, item.test, item.hstatus, item.hcomment);
var xhtmlLine = '';
if (item.xstatus == status)
xhtmlLine = _self.createExportLine(kXHTML1Data, item.test, item.xstatus, item.xcomment);
exportTests.push({
'test' : item.test,
'html4' : htmlLine,
'xhtml1' : xhtmlLine });
},
function() {
_self.exportResultsCompletion(exportTests);
}
);
}
/* -------------------------------------------------------- */
TestSuite.prototype.showResultsForTestsWithMismatchedResults = function()
{
this.beginAppendingOutput();
var _self = this;
this.queryDatabaseForTestsWithMixedStatus(
function(item) {
_self.appendResultToOutput(kHTML4Data, item.test, item.hstatus, item.hcomment);
_self.appendResultToOutput(kXHTML1Data, item.test, item.xstatus, item.xcomment);
},
function() {
_self.endAppendingOutput();
}
);
}
TestSuite.prototype.exportResultsForTestsWithMismatchedResults = function()
{
var exportTests = [];
var _self = this;
this.queryDatabaseForTestsWithMixedStatus(
function(item) {
var htmlLine= _self.createExportLine(kHTML4Data, item.test, item.hstatus ? item.hstatus : '?', item.hcomment);
var xhtmlLine = _self.createExportLine(kXHTML1Data, item.test, item.xstatus ? item.xstatus : '?', item.xcomment);
exportTests.push({
'test' : item.test,
'html4' : htmlLine,
'xhtml1' : xhtmlLine });
},
function() {
_self.exportResultsCompletion(exportTests);
}
);
}
/* -------------------------------------------------------- */
TestSuite.prototype.markTestCompleted = function(testID, htmlStatus, xhtmlStatus)
{
var test = this.tests[testID];
if (!test) {
window.console.log('markTestCompleted failed to find test ' + testID);
return;
}
if (htmlStatus) {
test.completedHTML = true;
test.statusHTML = htmlStatus;
}
if (xhtmlStatus) {
test.completedXHTML = true;
test.statusXHTML = xhtmlStatus;
}
}
TestSuite.prototype.testCompletionStateChanged = function()
{
this.updateTestList();
this.updateChapterPopup();
}
TestSuite.prototype.loadTestStatus = function()
{
var _self = this;
this.queryDatabaseForCompletedTests(
function(item) {
_self.markTestCompleted(item.test, item.hstatus, item.xstatus);
},
function() {
_self.testCompletionStateChanged();
}
);
this.updateChapterPopup();
}
TestSuite.prototype.resetTestStatus = function()
{
for (var testID in this.tests) {
var currTest = this.tests[testID];
currTest.completedHTML = false;
currTest.completedXHTML = false;
}
this.loadTestStatus();
}
/* -------------------------------------------------------- */
TestSuite.prototype.updateSummaryData = function()
{
this.queryDatabaseForSummary(
function(results) {
var hTotal, xTotal;
var hDone, xDone;
for (var i = 0; i < results.length; ++i) {
var result = results[i];
switch (result.name) {
case 'h-total': hTotal = result.count; break;
case 'x-total': xTotal = result.count; break;
case 'h-tested': hDone = result.count; break;
case 'x-tested': xDone = result.count; break;
}
document.getElementById(result.name).innerText = result.count;
}
// We should get these all together.
if (hTotal) {
document.getElementById('h-percent').innerText = Math.round(100.0 * hDone / hTotal);
document.getElementById('x-percent').innerText = Math.round(100.0 * xDone / xTotal);
}
}
);
}
/* ------------------------------------------------------- */
// Database stuff
function errorHandler(transaction, error)
{
alert('Database error: ' + error.message);
window.console.log('Database error: ' + error.message);
}
TestSuite.prototype.openDatabase = function()
{
if (!'openDatabase' in window) {
alert('Your browser does not support client-side SQL databases, so results will not be stored.');
return;
}
var _self = this;
this.db = window.openDatabase('css21testsuite', '', 'CSS 2.1 test suite results', 10 * 1024 * 1024);
// Migration handling. We assume migration will happen whenever the suite version changes,
// so that we can check for new or obsoleted tests.
function creation(tx) {
_self.databaseCreated(tx);
}
function migration1_0To1_1(tx) {
window.console.log('updating 1.0 to 1.1');
// We'll use the 'seen' column to cross-check with testinfo.data.
tx.executeSql('ALTER TABLE tests ADD COLUMN seen BOOLEAN DEFAULT \"FALSE\"', null, function() {
_self.syncDatabaseWithTestInfoData();
}, errorHandler);
}
if (this.db.version == '') {
_self.db.changeVersion('', '1.0', creation, null, function() {
_self.db.changeVersion('1.0', '1.1', migration1_0To1_1, null, function() {
_self.databaseReady();
}, errorHandler);
}, errorHandler);
return;
}
if (this.db.version == '1.0') {
_self.db.changeVersion('1.0', '1.1', migration1_0To1_1, null, function() {
window.console.log('ready')
_self.databaseReady();
}, errorHandler);
return;
}
this.databaseReady();
}
TestSuite.prototype.databaseCreated = function(tx)
{
window.console.log('databaseCreated');
this.populatingDatabase = true;
// hstatus: HTML4 result
// xstatus: XHTML1 result
var _self = this;
tx.executeSql('CREATE TABLE tests (test PRIMARY KEY UNIQUE, ref, title, flags, links, assertion, hstatus, hcomment, xstatus, xcomment)', null,
function(tx, results) {
_self.populateDatabaseFromTestInfoData();
}, errorHandler);
}
TestSuite.prototype.databaseReady = function()
{
this.updateSummaryData();
this.loadTestStatus();
}
TestSuite.prototype.storeTestResult = function(test, format, result, comment, useragent)
{
if (!this.db)
return;
this.db.transaction(function (tx) {
if (format == 'html4')
tx.executeSql('UPDATE tests SET hstatus=?, hcomment=? WHERE test=?\n', [result, comment, test], null, errorHandler);
else if (format == 'xhtml1')
tx.executeSql('UPDATE tests SET xstatus=?, xcomment=? WHERE test=?\n', [result, comment, test], null, errorHandler);
});
}
TestSuite.prototype.importTestResults = function(results)
{
if (!this.db)
return;
this.db.transaction(function (tx) {
for (var i = 0; i < results.length; ++i) {
var currResult = results[i];
var query;
if (currResult.format == 'html4')
query = 'UPDATE tests SET hstatus=?, hcomment=? WHERE test=?\n';
else if (currResult.format == 'xhtml1')
query = 'UPDATE tests SET xstatus=?, xcomment=? WHERE test=?\n';
tx.executeSql(query, [currResult.result, currResult.comment, currResult.id], null, errorHandler);
}
});
}
TestSuite.prototype.clearTestResults = function(results)
{
if (!this.db)
return;
this.db.transaction(function (tx) {
for (var i = 0; i < results.length; ++i) {
var currResult = results[i];
if (currResult.clearHTML)
tx.executeSql('UPDATE tests SET hstatus=NULL, hcomment=NULL WHERE test=?\n', [currResult.id], null, errorHandler);
if (currResult.clearXHTML)
tx.executeSql('UPDATE tests SET xstatus=NULL, xcomment=NULL WHERE test=?\n', [currResult.id], null, errorHandler);
}
});
}
TestSuite.prototype.populateDatabaseFromTestInfoData = function()
{
if (!this.testInfoLoaded) {
window.console.log('Tring to populate database before testinfo.data has been loaded');
return;
}
window.console.log('populateDatabaseFromTestInfoData')
var _self = this;
this.db.transaction(function (tx) {
for (var testID in _self.tests) {
var test = _self.tests[testID];
// Version 1.0, so no 'seen' column.
tx.executeSql('INSERT INTO tests (test, ref, title, flags, links, assertion) VALUES (?, ?, ?, ?, ?, ?)',
[test.id, test.reference, test.title, test.flags, test.links, test.assertion], null, errorHandler);
}
_self.populatingDatabase = false;
});
}
TestSuite.prototype.insertTest = function(tx, test)
{
tx.executeSql('INSERT INTO tests (test, ref, title, flags, links, assertion, seen) VALUES (?, ?, ?, ?, ?, ?, ?)',
[test.id, test.reference, test.title, test.flags, test.links, test.assertion, 'TRUE'], null, errorHandler);
}
// Deal with removed/renamed tests in a new version of the suite.
// self.tests is canonical; the database may contain stale entries.
TestSuite.prototype.syncDatabaseWithTestInfoData = function()
{
if (!this.testInfoLoaded) {
window.console.log('Trying to sync database before testinfo.data has been loaded');
return;
}
// Make an object with all tests that we'll use to track new tests.
var testsToInsert = {};
for (var testId in this.tests) {
var currTest = this.tests[testId];
testsToInsert[currTest.id] = currTest;
}
var _self = this;
this.db.transaction(function (tx) {
// Find tests that are not in the database yet.
// (Wasn't able to get INSERT ... IF NOT working.)
tx.executeSql('SELECT * FROM tests', [], function(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; ++i) {
var item = results.rows.item(i);
delete testsToInsert[item.test];
}
}, errorHandler);
});
this.db.transaction(function (tx) {
for (var testId in testsToInsert) {
var currTest = testsToInsert[testId];
window.console.log(currTest.id + ' is new; inserting');
_self.insertTest(tx, currTest);
}
});
this.db.transaction(function (tx) {
for (var testID in _self.tests)
tx.executeSql('UPDATE tests SET seen=\"TRUE\" WHERE test=?\n', [testID], null, errorHandler);
tx.executeSql('SELECT * FROM tests WHERE seen=\"FALSE\"', [], function(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; ++i) {
var item = results.rows.item(i);
window.console.log('Test ' + item.test + ' was in the database but is no longer in the suite; deleting.');
}
}, errorHandler);
// Delete rows for disappeared tests.
tx.executeSql('DELETE FROM tests WHERE seen=\"FALSE\"', [], function(tx, results) {
_self.populatingDatabase = false;
_self.databaseReady();
}, errorHandler);
});
}
TestSuite.prototype.queryDatabaseForAllTests = function(sortKey, perRowHandler, completionHandler)
{
if (this.populatingDatabase)
return;
var _self = this;
this.db.transaction(function (tx) {
if (_self.populatingDatabase)
return;
var query;
var args = [];
if (sortKey != '') {
query = 'SELECT * FROM tests ORDER BY ? ASC'; // ORDER BY doesn't seem to work
args.push(sortKey);
}
else
query = 'SELECT * FROM tests';
tx.executeSql(query, args, function(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; ++i)
perRowHandler(results.rows.item(i));
completionHandler();
}, errorHandler);
});
}
TestSuite.prototype.queryDatabaseForTestsWithStatus = function(status, perRowHandler, completionHandler)
{
if (this.populatingDatabase)
return;
var _self = this;
this.db.transaction(function (tx) {
if (_self.populatingDatabase)
return;
tx.executeSql('SELECT * FROM tests WHERE hstatus=? OR xstatus=?', [status, status], function(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; ++i)
perRowHandler(results.rows.item(i));
completionHandler();
}, errorHandler);
});
}
TestSuite.prototype.queryDatabaseForTestsWithMixedStatus = function(perRowHandler, completionHandler)
{
if (this.populatingDatabase)
return;
var _self = this;
this.db.transaction(function (tx) {
if (_self.populatingDatabase)
return;
tx.executeSql('SELECT * FROM tests WHERE hstatus IS NOT NULL AND xstatus IS NOT NULL AND hstatus <> xstatus', [], function(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; ++i)
perRowHandler(results.rows.item(i));
completionHandler();
}, errorHandler);
});
}
TestSuite.prototype.queryDatabaseForCompletedTests = function(perRowHandler, completionHandler)
{
if (this.populatingDatabase)
return;
var _self = this;
this.db.transaction(function (tx) {
if (_self.populatingDatabase)
return;
tx.executeSql('SELECT * FROM tests WHERE hstatus IS NOT NULL OR xstatus IS NOT NULL', [], function(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; ++i)
perRowHandler(results.rows.item(i));
completionHandler();
}, errorHandler);
});
}
TestSuite.prototype.queryDatabaseForTestsNotRun = function(perRowHandler, completionHandler)
{
if (this.populatingDatabase)
return;
var _self = this;
this.db.transaction(function (tx) {
if (_self.populatingDatabase)
return;
tx.executeSql('SELECT * FROM tests WHERE hstatus IS NULL OR xstatus IS NULL', [], function(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; ++i)
perRowHandler(results.rows.item(i));
completionHandler();
}, errorHandler);
});
}
/*
completionHandler gets called an array of results,
which may be some or all of:
data = [
{ 'name' : ,
'count' :
},
]
where name is one of:
'h-total'
'h-tested'
'h-passed'
'h-failed'
'h-skipped'
'x-total'
'x-tested'
'x-passed'
'x-failed'
'x-skipped'
*/
TestSuite.prototype.countTestsWithColumnValue = function(tx, completionHandler, column, value, label)
{
var allRowsCount = 'COUNT(*)';
tx.executeSql('SELECT COUNT(*) FROM tests WHERE ' + column + '=?', [value], function(tx, results) {
var data = [];
if (results.rows.length > 0)
data.push({ 'name' : label, 'count' : results.rows.item(0)[allRowsCount] })
completionHandler(data);
}, errorHandler);
}
TestSuite.prototype.countTestsWithFlag = function(tx, completionHandler, flag)
{
var allRowsCount = 'COUNT(*)';
tx.executeSql('SELECT COUNT(*) FROM tests WHERE flags LIKE \"%' + flag + '%\"', [], function(tx, results) {
var rowCount = 0;
if (results.rows.length > 0)
rowCount = results.rows.item(0)[allRowsCount];
completionHandler(rowCount);
}, errorHandler);
}
TestSuite.prototype.queryDatabaseForSummary = function(completionHandler)
{
if (!this.db || this.populatingDatabase)
return;
var _self = this;
var htmlOnlyTestCount = 0;
var xHtmlOnlyTestCount = 0;
this.db.transaction(function (tx) {
if (_self.populatingDatabase)
return;
var allRowsCount = 'COUNT(*)';
_self.countTestsWithFlag(tx, function(count) {
htmlOnlyTestCount = count;
}, 'htmlOnly');
_self.countTestsWithFlag(tx, function(count) {
xHtmlOnlyTestCount = count;
}, 'nonHTML');
});
this.db.transaction(function (tx) {
if (_self.populatingDatabase)
return;
var allRowsCount = 'COUNT(*)';
var html4RowsCount = 'COUNT(hstatus)';
var xhtml1RowsCount = 'COUNT(xstatus)';
tx.executeSql('SELECT COUNT(*), COUNT(hstatus), COUNT(xstatus) FROM tests', [], function(tx, results) {
var data = [];
if (results.rows.length > 0) {
var rowItem = results.rows.item(0);
data.push({ 'name' : 'h-total' , 'count' : rowItem[allRowsCount] - xHtmlOnlyTestCount })
data.push({ 'name' : 'x-total' , 'count' : rowItem[allRowsCount] - htmlOnlyTestCount })
data.push({ 'name' : 'h-tested', 'count' : rowItem[html4RowsCount] })
data.push({ 'name' : 'x-tested', 'count' : rowItem[xhtml1RowsCount] })
}
completionHandler(data);
}, errorHandler);
_self.countTestsWithColumnValue(tx, completionHandler, 'hstatus', 'pass', 'h-passed');
_self.countTestsWithColumnValue(tx, completionHandler, 'xstatus', 'pass', 'x-passed');
_self.countTestsWithColumnValue(tx, completionHandler, 'hstatus', 'fail', 'h-failed');
_self.countTestsWithColumnValue(tx, completionHandler, 'xstatus', 'fail', 'x-failed');
_self.countTestsWithColumnValue(tx, completionHandler, 'hstatus', 'skipped', 'h-skipped');
_self.countTestsWithColumnValue(tx, completionHandler, 'xstatus', 'skipped', 'x-skipped');
_self.countTestsWithColumnValue(tx, completionHandler, 'hstatus', 'invalid', 'h-invalid');
_self.countTestsWithColumnValue(tx, completionHandler, 'xstatus', 'invalid', 'x-invalid');
});
}
|