Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / timeline_view_test.html
1 <!DOCTYPE html>
2 <!--
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.
6 -->
7
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">
11
12 <script>
13 'use strict';
14
15 tvcm.unittest.testSuite(function() {
16   var newSliceNamed = tracing.test_utils.newSliceNamed;
17
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;
22
23     var num_tests = 50;
24     var testIndex = 0;
25     var startTime = 0;
26
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));
36       } else {
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));
42       }
43     }
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,
48                         'snapshot-1');
49     objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 25,
50                         'snapshot-2');
51     objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 40,
52                         'snapshot-3');
53     objects.idWasDeleted('0x1000', 'cc', 'LayerTreeHostImpl', 45);
54     model.updateCategories_();
55
56     // Add a known problematic piece of data to test the import errors UI.
57     model.importWarning({
58       type: 'test_error',
59       message: 'Synthetic Import Error'
60     });
61     model.updateBounds();
62
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'});
67
68     return model;
69   };
70
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;
76     }, 0);
77   };
78
79   var modelsEquivalent = function(lhs, rhs) {
80     if (lhs.length !== rhs.length)
81       return false;
82     return lhs.every(function(lhsItem, index) {
83       var rhsItem = rhs[index];
84       return rhsItem.regexpText === lhsItem.regexpText &&
85           rhsItem.isOn === lhsItem.isOn;
86     });
87   };
88
89   var buildView = function() {
90     var view = new tracing.TimelineView();
91     view.model = createFullyPopulatedModel();
92
93     var selection = new tracing.Selection();
94     view.timeline.addAllObjectsMatchingFilterToSelection({
95       matchSlice: function() { return true; }
96     }, selection);
97     view.timeline.selection = selection;
98
99     return view;
100   };
101
102   test('changeModelToSomethingDifferent', function() {
103     var model00 = createFullyPopulatedModel(false, false);
104     var model11 = createFullyPopulatedModel(true, true);
105
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;
112   });
113
114   test('setModelToSameThingAgain', function() {
115     var model = createFullyPopulatedModel(false, false);
116
117     // Create a view with am model.
118     var view = new tracing.TimelineView();
119     view.style.height = '400px';
120     view.model = model;
121
122     // Mutate the model and update the view.
123     var t123 = model.getOrCreateProcess(123).getOrCreateThread(123);
124     t123.sliceGroup.pushSlice(newSliceNamed('somethingUnusual', 0, 5));
125     view.model = model;
126
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);
132   });
133 });
134 </script>
135