3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="import" href="/tracing/test_utils.html">
9 <link rel="import" href="/tracing/timeline_view.html">
10 <link rel="import" href="/tracing/trace_model.html">
15 tvcm.unittest.testSuite(function() {
16 var newSliceNamed = tracing.test_utils.newSliceNamed;
18 var createFullyPopulatedModel = function(opt_withError, opt_withMetadata) {
19 var withError = opt_withError !== undefined ? opt_withError : true;
20 var withMetadata = opt_withMetadata !== undefined ?
21 opt_withMetadata : true;
27 var model = new tracing.TraceModel();
28 for (testIndex = 0; testIndex < num_tests; ++testIndex) {
29 var process = model.getOrCreateProcess(10000 + testIndex);
30 if (testIndex % 2 == 0) {
31 var thread = process.getOrCreateThread('Thread Name Here');
32 thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
33 'foo', 'a', 0, startTime, {}, 1));
34 thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
35 'bar', 'b', 0, startTime + 23, {}, 10));
37 var thread = process.getOrCreateThread('Name');
38 thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
39 'foo', 'a', 0, startTime + 4, {}, 11));
40 thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
41 'bar', 'b', 0, startTime + 22, {}, 14));
44 var p1000 = model.getOrCreateProcess(1000);
45 var objects = p1000.objects;
46 objects.idWasCreated('0x1000', 'cc', 'LayerTreeHostImpl', 10);
47 objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 10,
49 objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 25,
51 objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 40,
53 objects.idWasDeleted('0x1000', 'cc', 'LayerTreeHostImpl', 45);
54 model.updateCategories_();
56 // Add a known problematic piece of data to test the import errors UI.
59 message: 'Synthetic Import Error'
63 // Add data with metadata information stored
64 model.metadata.push({name: 'a', value: 'testA'});
65 model.metadata.push({name: 'b', value: 'testB'});
66 model.metadata.push({name: 'c', value: 'testC'});
71 var visibleTracks = function(trackButtons) {
72 return trackButtons.reduce(function(numVisible, button) {
73 var style = button.parentElement.style;
74 var visible = (style.display.indexOf('none') === -1);
75 return visible ? numVisible + 1 : numVisible;
79 var modelsEquivalent = function(lhs, rhs) {
80 if (lhs.length !== rhs.length)
82 return lhs.every(function(lhsItem, index) {
83 var rhsItem = rhs[index];
84 return rhsItem.regexpText === lhsItem.regexpText &&
85 rhsItem.isOn === lhsItem.isOn;
89 var buildView = function() {
90 var view = new tracing.TimelineView();
91 view.model = createFullyPopulatedModel();
93 var selection = new tracing.Selection();
94 view.timeline.addAllObjectsMatchingFilterToSelection({
95 matchSlice: function() { return true; }
97 view.timeline.selection = selection;
102 test('changeModelToSomethingDifferent', function() {
103 var model00 = createFullyPopulatedModel(false, false);
104 var model11 = createFullyPopulatedModel(true, true);
106 var view = new tracing.TimelineView();
107 view.style.height = '400px';
108 view.model = model00;
109 view.model = undefined;
110 view.model = model11;
111 view.model = model00;
114 test('setModelToSameThingAgain', function() {
115 var model = createFullyPopulatedModel(false, false);
117 // Create a view with am model.
118 var view = new tracing.TimelineView();
119 view.style.height = '400px';
122 // Mutate the model and update the view.
123 var t123 = model.getOrCreateProcess(123).getOrCreateThread(123);
124 t123.sliceGroup.pushSlice(newSliceNamed('somethingUnusual', 0, 5));
127 // Verify that the new bits of the model show up in the view.
128 var selection = new tracing.Selection();
129 var filter = new tracing.TitleFilter('somethingUnusual');
130 view.timeline.addAllObjectsMatchingFilterToSelection(filter, selection);
131 assertEquals(selection.length, 1);