blob: 754cb533bc26b8fc222b36b085007aae1b3a1383 [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() {
Robert Gindacf288e52012-10-15 11:13:52 -070011 hterm.defaultStorage = new lib.Storage.Memory();
12
Mike Frysinger7eb57172019-02-16 14:39:39 -050013 lib.init(function() {
Robert Gindacf288e52012-10-15 11:13:52 -070014 testManager = new lib.TestManager();
Mike Frysinger21571a72017-04-07 17:14:19 -040015 testManager.log.save = true;
Robert Gindacf288e52012-10-15 11:13:52 -070016
Mike Frysinger21571a72017-04-07 17:14:19 -040017 testManager.onTestRunComplete = (testRun) => {
18 var document = testRun.cx.window.document;
19 document.body.innerHTML = '';
20
21 var results = document.createElement('div');
22 var p, pre;
23
24 p = document.createElement('p');
25 p.innerText = 'Check JavaScript console for test log/status.';
26 results.appendChild(p);
27
28 p = document.createElement('p');
29 p.id = 'status';
30 p.innerText = 'Finished.';
31 p.className = (testRun.failures.length == 0) ? 'good' : 'bad';
32 results.appendChild(p);
33
34 p = document.createElement('p');
35 p.id = 'passed';
36 p.className = 'good';
Mike Frysingercd988ec2017-04-20 18:25:17 -040037 document.title = p.innerText = testRun.passes.length + ' tests passed.';
Mike Frysinger21571a72017-04-07 17:14:19 -040038 results.appendChild(p);
39
40 p = document.createElement('p');
41 p.id = 'failed';
42 p.className = 'bad';
43 if (testRun.failures.length != 0)
Mike Frysingercd988ec2017-04-20 18:25:17 -040044 document.title = p.innerText =
45 'ERROR: ' + testRun.failures.length + ' tests failed!';
Mike Frysinger21571a72017-04-07 17:14:19 -040046 results.appendChild(p);
47
48 pre = document.createElement('pre');
49 pre.id = 'log';
50 pre.innerText = testRun.testManager.log.data;
51 results.appendChild(pre);
52
53 // Only clear the body if everything passed in case the current rendering
54 // is useful to debugging. Insert our log/results above it.
55 if (testRun.failures.length == 0)
56 document.body.innerText = '';
57 document.body.insertBefore(results, document.body.firstChild);
58 };
59
Mike Frysingercd988ec2017-04-20 18:25:17 -040060 testManager.testPreamble = (result, cx) => {
61 var testRun = result.testRun;
62 cx.window.document.title =
63 '[' + (testRun.passes.length + testRun.failures.length) + '] ' +
64 result.test.fullName;
65 };
66
67 testRun = testManager.createTestRun({window: window});
68
Robert Gindacf288e52012-10-15 11:13:52 -070069 // Stop after the first failure to make it easier to debug in the
70 // JS console.
71 testRun.maxFailures = 1;
72
Mike Frysinger0a786052019-02-08 01:35:20 -050073 const params = new URLSearchParams(document.location.search);
74 const pattern = params.get('pattern');
75 testRun.selectPattern(new RegExp(pattern ? pattern : '.'));
Robert Gindacf288e52012-10-15 11:13:52 -070076 testRun.run();
77
Mike Frysinger7eb57172019-02-16 14:39:39 -050078 }, console.log.bind(console));
Robert Gindacf288e52012-10-15 11:13:52 -070079};