testdriver.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* eslint-disable object-property-newline */
  2. /* eslint-disable no-var */
  3. (function testDriver() {
  4. "use strict";
  5. var tests = [
  6. {"exec": false, "path": "test0.html"},
  7. {"exec": true, "path": "test1.html"},
  8. {"exec": true, "path": "test2.html"},
  9. {"exec": true, "path": "test3.html"},
  10. {"exec": true, "path": "test4.html"},
  11. {"exec": true, "path": "test5.html"},
  12. {"exec": true, "path": "test6.html"},
  13. {"exec": true, "path": "test7.html"},
  14. {"exec": true, "path": "test8.html"},
  15. {"exec": true, "path": "test9.html"},
  16. {"exec": true, "path": "test10.html"},
  17. {"exec": true, "path": "test11.html"},
  18. {"exec": true, "path": "test12.html"},
  19. {"exec": true, "path": "test13.html"},
  20. {"exec": true, "path": "test14.html"},
  21. {"exec": true, "path": "test15.html"},
  22. {"exec": true, "path": "test16.html"},
  23. {"exec": true, "path": "test17.html"},
  24. {"exec": true, "path": "test18.html"},
  25. {"exec": true, "path": "test19.html"},
  26. {"exec": true, "path": "test20.html"},
  27. {"exec": true, "path": "test21.html"},
  28. {"exec": true, "path": "test22.html"},
  29. {"exec": true, "path": "test23.html"},
  30. {"exec": true, "path": "test24.html"},
  31. {"exec": true, "path": "test25.html"},
  32. {"exec": true, "path": "test26.html"},
  33. {"exec": true, "path": "test27.html"},
  34. {"exec": true, "path": "test28.html"},
  35. {"exec": true, "path": "test29.html"},
  36. {"exec": true, "path": "test30.html"},
  37. {"exec": true, "path": "test31.html"},
  38. {"exec": true, "path": "test32.html"},
  39. {"exec": true, "path": "test33.html"},
  40. {"exec": true, "path": "test34.html"},
  41. {"exec": true, "path": "test35.html"},
  42. {"exec": true, "path": "test36.html"},
  43. {"exec": true, "path": "test37.html"},
  44. {"exec": true, "path": "test38.html"},
  45. {"exec": true, "path": "test39.html"},
  46. {"exec": true, "path": "test40.html"}
  47. ];
  48. var testframe = document.getElementById("testframe");
  49. var currentTest = 1;
  50. var total = "passed";
  51. /**
  52. * Add test result to the DOM
  53. * @param {string} name – Filename
  54. * @param {string} desc - Test description
  55. * @param {string} result - Result (failed or passed)
  56. */
  57. function addTestResult(name, desc, result) {
  58. var dl = document.getElementById("testresults");
  59. var li = document.createElement("li");
  60. var linkSpan = document.createElement("span");
  61. var filelink = document.createElement("a");
  62. var resultSpan = document.createElement("span");
  63. var descSpan = document.createElement("span");
  64. linkSpan.setAttribute("class", "testname");
  65. filelink.setAttribute("href", name);
  66. filelink.appendChild(document.createTextNode(name));
  67. linkSpan.appendChild(filelink);
  68. li.appendChild(linkSpan);
  69. resultSpan.setAttribute("class", "result " + result);
  70. resultSpan.appendChild(document.createTextNode("[" + result + "]"));
  71. li.appendChild(resultSpan);
  72. descSpan.setAttribute("class", "desc");
  73. descSpan.appendChild(document.createTextNode(desc));
  74. li.appendChild(descSpan);
  75. dl.appendChild(li);
  76. }
  77. /**
  78. * Runs tests
  79. * @param {number} index - Index of the test
  80. */
  81. function run(index) {
  82. /* eslint-disable security/detect-object-injection */
  83. if (tests[index]) {
  84. currentTest = index;
  85. if (tests[index].exec) {
  86. window.setTimeout(function defer() {
  87. testframe.src = tests[index].path;
  88. }, 0);
  89. } else {
  90. addTestResult(tests[index].path, "omitted", "omitted");
  91. run(index + 1);
  92. }
  93. } else {
  94. addTestResult("", navigator.userAgent, total);
  95. }
  96. /* eslint-enable security/detect-object-injection */
  97. }
  98. window.addEventListener(
  99. "message",
  100. function onMessage(e) {
  101. var msg = JSON.parse(e.data);
  102. addTestResult(tests[msg.index].path, msg.desc, msg.result);
  103. if (msg.result === "failed") {
  104. total = "failed";
  105. }
  106. run(msg.index + 1);
  107. },
  108. false
  109. );
  110. run(currentTest);
  111. }());