summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/tracing/tracing/value/value_test.html
blob: 07e73b030eed971fb53fdb44b0f89104e1f7aeb8 (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
<!DOCTYPE html>
<!--
Copyright (c) 2013 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/base/utils.html">
<link rel="import" href="/tracing/value/numeric.html">
<link rel="import" href="/tracing/value/unit.html">
<link rel="import" href="/tracing/value/value.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('numericValueBasic', function() {
    var n = new tr.v.ScalarNumeric(tr.v.Unit.byName.sizeInBytes, 314);
    var v = new tr.v.NumericValue('MyNumeric', n);
    assert.isDefined(v.guid);
    var d = v.asDict();

    var v2 = tr.v.Value.fromDict(d);
    assert.instanceOf(v2, tr.v.NumericValue);
    assert.equal(v.guid, v2.guid);
    assert.equal(v.name, v2.name);
    assert.equal(v.numeric.value, v2.numeric.value);
  });

  test('dictValueBasic', function() {
    var v = new tr.v.DictValue('MyDict', {my_key: 'my_value'});
    assert.isDefined(v.guid);
    var d = v.asDict();

    var v2 = tr.v.Value.fromDict(d);
    assert.instanceOf(v2, tr.v.DictValue);
    assert.equal(v.guid, v2.guid);
    assert.deepEqual(v.value, v2.value);
  });

  test('failureValueBasic', function() {
    var v = new tr.v.FailureValue(
      'MyFailure',
      {description: 'Description', stack: tr.b.stackTraceAsString()});
    assert.isDefined(v.guid);
    var d = v.asDict();

    var v2 = tr.v.Value.fromDict(d);
    assert.instanceOf(v2, tr.v.FailureValue);
    assert.equal(v.guid, v2.guid);
    assert.equal(v.name, v2.name);
    assert.equal(v.description, v2.description);
    assert.equal(v.stack, v2.stack);
  });

  test('skipValueBasic', function() {
    var v = new tr.v.SkipValue('MySkip',
                               {description: 'WhySkipped'});
    assert.isDefined(v.guid);
    var d = v.asDict();

    var v2 = tr.v.Value.fromDict(d);
    assert.equal(v.guid, v2.guid);
    assert.instanceOf(v2, tr.v.SkipValue);
    assert.equal(v.description, v2.description);
  });

  test('genericDiagnostic', function() {
    var skip = new tr.v.SkipValue('skip');
    skip.diagnostics.add('foo', new tr.v.d.Generic({
      t: true,
      f: false,
      z: 0,
      o: 1,
      ans: 0.42,
      s: 'string',
      a: [42.42, 'more string'],
      d: {a: {b: 'c'}}
    }));
    var skip2 = tr.v.Value.fromDict(skip.asDict());
    var foo2 = skip2.diagnostics.get('foo');
    assert.strictEqual(true, foo2.value.t);
    assert.strictEqual(false, foo2.value.f);
    assert.strictEqual(0, foo2.value.z);
    assert.strictEqual(1, foo2.value.o);
    assert.strictEqual(0.42, foo2.value.ans);
    assert.strictEqual('string', foo2.value.s);
    assert.deepEqual([42.42, 'more string'], foo2.value.a);
    assert.deepEqual({a: {b: 'c'}}, foo2.value.d);
  });
});
</script>