• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<!--
3Copyright (c) 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7<link rel="import" href="/tracing/base/base.html">
8<link rel="import" href="/tracing/base/unittest.html">
9<link rel="import" href="/tracing/base/unittest/test_runner.html">
10<link rel="import" href="/tracing/base/unittest/text_test_results.html">
11<script>
12'use strict';
13
14tr.exportTo('tr.b.unittest', function() {
15  if (!tr.isHeadless) {
16    throw new Error('headless_tests.html only works in headless mode');
17  }
18  function quit(errCode) {
19    if (tr.isVinn)
20      global.quit(errCode);
21    else
22      process.exit(errCode);
23  }
24
25  function printSpacer() {
26    console.log('\n\n------------------------------------------------------' +
27                '----------------');
28  }
29  function loadAndRunTests(suiteRelpathsToLoad) {
30    var results = new tr.b.unittest.TextTestResults();
31
32    var loader = new tr.b.unittest.SuiteLoader(suiteRelpathsToLoad);
33
34    var p = loader.allSuitesLoadedPromise;
35
36    p = p.then(
37      function didAllSuitesLoad() {
38        var tests = loader.getAllTests().filter(function(testCase) {
39          if (testCase instanceof tr.b.unittest.PerfTestCase)
40            return false;
41          return true;
42        });
43        if (tests.length === 0) {
44          printSpacer();
45          console.log('FAILED: No tests to run.');
46          console.log(err.stack);
47          quit(1);
48        }
49        var runner = new tr.b.unittest.TestRunner(results, tests);
50        return runner.beginRunning();
51      },
52      function suiteLoadingFailure(err) {
53        printSpacer();
54        console.log('FAILED: A test suite failed to load.');
55        console.log(err.stack);
56        quit(1);
57      });
58
59    p = p.then(
60      function didAllTestRun() {
61        if (results.numTestsThatFailed > 0)
62          quit(1);
63        else
64          quit(0);
65      },
66      function testHarnessError(e) {
67        console.log('FAILED: A test harness error has ocurred.');
68        console.log(e.stack);
69        quit(1);
70      });
71    return p;
72  }
73
74  return {
75    loadAndRunTests: loadAndRunTests
76  };
77});
78</script>
79