summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/model/object_collection_test.html
blob: 7137f89b201df91b49a3dfbd96cb5a2008ac69d2 (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!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/model/object_collection.html">
<link rel="import" href="/tracing/model/scoped_id.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  var TestObjectInstance = function(
      parent, scopedId, category, name, creationTs) {
    tr.model.ObjectInstance.call(
        this, parent, scopedId, category, name, creationTs);
  };

  TestObjectInstance.prototype = {
    __proto__: tr.model.ObjectInstance.prototype
  };

  test('objectInstanceSubtype', function() {
    // Register that TestObjects are bound to TestObjectInstance.
    tr.model.ObjectInstance.register(
        TestObjectInstance,
        {typeName: 'TestObject'});

    try {
      var collection = new tr.model.ObjectCollection({ });
      var scopedId = new tr.model.ScopedId('ptr', '0x1000');
      collection.idWasCreated(
          scopedId, 'tr.e.cc', 'Frame', 10);
      collection.idWasDeleted(
          scopedId, 'tr.e.cc', 'Frame', 15);
      collection.idWasCreated(
          scopedId, 'skia', 'TestObject', 20);
      collection.idWasDeleted(
          scopedId, 'skia', 'TestObject', 25);

      var testFrame = collection.getObjectInstanceAt(scopedId, 10);
      assert.instanceOf(testFrame, tr.model.ObjectInstance);
      assert.notInstanceOf(testFrame, TestObjectInstance);

      var testObject = collection.getObjectInstanceAt(scopedId, 20);
      assert.instanceOf(testObject, tr.model.ObjectInstance);
      assert.instanceOf(testObject, TestObjectInstance);
    } finally {
      tr.model.ObjectInstance.unregister(TestObjectInstance);
    }
  });

  test('twoSnapshots', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId = new tr.model.ScopedId('ptr', '0x1000');
    collection.idWasCreated(
        scopedId, 'cat', 'Frame', 10);
    collection.addSnapshot(
        scopedId, 'cat', 'Frame', 10, {foo: 1});
    collection.addSnapshot(
        scopedId, 'cat', 'Frame', 20, {foo: 2});

    collection.updateBounds();
    assert.equal(collection.bounds.min, 10);
    assert.equal(collection.bounds.max, 20);

    var s0 = collection.getSnapshotAt(scopedId, 1);
    assert.isUndefined(s0);

    var s1 = collection.getSnapshotAt(scopedId, 10);
    assert.equal(s1.args.foo, 1);

    var s2 = collection.getSnapshotAt(scopedId, 15);
    assert.equal(s2.args.foo, 1);
    assert.equal(s1, s2);

    var s3 = collection.getSnapshotAt(scopedId, 20);
    assert.equal(s3.args.foo, 2);
    assert.equal(s1.object, s3.object);

    var s4 = collection.getSnapshotAt(scopedId, 25);
    assert.equal(s4, s3);
  });

  test('twoObjectsSharingOneID', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId = new tr.model.ScopedId('ptr', '0x1000');
    collection.idWasCreated(
        scopedId, 'tr.e.cc', 'Frame', 10);
    collection.idWasDeleted(
        scopedId, 'tr.e.cc', 'Frame', 15);
    collection.idWasCreated(
        scopedId, 'skia', 'Picture', 20);
    collection.idWasDeleted(
        scopedId, 'skia', 'Picture', 25);

    var frame = collection.getObjectInstanceAt(scopedId, 10);
    assert.equal(frame.category, 'tr.e.cc');
    assert.equal(frame.name, 'Frame');

    var picture = collection.getObjectInstanceAt(scopedId, 20);
    assert.equal(picture.category, 'skia');
    assert.equal(picture.name, 'Picture');

    var typeNames = tr.b.dictionaryKeys(collection.getAllInstancesByTypeName());
    typeNames.sort();
    assert.deepEqual(
        ['Frame', 'Picture'],
        typeNames);
    assert.deepEqual(
        [frame],
        collection.getAllInstancesByTypeName()['Frame']);
    assert.deepEqual(
        [picture],
        collection.getAllInstancesByTypeName()['Picture']);
  });

  test('createSnapDelete', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId = new tr.model.ScopedId('ptr', '0x1000');
    collection.idWasCreated(
        scopedId, 'cat', 'Frame', 10);
    collection.addSnapshot(
        scopedId, 'cat', 'Frame', 10, {foo: 1});
    collection.idWasDeleted(
        scopedId, 'cat', 'Frame', 15);

    collection.updateBounds();
    assert.equal(collection.bounds.min, 10);
    assert.equal(collection.bounds.max, 15);

    var s10 = collection.getSnapshotAt(scopedId, 10);
    var i10 = s10.objectInstance;
    assert.equal(i10.creationTs, 10);
    assert.equal(i10.deletionTs, 15);
  });

  test('boundsOnUndeletedObject', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId = new tr.model.ScopedId('ptr', '0x1000');
    collection.idWasCreated(
        scopedId, 'cat', 'Frame', 10);
    collection.addSnapshot(
        scopedId, 'cat', 'Frame', 15, {foo: 1});

    collection.updateBounds();
    assert.equal(10, collection.bounds.min);
    assert.equal(15, collection.bounds.max);
  });

  test('snapshotWithCustomBaseTypeThenDelete', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId = new tr.model.ScopedId('ptr', '0x1000');
    var s10 = collection.addSnapshot(
        scopedId, 'cat', 'cc::PictureLayerImpl', 10, {}, 'cc::LayerImpl');
    collection.idWasDeleted(
        scopedId, 'cat', 'cc::LayerImpl', 15);
    collection.updateBounds();
    assert.equal(10, collection.bounds.min);
    assert.equal(15, collection.bounds.max);
    assert.equal(s10.objectInstance.name, 'cc::PictureLayerImpl');
    assert.equal(s10.objectInstance.baseTypeName, 'cc::LayerImpl');
  });

  test('newWithSnapshotThatChangesBaseType', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId = new tr.model.ScopedId('ptr', '0x1000');
    var i10 = collection.idWasCreated(
        scopedId, 'cat', 'cc::LayerImpl', 10);
    var s15 = collection.addSnapshot(
        scopedId, 'cat', 'cc::PictureLayerImpl', 15, {}, 'cc::LayerImpl');
    collection.updateBounds();
    assert.equal(10, collection.bounds.min);
    assert.equal(15, collection.bounds.max);
    assert.equal(s15.objectInstance, i10);
    assert.equal(i10.name, 'cc::PictureLayerImpl');
    assert.equal(i10.baseTypeName, 'cc::LayerImpl');
  });

  test('deleteThenSnapshotWithCustomBase', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId = new tr.model.ScopedId('ptr', '0x1000');
    collection.idWasDeleted(
        scopedId, 'cat', 'cc::LayerImpl', 10);
    var s15 = collection.addSnapshot(
        scopedId, 'cat', 'cc::PictureLayerImpl', 15, {}, 'cc::LayerImpl');
    collection.updateBounds();
    assert.equal(10, collection.bounds.min);
    assert.equal(15, collection.bounds.max);
    assert.equal(s15.objectInstance.name, 'cc::PictureLayerImpl');
  });

  test('autoDelete', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId = new tr.model.ScopedId('ptr', '0x1000');
    collection.idWasCreated(
        scopedId, 'cat', 'Frame', 10);
    collection.addSnapshot(
        scopedId, 'cat', 'Frame', 10, {foo: 1});
    collection.autoDeleteObjects(15);

    var s10 = collection.getSnapshotAt(scopedId, 10);
    var i10 = s10.objectInstance;
    assert.equal(15, i10.deletionTs);
  });

  test('differentScopes', function() {
    var collection = new tr.model.ObjectCollection({});
    var scopedId1 = new tr.model.ScopedId('ptr', '0x1000');
    var scopedId2 = new tr.model.ScopedId('cc', '0x1000');
    collection.idWasCreated(
        scopedId1, 'cat', 'ptr::object', 10);
    collection.idWasDeleted(
        scopedId1, 'cat', 'ptr::object', 15);
    collection.idWasCreated(
        scopedId2, 'cat', 'cc::object', 10);
    collection.idWasDeleted(
        scopedId2, 'cat', 'cc::object', 15);

    var instance = collection.getObjectInstanceAt(scopedId1, 10);
    assert.equal(instance.name, 'ptr::object');

    var instance = collection.getObjectInstanceAt(scopedId2, 10);
    assert.equal(instance.name, 'cc::object');
  });
});
</script>