1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 tvcm.require('tracing.test_utils');
8 tvcm.require('tracing.timeline_view');
9 tvcm.require('tracing.trace_model');
11 tvcm.unittest.testSuite('tracing.timeline_view_test', function() {
12 var newSliceNamed = tracing.test_utils.newSliceNamed;
14 var createFullyPopulatedModel = function(opt_withError, opt_withMetadata) {
15 var withError = opt_withError !== undefined ? opt_withError : true;
16 var withMetadata = opt_withMetadata !== undefined ?
17 opt_withMetadata : true;
23 var model = new tracing.TraceModel();
24 for (testIndex = 0; testIndex < num_tests; ++testIndex) {
25 var process = model.getOrCreateProcess(10000 + testIndex);
26 if (testIndex % 2 == 0) {
27 var thread = process.getOrCreateThread('Thread Name Here');
28 thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
29 'foo', 'a', 0, startTime, {}, 1));
30 thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
31 'bar', 'b', 0, startTime + 23, {}, 10));
33 var thread = process.getOrCreateThread('Name');
34 thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
35 'foo', 'a', 0, startTime + 4, {}, 11));
36 thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
37 'bar', 'b', 0, startTime + 22, {}, 14));
40 var p1000 = model.getOrCreateProcess(1000);
41 var objects = p1000.objects;
42 objects.idWasCreated('0x1000', 'cc', 'LayerTreeHostImpl', 10);
43 objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 10,
45 objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 25,
47 objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 40,
49 objects.idWasDeleted('0x1000', 'cc', 'LayerTreeHostImpl', 45);
50 model.updateCategories_();
52 // Add a known problematic piece of data to test the import errors UI.
55 message: 'Synthetic Import Error'
59 // Add data with metadata information stored
60 model.metadata.push({name: 'a', value: 'testA'});
61 model.metadata.push({name: 'b', value: 'testB'});
62 model.metadata.push({name: 'c', value: 'testC'});
67 var visibleTracks = function(trackButtons) {
68 return trackButtons.reduce(function(numVisible, button) {
69 var style = button.parentElement.style;
70 var visible = (style.display.indexOf('none') === -1);
71 return visible ? numVisible + 1 : numVisible;
75 var modelsEquivalent = function(lhs, rhs) {
76 if (lhs.length !== rhs.length)
78 return lhs.every(function(lhsItem, index) {
79 var rhsItem = rhs[index];
80 return rhsItem.regexpText === lhsItem.regexpText &&
81 rhsItem.isOn === lhsItem.isOn;
85 var buildView = function() {
86 var view = new tracing.TimelineView();
87 view.model = createFullyPopulatedModel();
89 var selection = new tracing.Selection();
90 view.timeline.addAllObjectsMatchingFilterToSelection({
91 matchSlice: function() { return true; }
93 view.timeline.selection = selection;
98 test('changeModelToSomethingDifferent', function() {
99 var model00 = createFullyPopulatedModel(false, false);
100 var model11 = createFullyPopulatedModel(true, true);
102 var view = new tracing.TimelineView();
103 view.style.height = '400px';
104 view.model = model00;
105 view.model = undefined;
106 view.model = model11;
107 view.model = model00;
110 test('setModelToSameThingAgain', function() {
111 var model = createFullyPopulatedModel(false, false);
113 // Create a view with am model.
114 var view = new tracing.TimelineView();
115 view.style.height = '400px';
118 // Mutate the model and update the view.
119 var t123 = model.getOrCreateProcess(123).getOrCreateThread(123);
120 t123.sliceGroup.pushSlice(newSliceNamed('somethingUnusual', 0, 5));
123 // Verify that the new bits of the model show up in the view.
124 var selection = new tracing.Selection();
125 var filter = new tracing.TitleFilter('somethingUnusual');
126 view.timeline.addAllObjectsMatchingFilterToSelection(filter, selection);
127 assertEquals(selection.length, 1);