testdriver.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. ];
  46. var testframe = document.getElementById("testframe");
  47. var currentTest = 1;
  48. var total = "passed";
  49. /**
  50. * Add test result to the DOM
  51. * @param {string} name – Filename
  52. * @param {string} desc - Test description
  53. * @param {string} result - Result (failed or passed)
  54. */
  55. function addTestResult(name, desc, result) {
  56. var dl = document.getElementById("testresults");
  57. var template = document.getElementById("template").innerHTML;
  58. template = template.replace(/@file@/g, name);
  59. template = template.replace(/@desc@/, desc);
  60. template = template.replace(/@result@/g, result);
  61. dl.innerHTML += template;
  62. window.scrollBy(0, 20);
  63. }
  64. /**
  65. * Runs tests
  66. * @param {number} index - Index of the test
  67. */
  68. function run(index) {
  69. /* eslint-disable security/detect-object-injection */
  70. if (tests[index]) {
  71. currentTest = index;
  72. if (tests[index].exec) {
  73. window.setTimeout(function defer() {
  74. testframe.src = tests[index].path;
  75. }, 0);
  76. } else {
  77. addTestResult(tests[index].path, "omitted", "omitted");
  78. run(index + 1);
  79. }
  80. } else {
  81. addTestResult("", navigator.userAgent, total);
  82. }
  83. /* eslint-enable security/detect-object-injection */
  84. }
  85. window.addEventListener("message", function onMessage(e) {
  86. var msg = JSON.parse(e.data);
  87. addTestResult(tests[msg.index].path, msg.desc, msg.result);
  88. if (msg.result === "failed") {
  89. total = "failed";
  90. }
  91. run(msg.index + 1);
  92. }, false);
  93. run(currentTest);
  94. }());