xref: /freebsd/sys/contrib/libsodium/test/default/index.html.tpl (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1<!doctype html>
2<html>
3<head>
4<style>
5<meta name="google" content="notranslate" />
6body {
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>
31var performance;
32if (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
40var Module = { preRun: function() { performance.mark('bench_start') } };
41
42function runTest(tname) {
43    var xhr, expected, hn, idx = 0, passed = true;
44
45    function outputReceived(e) {
46        var found = e.data;
47        var p = document.createElement('p');
48        if (found !== expected[idx++]) {
49            p.className = 'err';
50            passed = false;
51        }
52        p.appendChild(document.createTextNode(found));
53        document.getElementById('test-res').appendChild(p);
54        if (idx >= expected.length) {
55            if (passed) {
56                performance.mark('bench_end')
57                performance.measure('bench', 'bench_start', 'bench_end');
58                var duration = Math.round(performance.getEntriesByName('bench')[0].duration);
59                hn.appendChild(document.createTextNode(' - PASSED (time: ' + duration + ' ms)'));
60                hn.className = 'passed';
61            } else {
62                hn.appendChild(document.createTextNode(' - FAILED'));
63                hn.className = 'err';
64            }
65        }
66    }
67
68    hn = document.getElementsByTagName('h1')[0];
69    hn.appendChild(document.createTextNode('Test: ' + tname));
70
71    try {
72        xhr = new ActiveXObject('Microsoft.XMLHTTP');
73    } catch (e) {
74        xhr = new XMLHttpRequest();
75    }
76    xhr.open('GET', tname + '.exp');
77    xhr.onreadystatechange = function() {
78        if (xhr.readyState != 4 ||
79            (xhr.status != 200 && xhr.status != 302 && xhr.status != 0)) {
80            return;
81        }
82        expected = xhr.responseText.split('\n');
83        if (expected.length > 0 && expected[expected.length - 1] === '') {
84            expected.pop();
85        }
86        expected.push('--- SUCCESS ---');
87        window.addEventListener('test-output', outputReceived, false);
88        var s = document.getElementsByTagName('script')[0];
89        var st = document.createElement('script');
90        st.src = tname + '.js';
91        s.parentNode.insertBefore(st, s);
92    }
93    xhr.send(null);
94}
95runTest('{{tname}}');
96</script>
97</body>
98</html>
99