summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/extras/net/net_async_slice_test.html
blob: e8a2bd750fac844f8672e71879d36b347ad3301a (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!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/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/trace_event_importer.html">
<link rel="import" href="/tracing/extras/net/net.html">
<link rel="import" href="/tracing/model/model.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  var AsyncSlice = tr.model.AsyncSlice;
  var NetAsyncSlice = tr.e.net.NetAsyncSlice;

  test('basic', function() {
    var s = new NetAsyncSlice('netlog', 'HTTP_STREAM_JOB', 7, 0, {});
    s.duration = 100;

    assert.equal(
        AsyncSlice.subTypes.getConstructor('netlog', 'HTTP_STREAM_JOB'),
        NetAsyncSlice);
    assert.equal(s.viewSubGroupTitle, 'NetLog');
  });

  test('import', function() {
    var events = [
      {name: 'HTTP_STREAM_JOB', args: {}, pid: 1, ts: 100, cat: 'netlog', tid: 2, ph: 'b', id: 71}, // @suppress longLineCheck
      {name: 'HTTP_STREAM_JOB', args: {}, pid: 1, ts: 200, cat: 'netlog', tid: 2, ph: 'e', id: 71} // @suppress longLineCheck
    ];
    var m = tr.c.TestUtils.newModelWithEvents([events]);
    var t2 = m.getOrCreateProcess(1).getOrCreateThread(2);
    assert.equal(t2.asyncSliceGroup.length, 1);
    assert.instanceOf(t2.asyncSliceGroup.slices[0], NetAsyncSlice);
  });

  test('ExposeURLBasic', function() {
    var slice = new NetAsyncSlice('', 'a', 0, 1,
                                  {params: {url: 'https://google.com'},
                                   source_type: 'b'}, 0, true);
    // Make sure isTopLevel is populated in the constructor.
    assert.isTrue(slice.isTopLevel);
    // URL is exposed as the title of the parent slice.
    assert.equal(slice.title, 'https://google.com');
    assert.equal(slice.url, 'https://google.com');
  });

  test('ExposeURLNested', function() {
    var slice = new NetAsyncSlice(
        '', 'a', 0, 1, {params: {}, source_type: 'HELLO'}, 1, true);
    var childSlice = new NetAsyncSlice('', 'b', 0, 1,
                                       {params: {url: 'http://test.url'}});
    slice.subSlices = [childSlice];
    // Make sure isTopLevel is populated in the constructor.
    assert.isTrue(slice.isTopLevel);
    assert.isFalse(childSlice.isTopLevel);
    // URL is exposed as the title of the parent slice.
    assert.equal(slice.title, 'http://test.url');
    assert.equal(slice.title, 'http://test.url');
    assert.equal(childSlice.title, 'b');
    assert.equal(childSlice.url, 'http://test.url');
  });

  test('ExposeURLNestedNoURL', function() {
    var slice = new NetAsyncSlice('', 'a', 0, 1, {params: {}}, 1, true);
    var childSlice = new NetAsyncSlice('', 'b', 0, 1, {params: {}});
    slice.subSlices = [childSlice];
    // Make sure isTopLevel is populated in the constructor.
    assert.isTrue(slice.isTopLevel);
    assert.isFalse(childSlice.isTopLevel);
    // URL is exposed as the title of the parent slice.
    assert.equal(slice.title, 'a');
    assert.equal(slice.url, undefined);
    assert.equal(childSlice.title, 'b');
    assert.equal(childSlice.url, undefined);
  });

  test('ExposeURLNestedBothChildrenHaveURL', function() {
    var slice = new NetAsyncSlice('', 'a', 0, 1, {params: {}}, 1, true);
    var childSlice1 = new NetAsyncSlice('', 'b', 0, 1,
                                   {params: {url: 'http://test.url.net'}});
    var childSlice2 = new NetAsyncSlice('', 'c', 0, 1,
                                   {params: {url: 'http://test.url.com'}});
    slice.subSlices = [childSlice1, childSlice2];
    // Make sure isTopLevel is populated in the constructor.
    assert.isTrue(slice.isTopLevel);
    assert.isFalse(childSlice1.isTopLevel);
    assert.isFalse(childSlice2.isTopLevel);
    // Parent should take the first url param that it finds.
    assert.equal(slice.title, 'http://test.url.net');
    assert.equal(childSlice1.title, 'b');
    assert.equal(childSlice2.title, 'c');
  });

  test('ExposeURLNestedBothParentAndChildHaveURL', function() {
    var slice = new NetAsyncSlice('', 'a', 0, 1,
                                  {params: {url: 'parent123.url.com'}}, 1,
                                  true);
    var childSlice1 = new NetAsyncSlice('', 'b', 0, 1,
                                        {params: {url: 'http://test.url.net'}});
    var childSlice2 = new NetAsyncSlice('', 'c', 0, 1);

    slice.subSlices = [childSlice1, childSlice2];
    // Make sure isTopLevel is populated in the constructor.
    assert.isTrue(slice.isTopLevel);
    assert.isFalse(childSlice1.isTopLevel);
    assert.isFalse(childSlice2.isTopLevel);
    // Parent should take its own url param if there is one.
    assert.equal(slice.title, 'parent123.url.com');
    assert.equal(childSlice1.title, 'b');
    assert.equal(childSlice2.title, 'c');
  });

  test('ExposeURLDoNotComputeUrlTwice', function() {
    var slice = new NetAsyncSlice('', 'a', 0, 1, {params: {}}, 1, true);
    var childSlice1 = new NetAsyncSlice('', 'b', 0, 1,
                                        {params: {url: 'http://test.url.net'}});
    var childSlice2 = new NetAsyncSlice('', 'c', 0, 1);

    slice.subSlices = [childSlice1, childSlice2];
    // Make sure isTopLevel is populated in the constructor.
    assert.isTrue(slice.isTopLevel);
    assert.isFalse(childSlice1.isTopLevel);
    assert.isFalse(childSlice2.isTopLevel);
    // Parent should take its child's url param.
    assert.equal(slice.title, 'http://test.url.net');
    assert.equal(childSlice1.title, 'b');
    assert.equal(childSlice2.title, 'c');
    // Now if we change the url param of the child, the parent's title should
    // remain the same. We do not recompute.
    childSlice1.args.params.url = 'example.com';
    assert.equal(slice.title, 'http://test.url.net');
    assert.equal(childSlice1.title, 'b');
    assert.equal(childSlice2.title, 'c');
  });

  test('ExposeSourceTypeAsTitle', function() {
    var slice = new NetAsyncSlice('', 'a', 0, 1,
                                  {params: {}, source_type: 'UDP_SOCKET'}, 1,
                                  true);
    var childSlice1 = new NetAsyncSlice('', 'b', 0, 1,
                                        {params: {}, source_type: 'SOCKET'});
    var childSlice2 = new NetAsyncSlice('', 'c', 0, 1);

    slice.subSlices = [childSlice1, childSlice2];
    // Make sure isTopLevel is populated in the constructor.
    assert.isTrue(slice.isTopLevel);
    assert.isFalse(childSlice1.isTopLevel);
    assert.isFalse(childSlice2.isTopLevel);
    // Parent should take its own source_type.
    assert.equal(slice.title, 'UDP_SOCKET');
    assert.equal(childSlice1.title, 'b');
    assert.equal(childSlice2.title, 'c');
  });

  test('ByteCountBasic', function() {
    var slice = new NetAsyncSlice('', 'URL_REQUEST_JOB_BYTES_READ', 0, 1,
                                  {params: {byte_count: 12}}, 0, true);
    assert.equal(slice.byteCount, 12);
  });

  test('NoByteCount', function() {
    var slice = new NetAsyncSlice('', 'a', 0, 1, {}, 0, true);
    assert.equal(slice.byteCount, 0);
  });

  test('ByteCountNested', function() {
    var slice = new NetAsyncSlice('', 'URL_REQUEST_JOB_FILTERED_BYTES_READ',
                                  0, 1, {params: {byte_count: 12}}, 0, true);
    var childSlice = new NetAsyncSlice('', 'URL_REQUEST_JOB_BYTES_READ', 0, 1,
                                       {params: {byte_count: 50}});
    slice.subSlices = [childSlice];
    assert.equal(slice.byteCount, 62);
    assert.equal(childSlice.byteCount, 50);
  });

  test('ByteCountTwoChildren', function() {
    var slice = new NetAsyncSlice('', 'URL_REQUEST_JOB_FILTERED_BYTES_READ',
                                  0, 1, {params: {byte_count: 12}}, 0, true);
    var childSlice1 = new NetAsyncSlice('', 'URL_REQUEST_JOB_BYTES_READ', 0, 1,
                                        {params: {byte_count: 50}});
    var childSlice2 = new NetAsyncSlice('', 'URL_REQUEST_JOB_BYTES_READ', 0, 1,
                                        {params: {byte_count: 20}});
    slice.subSlices = [childSlice1, childSlice2];
    assert.equal(slice.byteCount, 82);
    assert.equal(childSlice1.byteCount, 50);
    assert.equal(childSlice2.byteCount, 20);
  });
});
</script>