blob: 0b05ae32733ff1b6a185712ef04f4edeea468957 [file] [log] [blame]
Robert Gindacf288e52012-10-15 11:13:52 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5'use strict';
6
7var testManager;
8var testRun;
9
10window.onload = function() {
11 lib.rtdep(hterm.testDeps);
12
13 hterm.defaultStorage = new lib.Storage.Memory();
14
15 lib.init(lib.f.alarm(function() {
16 testManager = new lib.TestManager();
Mike Frysinger21571a72017-04-07 17:14:19 -040017 testManager.log.save = true;
Robert Gindacf288e52012-10-15 11:13:52 -070018
Mike Frysinger21571a72017-04-07 17:14:19 -040019 testManager.onTestRunComplete = (testRun) => {
20 var document = testRun.cx.window.document;
21 document.body.innerHTML = '';
22
23 var results = document.createElement('div');
24 var p, pre;
25
26 p = document.createElement('p');
27 p.innerText = 'Check JavaScript console for test log/status.';
28 results.appendChild(p);
29
30 p = document.createElement('p');
31 p.id = 'status';
32 p.innerText = 'Finished.';
33 p.className = (testRun.failures.length == 0) ? 'good' : 'bad';
34 results.appendChild(p);
35
36 p = document.createElement('p');
37 p.id = 'passed';
38 p.className = 'good';
Mike Frysingercd988ec2017-04-20 18:25:17 -040039 document.title = p.innerText = testRun.passes.length + ' tests passed.';
Mike Frysinger21571a72017-04-07 17:14:19 -040040 results.appendChild(p);
41
42 p = document.createElement('p');
43 p.id = 'failed';
44 p.className = 'bad';
45 if (testRun.failures.length != 0)
Mike Frysingercd988ec2017-04-20 18:25:17 -040046 document.title = p.innerText =
47 'ERROR: ' + testRun.failures.length + ' tests failed!';
Mike Frysinger21571a72017-04-07 17:14:19 -040048 results.appendChild(p);
49
50 pre = document.createElement('pre');
51 pre.id = 'log';
52 pre.innerText = testRun.testManager.log.data;
53 results.appendChild(pre);
54
55 // Only clear the body if everything passed in case the current rendering
56 // is useful to debugging. Insert our log/results above it.
57 if (testRun.failures.length == 0)
58 document.body.innerText = '';
59 document.body.insertBefore(results, document.body.firstChild);
60 };
61
Mike Frysingercd988ec2017-04-20 18:25:17 -040062 testManager.testPreamble = (result, cx) => {
63 var testRun = result.testRun;
64 cx.window.document.title =
65 '[' + (testRun.passes.length + testRun.failures.length) + '] ' +
66 result.test.fullName;
67 };
68
69 testRun = testManager.createTestRun({window: window});
70
Robert Gindacf288e52012-10-15 11:13:52 -070071 // Stop after the first failure to make it easier to debug in the
72 // JS console.
73 testRun.maxFailures = 1;
74
75 testRun.selectPattern(testRun.ALL_TESTS);
76 testRun.run();
77
78 }), console.log.bind(console));
79};