Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / tracing / timeline_view_test.js
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.
4
5 'use strict';
6
7 tvcm.require('tracing.test_utils');
8 tvcm.require('tracing.timeline_view');
9 tvcm.require('tracing.trace_model');
10
11 tvcm.unittest.testSuite('tracing.timeline_view_test', function() {
12   var newSliceNamed = tracing.test_utils.newSliceNamed;
13
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;
18
19     var num_tests = 50;
20     var testIndex = 0;
21     var startTime = 0;
22
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));
32       } else {
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));
38       }
39     }
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,
44                         'snapshot-1');
45     objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 25,
46                         'snapshot-2');
47     objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 40,
48                         'snapshot-3');
49     objects.idWasDeleted('0x1000', 'cc', 'LayerTreeHostImpl', 45);
50     model.updateCategories_();
51
52     // Add a known problematic piece of data to test the import errors UI.
53     model.importWarning({
54       type: 'test_error',
55       message: 'Synthetic Import Error'
56     });
57     model.updateBounds();
58
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'});
63
64     return model;
65   };
66
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;
72     }, 0);
73   };
74
75   var modelsEquivalent = function(lhs, rhs) {
76     if (lhs.length !== rhs.length)
77       return false;
78     return lhs.every(function(lhsItem, index) {
79       var rhsItem = rhs[index];
80       return rhsItem.regexpText === lhsItem.regexpText &&
81           rhsItem.isOn === lhsItem.isOn;
82     });
83   };
84
85   var buildView = function() {
86     var view = new tracing.TimelineView();
87     view.model = createFullyPopulatedModel();
88
89     var selection = new tracing.Selection();
90     view.timeline.addAllObjectsMatchingFilterToSelection({
91       matchSlice: function() { return true; }
92     }, selection);
93     view.timeline.selection = selection;
94
95     return view;
96   };
97
98   test('changeModelToSomethingDifferent', function() {
99     var model00 = createFullyPopulatedModel(false, false);
100     var model11 = createFullyPopulatedModel(true, true);
101
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;
108   });
109
110   test('setModelToSameThingAgain', function() {
111     var model = createFullyPopulatedModel(false, false);
112
113     // Create a view with am model.
114     var view = new tracing.TimelineView();
115     view.style.height = '400px';
116     view.model = model;
117
118     // Mutate the model and update the view.
119     var t123 = model.getOrCreateProcess(123).getOrCreateThread(123);
120     t123.sliceGroup.pushSlice(newSliceNamed('somethingUnusual', 0, 5));
121     view.model = model;
122
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);
128   });
129
130 });