blob: 953b535db49ca06801df6288da3a81722fbeab46 [file] [log] [blame]
<!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.subTypes.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.subTypes.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>