summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/metrics/console_error_metric_unittest.html
blob: eff2917fc4752e14b5b4ef62cdf280fc698347c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<!--
Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/trace_event_importer.html">
<link rel="import" href="/tracing/metrics/console_error_metric.html">
<link rel="import" href="/tracing/value/histogram_set.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  function makeEvent(cat, name, source, timestamp) {
    return {
      cat,
      name,
      args: {source},
      ts: timestamp,
      pid: 52,
      tid: 53,
      ph: 'B'
    };
  }

  test('consoleErrorMetric_noErrors', function() {
    const histograms = new tr.v.HistogramSet();
    const events = [
      makeEvent('foo', '', 10),
      makeEvent('bar', '', 20)
    ];
    tr.metrics.console.consoleErrorMetric(histograms,
        tr.c.TestUtils.newModelWithEvents([events]));
    const all = histograms.getHistogramNamed('console:error:all').running;
    assert.strictEqual(all.count, 1);
    assert.strictEqual(all.mean, 0);
    const js = histograms.getHistogramNamed('console:error:js').running;
    assert.strictEqual(js.count, 1);
    assert.strictEqual(js.mean, 0);
    const net = histograms.getHistogramNamed('console:error:network').running;
    assert.strictEqual(net.count, 1);
    assert.strictEqual(net.mean, 0);
  });

  test('consoleErrorMetric_Errors', function() {
    const histograms = new tr.v.HistogramSet();
    const events = [
      makeEvent('blink.console', 'foo', '', 10),
      makeEvent('blink.console', 'ConsoleMessage::Error', 'XML', 20),
      makeEvent('blink.console', 'bar', '', 30),
      makeEvent('blink.console', 'ConsoleMessage::Error', 'Network', 40),
      makeEvent('blink.console', 'ConsoleMessage::Error', 'JS', 50),
      makeEvent('blink.console', 'ConsoleMessage::Error', 'Network', 60),
      makeEvent('blink.console', 'ConsoleMessage::Error', 'Network', 70),
      makeEvent('blink.console', 'ConsoleMessage::Error', 'JS', 80),
      makeEvent('blink.console', 'ConsoleMessage::Error', 'Network', 90),
      makeEvent('bar', '', 300)
    ];
    tr.metrics.console.consoleErrorMetric(histograms,
        tr.c.TestUtils.newModelWithEvents([events]));
    const all = histograms.getHistogramNamed('console:error:all').running;
    assert.strictEqual(all.count, 1);
    assert.strictEqual(all.mean, 7);
    const js = histograms.getHistogramNamed('console:error:js').running;
    assert.strictEqual(js.count, 1);
    assert.strictEqual(js.mean, 2);
    const net = histograms.getHistogramNamed('console:error:network').running;
    assert.strictEqual(net.count, 1);
    assert.strictEqual(net.mean, 4);
  });

  test('consoleErrorMetric_V8', function() {
    const histograms = new tr.v.HistogramSet();
    const events = [
      makeEvent('v8.console', 'foo', '', 10),
      makeEvent('v8.console', 'V8ConsoleMessage::Error', '', 20),
      makeEvent('v8.console', 'bar', '', 30),
      makeEvent('v8.console', 'V8ConsoleMessage::Exception', '', 40),
      makeEvent('v8.console', 'V8ConsoleMessage::Assert', '', 50),
      makeEvent('v8.console', 'V8ConsoleMessage::Ignore', '', 60),
      makeEvent('v8.console', 'V8ConsoleMessage::Ignore', '', 70),
      makeEvent('v8.console', 'bar', '', 300)
    ];
    tr.metrics.console.consoleErrorMetric(histograms,
        tr.c.TestUtils.newModelWithEvents([events]));
    const all = histograms.getHistogramNamed('console:error:all').running;
    assert.strictEqual(all.count, 1);
    assert.strictEqual(all.mean, 3);
    const js = histograms.getHistogramNamed('console:error:js').running;
    assert.strictEqual(js.count, 1);
    assert.strictEqual(js.mean, 3);
    const net = histograms.getHistogramNamed('console:error:network').running;
    assert.strictEqual(net.count, 1);
    assert.strictEqual(net.mean, 0);
  });
});
</script>