index.html.tpl 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <style>
  5. <meta name="google" content="notranslate" />
  6. body {
  7. background: white;
  8. color: black;
  9. }
  10. .test p {
  11. margin: 1px;
  12. }
  13. .test {
  14. font-family: monospace;
  15. white-space: pre;
  16. }
  17. .err {
  18. background: red;
  19. color: white;
  20. }
  21. .passed {
  22. background: green;
  23. color: white;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <h1></h1>
  29. <section class="test" id="test-res"></section>
  30. <script>
  31. var performance;
  32. if (typeof performance !== 'object') {
  33. performance = {
  34. mark: function(s) { this[s] = new Date() },
  35. measure: function(_t, s1, s2) { this.t = this[s2] - this[s1] },
  36. getEntriesByName: function() { return [ { duration: this.t } ] }
  37. };
  38. }
  39. var Module = { preRun: function() { performance.mark('bench_start') } };
  40. function runTest(tname) {
  41. var xhr, expected, hn, idx = 0, passed = true;
  42. function outputReceived(e) {
  43. var found = e.data;
  44. var p = document.createElement('p');
  45. if (found !== expected[idx++]) {
  46. p.className = 'err';
  47. passed = false;
  48. }
  49. p.appendChild(document.createTextNode(found));
  50. document.getElementById('test-res').appendChild(p);
  51. if (idx >= expected.length) {
  52. if (passed) {
  53. performance.mark('bench_end')
  54. performance.measure('bench', 'bench_start', 'bench_end');
  55. var duration = Math.round(performance.getEntriesByName('bench')[0].duration);
  56. hn.appendChild(document.createTextNode(' - PASSED (time: ' + duration + ' ms)'));
  57. hn.className = 'passed';
  58. } else {
  59. hn.appendChild(document.createTextNode(' - FAILED'));
  60. hn.className = 'err';
  61. }
  62. }
  63. }
  64. hn = document.getElementsByTagName('h1')[0];
  65. hn.appendChild(document.createTextNode('Test: ' + tname));
  66. try {
  67. xhr = new ActiveXObject('Microsoft.XMLHTTP');
  68. } catch (e) {
  69. xhr = new XMLHttpRequest();
  70. }
  71. xhr.open('GET', tname + '.exp');
  72. xhr.onreadystatechange = function() {
  73. if (xhr.readyState != 4 ||
  74. (xhr.status != 200 && xhr.status != 302 && xhr.status != 0)) {
  75. return;
  76. }
  77. expected = xhr.responseText.split('\n');
  78. if (expected.length > 0 && expected[expected.length - 1] === '') {
  79. expected.pop();
  80. }
  81. expected.push('--- SUCCESS ---');
  82. window.addEventListener('test-output', outputReceived, false);
  83. var s = document.getElementsByTagName('script')[0];
  84. var st = document.createElement('script');
  85. st.src = tname + '.js';
  86. s.parentNode.insertBefore(st, s);
  87. }
  88. xhr.send(null);
  89. }
  90. runTest('{{tname}}');
  91. </script>
  92. </body>
  93. </html>